/** * PUBLIC: Merges the source topic name into the target topic in * another topic map. Makes no attempt to verify that the source * topic represents the same subject as the target topic. * @return The new topic name in the target topic map. * @since 5.1.3 */ public static TopicNameIF mergeInto(TopicIF target, TopicNameIF source) { TopicMapIF tm = target.getTopicMap(); TopicMapBuilderIF builder = tm.getBuilder(); TopicIF type = findTopic(tm, source.getType()); TopicNameIF newtn = builder.makeTopicName(target, type, source.getValue()); for (TopicIF theme : source.getScope()) newtn.addTheme(findTopic(tm, theme)); return newtn; }
@Override public TopicIF getTopic() { TopicNameIF name = getTopicName(); if (name == null) return null; return name.getTopic(); }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { TopicNameIF removed = (TopicNameIF)old_value; // Fire tree event treeRemoveEvent(object, TopicNameIF.EVENT_REMOVED, removed); // Remove variants Object[] variants = removed.getVariants().toArray(); for (int i=0; i < variants.length; i++) otree.processEvent(removed, TopicNameIF.EVENT_REMOVE_VARIANT, null, variants[i]); } }
@Override public int compare(TopicNameIF bn1, TopicNameIF bn2) { if (Objects.equals(bn1, bn2)) return 0; int retVal = scopeComparator.compare(filterCollection(bn1.getScope()), filterCollection(bn2.getScope())); if (retVal == 0) retVal = lazyStringCompare(bn1.getValue(), bn2.getValue()); return retVal; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, String value) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (Objects.equals(nameIF.getValue(), value) && Objects.equals(nameIF.getType(), nType)) result.add(nameIF); } return result; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, String value, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (Objects.equals(nameIF.getValue(), value) && Objects.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
@Override public void run(MasterTest mt) { TopicNameIF bn = (TopicNameIF)topicmap.getObjectById(mt.objectId); assertTrue("Added base name not found", bn != null); if (testInitialProperties) { assertTrue("Source locators is set", bn.getItemIdentifiers().isEmpty()); assertTrue("Scope is set", bn.getScope().isEmpty()); assertTrue("Type is set", bn.getType() == null); assertTrue("Value is set", "".equals(bn.getValue())); assertTrue("Variants is set", bn.getVariants().isEmpty()); } } });
topic = basename.getTopic(); basename.remove(); log.debug("No string value, so removed topic name."); } else basename.setType(type); while (it.hasNext()) { TopicIF theme = (TopicIF) it.next(); basename.addTheme(theme); log.debug("Added theme " + theme); basename.setValue(value); log.debug("Set value of existing topic name");
private void verifySingleTopicName(TopicIF topic, String name) { Assert.assertTrue("topic has spurious children", topic.getTypes().size() == 0 && topic.getRoles().size() == 0 && topic.getOccurrences().size() == 0); Assert.assertTrue("topic has wrong number of base names", topic.getTopicNames() .size() == 1); TopicNameIF basename = (TopicNameIF) topic.getTopicNames().iterator() .next(); Assert.assertTrue("wrong basename value: '" + basename.getValue() + "'", basename .getValue().equals(name)); Assert.assertTrue("basename has spurious children", basename.getVariants().size() == 0); Assert.assertTrue("basename has spurious themes", basename.getScope().size() == 0); }
protected static void normalizeTopicNames(TopicMapIF tm) { Iterator it = tm.getTopics().iterator(); while (it.hasNext()) { TopicIF topic = (TopicIF) it.next(); Iterator it2 = topic.getTopicNames().iterator(); while (it2.hasNext()) { TopicNameIF bn = (TopicNameIF) it2.next(); bn.setValue(StringUtils.normalizeSpace(bn.getValue())); } } }
@Override public TopicNameIF makeTopicName(TopicIF topic, String value) { if (topic == null) throw new NullPointerException(MSG_TOPIC_NOT_NULL); if (value == null) throw new NullPointerException(MSG_TOPIC_NAME_VALUE_NOT_NULL); CrossTopicMapException.check(topic, this.tm); TopicNameIF name = new TopicName(tm); ((Topic)topic).addTopicName(name); name.setValue(value); name.setType(getDefaultNameType()); return name; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (Objects.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
@Test public void testTopicName() throws Exception { TopicNameIF name = tm1.getBuilder().makeTopicName(foo1, foo1, "foo"); name.setReifier(foo1); // todo: scope, pending #265 concurrentCommit(); // verify no inconsistenties were created check(tm1, name.getType(), "Topic name", "type"); check(tm1, name.getTopic(), "Topic name", "topic"); check(tm1, name.getReifier(), "Topic name", "reifier"); }
public void remove(TopicNameIF name) { name.remove(); }
/** * PUBLIC: Merges the source name into the target name. The two * names must be in the same topic map, but need not have the same * parent topic. It is assumed (but not verified) that the two * names are actually equal. * @since 5.1.0 */ public static void mergeInto(TopicNameIF target, TopicNameIF source) { Iterator<VariantNameIF> it = new ArrayList<VariantNameIF>(source.getVariants()).iterator(); while (it.hasNext()) { VariantNameIF sourcevn = it.next(); VariantNameIF targetvn = CopyUtils.copyVariant(target, sourcevn); moveReifier(targetvn, sourcevn); sourcevn.remove(); } moveReifier(target, source); moveItemIdentifiers(target, source); source.remove(); }
public static void setName(TopicIF nType, TopicIF topic, String value, Collection<TopicIF> scope) { if (value != null && topic != null) { // update existing new name or create a new one Collection<TopicNameIF> names = OntopolyModelUtils.findTopicNames(null, topic, scope); Iterator<TopicNameIF> iter = names.iterator(); if (iter.hasNext()) { TopicNameIF bn = iter.next(); bn.setValue(value); } else { topic.getTopicMap().getBuilder().makeTopicName(topic, value); } // remove superfluous names while (iter.hasNext()) ((TopicNameIF) iter.next()).remove(); } }
/** * Accepts or rejects a TopicNameIF * @param baseName to be accepted/rejected. * @return true iff baseName is accepted by the filter and its scope is also * accepted by the filter. */ public boolean ok(TopicNameIF baseName) { return filter.ok(baseName) && filter.ok(baseName.getScope()); }
public void testParam2() throws InvalidQueryException, IOException { load("subclasses.ltm"); TopicIF subclass = getTopicById("subclass"); TopicNameIF name = subclass.getTopicNames().iterator().next(); Map params = new HashMap(); params.put("v", "SUBCLASS"); update("update value(@" + name.getObjectId() + ", %v%)", params); assertTrue("name value not changed", name.getValue().equals("SUBCLASS")); }