public void remove(AssociationIF association) { association.remove(); }
private static AssociationIF removeDuplicateAssociations(Collection<AssociationIF> associations) { AssociationIF uniqueAssoc = null; Iterator<AssociationIF> it = associations.iterator(); if (it.hasNext()) { uniqueAssoc = it.next(); } while (it.hasNext()) { it.next().remove(); } return uniqueAssoc; }
private static AssociationIF removeDuplicateAssociations(Collection<AssociationIF> associations) { AssociationIF uniqueAssoc = null; Iterator<AssociationIF> it = associations.iterator(); if (it.hasNext()) { uniqueAssoc = it.next(); } while (it.hasNext()) { it.next().remove(); } return uniqueAssoc; }
protected static void removeDuplicates(TopicMapIF tm) { Map keymap = new HashMap(); AssociationIF[] assocs = new AssociationIF[tm.getAssociations().size()]; tm.getAssociations().toArray(assocs); for (int i=0; i < assocs.length; i++) { AssociationIF assoc = assocs[i]; String key = KeyGenerator.makeAssociationKey(assoc); if (keymap.containsKey(key)) { System.out.println("Removing: " + key); // If map contains key remove this association assoc.remove(); } else { keymap.put(key, null); } } }
/** * PUBLIC: Updates the target topic map against the source topic, * synchronizing only the characteristics from the target and source * that are accepted by the filters. * @param target the topic map to update * @param source the topic to get updates from * @param tfilter filter for the target characteristics to update * @param sfilter filter for the source characteristics to include * @since 3.2.0 */ public static void update(TopicMapIF target, TopicIF source, DeciderIF<TMObjectIF> tfilter, DeciderIF<TMObjectIF> sfilter) { AssociationTracker tracker = new AssociationTracker(); update(target, source, tfilter, sfilter, tracker); // delete unsupported associations Iterator<AssociationIF> it = tracker.getUnsupported().iterator(); while (it.hasNext()) { AssociationIF tassoc = it.next(); log.debug(" target associations removed {}", tassoc); tassoc.remove(); } }
protected static void removeAssociations(String atype, String[] rtypes, QueryProcessorIF qp, DeclarationContextIF dc) throws InvalidQueryException { StringBuffer sb = new StringBuffer(); sb.append("select $A from "); sb.append("association($A), type($A, " + atype + ")"); for (int i=0; i < rtypes.length; i++) { sb.append(", association-role($A, $R"+ i + "), type($R" + i + ", " + rtypes[i] + ")"); if (i > 0) sb.append(", $R" + i + " /= $R" + (i-1)); } sb.append(", not(association-role($A, $R" + rtypes.length + ")"); for (int i=0; i < rtypes.length; i++) { sb.append(", $R" + rtypes.length + " /= $R" + i); } sb.append(")"); sb.append("?"); QueryResultIF qr = null; int c = 0; try { qr = qp.execute(sb.toString(), dc); while (qr.next()) { AssociationIF a = (AssociationIF)qr.getValue(0); a.remove(); c++; } } finally { if (qr != null) qr.close(); } }
@Override public void run() { AssociationIF a = (AssociationIF)this.data.remove("AssociationIF"); this.objectId = a.getObjectId(); a.remove(); } });
/** * Removes an instance topic from the other side of an association an instance topic takes part in. * * @param _value an object representing the instance topic that will be removed from the other * side of the association the instance topic (topic) takes part in. */ @Override public void removeValue(Topic topic, Object _value, LifeCycleListener listener) { ValueIF value = (ValueIF) _value; AssociationType atype = getAssociationType(); if (atype == null) return; TopicIF atypeIf = atype.getTopicIF(); TopicIF[] rtypes = getRoleTypes(value); TopicIF[] players = getPlayers(value); if (listener != null) listener.onBeforeRemove(topic, this, value); Collection<TopicIF> scope = Collections.emptySet(); Collection<AssociationIF> assocs = OntopolyModelUtils.findAssociations(atypeIf, rtypes, players, scope); if (!assocs.isEmpty()) { // remove all the matching Iterator<AssociationIF> iter = assocs.iterator(); while (iter.hasNext()) { AssociationIF assoc = iter.next(); assoc.remove(); } } // TODO: consider removing field value order also }
/** * Removes an instance topic from the other side of an association an instance topic takes part in. * * @param _value an object representing the instance topic that will be removed from the other * side of the association the instance topic (topic) takes part in. */ @Override public void removeValue(Topic topic, Object _value, LifeCycleListener listener) { ValueIF value = (ValueIF) _value; AssociationType atype = getAssociationType(); if (atype == null) return; TopicIF atypeIf = atype.getTopicIF(); TopicIF[] rtypes = getRoleTypes(value); TopicIF[] players = getPlayers(value); if (listener != null) listener.onBeforeRemove(topic, this, value); Collection<TopicIF> scope = Collections.emptySet(); Collection<AssociationIF> assocs = OntopolyModelUtils.findAssociations(atypeIf, rtypes, players, scope); if (!assocs.isEmpty()) { // remove all the matching Iterator<AssociationIF> iter = assocs.iterator(); while (iter.hasNext()) { AssociationIF assoc = iter.next(); assoc.remove(); } } // TODO: consider removing field value order also }
AssociationIF assoc = (AssociationIF)iter.next(); log.debug(" !" + assoc); assoc.remove();
/** * Sets the cardinality of the field on this topic type. */ public void setCardinality(Cardinality cardinality) { // NOTE: used by FieldsEditor TopicMap tm = getTopicMap(); TopicIF aType = OntopolyModelUtils.getTopicIF(tm, PSI.ON_HAS_CARDINALITY); TopicIF type2 = OntopolyModelUtils.getTopicIF(tm, PSI.ON_FIELD_DEFINITION); TopicIF type3 = OntopolyModelUtils.getTopicIF(tm, PSI.ON_CARDINALITY); TopicIF player2 = getTopicIF(); TopicIF player3 = cardinality.getTopicIF(); Collection<AssociationIF> associationIFs = OntopolyModelUtils.findBinaryAssociations( tm, aType, player2, type2, type3); Iterator<AssociationIF> it = associationIFs.iterator(); while (it.hasNext()) { it.next().remove(); } OntopolyModelUtils.makeBinaryAssociation(aType, player2, type2, player3, type3); cachedCardinality = cardinality; }
/** * Sets the cardinality of the field on this topic type. */ public void setCardinality(Cardinality cardinality) { // NOTE: used by FieldsEditor TopicMap tm = getTopicMap(); TopicIF aType = OntopolyModelUtils.getTopicIF(tm, PSI.ON_HAS_CARDINALITY); TopicIF type2 = OntopolyModelUtils.getTopicIF(tm, PSI.ON_FIELD_DEFINITION); TopicIF type3 = OntopolyModelUtils.getTopicIF(tm, PSI.ON_CARDINALITY); TopicIF player2 = getTopicIF(); TopicIF player3 = cardinality.getTopicIF(); Collection<AssociationIF> associationIFs = OntopolyModelUtils.findBinaryAssociations( tm, aType, player2, type2, type3); Iterator<AssociationIF> it = associationIFs.iterator(); while (it.hasNext()) { it.next().remove(); } OntopolyModelUtils.makeBinaryAssociation(aType, player2, type2, player3, type3); cachedCardinality = cardinality; }
public void testAssociations() { // STATE 1 assertTrue("association set not empty initially", tm.getAssociations().size() == 0); // STATE 2 AssociationIF association = builder.makeAssociation(builder.makeTopic()); // added by builder assertTrue("association not added", tm.getAssociations().size() == 1); assertTrue("association identity not retained", tm.getAssociations().iterator().next().equals(association)); // STATE 2 association.remove(); assertTrue("association not removed", tm.getAssociations().size() == 0); // verify that it's safe association.remove(); }
public void perform(ActionParametersIF params, ActionResponseIF response) { log.debug("perform() started"); // verify parameters ActionSignature paramsType = ActionSignature.getSignature("a t t t"); paramsType.validateArguments(params, this); // get parameters AssociationIF association = (AssociationIF) params.get(0); log.debug("association: " + association); TopicIF assoctype = (TopicIF) params.get(1); TopicIF playerA = (TopicIF) params.get(2); TopicIF typeA = (TopicIF) params.get(3); TopicMapIF topicmap = playerA.getTopicMap(); // last param given; only use topic if we have a request param value if (params.getStringValue() == null) { association.remove(); } else { TopicMapBuilderIF builder = topicmap.getBuilder(); association = builder.makeAssociation(assoctype); // create role A builder.makeAssociationRole(association, typeA, playerA); } } }
private static void copyAssociation(TopicMapIF targettm, AssociationIF source, Map<TopicIF, TopicIF> mergemap, Set<String> assocs) { TopicMapBuilderIF builder = targettm.getBuilder(); AssociationIF target = builder.makeAssociation(resolveTopic(builder.getTopicMap(), source.getType(), mergemap)); copyScope(target, source, mergemap); Iterator<AssociationRoleIF> it = source.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF sourceRole = it.next(); builder.makeAssociationRole(target, resolveTopic(builder.getTopicMap(), sourceRole.getType(), mergemap), resolveTopic(builder.getTopicMap(), sourceRole.getPlayer(), mergemap)); } if (assocs.contains(KeyGenerator.makeAssociationKey(target))) target.remove(); else { copyReifier(target, source, mergemap); copySourceLocators(target, source); } }
protected static void removeEntity(Relation relation, Entity entity, String[] tuple, Context ctx) { // find candidate topic TopicIF topic = null; if (entity.requiresTopic()) topic = findTopicByIdentities(relation, entity, tuple, ctx); if (entity.getEntityType() == Entity.TYPE_TOPIC) { // remove topic if (topic != null) removeTopic(topic, relation, entity, tuple, ctx); } else if (entity.getEntityType() == Entity.TYPE_ASSOCIATION) { if (topic != null) { // if reifier topic found, then use that topic to find association instance TMObjectIF reified = topic.getReified(); if (reified instanceof AssociationIF) { // remove association AssociationIF assoc = (AssociationIF)reified; log.trace(" -A-reified {} -> {} {}", new Object[] {topic, assoc, assoc.getType()}); assoc.remove(); } // remove reifier topic removeTopic(topic, relation, entity, tuple, ctx); } else { // find association removeAssociation(relation, entity, tuple, ctx); } } }
protected static void removeEntity(Relation relation, Entity entity, String[] tuple, Context ctx) { // find candidate topic TopicIF topic = null; if (entity.requiresTopic()) topic = findTopicByIdentities(relation, entity, tuple, ctx); if (entity.getEntityType() == Entity.TYPE_TOPIC) { // remove topic if (topic != null) removeTopic(topic, relation, entity, tuple, ctx); } else if (entity.getEntityType() == Entity.TYPE_ASSOCIATION) { if (topic != null) { // if reifier topic found, then use that topic to find association instance TMObjectIF reified = topic.getReified(); if (reified instanceof AssociationIF) { // remove association AssociationIF assoc = (AssociationIF)reified; log.trace(" -A-reified " + topic + " -> " + assoc + " " + assoc.getType()); assoc.remove(); } // remove reifier topic removeTopic(topic, relation, entity, tuple, ctx); } else { // find association removeAssociation(relation, entity, tuple, ctx); } } }
public void testAssociationsDynamic() { TopicIF at1 = builder.makeTopic(); TopicIF at2 = builder.makeTopic(); AssociationIF a = builder.makeAssociation(at1); assertTrue("TopicMapIF.addAssociation does not update index", index.getAssociations(at1).size() == 1); a.setType(at2); assertTrue("AssociationIF.setType(at2) does not update index", index.getAssociations(at1).size() == 0); a.setType(at1); assertTrue("AssociationIF.addType does not update index", index.getAssociations(at1).size() == 1); a.remove(); assertTrue("TopicMapIF.removeAssociation does not update index", index.getAssociations(at1).size() == 0); }
public void testAssociationRemove() { TopicIF at = builder.makeTopic(); TopicIF rt1 = builder.makeTopic(); TopicIF rt2 = builder.makeTopic(); TopicIF t1 = builder.makeTopic(); TopicIF t2 = builder.makeTopic(); AssociationIF association = builder.makeAssociation(at); AssociationRoleIF role1 = builder.makeAssociationRole(association, rt1, t1); AssociationRoleIF role2 = builder.makeAssociationRole(association, rt2, t2); association.remove(); assertTrue("removing association from topic map does not remove child roles from their players", t1.getRoles().size() == 0); assertTrue("removing association from topic map does not remove child roles from their players", t2.getRoles().size() == 0); }
public void testAssociationRolesDynamic() { TopicIF at1 = builder.makeTopic(); TopicIF art1 = builder.makeTopic(); TopicIF art2 = builder.makeTopic(); TopicIF player = builder.makeTopic(); AssociationIF a = builder.makeAssociation(at1); AssociationRoleIF r1 = builder.makeAssociationRole(a, art1, player); assertTrue("TopicMapIF.addAssociation does not update role type index", index.getAssociationRoles(art1).size() == 1); r1.setType(art2); assertTrue("AssociationRoleIF.setType(art2) does not update index", index.getAssociationRoles(art1).size() == 0); assertTrue("AssociationRoleIF.setType(art2) does not update index", index.getAssociationRoles(art2).size() == 1); r1.setType(art1); assertTrue("AssociationRoleIF.setType does not update index", index.getAssociationRoles(art1).size() == 1); assertTrue("AssociationRoleIF.setType does not update index", index.getAssociationRoles(art2).size() == 0); a.remove(); assertTrue("TopicMapIF.removeAssociation does not update role type index", index.getAssociationRoles(art1).size() == 0); }