/** Convert strings to a List of {@link Node Nodes}. */ public static List<Node> convertToListNodes(List<String> namedGraphs) { List<Node> nodes = ListUtils.toList( namedGraphs.stream().map(NodeFactory::createURI) ); return nodes; }
private static Set<Integer> set(int... values) { return new HashSet<>(asList(values)) ; }
public static <T> void print(IndentedWriter out, List<T> list) { print(out, list, " "); }
public static void testIndexContents(Index index, int... records) { List<Integer> x = toIntList(index.iterator()) ; // Make a unique list of expected records. Remove duplicates List<Integer> y = unique(asList(records)) ; assertEquals("Expected records size and tree size different", y.size(), index.size()) ; assertEquals("Expected records size and iteration over all keys are of different sizes", y.size(), x.size()) ; if ( index instanceof RangeIndex ) { // Check sorted order for ( int i = 0 ; i < x.size() - 2 ; i++ ) { if ( x.get(i) > x.get(i + 1) ) { fail("check failed: " + strings(records)) ; return ; } } } // Check each expected record is in the tree for ( int k : y ) { Record rec = intToRecord(k) ; Record r2 = index.find(rec) ; assertNotNull(r2) ; } } }
@Test public void list03() { List<Integer> x = new ArrayList<>() ; x = unique(x) ; assertEquals(0, x.size()) ; test(x) ; }
/** * Construct a mapping - the elements are the mappings of a tuple * originally in the order 0,1,2,... so SPO{@literal ->}POS is 2,0,1 (SPO{@literal ->}POS so S{@literal ->}2, * P{@literal ->}0, O{@literal ->}1) and not 1,2,0 (which is the extraction mapping). The label is * just a label and is not interpreted here. */ private TupleMap(String label, int... elements) { this.len = elements.length ; this.label = label; this.putTransform = new int[elements.length]; Arrays.fill(putTransform, -1); this.getTransform = new int[elements.length]; Arrays.fill(getTransform, -1); for ( int i = 0 ; i < elements.length ; i++ ) { int x = elements[i]; if ( x < 0 || x >= elements.length ) throw new IllegalArgumentException("Out of range: " + x); // Checking if ( putTransform[i] != -1 || getTransform[x] != -1 ) throw new IllegalArgumentException("Inconsistent: " + ListUtils.str(elements)); putTransform[i] = x; // The elements are the putTransform. getTransform[x] = i; } }
public static <T> void assertEqualsUnordered(String msg, List<T> list1, List<T> list2) { if ( ! ListUtils.equalsUnordered(list1, list2) ) fail(msg(msg, list1, list2)) ; }
List<T> c2 = new ArrayList<>(c); c2.remove(obj); List<List<T>> x2 = permute(c2);
public static void testIndexContents(Index index, int... records) { List<Integer> x = toIntList(index.iterator()) ; // Make a unique list of expected records. Remove duplicates List<Integer> y = unique(asList(records)) ; assertEquals("Expected records size and tree size different", y.size(), index.size()) ; assertEquals("Expected records size and iteration over all keys are of different sizes", y.size(), x.size()) ; if ( index instanceof RangeIndex ) { // Check sorted order for ( int i = 0 ; i < x.size() - 2 ; i++ ) { if ( x.get(i) > x.get(i + 1) ) { fail("check failed: " + strings(records)) ; return ; } } } // Check each expected record is in the tree for ( int k : y ) { Record rec = intToRecord(k) ; Record r2 = index.find(rec) ; assertNotNull(r2) ; } } }
@Test public void list05() { List<Integer> x = Arrays.asList(1,1,2,3,1,1,3) ; x = unique(x) ; assertEquals(3, x.size()) ; test(x, 1,2,3) ; }
/** * Construct a mapping - the elements are the mappings of a tuple * originally in the order 0,1,2,... so SPO{@literal ->}POS is 2,0,1 (SPO{@literal ->}POS so S{@literal ->}2, * P{@literal ->}0, O{@literal ->}1) and not 1,2,0 (which is the extraction mapping). The label is * just a label and is not interpreted here. */ private TupleMap(String label, int... elements) { this.len = elements.length ; this.label = label; this.putTransform = new int[elements.length]; Arrays.fill(putTransform, -1); this.getTransform = new int[elements.length]; Arrays.fill(getTransform, -1); for ( int i = 0 ; i < elements.length ; i++ ) { int x = elements[i]; if ( x < 0 || x >= elements.length ) throw new IllegalArgumentException("Out of range: " + x); // Checking if ( putTransform[i] != -1 || getTransform[x] != -1 ) throw new IllegalArgumentException("Inconsistent: " + ListUtils.str(elements)); putTransform[i] = x; // The elements are the putTransform. getTransform[x] = i; } }
private static void test(Graph graph, Node start, String string, Node[] expectedNodes, boolean directionForward, boolean ordered) { Path p = PathParser.parse(string, pmap) ; Iterator<Node> resultsIter = directionForward ? PathEval.eval(graph, start, p, ARQ.getContext()) : PathEval.evalReverse(graph, start, p, ARQ.getContext()) ; List<Node> results = Iter.toList(resultsIter) ; List<Node> expected = Arrays.asList(expectedNodes) ; Assert.assertTrue("expected:"+expected+", got:"+results, equalsUnordered(expected, results)) ; if ( ordered ) Assert.assertEquals("expected(ordered)", expected, results) ; } }
List<T> c2 = new ArrayList<>(c); c2.remove(obj); List<List<T>> x2 = permute(c2);
public static <T> List<T> unique(List<T> list) { return toList(list.stream().distinct()); }
@Test public void list01() { List<Integer> x = Arrays.asList(1,2,3) ; x = unique(x) ; assertEquals(3, x.size()) ; test(x, 1,2,3) ; }
public static <T> void print(IndentedWriter out, List<T> list) { print(out, list, " ") ; }
/** Construct a column map - the elements are the * mappings of a tuple originally in the order 0,1,2,... * so SPO->POS is 2,0,1 (SPO->POS so S->2, P->0, O->1) * and not 1,2,0 (which is the extraction mapping). * The label is just a label and is not interpreted. */ public ColumnMap(String label, int...elements) { this.label = label ; this.insertOrder = new int[elements.length] ; System.arraycopy(elements, 0, elements, 0, elements.length) ; Arrays.fill(insertOrder, -1) ; this.fetchOrder = new int[elements.length] ; Arrays.fill(fetchOrder, -1) ; for ( int i = 0 ; i < elements.length ; i++ ) { int x = elements[i] ; if ( x < 0 || x >= elements.length) throw new IllegalArgumentException("Out of range: "+x) ; // Checking if ( insertOrder[i] != -1 || fetchOrder[x] != -1 ) throw new IllegalArgumentException("Inconsistent: "+ListUtils.str(elements)) ; insertOrder[i] = x ; fetchOrder[x] = i ; } }
private static void test(Set<Integer> x, int...values) { List<Integer> y = asList(values) ; assertEquals(y.size(), x.size()) ; for ( Integer aY : y ) { assertTrue( x.contains( aY ) ); } } }
private void test(String queryStr) { Query ast = QueryFactory.create(queryStr); List<Binding> x1 = exec(queryStr, QueryEngineRef.getFactory()); List<Binding> x2 = exec(queryStr, QueryEngineMain.getFactory()); boolean b = ListUtils.equalsUnordered(x1, x2); // if ( !b ) { // System.out.println("Ref: "+x1); // System.out.println("Main: "+x2); // } assertTrue("Ref != main", b); }