Return-Path: X-Original-To: apmail-jena-commits-archive@www.apache.org Delivered-To: apmail-jena-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D6FEF11CBE for ; Tue, 24 Jun 2014 09:08:27 +0000 (UTC) Received: (qmail 75043 invoked by uid 500); 24 Jun 2014 09:08:27 -0000 Delivered-To: apmail-jena-commits-archive@jena.apache.org Received: (qmail 75018 invoked by uid 500); 24 Jun 2014 09:08:27 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 75009 invoked by uid 99); 24 Jun 2014 09:08:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jun 2014 09:08:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jun 2014 09:08:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CE2512388BEC; Tue, 24 Jun 2014 09:07:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1605034 [10/16] - in /jena/trunk: jena-arq/src/main/java/arq/ jena-arq/src/main/java/arq/cmdline/ jena-arq/src/main/java/com/hp/hpl/jena/query/ jena-arq/src/main/java/com/hp/hpl/jena/sparql/ jena-arq/src/main/java/com/hp/hpl/jena/sparql/al... Date: Tue, 24 Jun 2014 09:07:06 -0000 To: commits@jena.apache.org From: andy@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140624090739.CE2512388BEC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java Tue Jun 24 09:06:50 2014 @@ -142,7 +142,7 @@ public class FBRuleInfGraph extends Bas initLP(schema); tempNodecache = new TempNodeCache(this); if (JenaParameters.enableFilteringOfHiddenInfNodes) { - hiddenNodes = new HashSet(); + hiddenNodes = new HashSet<>(); if (schema != null && schema instanceof FBRuleInfGraph) { hiddenNodes.addAll(((FBRuleInfGraph)schema).hiddenNodes); } @@ -268,10 +268,10 @@ public class FBRuleInfGraph extends Bas * Adds a set of new Backward rules */ public void addBRules(List rules) { - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule rule = i.next(); -// logger.debug("Adding rule " + rule); - bEngine.addRule(rule); + for ( Rule rule : rules ) + { + // logger.debug("Adding rule " + rule); + bEngine.addRule( rule ); } bEngine.reset(); } @@ -345,7 +345,7 @@ public class FBRuleInfGraph extends Bas public void addRuleDuringPrepare(Rule rule) { if (rules == rawRules) { // Ensure the original is preserved in case we need to do a restart - rules = new ArrayList( rawRules ); + rules = new ArrayList<>( rawRules ); // if (rawRules instanceof ArrayList) { // rules = (ArrayList) ((ArrayList)rawRules).clone(); // } else { @@ -363,7 +363,7 @@ public class FBRuleInfGraph extends Bas */ public void addPreprocessingHook(RulePreprocessHook hook) { if (preprocessorHooks == null) { - preprocessorHooks = new ArrayList(); + preprocessorHooks = new ArrayList<>(); } preprocessorHooks.add(hook); } @@ -420,15 +420,18 @@ public class FBRuleInfGraph extends Bas } } // Insert any axiomatic statements into the caches - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule r = i.next(); - if (r.bodyLength() == 0) { + for ( Rule r : rules ) + { + if ( r.bodyLength() == 0 ) + { // An axiom - for (int j = 0; j < r.headLength(); j++) { - Object head = r.getHeadElement(j); - if (head instanceof TriplePattern) { + for ( int j = 0; j < r.headLength(); j++ ) + { + Object head = r.getHeadElement( j ); + if ( head instanceof TriplePattern ) + { TriplePattern h = (TriplePattern) head; - transitiveEngine.add(h.asTriple()); + transitiveEngine.add( h.asTriple() ); } } } @@ -448,9 +451,9 @@ public class FBRuleInfGraph extends Bas // Call any optional preprocessing hook if (preprocessorHooks != null && preprocessorHooks.size() > 0) { Graph inserts = Factory.createGraphMem(); - for (Iterator i = preprocessorHooks.iterator(); i.hasNext(); ) { - RulePreprocessHook hook = i.next(); - hook.run(this, dataFind, inserts); + for ( RulePreprocessHook hook : preprocessorHooks ) + { + hook.run( this, dataFind, inserts ); } if (inserts.size() > 0) { FGraph finserts = new FGraph(inserts); @@ -523,7 +526,7 @@ public class FBRuleInfGraph extends Bas engine.setDerivationLogging(recordDerivations); bEngine.setDerivationLogging(recordDerivations); if (recordDerivations) { - derivations = new OneToManyMap(); + derivations = new OneToManyMap<>(); } else { derivations = null; } @@ -627,9 +630,12 @@ public class FBRuleInfGraph extends Bas boolean needReset = false; if (preprocessorHooks != null && preprocessorHooks.size() > 0) { if (preprocessorHooks.size() > 1) { - for (Iterator i = preprocessorHooks.iterator(); i.hasNext();) { - if (i.next().needsRerun(this, t)) { - needReset = true; break; + for ( RulePreprocessHook preprocessorHook : preprocessorHooks ) + { + if ( preprocessorHook.needsRerun( this, t ) ) + { + needReset = true; + break; } } } else { @@ -779,11 +785,12 @@ public class FBRuleInfGraph extends Bas */ protected void performDatatypeRangeValidation(StandardValidityReport report) { HashMap> dtRange = getDTRange(); - for (Iterator props = dtRange.keySet().iterator(); props.hasNext(); ) { - Node prop = props.next(); - for (Iterator i = find(null, prop, null); i.hasNext(); ) { + for ( Node prop : dtRange.keySet() ) + { + for ( Iterator i = find( null, prop, null ); i.hasNext(); ) + { Triple triple = i.next(); - report.add(checkLiteral(prop, triple)); + report.add( checkLiteral( prop, triple ) ); } } } @@ -805,13 +812,13 @@ public class FBRuleInfGraph extends Bas return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value); } - LiteralLabel ll = value.getLiteral(); - for (Iterator i = range.iterator(); i.hasNext(); ) { - RDFDatatype dt = i.next(); - if (!dt.isValidLiteral(ll)) { - return new ValidityReport.Report(true, "dtRange", - "Property " + prop + " has a typed range " + dt + - "that is not compatible with " + value, triple); + LiteralLabel ll = value.getLiteral(); + for ( RDFDatatype dt : range ) + { + if ( !dt.isValidLiteral( ll ) ) + { + return new ValidityReport.Report( true, "dtRange", "Property " + prop + " has a typed range " + dt + + "that is not compatible with " + value, triple ); } } } @@ -824,7 +831,7 @@ public class FBRuleInfGraph extends Bas */ protected HashMap> getDTRange() { if (dtRange == null) { - dtRange = new HashMap>(); + dtRange = new HashMap<>(); for (Iterator i = find(null, RDFS.range.asNode(), null); i.hasNext(); ) { Triple triple = i.next(); Node prop = triple.getSubject(); @@ -834,7 +841,7 @@ public class FBRuleInfGraph extends Bas if (dt != null) { List range = dtRange.get(prop); if (range == null) { - range = new ArrayList(); + range = new ArrayList<>(); dtRange.put(prop, range); } range.add(dt); @@ -853,11 +860,12 @@ public class FBRuleInfGraph extends Bas * and transfer these rules to the backward engine. */ private static List extractPureBackwardRules(List rules) { - List bRules = new ArrayList(); - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule r = i.next(); - if (r.isBackward() && r.bodyLength() > 0) { - bRules.add(r); + List bRules = new ArrayList<>(); + for ( Rule r : rules ) + { + if ( r.isBackward() && r.bodyLength() > 0 ) + { + bRules.add( r ); } } return bRules; @@ -897,7 +905,7 @@ public class FBRuleInfGraph extends Bas public void hideNode(Node n) { if (! JenaParameters.enableFilteringOfHiddenInfNodes) return; if (hiddenNodes == null) { - hiddenNodes = new HashSet(); + hiddenNodes = new HashSet<>(); } synchronized (hiddenNodes) { hiddenNodes.add(n); Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java Tue Jun 24 09:06:50 2014 @@ -37,7 +37,7 @@ public class FBRuleReasoner implements R protected ReasonerFactory factory; /** The rules to be used by this instance of the forward engine */ - protected List rules = new ArrayList(); + protected List rules = new ArrayList<>(); /** A precomputed set of schema deductions */ protected Graph schemaGraph; @@ -128,7 +128,7 @@ public class FBRuleReasoner implements R TODO review & revise */ public FBRuleReasoner addRules(List rules) { - List combined = new ArrayList( this.rules ); + List combined = new ArrayList<>( this.rules ); combined.addAll( rules ); setRules( combined ); return this; Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Functor.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Functor.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Functor.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Functor.java Tue Jun 24 09:06:50 2014 @@ -117,9 +117,10 @@ public class Functor implements ClauseEn * Returns true if the functor is fully ground, no variables */ public boolean isGround() { - for (int i = 0; i < args.length; i++) { - Node n = args[i]; - if (n instanceof Node_RuleVariable || n instanceof Node_ANY) { + for ( Node n : args ) + { + if ( n instanceof Node_RuleVariable || n instanceof Node_ANY ) + { return false; } } @@ -130,9 +131,12 @@ public class Functor implements ClauseEn * Returns true if the functor is fully ground in the given environment */ public boolean isGround(BindingEnvironment env) { - for (int i = 0; i < args.length; i++) { - Node n = args[i]; - if (env.getGroundVersion(args[i]).isVariable()) return false; + for ( Node n : args ) + { + if ( env.getGroundVersion( n ).isVariable() ) + { + return false; + } } return true; } @@ -201,7 +205,7 @@ public class Functor implements ClauseEn */ @Override public String toString() { - StringBuffer buff = new StringBuffer(name); + StringBuilder buff = new StringBuilder(name); buff.append("("); for (int i = 0; i < args.length; i++) { buff.append(PrintUtil.print(args[i])); Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/GenericRuleReasoner.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/GenericRuleReasoner.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/GenericRuleReasoner.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/GenericRuleReasoner.java Tue Jun 24 09:06:50 2014 @@ -192,7 +192,7 @@ public class GenericRuleReasoner extends */ public void addPreprocessingHook(RulePreprocessHook hook) { if (preprocessorHooks == null) { - preprocessorHooks = new HashSet(); + preprocessorHooks = new HashSet<>(); } preprocessorHooks.add(hook); } @@ -341,8 +341,9 @@ public class GenericRuleReasoner extends grr.setTransitiveClosureCaching(enableTGCCaching); grr.setFunctorFiltering(filterFunctors); if (preprocessorHooks != null) { - for (Iterator i = preprocessorHooks.iterator(); i.hasNext(); ) { - grr.addPreprocessingHook(i.next()); + for ( RulePreprocessHook preprocessorHook : preprocessorHooks ) + { + grr.addPreprocessingHook( preprocessorHook ); } } return grr; @@ -381,8 +382,9 @@ public class GenericRuleReasoner extends fbgraph.setTraceOn(traceOn); fbgraph.setFunctorFiltering(filterFunctors); if (preprocessorHooks!= null) { - for (Iterator i = preprocessorHooks.iterator(); i.hasNext(); ) { - fbgraph.addPreprocessingHook(i.next()); + for ( RulePreprocessHook preprocessorHook : preprocessorHooks ) + { + fbgraph.addPreprocessingHook( preprocessorHook ); } } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java Tue Jun 24 09:06:50 2014 @@ -240,7 +240,7 @@ public class LPBackwardRuleInfGraph exte public void setDerivationLogging(boolean recordDerivations) { engine.setDerivationLogging(recordDerivations); if (recordDerivations) { - derivations = new OneToManyMap(); + derivations = new OneToManyMap<>(); } else { derivations = null; } @@ -253,7 +253,7 @@ public class LPBackwardRuleInfGraph exte @Override public Iterator getDerivation(Triple t) { if (derivations == null) { - return new NullIterator(); + return new NullIterator<>(); } else { return derivations.getAll(t); } @@ -336,27 +336,34 @@ public class LPBackwardRuleInfGraph exte protected void extractAxioms() { Graph axioms = fdeductions.getGraph(); BBRuleContext contextForBuiltins = null; - for (Iterator i = engine.getRuleStore().getAllRules().iterator(); i.hasNext(); ) { - Rule rule = i.next(); - if (rule.bodyLength() == 0) { + for ( Rule rule : engine.getRuleStore().getAllRules() ) + { + if ( rule.bodyLength() == 0 ) + { // An axiom - for (int j = 0; j < rule.headLength(); j++) { - ClauseEntry axiom = rule.getHeadElement(j); - if (axiom instanceof TriplePattern) { - axioms.add(((TriplePattern)axiom).asTriple()); - } else if (axiom instanceof Functor) { - if (contextForBuiltins == null) { - contextForBuiltins = new BBRuleContext(this); + for ( int j = 0; j < rule.headLength(); j++ ) + { + ClauseEntry axiom = rule.getHeadElement( j ); + if ( axiom instanceof TriplePattern ) + { + axioms.add( ( (TriplePattern) axiom ).asTriple() ); + } + else if ( axiom instanceof Functor ) + { + if ( contextForBuiltins == null ) + { + contextForBuiltins = new BBRuleContext( this ); } - Functor f = (Functor)axiom; + Functor f = (Functor) axiom; Builtin implementation = f.getImplementor(); - if (implementation == null) { - throw new ReasonerException("Attempted to invoke undefined functor: " + f); + if ( implementation == null ) + { + throw new ReasonerException( "Attempted to invoke undefined functor: " + f ); } Node[] args = f.getArgs(); - contextForBuiltins.setEnv(new BindingVector(args)); - contextForBuiltins.setRule(rule); - implementation.headAction(args, args.length, contextForBuiltins); + contextForBuiltins.setEnv( new BindingVector( args ) ); + contextForBuiltins.setRule( rule ); + implementation.headAction( args, args.length, contextForBuiltins ); } } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasonerFactory.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasonerFactory.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasonerFactory.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLFBRuleReasonerFactory.java Tue Jun 24 09:06:50 2014 @@ -68,7 +68,7 @@ public class OWLFBRuleReasonerFactory im } Boolean doTrace = Util.checkBinaryPredicate(ReasonerVocabulary.PROPtraceOn, configuration); if (doTrace != null) { - reasoner.setTraceOn(doTrace.booleanValue()); + reasoner.setTraceOn( doTrace ); } } return reasoner; Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMicroReasonerFactory.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMicroReasonerFactory.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMicroReasonerFactory.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMicroReasonerFactory.java Tue Jun 24 09:06:50 2014 @@ -71,7 +71,7 @@ public class OWLMicroReasonerFactory imp } Boolean doTrace = Util.checkBinaryPredicate(ReasonerVocabulary.PROPtraceOn, configuration); if (doTrace != null) { - reasoner.setTraceOn(doTrace.booleanValue()); + reasoner.setTraceOn( doTrace ); } } return reasoner; Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMiniReasonerFactory.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMiniReasonerFactory.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMiniReasonerFactory.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/OWLMiniReasonerFactory.java Tue Jun 24 09:06:50 2014 @@ -66,7 +66,7 @@ public class OWLMiniReasonerFactory impl } Boolean doTrace = Util.checkBinaryPredicate(ReasonerVocabulary.PROPtraceOn, configuration); if (doTrace != null) { - reasoner.setTraceOn(doTrace.booleanValue()); + reasoner.setTraceOn( doTrace ); } } return reasoner; Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/RDFSRuleReasoner.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/RDFSRuleReasoner.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/RDFSRuleReasoner.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/RDFSRuleReasoner.java Tue Jun 24 09:06:50 2014 @@ -53,7 +53,7 @@ public class RDFSRuleReasoner extends Ge protected static final String SIMPLE_RULE_FILE = "etc/rdfs-fb-tgc-simple.rules"; /** The cached rule sets, indexed by processing level */ - protected static Map> ruleSets = new HashMap>(); + protected static Map> ruleSets = new HashMap<>(); /** The rule file names, indexed by processing level */ protected static Map ruleFiles; @@ -62,7 +62,7 @@ public class RDFSRuleReasoner extends Ge protected static RulePreprocessHook cmpProcessor = new RDFSCMPPreprocessHook(); static { - ruleFiles = new HashMap(); + ruleFiles = new HashMap<>(); ruleFiles.put(DEFAULT_RULES, RULE_FILE); ruleFiles.put(FULL_RULES, FULL_RULE_FILE); ruleFiles.put(SIMPLE_RULES, SIMPLE_RULE_FILE); Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Rule.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Rule.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Rule.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Rule.java Tue Jun 24 09:06:50 2014 @@ -149,14 +149,22 @@ public class Rule implements ClauseEntry // Compute the monotonicity flag // Future support for negation would affect this private boolean allMonotonic(ClauseEntry[] elts) { - for (int i = 0; i < elts.length; i++) { - ClauseEntry elt = elts[i]; - if (elt instanceof Functor) { - Builtin b = ((Functor)elt).getImplementor(); - if (b != null) { - if (! b.isMonotonic() ) return false; - } else { - throw new ReasonerException("Undefined Functor " + ((Functor)elt).getName() +" in " + toShortString()); + for ( ClauseEntry elt : elts ) + { + if ( elt instanceof Functor ) + { + Builtin b = ( (Functor) elt ).getImplementor(); + if ( b != null ) + { + if ( !b.isMonotonic() ) + { + return false; + } + } + else + { + throw new ReasonerException( + "Undefined Functor " + ( (Functor) elt ).getName() + " in " + toShortString() ); } } } @@ -259,12 +267,15 @@ public class Rule implements ClauseEntry */ private int findVars(Object[] nodes, int maxIn) { int max = maxIn; - for (int i = 0; i < nodes.length; i++) { - Object node = nodes[i]; - if (node instanceof TriplePattern) { - max = findVars((TriplePattern)node, max); - } else { - max = findVars((Functor)node, max); + for ( Object node : nodes ) + { + if ( node instanceof TriplePattern ) + { + max = findVars( (TriplePattern) node, max ); + } + else + { + max = findVars( (Functor) node, max ); } } return max; @@ -292,8 +303,12 @@ public class Rule implements ClauseEntry private int findVars(Functor f, int maxIn) { int max = maxIn; Node[] args = f.getArgs(); - for (int i = 0; i < args.length; i++) { - if (args[i].isVariable()) max = maxVarIndex(args[i], max); + for ( Node arg : args ) + { + if ( arg.isVariable() ) + { + max = maxVarIndex( arg, max ); + } } return max; } @@ -315,7 +330,7 @@ public class Rule implements ClauseEntry * for trail implementations. */ public Rule instantiate(BindingEnvironment env) { - HashMap vmap = new HashMap(); + HashMap vmap = new HashMap<>(); return new Rule(name, cloneClauseArray(head, vmap, env), cloneClauseArray(body, vmap, env)); } @@ -324,7 +339,7 @@ public class Rule implements ClauseEntry */ public Rule cloneRule() { if (getNumVars() > 0) { - HashMap vmap = new HashMap(); + HashMap vmap = new HashMap<>(); return new Rule(name, cloneClauseArray(head, vmap, null), cloneClauseArray(body, vmap, null)); } else { return this; @@ -407,8 +422,10 @@ public class Rule implements ClauseEntry */ public boolean isAxiom() { if (isBackward() && body.length > 0) return false; - for (int i = 0; i < body.length; i++) { - if (body[i] instanceof TriplePattern) { + for ( ClauseEntry aBody : body ) + { + if ( aBody instanceof TriplePattern ) + { return false; } } @@ -420,31 +437,35 @@ public class Rule implements ClauseEntry */ @Override public String toString() { - StringBuffer buff = new StringBuffer(); + StringBuilder buff = new StringBuilder(); buff.append("[ "); if (name != null) { buff.append(name); buff.append(": "); } - if (isBackward) { - for (int i = 0; i < head.length; i++) { - buff.append(PrintUtil.print(head[i])); - buff.append(" "); + if (isBackward) { + for ( ClauseEntry aHead : head ) + { + buff.append( PrintUtil.print( aHead ) ); + buff.append( " " ); } buff.append("<- "); - for (int i = 0; i < body.length; i++) { - buff.append(PrintUtil.print(body[i])); - buff.append(" "); + for ( ClauseEntry aBody : body ) + { + buff.append( PrintUtil.print( aBody ) ); + buff.append( " " ); } } else { - for (int i = 0; i < body.length; i++) { - buff.append(PrintUtil.print(body[i])); - buff.append(" "); + for ( ClauseEntry aBody : body ) + { + buff.append( PrintUtil.print( aBody ) ); + buff.append( " " ); } buff.append("-> "); - for (int i = 0; i < head.length; i++) { - buff.append(PrintUtil.print(head[i])); - buff.append(" "); + for ( ClauseEntry aHead : head ) + { + buff.append( PrintUtil.print( aHead ) ); + buff.append( " " ); } } buff.append("]"); @@ -499,10 +520,10 @@ public class Rule implements ClauseEntry */ public static Parser rulesParserFromReader( BufferedReader src ) { try { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); String line; - Map prefixes = new HashMap(); - List preloadedRules = new ArrayList(); + Map prefixes = new HashMap<>(); + List preloadedRules = new ArrayList<>(); while ((line = src.readLine()) != null) { if (line.startsWith("#")) continue; // Skip comment lines line = line.trim(); @@ -609,7 +630,7 @@ public class Rule implements ClauseEntry */ public static List parseRules(Parser parser) throws ParserException { boolean finished = false; - List ruleset = new ArrayList(); + List ruleset = new ArrayList<>(); ruleset.addAll(parser.getRulesPreload()); while (!finished) { try { @@ -658,7 +679,7 @@ public class Rule implements ClauseEntry private int literalState = NORMAL; /** Trace back of recent tokens for error reporting */ - protected List priorTokens = new ArrayList(); + protected List priorTokens = new ArrayList<>(); /** Maximum number of recent tokens to remember */ private static final int maxPriors = 20; @@ -670,7 +691,7 @@ public class Rule implements ClauseEntry private PrefixMapping prefixMapping = PrefixMapping.Factory.create(); /** Pre-included rules */ - private List preloadedRules = new ArrayList(); + private List preloadedRules = new ArrayList<>(); /** * Constructor @@ -752,7 +773,7 @@ public class Rule implements ClauseEntry * in error reporting */ public String recentTokens() { - StringBuffer trace = new StringBuffer(); + StringBuilder trace = new StringBuilder(); for (int i = priorTokens.size()-1; i >= 0; i--) { trace.append(priorTokens.get(i)); trace.append(" "); @@ -894,7 +915,7 @@ public class Rule implements ClauseEntry Node parseNumber(String lit) { if ( Character.isDigit(lit.charAt(0)) || (lit.charAt(0) == '-' && lit.length() > 1 && Character.isDigit(lit.charAt(1))) ) { - if (lit.indexOf(".") != -1) { + if ( lit.contains( "." ) ) { // Float? if (XSDDatatype.XSDfloat.isValid(lit)) { return NodeFactory.createLiteral(lit, "", XSDDatatype.XSDfloat); @@ -919,7 +940,7 @@ public class Rule implements ClauseEntry throw new ParserException("Expected '(' at start of clause, found " + token, this); } token = nextToken(); - List nodeList = new ArrayList(); + List nodeList = new ArrayList<>(); while (!isSyntax(token)) { nodeList.add(parseNode(token)); token = nextToken(); @@ -990,16 +1011,16 @@ public class Rule implements ClauseEntry nextToken(); } // Start rule parsing with empty variable table - if (!retainVarMap) varMap = new HashMap(); + if (!retainVarMap) varMap = new HashMap<>(); // Body - List body = new ArrayList(); + List body = new ArrayList<>(); token = peekToken(); while ( !(token.equals("->") || token.equals("<-")) ) { body.add(parseClause()); token = peekToken(); } boolean backwardRule = token.equals("<-"); - List head = new ArrayList(); + List head = new ArrayList<>(); token = nextToken(); // skip -> token token = peekToken(); while ( !(token.equals(".") || token.equals("]")) ) { @@ -1051,11 +1072,13 @@ public class Rule implements ClauseEntry @Override public int hashCode() { int hash = 0; - for (int i = 0; i < body.length; i++) { - hash = (hash << 1) ^ body[i].hashCode(); - } - for (int i = 0; i < head.length; i++) { - hash = (hash << 1) ^ head[i].hashCode(); + for ( ClauseEntry aBody : body ) + { + hash = ( hash << 1 ) ^ aBody.hashCode(); + } + for ( ClauseEntry aHead : head ) + { + hash = ( hash << 1 ) ^ aHead.hashCode(); } return hash; } @@ -1087,7 +1110,7 @@ public class Rule implements ClauseEntry * Extract context trace from prior tokens stack */ private static String constructMessage(String baseMessage, Parser parser) { - StringBuffer message = new StringBuffer(); + StringBuilder message = new StringBuilder(); message.append(baseMessage); message.append("\nAt '"); message.append(parser.recentTokens()); Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Util.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Util.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Util.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/Util.java Tue Jun 24 09:06:50 2014 @@ -213,7 +213,7 @@ public class Util { * Construct a new integer valued node */ public static Node makeIntNode(int value) { - return NodeFactory.createLiteral(LiteralLabelFactory.create(new Integer(value))); + return NodeFactory.createLiteral(LiteralLabelFactory.create( value )); } /** @@ -221,9 +221,9 @@ public class Util { */ public static Node makeLongNode(long value) { if (value > Integer.MAX_VALUE) { - return NodeFactory.createLiteral(LiteralLabelFactory.create(new Long(value))); + return NodeFactory.createLiteral(LiteralLabelFactory.create( value )); } else { - return NodeFactory.createLiteral(LiteralLabelFactory.create(new Integer((int)value))); + return NodeFactory.createLiteral(LiteralLabelFactory.create( (int) value )); } } @@ -231,7 +231,7 @@ public class Util { * Construct a new double valued node */ public static Node makeDoubleNode(double value) { - return NodeFactory.createLiteral(LiteralLabelFactory.create(new Double(value))); + return NodeFactory.createLiteral(LiteralLabelFactory.create( value )); } /** @@ -293,7 +293,7 @@ public class Util { public static Boolean checkBinaryPredicate(Property predicate, Resource configuration) { StmtIterator i = configuration.listProperties(predicate); if (i.hasNext()) { - return new Boolean(i.nextStatement().getObject().toString().equalsIgnoreCase("true")); + return i.nextStatement().getObject().toString().equalsIgnoreCase( "true" ); } else { return null; } @@ -311,7 +311,7 @@ public class Util { if (i.hasNext()) { RDFNode lit = i.nextStatement().getObject(); if (lit instanceof Literal) { - return new Integer(((Literal)lit).getInt()); + return ( (Literal) lit ).getInt(); } } return null; Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/AssertDisjointPairs.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/AssertDisjointPairs.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/AssertDisjointPairs.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/AssertDisjointPairs.java Tue Jun 24 09:06:50 2014 @@ -58,12 +58,13 @@ public class AssertDisjointPairs extends public void headAction(Node[] args, int length, RuleContext context) { checkArgs(length, context); List l = Util.convertList(args[0], context); - for (Iterator i = l.iterator(); i.hasNext(); ) { - Node x = i.next(); - for (Iterator j = l.iterator(); j.hasNext(); ) { - Node y = j.next(); - if (!x.sameValueAs(y)) { - context.add( new Triple(x, OWL.differentFrom.asNode(), y) ); + for ( Node x : l ) + { + for ( Node y : l ) + { + if ( !x.sameValueAs( y ) ) + { + context.add( new Triple( x, OWL.differentFrom.asNode(), y ) ); } } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/CountLiteralValues.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/CountLiteralValues.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/CountLiteralValues.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/CountLiteralValues.java Tue Jun 24 09:06:50 2014 @@ -57,7 +57,7 @@ public class CountLiteralValues extends */ @Override public boolean bodyCall(Node[] args, int length, RuleContext context) { - List values = new ArrayList(); + List values = new ArrayList<>(); Node a0 = getArg(0, args, context); Node a1 = getArg(1, args, context); for (Iterator ni = context.find(a0, a1, null); ni.hasNext(); ) { @@ -66,8 +66,10 @@ public class CountLiteralValues extends // Can't just use contains because distinct objects may // be semantically equal boolean gotit = false; - for (Iterator i = values.iterator(); i.hasNext(); ) { - if (v.sameValueAs(i.next())) { + for ( Node value : values ) + { + if ( v.sameValueAs( value ) ) + { gotit = true; break; } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListEqual.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListEqual.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListEqual.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListEqual.java Tue Jun 24 09:06:50 2014 @@ -70,19 +70,22 @@ public class ListEqual extends BaseBuilt List elts1 = Util.convertList(list1, context); List elts2 = Util.convertList(list2, context); if (elts1.size() != elts2.size()) return false; - for (Iterator i = elts1.iterator(); i.hasNext(); ) { - Node elt = i.next(); + for ( Node elt : elts1 ) + { boolean matched = false; - for (Iterator j = elts2.iterator(); j.hasNext(); ) { + for ( Iterator j = elts2.iterator(); j.hasNext(); ) + { Node elt2 = j.next(); - if (elt.sameValueAs(elt2)) { + if ( elt.sameValueAs( elt2 ) ) + { // Found match, consume it j.remove(); matched = true; break; } } - if (!matched) { + if ( !matched ) + { return false; } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsObject.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsObject.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsObject.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsObject.java Tue Jun 24 09:06:50 2014 @@ -64,8 +64,8 @@ public class ListMapAsObject extends Bas Node n1 = getArg(1, args, context); Node n2 = getArg(2, args, context); List l = Util.convertList(n2, context); - for (Iterator i = l.iterator(); i.hasNext(); ) { - Node x = i.next(); + for ( Node x : l ) + { context.add( new Triple( n0, n1, x ) ); } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsSubject.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsSubject.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsSubject.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/ListMapAsSubject.java Tue Jun 24 09:06:50 2014 @@ -63,9 +63,9 @@ public class ListMapAsSubject extends Ba Node n1 = getArg(1, args, context); Node n2 = getArg(2, args, context); Listl = Util.convertList(n0, context); - for (Iterator i = l.iterator(); i.hasNext(); ) { - Node x = i.next(); - context.add( new Triple(x, n1, n2)); + for ( Node x : l ) + { + context.add( new Triple( x, n1, n2 ) ); } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/StrConcat.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/StrConcat.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/StrConcat.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/StrConcat.java Tue Jun 24 09:06:50 2014 @@ -62,7 +62,7 @@ public class StrConcat extends BaseBuilt public boolean bodyCall(Node[] args, int length, RuleContext context) { if (length < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); - StringBuffer buff = new StringBuffer(); + StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/UriConcat.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/UriConcat.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/UriConcat.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/builtins/UriConcat.java Tue Jun 24 09:06:50 2014 @@ -53,7 +53,7 @@ public class UriConcat extends StrConcat public boolean bodyCall(Node[] args, int length, RuleContext context) { if (length < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); - StringBuffer buff = new StringBuffer(); + StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BFRuleContext.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BFRuleContext.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BFRuleContext.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BFRuleContext.java Tue Jun 24 09:06:50 2014 @@ -50,7 +50,7 @@ public class BFRuleContext implements Ru protected List pending; /** A temporary list of Triples which will be removed from the graph at the end of a rule scan */ - protected List deletesPending = new ArrayList(); + protected List deletesPending = new ArrayList<>(); /** A searchable index into the pending triples */ protected Graph pendingCache; @@ -64,8 +64,8 @@ public class BFRuleContext implements Ru public BFRuleContext(ForwardRuleInfGraphI graph) { this.graph = graph; env = new BindingStack(); - stack = new ArrayList(); - pending = new ArrayList(); + stack = new ArrayList<>(); + pending = new ArrayList<>(); pendingCache = Factory.createGraphMem(); } @@ -162,9 +162,9 @@ public class BFRuleContext implements Ru } pending.clear(); // Flush out pending removes as well - for (Iterator i = deletesPending.iterator(); i.hasNext(); ) { - Triple t = i.next(); - graph.delete(t); + for ( Triple t : deletesPending ) + { + graph.delete( t ); } deletesPending.clear(); } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingStack.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingStack.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingStack.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingStack.java Tue Jun 24 09:06:50 2014 @@ -41,7 +41,7 @@ public class BindingStack implements Bin protected Node[] environment; /** A stack of prior binding sets */ - protected ArrayList trail = new ArrayList(); + protected ArrayList trail = new ArrayList<>(); /** Index of the current binding set */ protected int index = 0; @@ -126,14 +126,16 @@ public class BindingStack implements Bin Functor functor = (Functor)node.getLiteralValue(); if (functor.isGround()) return node; Node[] args = functor.getArgs(); - List boundargs = new ArrayList(args.length); - for (int i = 0; i < args.length; i++) { - Node binding = getBinding(args[i]); - if (binding == null) { + List boundargs = new ArrayList<>(args.length); + for ( Node arg : args ) + { + Node binding = getBinding( arg ); + if ( binding == null ) + { // Not sufficent bound to instantiate functor yet return null; } - boundargs.add(binding); + boundargs.add( binding ); } Functor newf = new Functor(functor.getName(), boundargs); return Functor.makeFunctorNode( newf ); Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVector.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVector.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVector.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVector.java Tue Jun 24 09:06:50 2014 @@ -87,14 +87,16 @@ public class BindingVector implements Bi Functor functor = (Functor)node.getLiteralValue(); if (functor.isGround()) return node; Node[] args = functor.getArgs(); - List boundargs = new ArrayList(args.length); - for (int i = 0; i < args.length; i++) { - Node binding = getBinding(args[i]); - if (binding == null) { + List boundargs = new ArrayList<>(args.length); + for ( Node arg : args ) + { + Node binding = getBinding( arg ); + if ( binding == null ) + { // Not sufficently bound to instantiate functor yet return null; } - boundargs.add(binding); + boundargs.add( binding ); } Functor newf = new Functor( functor.getName(), boundargs ); return Functor.makeFunctorNode( newf ); @@ -205,13 +207,17 @@ public class BindingVector implements Bi @Override public String toString() { StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < environment.length; i++) { - if (environment[i] == null) { - buffer.append("-"); - } else { - buffer.append(PrintUtil.print(environment[i])); + for ( Node anEnvironment : environment ) + { + if ( anEnvironment == null ) + { + buffer.append( "-" ); + } + else + { + buffer.append( PrintUtil.print( anEnvironment ) ); } - buffer.append(" "); + buffer.append( " " ); } return buffer.toString(); } @@ -360,9 +366,9 @@ public class BindingVector implements Bi @Override public int hashCode() { int hash = 0; - for (int i = 0; i < environment.length; i++) { - Node n = environment[i]; - hash = (hash << 1) ^ (n == null ? 0x537c: n.hashCode()); + for ( Node n : environment ) + { + hash = ( hash << 1 ) ^ ( n == null ? 0x537c : n.hashCode() ); } return hash; } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVectorMultiSet.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVectorMultiSet.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVectorMultiSet.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/BindingVectorMultiSet.java Tue Jun 24 09:06:50 2014 @@ -65,7 +65,7 @@ public class BindingVectorMultiSet { } /** Inner representation */ - protected Map> data = new HashMap>(); + protected Map> data = new HashMap<>(); /** An array of indices which mark the primary key */ protected byte[] matchIndices; @@ -156,7 +156,7 @@ public class BindingVectorMultiSet { protected void put(BindingVector env, Count c) { Map set = getRawSubSet(env); if (set == null) { - set = new HashMap(); + set = new HashMap<>(); data.put(getPartialEnv(env), set); } set.put(env, c); @@ -170,16 +170,16 @@ public class BindingVectorMultiSet { * @param queue */ public void putAll(BindingVectorMultiSet queue) { - for (Iterator it = queue.data.keySet().iterator(); it - .hasNext();) { - BindingVector env = it.next(); - Map set = getRawSubSet(env); - if (set == null) { - set = new HashMap(); - data.put(env, set); - } - set.putAll(queue.data.get(env)); - } + for ( BindingVector env : queue.data.keySet() ) + { + Map set = getRawSubSet( env ); + if ( set == null ) + { + set = new HashMap<>(); + data.put( env, set ); + } + set.putAll( queue.data.get( env ) ); + } } /** Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/EnvironmentFrameWithDerivation.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/EnvironmentFrameWithDerivation.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/EnvironmentFrameWithDerivation.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/EnvironmentFrameWithDerivation.java Tue Jun 24 09:06:50 2014 @@ -69,9 +69,10 @@ public class EnvironmentFrameWithDerivat * Return a safe copy of the list of matched subgoals in this subderivation. */ public List getMatchList() { - ArrayList matchList = new ArrayList(); - for (int i = 0; i < matches.length; i++) { - matchList.add( LPInterpreter.deref(matches[i])); + ArrayList matchList = new ArrayList<>(); + for ( TriplePattern matche : matches ) + { + matchList.add( LPInterpreter.deref( matche ) ); } return matchList; } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/FRuleEngine.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/FRuleEngine.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/FRuleEngine.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/FRuleEngine.java Tue Jun 24 09:06:50 2014 @@ -131,10 +131,11 @@ public class FRuleEngine implements FRul context.addTriple(i.next()); } } else { - for (Iterator p = predicatesUsed.iterator(); p.hasNext(); ) { - Node predicate = p.next(); - for (Iterator i = inserts.find(new TriplePattern(null, predicate, null)); i.hasNext(); ) { - context.addTriple(i.next()); + for ( Node predicate : predicatesUsed ) + { + for ( Iterator i = inserts.find( new TriplePattern( null, predicate, null ) ); i.hasNext(); ) + { + context.addTriple( i.next() ); } } } @@ -229,7 +230,7 @@ public class FRuleEngine implements FRul logger.info("Processing: " + PrintUtil.print(t)); } // Check for rule triggers - HashSet firedRules = new HashSet(); + HashSet firedRules = new HashSet<>(); Iterator i1 = clauseIndex.getAll(t.getPredicate()); Iterator i2 = clauseIndex.getAll(Node.ANY); Iterator i = WrappedIterator.create(i1).andThen(i2); @@ -258,25 +259,34 @@ public class FRuleEngine implements FRul * @return an object that can be installed into the engine using setRuleStore. */ public void compile(List rules, boolean ignoreBrules) { - clauseIndex = new OneToManyMap(); - predicatesUsed = new HashSet(); + clauseIndex = new OneToManyMap<>(); + predicatesUsed = new HashSet<>(); wildcardRule = false; - - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule r = i.next(); - if (ignoreBrules && r.isBackward()) continue; + + for ( Rule r : rules ) + { + if ( ignoreBrules && r.isBackward() ) + { + continue; + } Object[] body = r.getBody(); - for (int j = 0; j < body.length; j++) { - if (body[j] instanceof TriplePattern) { - Node predicate = ((TriplePattern) body[j]).getPredicate(); - ClausePointer cp = new ClausePointer(r, j); - if (predicate.isVariable()) { - clauseIndex.put(Node.ANY, cp); + for ( int j = 0; j < body.length; j++ ) + { + if ( body[j] instanceof TriplePattern ) + { + Node predicate = ( (TriplePattern) body[j] ).getPredicate(); + ClausePointer cp = new ClausePointer( r, j ); + if ( predicate.isVariable() ) + { + clauseIndex.put( Node.ANY, cp ); wildcardRule = true; - } else { - clauseIndex.put(predicate, cp); - if (! wildcardRule) { - predicatesUsed.add(predicate); + } + else + { + clauseIndex.put( predicate, cp ); + if ( !wildcardRule ) + { + predicatesUsed.add( predicate ); } } } @@ -291,17 +301,20 @@ public class FRuleEngine implements FRul */ protected void findAndProcessAxioms() { BFRuleContext context = new BFRuleContext(infGraph); - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule r = i.next(); - if (r.bodyLength() == 0) { + for ( Rule r : rules ) + { + if ( r.bodyLength() == 0 ) + { // An axiom - for (int j = 0; j < r.headLength(); j++) { - Object head = r.getHeadElement(j); - if (head instanceof TriplePattern) { + for ( int j = 0; j < r.headLength(); j++ ) + { + Object head = r.getHeadElement( j ); + if ( head instanceof TriplePattern ) + { TriplePattern h = (TriplePattern) head; - Triple t = new Triple(h.getSubject(), h.getPredicate(), h.getObject()); - context.addTriple(t); - infGraph.getDeductionsGraph().add(t); + Triple t = new Triple( h.getSubject(), h.getPredicate(), h.getObject() ); + context.addTriple( t ); + infGraph.getDeductionsGraph().add( t ); } } } @@ -315,20 +328,27 @@ public class FRuleEngine implements FRul */ protected void findAndProcessActions() { BFRuleContext context = new BFRuleContext(infGraph); - for (Iterator i = rules.iterator(); i.hasNext(); ) { - Rule r = i.next(); - if (r.bodyLength() == 0) { + for ( Rule r : rules ) + { + if ( r.bodyLength() == 0 ) + { // An axiom - for (int j = 0; j < r.headLength(); j++) { - Object head = r.getHeadElement(j); - if (head instanceof Functor) { - Functor f = (Functor)head; + for ( int j = 0; j < r.headLength(); j++ ) + { + Object head = r.getHeadElement( j ); + if ( head instanceof Functor ) + { + Functor f = (Functor) head; Builtin imp = f.getImplementor(); - if (imp != null) { - context.setRule(r); - imp.headAction(f.getArgs(), f.getArgLength(), context); - } else { - throw new ReasonerException("Invoking undefined Functor " + f.getName() +" in " + r.toShortString()); + if ( imp != null ) + { + context.setRule( r ); + imp.headAction( f.getArgs(), f.getArgLength(), context ); + } + else + { + throw new ReasonerException( + "Invoking undefined Functor " + f.getName() + " in " + r.toShortString() ); } } } @@ -348,7 +368,7 @@ public class FRuleEngine implements FRul // Create an ordered list of body clauses to process, best at the end ClauseEntry[] body = rule.getBody(); int len = body.length; - List clauses = new ArrayList(len-1); + List clauses = new ArrayList<>(len-1); if (len <= 1) { // No clauses to add, just fall through to clause matcher @@ -425,7 +445,7 @@ public class FRuleEngine implements FRul List matchList = null; if (recordDerivations) { // Create derivation record - matchList = new ArrayList(rule.bodyLength()); + matchList = new ArrayList<>(rule.bodyLength()); for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof TriplePattern) { @@ -468,7 +488,7 @@ public class FRuleEngine implements FRul return true; } // More clauses left to match ... - List clausesCopy = new ArrayList(clauses); + List clausesCopy = new ArrayList<>(clauses); TriplePattern clause = (TriplePattern) clausesCopy.remove(index); Node objPattern = env.getBinding(clause.getObject()); if (Functor.isFunctor(objPattern)) { Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/Generator.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/Generator.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/Generator.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/Generator.java Tue Jun 24 09:06:50 2014 @@ -40,7 +40,7 @@ public class Generator implements LPAgen protected LPInterpreter interpreter; /** The ordered set of results available for the goal */ - protected ArrayList results = new ArrayList(); + protected ArrayList results = new ArrayList<>(); /** A indexed version of the result set, used while the generator is live * to detect duplicate results */ @@ -53,10 +53,10 @@ public class Generator implements LPAgen protected boolean checkReadyNeeded = false; /** The set of choice points producing results for us to use */ - protected Set generatingCPs = new HashSet(); + protected Set generatingCPs = new HashSet<>(); /** The list of active consumer choice points consuming results from this generator */ - protected Set consumingCPs = new HashSet(); + protected Set consumingCPs = new HashSet<>(); /** Flags whether the generator is live/dead/unknown during completion checking */ protected LFlag completionState; @@ -83,7 +83,7 @@ public class Generator implements LPAgen this.interpreter = interpreter; this.goal = goal; // Just used for debugging isSingleton = goal.isGround(); - if (!isSingleton) resultSet = new HashSet(); + if (!isSingleton) resultSet = new HashSet<>(); } /** @@ -102,8 +102,10 @@ public class Generator implements LPAgen if (isComplete()) return false; if (checkReadyNeeded) { isReady = false; - for (Iterator i = generatingCPs.iterator(); i.hasNext(); ) { - if ( i.next().isReady() ) { + for ( ConsumerChoicePointFrame generatingCP : generatingCPs ) + { + if ( generatingCP.isReady() ) + { isReady = true; break; } @@ -161,9 +163,10 @@ public class Generator implements LPAgen isReady = false; completionState = LFlag.DEAD; // Anyone we were generating results for is now finished - for (Iterator i = consumingCPs.iterator(); i.hasNext(); ) { - ConsumerChoicePointFrame ccp = i.next(); - if ( ! ccp.isReady()) { + for ( ConsumerChoicePointFrame ccp : consumingCPs ) + { + if ( !ccp.isReady() ) + { ccp.setFinished(); } } @@ -201,8 +204,8 @@ public class Generator implements LPAgen */ public void notifyResults() { LPBRuleEngine engine = interpreter.getEngine(); - for (Iterator i = consumingCPs.iterator(); i.hasNext(); ) { - ConsumerChoicePointFrame cons = i.next(); + for ( ConsumerChoicePointFrame cons : consumingCPs ) + { cons.setReady(); } } @@ -287,7 +290,7 @@ public class Generator implements LPAgen * dependent on can run. */ public void checkForCompletions() { - HashSet visited = new HashSet(); + HashSet visited = new HashSet<>(); if (runCompletionCheck(visited) != LFlag.LIVE) { postCompletionCheckScan(visited); } @@ -298,11 +301,12 @@ public class Generator implements LPAgen * been run. */ public static void checkForCompletions(Collection completions) { - HashSet visited = new HashSet(); + HashSet visited = new HashSet<>(); boolean atLeastOneZombie = false; - for (Iterator i = completions.iterator(); i.hasNext(); ) { - Generator g = i.next(); - if (g.runCompletionCheck(visited) != LFlag.LIVE) { + for ( Generator g : completions ) + { + if ( g.runCompletionCheck( visited ) != LFlag.LIVE ) + { atLeastOneZombie = true; } } @@ -323,12 +327,15 @@ public class Generator implements LPAgen if (isReady()) { completionState = LFlag.LIVE; } else { - for (Iterator i = generatingCPs.iterator(); i.hasNext(); ) { - ConsumerChoicePointFrame ccp = i.next(); - if (ccp.isReady()) { + for ( ConsumerChoicePointFrame ccp : generatingCPs ) + { + if ( ccp.isReady() ) + { completionState = LFlag.LIVE; break; - } else if ( ccp.generator.runCompletionCheck(visited) == LFlag.LIVE) { + } + else if ( ccp.generator.runCompletionCheck( visited ) == LFlag.LIVE ) + { completionState = LFlag.LIVE; break; } @@ -343,21 +350,25 @@ public class Generator implements LPAgen * to complete. */ protected static void postCompletionCheckScan(Set visited ) { - for (Iterator iv = visited.iterator(); iv.hasNext(); ) { - Generator g = iv.next(); - if (g.completionState == LFlag.LIVE) { - for (Iterator i = g.consumingCPs.iterator(); i.hasNext(); ) { + for ( Generator g : visited ) + { + if ( g.completionState == LFlag.LIVE ) + { + for ( Iterator i = g.consumingCPs.iterator(); i.hasNext(); ) + { LPInterpreterContext link = i.next().getConsumingContext(); - if (link instanceof Generator) { - ((Generator)link).propagateLive(visited); + if ( link instanceof Generator ) + { + ( (Generator) link ).propagateLive( visited ); } } } } - - for (Iterator iv = visited.iterator(); iv.hasNext(); ) { - Generator g = iv.next(); - if (g.completionState != LFlag.LIVE) { + + for ( Generator g : visited ) + { + if ( g.completionState != LFlag.LIVE ) + { g.setComplete(); } } @@ -371,10 +382,12 @@ public class Generator implements LPAgen protected void propagateLive(Set filter) { if (completionState != LFlag.LIVE) { completionState = LFlag.LIVE; - for (Iterator i = consumingCPs.iterator(); i.hasNext(); ) { - LPInterpreterContext link = i.next().getConsumingContext(); - if (link instanceof Generator) { - ((Generator)link).propagateLive(filter); + for ( ConsumerChoicePointFrame consumingCP : consumingCPs ) + { + LPInterpreterContext link = consumingCP.getConsumingContext(); + if ( link instanceof Generator ) + { + ( (Generator) link ).propagateLive( filter ); } } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPBRuleEngine.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPBRuleEngine.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPBRuleEngine.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPBRuleEngine.java Tue Jun 24 09:06:50 2014 @@ -52,14 +52,14 @@ public class LPBRuleEngine { protected boolean recordDerivations; /** List of engine instances which are still processing queries */ - protected List activeInterpreters = new ArrayList(); + protected List activeInterpreters = new ArrayList<>(); /** Table mapping tabled goals to generators for those goals. * This is here so that partial goal state can be shared across multiple queries. */ - protected HashMap tabledGoals = new HashMap(); + protected HashMap tabledGoals = new HashMap<>(); /** Set of generators waiting to be run */ - protected LinkedList agenda = new LinkedList(); + protected LinkedList agenda = new LinkedList<>(); // protected List agenda = new ArrayList(); // protected Collection agenda = new HashSet(); @@ -113,7 +113,7 @@ public class LPBRuleEngine { */ public synchronized void reset() { checkSafeToUpdate(); - tabledGoals = new HashMap(); + tabledGoals = new HashMap<>(); agenda.clear(); } @@ -160,10 +160,11 @@ public class LPBRuleEngine { * Stop the current work. Forcibly stop all current query instances over this engine. */ public synchronized void halt() { - ArrayList copy = new ArrayList(activeInterpreters); + ArrayList copy = new ArrayList<>(activeInterpreters); // Copy because closing the LPInterpreter will detach it from this engine which affects activeInterpreters - for (Iterator i = copy.iterator(); i.hasNext(); ) { - i.next().close(); + for ( LPInterpreter aCopy : copy ) + { + aCopy.close(); } } @@ -221,15 +222,17 @@ public class LPBRuleEngine { */ public void checkSafeToUpdate() { if (!activeInterpreters.isEmpty()) { - ArrayList toClose = new ArrayList(); - for (Iterator i = activeInterpreters.iterator(); i.hasNext(); ) { - LPInterpreter interpreter = i.next(); - if (interpreter.getContext() instanceof LPTopGoalIterator) { - toClose.add(interpreter.getContext()); + ArrayList toClose = new ArrayList<>(); + for ( LPInterpreter interpreter : activeInterpreters ) + { + if ( interpreter.getContext() instanceof LPTopGoalIterator ) + { + toClose.add( interpreter.getContext() ); } } - for (Iterator i = toClose.iterator(); i.hasNext(); ) { - ((LPTopGoalIterator)i.next()).close(); + for ( LPInterpreterContext aToClose : toClose ) + { + ( (LPTopGoalIterator) aToClose ).close(); } } } @@ -295,7 +298,7 @@ public class LPBRuleEngine { public void pump(LPInterpreterContext gen) { Collection batch = null; if (CYCLES_BETWEEN_COMPLETION_CHECK > 0) { - batch = new ArrayList(CYCLES_BETWEEN_COMPLETION_CHECK); + batch = new ArrayList<>(CYCLES_BETWEEN_COMPLETION_CHECK); } int count = 0; while(!gen.isReady()) { @@ -340,11 +343,13 @@ public class LPBRuleEngine { public void checkForCompletions() { List contexts = null; synchronized (activeInterpreters) { - contexts = new ArrayList(activeInterpreters.size()); - for (Iterator i = activeInterpreters.iterator(); i.hasNext(); ) { - LPInterpreterContext context = i.next().getContext(); - if (context instanceof Generator) { - contexts.add( (Generator) context); + contexts = new ArrayList<>(activeInterpreters.size()); + for ( LPInterpreter activeInterpreter : activeInterpreters ) + { + LPInterpreterContext context = activeInterpreter.getContext(); + if ( context instanceof Generator ) + { + contexts.add( (Generator) context ); } } @@ -386,12 +391,13 @@ public class LPBRuleEngine { if (profile == null) { System.out.println("No profile collected"); } else { - ArrayList counts = new ArrayList(); + ArrayList counts = new ArrayList<>(); counts.addAll(profile.values()); Collections.sort(counts); System.out.println("LP engine rule profile"); - for (Iterator i = counts.iterator(); i.hasNext(); ) { - System.out.println(i.next()); + for ( Count count : counts ) + { + System.out.println( count ); } } } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPInterpreter.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPInterpreter.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPInterpreter.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPInterpreter.java Tue Jun 24 09:06:50 2014 @@ -63,7 +63,7 @@ public class LPInterpreter { protected FrameObject cpFrame; /** The trail of variable bindings that have to be unwound on backtrack */ - protected ArrayList trail = new ArrayList(); + protected ArrayList trail = new ArrayList<>(); /** The execution context description to be passed to builtins */ protected RuleContext context; @@ -119,7 +119,7 @@ public class LPInterpreter { envFrame = new EnvironmentFrame(RuleClauseCode.returnCodeBlock); } envFrame.allocate(RuleClauseCode.MAX_PERMANENT_VARS); - HashMap mappedVars = new HashMap(); + HashMap mappedVars = new HashMap<>(); envFrame.pVars[0] = argVars[0] = standardize(goal.getSubject(), mappedVars); envFrame.pVars[1] = argVars[1] = standardize(goal.getPredicate(), mappedVars); envFrame.pVars[2] = argVars[2] = standardize(goal.getObject(), mappedVars); @@ -641,7 +641,7 @@ public class LPInterpreter { * Tracing support - return a format set of triple queries/results. */ private String getArgTrace() { - StringBuffer temp = new StringBuffer(); + StringBuilder temp = new StringBuilder(); temp.append(PrintUtil.print(deref(argVars[0]))); temp.append(" "); temp.append(PrintUtil.print(deref(argVars[1]))); @@ -784,8 +784,10 @@ public class LPInterpreter { Functor f = (Functor) dnode.getLiteralValue(); Node[] fargs = f.getArgs(); boolean needCopy = false; - for (int i = 0; i < fargs.length; i++) { - if (fargs[i].isVariable()) { + for ( Node farg : fargs ) + { + if ( farg.isVariable() ) + { needCopy = true; break; } Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPRuleStore.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPRuleStore.java?rev=1605034&r1=1605033&r2=1605034&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPRuleStore.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPRuleStore.java Tue Jun 24 09:06:50 2014 @@ -45,7 +45,7 @@ public class LPRuleStore extends RuleSto protected Map>> indexPredicateToCodeMap; /** Set of predicates which should be tabled */ - protected HashSet tabledPredicates = new HashSet(); + protected HashSet tabledPredicates = new HashSet<>(); /** Threshold for number of rule entries in a predicate bucket before second level indexing kicks in */ private static final int INDEX_THRESHOLD = 20; @@ -164,27 +164,31 @@ public class LPRuleStore extends RuleSto protected void compileAll() { isCompiled = true; - predicateToCodeMap = new HashMap>(); - allRuleClauseCodes = new ArrayList(); - indexPredicateToCodeMap = new HashMap>>(); - for (Iterator ri = getAllRules().iterator(); ri.hasNext(); ) { - Rule r = ri.next(); - ClauseEntry term = r.getHeadElement(0); - if (term instanceof TriplePattern) { - RuleClauseCode code = new RuleClauseCode(r); - allRuleClauseCodes.add(code); - Node predicate = ((TriplePattern)term).getPredicate(); - if (predicate.isVariable()) { + predicateToCodeMap = new HashMap<>(); + allRuleClauseCodes = new ArrayList<>(); + indexPredicateToCodeMap = new HashMap<>(); + for ( Rule r : getAllRules() ) + { + ClauseEntry term = r.getHeadElement( 0 ); + if ( term instanceof TriplePattern ) + { + RuleClauseCode code = new RuleClauseCode( r ); + allRuleClauseCodes.add( code ); + Node predicate = ( (TriplePattern) term ).getPredicate(); + if ( predicate.isVariable() ) + { predicate = Node_RuleVariable.WILD; } - List predicateCode = predicateToCodeMap.get(predicate); - if (predicateCode == null) { - predicateCode = new ArrayList(); - predicateToCodeMap.put(predicate, predicateCode); - } - predicateCode.add(code); - if (predicateCode.size() > INDEX_THRESHOLD) { - indexPredicateToCodeMap.put(predicate, new HashMap>()); + List predicateCode = predicateToCodeMap.get( predicate ); + if ( predicateCode == null ) + { + predicateCode = new ArrayList<>(); + predicateToCodeMap.put( predicate, predicateCode ); + } + predicateCode.add( code ); + if ( predicateCode.size() > INDEX_THRESHOLD ) + { + indexPredicateToCodeMap.put( predicate, new HashMap>() ); } } } @@ -192,58 +196,66 @@ public class LPRuleStore extends RuleSto // Now add the wild card rules into the list for each non-wild predicate) List wildRules = predicateToCodeMap.get(Node_RuleVariable.WILD); if (wildRules != null) { - for (Iterator>> i = predicateToCodeMap.entrySet().iterator(); i.hasNext(); ) { - Map.Entry> entry = i.next(); + for ( Map.Entry> entry : predicateToCodeMap.entrySet() ) + { Node predicate = entry.getKey(); List predicateCode = entry.getValue(); - if (predicate != Node_RuleVariable.WILD) { - predicateCode.addAll(wildRules); + if ( predicate != Node_RuleVariable.WILD ) + { + predicateCode.addAll( wildRules ); } } } indexPredicateToCodeMap.put(Node_RuleVariable.WILD, new HashMap>()); // Now built any required two level indices - for (Iterator>>> i = indexPredicateToCodeMap.entrySet().iterator(); i.hasNext(); ) { - Map.Entry>> entry = i.next(); + for ( Map.Entry>> entry : indexPredicateToCodeMap.entrySet() ) + { Node predicate = entry.getKey(); Map> predicateMap = entry.getValue(); - List wildRulesForPredicate = new ArrayList(); - List allRulesForPredicate = predicate.isVariable() ? allRuleClauseCodes : predicateToCodeMap.get(predicate); - for (Iterator j = allRulesForPredicate.iterator(); j.hasNext(); ) { + List wildRulesForPredicate = new ArrayList<>(); + List allRulesForPredicate = + predicate.isVariable() ? allRuleClauseCodes : predicateToCodeMap.get( predicate ); + for ( Iterator j = allRulesForPredicate.iterator(); j.hasNext(); ) + { RuleClauseCode code = j.next(); - ClauseEntry head = code.getRule().getHeadElement(0); + ClauseEntry head = code.getRule().getHeadElement( 0 ); boolean indexed = false; - if (head instanceof TriplePattern) { - Node objectPattern = ((TriplePattern)head).getObject(); - if (!objectPattern.isVariable() && !Functor.isFunctor(objectPattern)) { + if ( head instanceof TriplePattern ) + { + Node objectPattern = ( (TriplePattern) head ).getObject(); + if ( !objectPattern.isVariable() && !Functor.isFunctor( objectPattern ) ) + { // Index against object - List indexedCode = predicateMap.get(objectPattern); - if (indexedCode == null) { - indexedCode = new ArrayList(); - predicateMap.put(objectPattern, indexedCode); + List indexedCode = predicateMap.get( objectPattern ); + if ( indexedCode == null ) + { + indexedCode = new ArrayList<>(); + predicateMap.put( objectPattern, indexedCode ); } - indexedCode.add(code); + indexedCode.add( code ); indexed = true; } } - if (!indexed) { - wildRulesForPredicate.add(code); + if ( !indexed ) + { + wildRulesForPredicate.add( code ); } } // Now fold the rules that apply to any index entry into all the indexed entries - for (Iterator>> k = predicateMap.entrySet().iterator(); k.hasNext(); ) { + for ( Iterator>> k = predicateMap.entrySet().iterator(); k.hasNext(); ) + { Map.Entry> ent = k.next(); Node pred = ent.getKey(); List predicateCode = ent.getValue(); - predicateCode.addAll(wildRulesForPredicate); + predicateCode.addAll( wildRulesForPredicate ); } } // Now compile all the clauses - for (Iterator i = allRuleClauseCodes.iterator(); i.hasNext(); ) { - RuleClauseCode code = i.next(); - code.compile(this); + for ( RuleClauseCode code : allRuleClauseCodes ) + { + code.compile( this ); } }