public void remove(OccurrenceIF occurrence) { occurrence.remove(); }
/** Clear the start topic if it was set. */ public void clearTopic(TopicIF aTopic) { if (!aTopic.getOccurrences().isEmpty()) { Iterator it = new ArrayList(aTopic.getOccurrences()).iterator(); while (it.hasNext()) { OccurrenceIF occur = (OccurrenceIF) it.next(); occur.remove(); } } }
/** * PUBLIC: Merges the source occurrence into the target * occurrence. The two occurrences must be in the same topic map, but * need not have the same parent topic. It is assumed (but not * verified) that the two occurrences are actually equal. * @since 5.1.0 */ public static void mergeInto(OccurrenceIF target, OccurrenceIF source) { moveReifier(target, source); moveItemIdentifiers(target, source); source.remove(); }
/** * Removes the occurrence of a given type from a given configuration topic. * Returns true iff the occurrence was found and removed. */ protected boolean removeOccurrence(TopicIF topic, TopicIF type) { if (topic == null) return false; OccurrenceIF occurrence = CharacteristicUtils .getByType(topic.getOccurrences(), type); if (occurrence == null) return false; occurrence.remove(); return true; }
public static void setOrder(TopicMap topicmap, TopicIF tt, TopicIF fd, int order, boolean replace) { String value = Ordering.orderToString(order); LocatorIF datatype = DataTypes.TYPE_STRING; TopicIF topicIf = tt; TopicIF typeIf = OntopolyModelUtils.getTopicIF(topicmap, PSI.ON_FIELD_ORDER); TopicIF themeIf = fd; Collection<TopicIF> scope = Collections.singleton(themeIf); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, datatype, scope); if (!occs.isEmpty()) { if (!replace) return; // stop here if we're not replacing Iterator<OccurrenceIF> iter = occs.iterator(); while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } OntopolyModelUtils.makeOccurrence(typeIf, topicIf, value, datatype, scope); }
public static void setOrder(TopicMap topicmap, TopicIF tt, TopicIF fd, int order, boolean replace) { String value = Ordering.orderToString(order); LocatorIF datatype = DataTypes.TYPE_STRING; TopicIF topicIf = tt; TopicIF typeIf = OntopolyModelUtils.getTopicIF(topicmap, PSI.ON_FIELD_ORDER); TopicIF themeIf = fd; Collection<TopicIF> scope = Collections.singleton(themeIf); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, datatype, scope); if (!occs.isEmpty()) { if (!replace) return; // stop here if we're not replacing Iterator<OccurrenceIF> iter = occs.iterator(); while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } OntopolyModelUtils.makeOccurrence(typeIf, topicIf, value, datatype, scope); }
protected void removeOccurence(TopicIF type, TopicIF occtype) { TopicIF target = getConfigTopic(type); OccurrenceIF occ = getOccurrence(target, occtype); if (occ != null) getOccurrence(target, occtype).remove(); }
@Override public void removeValue(Topic topic, Object _value, LifeCycleListener listener) { TopicIF topicIf = topic.getTopicIF(); String value = (_value instanceof OccurrenceIF ? ((OccurrenceIF) _value) .getValue() : (String) _value); // LocatorIF datatype = getDataType().getLocator(); OccurrenceType otype = getOccurrenceType(); if (otype == null) return; TopicIF typeIf = otype.getTopicIF(); if (listener != null) listener.onBeforeRemove(topic, this, value); // HACK: we're ignoring the datatype when looking up existing ones // Collection occs = OntopolyModelUtils.findOccurrences(typeIf, // topicIf, value, datatype, Collections.EMPTY_SET); Collection<TopicIF> scope = Collections.emptySet(); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, value, scope); if (!occs.isEmpty()) { // remove all the matching Iterator<OccurrenceIF> iter = occs.iterator(); while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } }
/** * Set the occurrence of a given type on a given topic, removing any existing * occurrences of the same type on that topic. * @param topic The topic that should have the occurrence. * @param typeId The type, as refered to in the query (e.g. "menu:link") * @param value The value of the occurrence. */ public static void setUniqueOccurrence(TopicIF topic, String typeId, String value) { String query = "select $LINK from " + "occurrence(%topic%, $LINK), type($LINK, " + typeId + ")?"; List occs = getResultValues(topic, query); Iterator occsIt = occs.iterator(); while (occsIt.hasNext()) { OccurrenceIF occ = (OccurrenceIF)occsIt.next(); occ.remove(); } TopicMapIF tm = topic.getTopicMap(); TopicIF type = getTopic(typeId, tm); TopicMapBuilderIF builder = tm.getBuilder(); builder.makeOccurrence(topic, type, value); }
@Override public void removeValue(Topic topic, Object _value, LifeCycleListener listener) { TopicIF topicIf = topic.getTopicIF(); String value = (_value instanceof OccurrenceIF ? ((OccurrenceIF) _value) .getValue() : (String) _value); // LocatorIF datatype = getDataType().getLocator(); OccurrenceType otype = getOccurrenceType(); if (otype == null) return; TopicIF typeIf = otype.getTopicIF(); if (listener != null) listener.onBeforeRemove(topic, this, value); // HACK: we're ignoring the datatype when looking up existing ones // Collection occs = OntopolyModelUtils.findOccurrences(typeIf, // topicIf, value, datatype, Collections.EMPTY_SET); Collection<TopicIF> scope = Collections.emptySet(); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, value, scope); if (!occs.isEmpty()) { // remove all the matching Iterator<OccurrenceIF> iter = occs.iterator(); while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } }
@Override public void addValue(Topic topic, Object _value, LifeCycleListener listener) { TopicIF topicIf = topic.getTopicIF(); String value = (String) _value; LocatorIF datatype = getDataType().getLocator(); OccurrenceType otype = getOccurrenceType(); if (otype == null) return; TopicIF typeIf = otype.getTopicIF(); // HACK: we're ignoring the datatype when looking up existing ones // Collection occs = OntopolyModelUtils.findOccurrences(getTopicIF(), // topicIf, value, datatype, Collections.EMPTY_SET); Collection<TopicIF> scope = Collections.emptySet(); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, value, scope); if (occs.isEmpty()) { // create new OntopolyModelUtils.makeOccurrence(typeIf, topicIf, value, datatype, scope); } else { // remove all except the first one Iterator<OccurrenceIF> iter = occs.iterator(); iter.next(); // skip first while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } if (listener != null) listener.onAfterAdd(topic, this, value); }
@Override public void addValue(Topic topic, Object _value, LifeCycleListener listener) { TopicIF topicIf = topic.getTopicIF(); String value = (String) _value; LocatorIF datatype = getDataType().getLocator(); OccurrenceType otype = getOccurrenceType(); if (otype == null) return; TopicIF typeIf = otype.getTopicIF(); // HACK: we're ignoring the datatype when looking up existing ones // Collection occs = OntopolyModelUtils.findOccurrences(getTopicIF(), // topicIf, value, datatype, Collections.EMPTY_SET); Collection<TopicIF> scope = Collections.emptySet(); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, value, scope); if (occs.isEmpty()) { // create new OntopolyModelUtils.makeOccurrence(typeIf, topicIf, value, datatype, scope); } else { // remove all except the first one Iterator<OccurrenceIF> iter = occs.iterator(); iter.next(); // skip first while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } if (listener != null) listener.onAfterAdd(topic, this, value); }
@Override public void run() { TopicIF t = getTopic(); OccurrenceIF o = (OccurrenceIF)this.data.remove("OccurrenceIF"); this.objectId = o.getObjectId(); o.remove(); } });
protected static void removeOccurrence(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) throw new DB2TMInputException("Occurrence type not found", entity, tuple, field.getType()); //! String datatype = (field.getDatatype() == null ? null : Utils.expandPrefixedValue(field.getDatatype(), ctx)); // loop over occurrences and remove first matching Iterator<OccurrenceIF> iter = topic.getOccurrences().iterator(); while (iter.hasNext()) { OccurrenceIF _occ = iter.next(); // check value or locator if (!Objects.equals(_occ.getValue(), value)) continue; // FIXME: compare datatype? // check type if (!Objects.equals(_occ.getType(), type)) continue; // check scope if (!compareScope(field.getScope(), _occ.getScope(), entity, tuple, ctx)) continue; log.trace(" -O {} {}", topic, _occ); // remove matching occurrence _occ.remove(); // notify context ctx.characteristicsChanged(topic); break; } }
occurrenceIF.remove();
public void testOccurrences() { // STATE 1 assertTrue("occurrence set not empty initially", topic.getOccurrences().size() == 0); // STATE 2 TopicIF otype = builder.makeTopic(); OccurrenceIF occurrence = builder.makeOccurrence(topic, otype, ""); // added by builder assertTrue("occurrence not added", topic.getOccurrences().size() == 1); assertTrue("occurrence identity not retained", topic.getOccurrences().iterator().next().equals(occurrence)); // STATE 2 occurrence.remove(); assertTrue("occurrence not removed", topic.getOccurrences().size() == 0); // verify that it's safe occurrence.remove(); }
public void testAllOccurrences() { assertEquals(0, clsix.getAllOccurrences().size()); TopicIF topic = builder.makeTopic(); OccurrenceIF o = builder.makeOccurrence(topic, topic, "foo"); OccurrenceIF o2 = builder.makeOccurrence(topic, topic, "bar"); assertEquals(2, clsix.getAllOccurrences().size()); assertTrue(clsix.getAllOccurrences().contains(o)); assertTrue(clsix.getAllOccurrences().contains(o2)); o.remove(); assertEquals(1, clsix.getAllOccurrences().size()); assertFalse(clsix.getAllOccurrences().contains(o)); topic.remove(); assertEquals(0, clsix.getAllOccurrences().size()); assertFalse(clsix.getAllOccurrences().contains(o2)); }
version = _v; } else { _oc.remove();
public void testItemIdentifiers() { assertEquals(0, ix.getItemIdentifiers().size()); TopicIF topic1 = builder.makeTopic(); TopicIF topic2 = builder.makeTopic(); topic1.addItemIdentifier(loc1); topic2.addItemIdentifier(loc2); assertEquals(2, ix.getItemIdentifiers().size()); OccurrenceIF o = builder.makeOccurrence(topic1, topic1, "foo"); o.addItemIdentifier(loc3); assertEquals(3, ix.getItemIdentifiers().size()); assertTrue(ix.getItemIdentifiers().contains(loc1)); assertTrue(ix.getItemIdentifiers().contains(loc2)); assertTrue(ix.getItemIdentifiers().contains(loc3)); o.remove(); assertEquals(2, ix.getItemIdentifiers().size()); topic1.remove(); assertEquals(1, ix.getItemIdentifiers().size()); }
assertTrue(ix.getItemIdentifiers().contains(loc3)); o.remove(); assertEquals(2, ix.getItemIdentifiersByPrefix("foo").size()); assertEquals(0, ix.getItemIdentifiersByPrefix("bar").size());