public void remove(TopicNameIF name) { name.remove(); }
/** * Set the basename of a given topic, removing any old basenames. * @param topic The topic. * @param baseName The new basename. */ public static void setUniqueTopicName(TopicIF topic, String baseName) { TopicMapBuilderIF builder = topic.getTopicMap().getBuilder(); Collection oldTopicNames = new HashSet(topic.getTopicNames()); Iterator oldTopicNamesIt = oldTopicNames.iterator(); while (oldTopicNamesIt.hasNext()) { TopicNameIF currentTopicName = (TopicNameIF)oldTopicNamesIt.next(); currentTopicName.remove(); } builder.makeTopicName(topic, baseName); }
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(); } }
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(); } }
/** * 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(); }
while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove();
while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove();
while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove();
@Override public void run() { TopicIF t = getTopic(); TopicNameIF bn = (TopicNameIF)this.data.remove("TopicNameIF"); this.objectId = bn.getObjectId(); bn.remove(); } });
@Override public void onBeforeRemove(Topic topic, FieldDefinition fieldDefinition, Object value) { // System.out.println("oBR: " + fieldInstance + " " + value); // remove name scoped by role type from association type if (fieldDefinition.getFieldType() == FieldDefinition.FIELD_TYPE_NAME) { if (topic.isInstanceOf(PSI.ON_ROLE_FIELD)) { RoleField rfield = new RoleField(topic.getTopicIF(), topic.getTopicMap()); TopicIF atype = rfield.getAssociationField().getAssociationType().getTopicIF(); TopicIF rtype = rfield.getRoleType().getTopicIF(); if (atype != null && rtype != null) { Collection<TopicIF> scope = Collections.singleton(rtype); List<TopicNameIF> names = OntopolyModelUtils.findTopicNames(null, atype, (String)value, scope); if (!names.isEmpty()) { Iterator<TopicNameIF> iter = names.iterator(); while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove(); } } } } } }
public void onBeforeRemove(Topic topic, FieldDefinition fieldDefinition, Object value) { // System.out.println("oBR: " + fieldInstance + " " + value); // remove name scoped by role type from association type if (fieldDefinition.getFieldType() == FieldDefinition.FIELD_TYPE_NAME) { if (topic.isInstanceOf(PSI.ON_ROLE_FIELD)) { RoleField rfield = new RoleField(topic.getTopicIF(), topic.getTopicMap()); TopicIF atype = rfield.getAssociationField().getAssociationType().getTopicIF(); TopicIF rtype = rfield.getRoleType().getTopicIF(); if (atype != null && rtype != null) { Collection<TopicIF> scope = Collections.singleton(rtype); List<TopicNameIF> names = OntopolyModelUtils.findTopicNames(null, atype, (String)value, scope); if (!names.isEmpty()) { Iterator<TopicNameIF> iter = names.iterator(); while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove(); } } } } } }
public void onAfterAdd(Topic topic, FieldDefinition fieldDefinition, Object value) { // System.out.println("oAA: " + fieldInstance + " " + value); // add name scoped by role type to association type if (fieldDefinition.getFieldType() == FieldDefinition.FIELD_TYPE_NAME) { if (topic.isInstanceOf(PSI.ON_ROLE_FIELD)) { RoleField rfield = new RoleField(topic.getTopicIF(), topic.getTopicMap()); TopicIF atype = rfield.getAssociationField().getAssociationType().getTopicIF(); TopicIF rtype = rfield.getRoleType().getTopicIF(); if (atype != null && rtype != null) { Collection<TopicIF> scope = Collections.singleton(rtype); List<TopicNameIF> names = OntopolyModelUtils.findTopicNames(null, atype, scope); if (!names.isEmpty()) { // remove all except the first one Iterator<TopicNameIF> iter = names.iterator(); iter.next(); while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove(); } } OntopolyModelUtils.makeTopicName(null, atype, (String)value, scope); } } } }
@Override public void onAfterAdd(Topic topic, FieldDefinition fieldDefinition, Object value) { // System.out.println("oAA: " + fieldInstance + " " + value); // add name scoped by role type to association type if (fieldDefinition.getFieldType() == FieldDefinition.FIELD_TYPE_NAME) { if (topic.isInstanceOf(PSI.ON_ROLE_FIELD)) { RoleField rfield = new RoleField(topic.getTopicIF(), topic.getTopicMap()); TopicIF atype = rfield.getAssociationField().getAssociationType().getTopicIF(); TopicIF rtype = rfield.getRoleType().getTopicIF(); if (atype != null && rtype != null) { Collection<TopicIF> scope = Collections.singleton(rtype); List<TopicNameIF> names = OntopolyModelUtils.findTopicNames(null, atype, scope); if (!names.isEmpty()) { // remove all except the first one Iterator<TopicNameIF> iter = names.iterator(); iter.next(); while (iter.hasNext()) { TopicNameIF name = iter.next(); name.remove(); } } OntopolyModelUtils.makeTopicName(null, atype, (String)value, scope); } } } }
protected static void removeTopicName(TopicIF topic, Relation relation, Entity entity, Field field, String[] tuple, Context ctx) { String value = Utils.getValue(relation, entity, field, tuple, ctx); TopicIF type = Utils.getTopic(field.getType(), ctx); if (type == null) { if (field.getType() != null) throw new DB2TMInputException("Name type not found", entity, tuple, field.getType()); // this means the type is the default name type. remove will fail // because null != defaultnametype. type = getDefaultNameType(ctx); } // loop over names and remove first matching Iterator<TopicNameIF> iter = topic.getTopicNames().iterator(); while (iter.hasNext()) { TopicNameIF _bn = iter.next(); // check value if (!Objects.equals(_bn.getValue(), value)) continue; // check type if (!Objects.equals(_bn.getType(), type)) continue; // check scope if (!compareScope(field.getScope(), _bn.getScope(), entity, tuple, ctx)) continue; log.trace(" -N {} {}", topic, _bn); // remove matching name _bn.remove(); // notify context ctx.characteristicsChanged(topic); break; } }
public void testTopicNames() { // STATE 1 assertTrue("basename set not empty initially", topic.getTopicNames().size() == 0); // STATE 2 TopicNameIF basename = builder.makeTopicName(topic, ""); // added by builder assertTrue("basename not added", topic.getTopicNames().size() == 1); assertTrue("basename identity not retained", topic.getTopicNames().iterator().next().equals(basename)); // STATE 2 basename.remove(); assertTrue("basename not removed", topic.getTopicNames().size() == 0); // verify that it's safe basename.remove(); }
public void testBug1438_basenames() { assertTrue("index finds spurious occurrence types", clsix.getTopicNames(null).size() == 0); TopicIF topic = builder.makeTopic(); TopicIF otype = builder.makeTopic(); TopicNameIF bn1 = builder.makeTopicName(topic, otype, "foo"); assertTrue("index finds spurious basename types", clsix.getTopicNames(null).size() == 0); TopicNameIF bn2 = builder.makeTopicName(topic, otype, "foo"); bn2.remove(); assertTrue("index finds spurious basename types", clsix.getTopicNames(null).size() == 0); }
public void testAllVariantNames() { assertEquals(0, clsix.getAllVariantNames().size()); TopicIF topic = builder.makeTopic(); TopicNameIF tn = builder.makeTopicName(topic, "foo"); VariantNameIF vn = builder.makeVariantName(tn, "bar", Collections.singleton(topic)); VariantNameIF vn2 = builder.makeVariantName(tn, "bar2", Collections.singleton(topic)); assertEquals(2, clsix.getAllVariantNames().size()); assertTrue(clsix.getAllVariantNames().contains(vn)); assertTrue(clsix.getAllVariantNames().contains(vn2)); vn2.remove(); assertEquals(1, clsix.getAllVariantNames().size()); assertFalse(clsix.getAllVariantNames().contains(vn2)); tn.remove(); assertEquals(0, clsix.getAllVariantNames().size()); assertFalse(clsix.getAllVariantNames().contains(vn)); }
public void testAllTopicNames() { assertEquals(0, clsix.getAllTopicNames().size()); TopicIF topic = builder.makeTopic(); TopicNameIF tn = builder.makeTopicName(topic, "foo"); TopicNameIF tn2 = builder.makeTopicName(topic, topic, "bar"); assertEquals(2, clsix.getAllTopicNames().size()); assertTrue(clsix.getAllTopicNames().contains(tn)); assertTrue(clsix.getAllTopicNames().contains(tn2)); tn.setType(topic); assertEquals(2, clsix.getAllTopicNames().size()); tn.remove(); assertEquals(1, clsix.getAllTopicNames().size()); assertFalse(clsix.getAllTopicNames().contains(tn)); topic.remove(); assertEquals(0, clsix.getAllTopicNames().size()); assertFalse(clsix.getAllTopicNames().contains(tn2)); }
public void testTopicName() { LocatorIF loc1 = base.resolveAbsolute("#topic-2"); LocatorIF loc2 = base.resolveAbsolute("#double"); TopicIF topic = (TopicIF)tm.getObjectByItemIdentifier(loc1); TopicIF dtheme = (TopicIF)tm.getObjectByItemIdentifier(loc2); assertTrue("TopicIF.getTopicNames() size == 3", topic.getTopicNames().size() == 3); // Get appropriate base name by scope filtering Iterator deciter = new DeciderIterator(new IntersectionOfContextDecider(Collections.singleton(dtheme)), topic.getTopicNames().iterator()); TopicNameIF topic_name = (TopicNameIF)deciter.next(); //TopicNameIF topic_name = (TopicNameIF)ScopeUtils.getInBroadScope(topic.getTopicNames(), dtheme).iterator().next(); tmobjectTest(topic_name, true, true); assertTrue("getTopic", topic_name.getTopic() == topic); // assertTrue("getTopicNames (size check before add)", topic_name.getTopicNames().size() == 2); // assertTrue("getDisplayNames (size check before add)", topic_name.getDisplayNames().size() == 2); // assertTrue("getSortNames (size check before add)", topic_name.getSortNames().size() == 2); int org_count = topic.getTopicNames().size(); TopicMapBuilderIF builder = tm.getBuilder(); TopicNameIF basename = builder.makeTopicName(topic, ""); assertTrue("getTopicNames (size check after add)"+topic.getTopicNames().size(), topic.getTopicNames().size() == org_count + 1); basename.remove(); assertTrue("getTopicNames (size check after remove)", topic.getTopicNames().size() == org_count); }