public boolean resolveResolutions() { ArrayList<Resolution> resolutions = mResolutions; mResolutions = new ArrayList<Resolution>(); boolean allResolved = true; for (Resolution resolution : resolutions) { StringBuilder qualifiedClassName = new StringBuilder(); InfoBuilder.resolveQualifiedName( resolution.getValue(), qualifiedClassName, resolution.getInfoBuilder()); // if we still couldn't resolve it, save it for the next pass if ("".equals(qualifiedClassName.toString())) { mResolutions.add(resolution); allResolved = false; } else if ("thrownException".equals(resolution.getVariable())) { mThrownExceptions.add(InfoBuilder.Caches.obtainClass(qualifiedClassName.toString())); } } return allResolved; }
public static void main(String[] args) throws Exception { LinkedList<Clause> clauses = new LinkedList<Clause>(); // the list of the clauses // Read files and add the corresponding clauses to the linkedlist // call the resolution function on each clause against all other clauses above it. start with // the clause on the bottom. O(n^2) calls. // each resolution call may add new clauses to the linked list. to avoid redundant resolution // calls and thus prevent infinite loops, use a stack to determine which clause will be calling // the resolution function next // To implement, compare the size of the new linkedlist to the old linkedlist. if the sizes are // different (the new linkedlist has a new clause), then add the ID of the new clause(s) to the // stack // Example, linkedlist - before: <1 2 3>, after <1 2 3 4>. We would add 4 to the stack. Assuming // 4 was added after resolving clause 3, the stack would be <4 2 1>, so we would resolve 4 next. // We stop when the resolution function returns "false", which means that the resolution found // contradicting clauses. Otherwise, if the loop continues to completion, then every clause has // been tested. // At this point, we return failure. BufferedReader fileReader; if (args.length != 1) { System.out.println("Wrong input parameters!"); System.out.println("Format:"); System.out.println("java Resolution <inputfile>"); System.exit(0); } fileReader = new BufferedReader(new FileReader(args[0])); String line = fileReader.readLine(); int clauseCount = 1; while (line != null) { String[] literals = line.split(" "); boolean[] literalValuesNegated = new boolean[literals.length]; for (int literalCount = 0; literalCount < literals.length; literalCount++) { if (literals[literalCount].charAt(0) == '~') { literals[literalCount] = literals[literalCount].substring(1); literalValuesNegated[literalCount] = true; } else { literalValuesNegated[literalCount] = false; } } clauses.add(new Clause(clauseCount, literals, literalValuesNegated)); clauseCount++; line = fileReader.readLine(); } /*String[] testString1 = {"z", "y", "x"}; String[] testString2 = {"y", "z", "x"}; boolean[] testBool1 = {true, false, true}; boolean[] testBool2 = {true, true, true}; Clause testClause1 = new Clause(1, testString1, testBool1); Clause testClause2 = new Clause(2, testString2, testBool2); testClause1.resolution(testClause2, clauses); Clause resultClause = clauses.getFirst(); resultClause.outputClause(); String[] testString3 = {"z"}; String[] testString4 = {"z"}; boolean[] testBool3 = {false}; boolean[] testBool4 = {true}; Clause testClause3 = new Clause(3, testString3, testBool3); Clause testClause4 = new Clause(4, testString4, testBool4); testClause3.resolution(testClause4, clauses); resultClause = clauses.get(1); resultClause.outputClause(); System.out.println("End");*/ /*String[] testString1 = {"z", "y", "x"}; String[] testString2 = {"y", "z", "x"}; boolean[] testBool1 = {true, false, true}; boolean[] testBool2 = {true, true, true}; clauses.add(new Clause(1, testString1, testBool1)); clauses.add(new Clause(2, testString2, testBool2));*/ /*String[] testString1 = {"z"}; String[] testString2 = {"z"}; boolean[] testBool1 = {true}; boolean[] testBool2 = {false}; clauses.add(new Clause(1, testString1, testBool1)); clauses.add(new Clause(2, testString2, testBool2));*/ Resolution resolution = new Resolution(); if (!resolution.resolve(clauses)) // if the resolution results in false being generated { resolution.printProofTree(clauses.getLast(), clauses); } else { System.out.println("Failure"); } System.out.println("Size of final clause set: " + clauses.size()); }
/** * Asynchronously sends a message to multiple servers, potentially multiple times, registering a * listener to receive a callback on success or exception. Multiple asynchronous lookups can be * performed in parallel. Since the callback may be invoked before the function returns, external * synchronization is necessary. * * @param query The query to send * @param listener The object containing the callbacks. * @return An identifier, which is also a parameter in the callback */ public Object sendAsync(final Message query, final ResolverListener listener) { Resolution res = new Resolution(this, query); res.startAsync(listener); return res; }
/** * Sends a message and waits for a response. Multiple servers are queried, and queries are sent * multiple times until either a successful response is received, or it is clear that there is no * successful response. * * @param query The query to send. * @return The response. * @throws IOException An error occurred while sending or receiving. */ public Message send(Message query) throws IOException { Resolution res = new Resolution(this, query); return res.start(); }