+ public void sortStatement(List<Statement> list1, List<Statement> list2) {\r
+ Collections.sort(list1,scomp);\r
+ Collections.sort(list2,scomp);\r
+ \r
+ List<Statement> sorted1 = new ArrayList<Statement>(list1.size());\r
+ List<Statement> sorted2 = new ArrayList<Statement>(list2.size());\r
+ sorted1.addAll(list1);\r
+ sorted2.addAll(list2);\r
+ \r
+ int ss1 = 0;\r
+ int ss2 = 0;\r
+ for (int i = 0; i < list1.size(); ) {\r
+ Statement s1 = list1.get(i);\r
+ int same1 = sameRel(list1, i); \r
+ for (int j = 0; j < list2.size(); j++) {\r
+ Statement s2 = list2.get(j);\r
+ if (scomp.compare(s1, s2) == 0) {\r
+ int same2 = sameRel(list2, j);\r
+ copy(sorted1,ss1,list1,i,same1);\r
+ ss1 += same1;\r
+ copy(sorted2,ss2,list2,j,same2);\r
+ ss2 += same2;\r
+ break;\r
+ }\r
+ }\r
+ i+= same1;\r
+ }\r
+ if (ss1 < sorted1.size()) {\r
+ for (Statement s : list1) {\r
+ if (!sorted1.contains(s)) {\r
+ sorted1.set(ss1,s);\r
+ ss1++;\r
+ }\r
+ }\r
+ }\r
+ if (ss2 < sorted2.size()) {\r
+ for (Statement s : list2) {\r
+ if (!sorted2.contains(s)) {\r
+ sorted2.set(ss2,s);\r
+ ss2++;\r
+ }\r
+ }\r
+ }\r
+ \r
+ list1.clear();\r
+ list2.clear();\r
+ list1.addAll(sorted1);\r
+ list2.addAll(sorted2);\r
+ }\r
+ \r
+ public <T> void copy(List<T> to, int toIndex, List<T> from, int fromIndex, int amount) {\r
+ for (int i = 0; i < amount; i++) {\r
+ to.set(toIndex + i, from.get(fromIndex+ i));\r
+ }\r
+ }\r
+ \r
+ public void sortResource(List<Resource> list1, List<Resource> list2) {\r
+ Collections.sort(list1,rcomp);\r
+ int js = 0;\r
+ for (int i = 0; i < list1.size(); i++) {\r
+ Resource s1 = list1.get(i);\r
+ for (int j = js; j < list2.size(); j++) {\r
+ Resource s2 = list2.get(j);\r
+ if (rcomp.compare(s1, s2) == 0) {\r
+ Resource t = list2.get(js);\r
+ list2.set(js, s2);\r
+ list2.set(j, t);\r
+ break;\r
+ }\r
+ }\r
+ js++;\r
+ \r
+ }\r
+ }\r
+ \r