void left(Node node) { String str = node.getState(); String parent = node.getParent(); Node newState = new Node(); int a = str.indexOf("0"); char temp; char[] s = str.toCharArray(); String newStr; if (a != 0) { temp = s[a - 1]; s[a - 1] = '0'; s[a] = temp; newStr = this.gString(s); newState.setState(newStr); newState.setParent(str); // newState.setLevel(node.getLevel()+1); // newState.setHeuristic(newState.calculateHeuristic(goal)); // newState.setFvalue(newState.getHeuristic() + newState.getLevel()); add(newState, map.get(str) + 1); // add(s,map.get(str)+1); if (newStr.equals("www0bbb")) { System.out.println( "Solution found after searching through " + map.get(newStr) + " states of the tree"); printSolution(); System.exit(0); } } }
@Test public void testCompareWithRemovedItem() throws Exception { final Collection<String> working = new LinkedList<String>(); final Collection<String> base = new LinkedList<String>(Arrays.asList("foo")); final CollectionNode node = differ.compare(working, base); assertThat(node.hasChanges(), is(true)); final Node child = node.getChild(PropertyPath.createBuilder().withRoot().withCollectionItem("foo").build()); assertThat(child.getState(), is(Node.State.REMOVED)); }
void add(Node node, int n) { String tempState = ""; String tempParent = ""; if (node != null) { tempState = node.getState(); tempParent = node.getParent(); } if (!map.containsKey(tempState)) { map.put(tempState, n); // s.push(str); parentMap.put(tempState, tempParent); this.s.push(node); } }
@Test public void testCompareWithChangedItem() throws Exception { final List<ObjectWithHashCodeAndEquals> working = Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "1")); final List<ObjectWithHashCodeAndEquals> base = Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "2")); final CollectionNode node = differ.compare(working, base); assertThat(node.hasChanges(), is(true)); final PropertyPath propertyPath = PropertyPath.createBuilder() .withRoot() .withCollectionItem(new ObjectWithHashCodeAndEquals("foo")) .build(); final Node child = node.getChild(propertyPath); assertThat(child.getState(), is(Node.State.CHANGED)); }