/** * <p>Answer true if this mapping contains the pair * <code>(key, value)</code>.</p> * @param key A key object * @param value A value object * @return True if <code>key</code> has <code>value</code> * as one of its values in this mapping */ public boolean contains( Object key, Object value ) { for (Iterator<To> i = getAll( key ); i.hasNext(); ) { if (i.next().equals( value )) return true; } return false; }
/** * <p>Answer true if this mapping contains the pair * <code>(key, value)</code>.</p> * @param key A key object * @param value A value object * @return True if <code>key</code> has <code>value</code> * as one of its values in this mapping */ public boolean contains( Object key, Object value ) { for (Iterator<To> i = getAll( key ); i.hasNext(); ) { if (i.next().equals( value )) return true; } return false; }
/** * Return the derivation of at triple. * The derivation is a List of DerivationRecords */ @Override public Iterator<Derivation> getDerivation(Triple t) { if (derivations == null) { return new NullIterator<>(); } else { return derivations.getAll(t); } }
/** * Return the derivation of at triple. * The derivation is a List of DerivationRecords */ @Override public Iterator<Derivation> getDerivation(Triple t) { if (derivations == null) { return new NullIterator<>(); } else { return derivations.getAll(t); } }
/** * Return the derivation of at triple. * The derivation is a List of DerivationRecords */ @Override public Iterator<Derivation> getDerivation(Triple t) { if (derivations == null) { return new NullIterator<>(); } else { return derivations.getAll(t); } }
/** * <p> * Answer an iterator over the defined aliases for a resource. * </p> * * @param res A resource (including properties) * @return An iterator over the aliases for <code>res</code>. If there are * no aliases, the empty iterator is returned. */ @Override public Iterator<Resource> listAliasesFor( Resource res ) { return aliasMap().getAll( res ); }
/** * Return the derivation of at triple. * The derivation is a List of DerivationRecords */ @Override public Iterator<Derivation> getDerivation(Triple t) { if (derivations == null) { return new NullIterator<>(); } else { return derivations.getAll(t); } }
/** * <p> * Answer an iterator over the defined aliases for a resource. * </p> * * @param res A resource (including properties) * @return An iterator over the aliases for <code>res</code>. If there are * no aliases, the empty iterator is returned. */ @Override public Iterator<Resource> listAliasesFor( Resource res ) { return aliasMap().getAll( res ); }
/** * <p>Answer a string representation of this map. This can be quite a long string for * large maps.<p> */ @Override public String toString() { StringBuffer buf = new StringBuffer( "OneToManyMap{" ); String sep = ""; for ( From key : keySet() ) { buf.append( sep ); buf.append( key ); buf.append( "={" ); String sep1 = ""; for ( Iterator<To> j = getAll( key ); j.hasNext(); ) { buf.append( sep1 ); buf.append( j.next() ); sep1 = ","; } buf.append( "}" ); sep = ","; } buf.append("}"); return buf.toString(); }
/** * <p>Answer a string representation of this map. This can be quite a long string for * large maps.<p> */ @Override public String toString() { StringBuffer buf = new StringBuffer( "OneToManyMap{" ); String sep = ""; for ( From key : keySet() ) { buf.append( sep ); buf.append( key ); buf.append( "={" ); String sep1 = ""; for ( Iterator<To> j = getAll( key ); j.hasNext(); ) { buf.append( sep1 ); buf.append( j.next() ); sep1 = ","; } buf.append( "}" ); sep = ","; } buf.append("}"); return buf.toString(); }
/** * This fires a triple into the current RETE network. * This format of call is used in the unit testing but needs to be public * because the tester is in another package. */ public void testTripleInsert(Triple t) { Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create( i1 ).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); cf.fire(t, true); } }
/** * <p>Construct a new one-to-many map whose contents are * initialised from the existing map.</p> * * @param map An existing one-to-many map */ public OneToManyMap( OneToManyMap<From, To> map ) { // copy the contents of the existing map // note we can't just use the copying constructor for hashmap // as we don't want to share the arraylists that are the key values for ( From key : map.keySet() ) { for ( Iterator<To> j = map.getAll( key ); j.hasNext(); ) { put( key, j.next() ); } } }
/** * This fires a triple into the current RETE network. * This format of call is used in the unit testing but needs to be public * because the tester is in another package. */ public void testTripleInsert(Triple t) { Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create( i1 ).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); cf.fire(t, true); } }
/** * <p>Construct a new one-to-many map whose contents are * initialised from the existing map.</p> * * @param map An existing one-to-many map */ public OneToManyMap( OneToManyMap<From, To> map ) { // copy the contents of the existing map // note we can't just use the copying constructor for hashmap // as we don't want to share the arraylists that are the key values for ( From key : map.keySet() ) { for ( Iterator<To> j = map.getAll( key ); j.hasNext(); ) { put( key, j.next() ); } } }
/** * <p>Put all entries from one map into this map. Tests for m being a * OneToManyMap, and, if so, copies all of the entries for each key.</p> * @param m The map whose contents are to be copied into this map */ @Override public void putAll( Map<? extends From, ? extends To> m ) { boolean many = (m instanceof OneToManyMap<?,?>); for ( From key : m.keySet() ) { if ( many ) { // Bizare way to write it but this way makes all compilers happy. OneToManyMap<?, ?> Z = (OneToManyMap<?, ?>) m; @SuppressWarnings( "unchecked" ) OneToManyMap<? extends From, ? extends To> X = (OneToManyMap<? extends From, ? extends To>) Z; Iterator<? extends To> j = X.getAll( key ); for (; j.hasNext(); ) { put( key, j.next() ); } } else { put( key, m.get( key ) ); } } }
/** * <p>Put all entries from one map into this map. Tests for m being a * OneToManyMap, and, if so, copies all of the entries for each key.</p> * @param m The map whose contents are to be copied into this map */ @Override public void putAll( Map<? extends From, ? extends To> m ) { boolean many = (m instanceof OneToManyMap<?,?>); for ( From key : m.keySet() ) { if ( many ) { // Bizare way to write it but this way makes all compilers happy. OneToManyMap<?, ?> Z = (OneToManyMap<?, ?>) m; @SuppressWarnings( "unchecked" ) OneToManyMap<? extends From, ? extends To> X = (OneToManyMap<? extends From, ? extends To>) Z; Iterator<? extends To> j = X.getAll( key ); for (; j.hasNext(); ) { put( key, j.next() ); } } else { put( key, m.get( key ) ); } } }
/** * Inject a single triple into the RETE network */ private void inject(Triple t, boolean isAdd) { if (infGraph.shouldTrace()) { logger.debug((isAdd ? "Inserting" : "Deleting") + " triple: " + PrintUtil.print(t)); } Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create(i1).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); // firedRules guard in here? cf.fire(t, isAdd); } }
/** * Inject a single triple into the RETE network */ private void inject(Triple t, boolean isAdd) { if (infGraph.shouldTrace()) { logger.debug((isAdd ? "Inserting" : "Deleting") + " triple: " + PrintUtil.print(t)); } Iterator<RETENode> i1 = clauseIndex.getAll(t.getPredicate()); Iterator<RETENode> i2 = clauseIndex.getAll(Node.ANY); Iterator<RETENode> i = WrappedIterator.create(i1).andThen( i2 ); while (i.hasNext()) { RETEClauseFilter cf = (RETEClauseFilter) i.next(); // firedRules guard in here? cf.fire(t, isAdd); } }
/** * Return a list of rules that match the given goal pattern * @param goal the goal being matched */ public List<Rule> rulesFor(TriplePattern goal) { List<Rule> rules = new ArrayList<>(); if (goal.getPredicate().isVariable()) { checkAll(goalMap.values().iterator(), goal, rules); } else { checkAll(goalMap.getAll(goal.getPredicate()), goal, rules); checkAll(goalMap.getAll(Node.ANY), goal, rules); } return rules; }
/** * Return a list of rules that match the given goal pattern * @param goal the goal being matched */ public List<Rule> rulesFor(TriplePattern goal) { List<Rule> rules = new ArrayList<>(); if (goal.getPredicate().isVariable()) { checkAll(goalMap.values().iterator(), goal, rules); } else { checkAll(goalMap.getAll(goal.getPredicate()), goal, rules); checkAll(goalMap.getAll(Node.ANY), goal, rules); } return rules; }