/** * EXPERIMENTAL: */ public static boolean isSupersetOfContext(ScopedIF obj, TopicIF[] context) { // Get object scope Collection<TopicIF> objscope = obj.getScope(); for (int i=0; i < context.length; i++) { if (!objscope.contains(context[i])) return false; } return true; }
public void setScope(ScopedIF scoped, Collection<Topic> scope) { if (scope != null) { Collection<TopicIF> newScope = new HashSet<>(scope.size()); for (Topic t : scope) { TopicIF resolved = topic.resolve(scoped.getTopicMap(), t); newScope.add(resolved); scoped.addTheme(resolved); } for (TopicIF remove : CollectionUtils.subtract(scoped.getScope(), newScope)) { scoped.removeTheme(remove); } } }
private static <S extends ScopedIF> void replaceTopicInScope(Collection<S> objects, TopicIF t1, TopicIF t2) { Iterator<S> it = objects.iterator(); while (it.hasNext()) { S object = it.next(); object.removeTheme(t2); object.addTheme(t1); } }
public void add(ScopedIF scoped, Topic scope) { scoped.addTheme( topic.resolve(scoped.getTopicMap(), scope) ); }
protected void scopedTest(ScopedIF scoped) { LocatorIF loc = base.resolveAbsolute("#theme-1"); TopicIF theme = (TopicIF)tm.getObjectByItemIdentifier(loc); assertTrue("getScope (type check)", scoped.getScope() instanceof java.util.Collection); int scope_count = scoped.getScope().size(); scoped.addTheme(theme); assertTrue("getScope (size check after add)", scoped.getScope().size() == scope_count + 1); scoped.removeTheme(theme); assertTrue("getScope (size check after remove)", scoped.getScope().size() == scope_count); }
private static void copyScope(ScopedIF target, ScopedIF source) { Iterator<TopicIF> it = source.getScope().iterator(); while (it.hasNext()) target.addTheme(copyTopic(target.getTopicMap(), it.next())); }
/** * INTERNAL: Assign the given scopes to the specified scoped topic map * construct. */ private void setScopes(ScopedIF object, Collection<TopicIF> scopes) { if (scopes != null) { for (TopicIF scope : scopes) { object.addTheme(scope); } } }
protected static void updateScope(ScopedIF scoped, String[] scope, Entity entity, String[] tuple, Context ctx) { // clear existing scope Collection _scope = scoped.getScope(); if (!_scope.isEmpty()) { Object[] themes = _scope.toArray(); for (int i=0; i < themes.length; i++) { scoped.removeTheme((TopicIF)themes[i]); } } // add new scoping topics addScope(scoped, scope, entity, tuple, ctx); }
public void remove(ScopedIF scoped, Topic scope) { scoped.removeTheme( topic.resolve(scoped.getTopicMap(), scope) ); } }
@Override public void modify(TMObjectIF object, Object v) { ScopedIF scoped = (ScopedIF) object; TopicIF theme = (TopicIF) v; scoped.removeTheme(theme); } }
public void testScope() { // STATE 1: empty scope assertTrue("scope initially not empty", scoped.getScope().size() == 0); TopicIF theme = builder.makeTopic(); scoped.removeTheme(theme); // just checking that this works, is all // STATE 2: one topic in scope TopicIF topic = builder.makeTopic(); scoped.addTheme(topic); assertTrue("theme not added", scoped.getScope().size() == 1); scoped.addTheme(topic); assertTrue("duplicate not rejected", scoped.getScope().size() == 1); // STATE 3: empty scope again scoped.removeTheme(topic); assertTrue("theme not removed", scoped.getScope().size() == 0); scoped.removeTheme(topic); // removing theme that is not present }
private static void copyScope(ScopedIF target, ScopedIF source, Map<TopicIF, TopicIF> mergemap) { Iterator<TopicIF> it = source.getScope().iterator(); while (it.hasNext()) { TopicIF replacement = it.next(); target.addTheme(resolveTopic(target.getTopicMap(), replacement, mergemap)); } }
protected void propagateThemes(ScopedIF scoped) { if (propagated_themes != null) { for (TopicIF scope : propagated_themes) { scoped.addTheme(scope); } } }
protected static void updateScope(ScopedIF scoped, String[] scope, Entity entity, String[] tuple, Context ctx) { // clear existing scope Collection<TopicIF> _scope = scoped.getScope(); if (!_scope.isEmpty()) { TopicIF[] themes = _scope.toArray(new TopicIF[0]); for (int i=0; i < themes.length; i++) { scoped.removeTheme(themes[i]); } } // add new scoping topics addScope(scoped, scope, entity, tuple, ctx); }
/** * Verify that methods handle null arguments the way they should. */ public void testNullScopedArguments() { try { scoped.addTheme(null); fail("was allowed to add null theme"); } catch (NullPointerException e) { // expected } try { scoped.removeTheme(null); fail("was allowed to remove null theme"); } catch (NullPointerException e) { // expected } }
@Override public void removeTheme(Topic theme) { Check.themeNotNull(this, theme); ((ScopedIF) getWrapped()).removeTheme(topicMap.unwrapTopic(theme)); }
/** * EXPERIMENTAL: */ public static boolean isIntersectionOfContext(ScopedIF obj, TopicIF[] context) { // Get object scope Collection<TopicIF> objscope = obj.getScope(); // Loop over context to see if there is an intersection with the object scope. for (int i=0; i < context.length; i++) { // If object scope contains context theme then there is an intersection. if (objscope.contains(context[i])) return true; } // There is no intersection with the object scope. return false; }
TopicMapIF tm = tmobject.getTopicMap(); Collection objScopes = tmobject.getScope(); Collection newScopes = params.getCollection(1); TopicIF scope = (TopicIF) newScopesIt.next(); if (!objScopes.contains(scope)) tmobject.addTheme(scope); Iterator objScopesIt = new ArrayList(tmobject.getScope()).iterator(); tmobject.removeTheme(scope);