/** * Create a tuple from an array of elements. The array is not copied and * should not be modified after this call. * <p> * There is also a {@linkplain TupleBuilder} which does create an idendent * copy, in case that style is preferrable for creating tuples. */ public static <X> Tuple<X> create(X[] elements) { return new Tuple<X>(elements) ; }
/** Apply to an <em>unmapped</em> tuple to get the i'th slot after mapping : SPO->POS : 0'th slot is P from SPO */ public <T> T fetchSlot(int idx, Tuple<T> tuple) { idx = fetchOrder[idx] ; // Apply the reverse mapping as we are doing zero is P, so it's an unmap. return tuple.get(idx) ; }
/** Equality of tuples is based on equality of the elements in the tuple */ @Override public boolean equals(Object other) { if ( this == other ) return true ; if ( !(other instanceof Tuple<? >) ) return false ; Tuple<? > x = (Tuple<? >)other ; if ( x.size() != this.size() ) return false ; for ( int i = 0 ; i < tuple.length ; i++ ) { Object obj1 = tuple[i] ; Object obj2 = x.tuple[i] ; if ( !Lib.equal(obj1, obj2) ) return false ; } return true ; }
/** Split a file name into path and filename. Nulls returned if don't make sense. */ public static Tuple<String> splitDirFile(String filename) { String path = null ; String fn = filename ; int j = filename.lastIndexOf('/') ; if ( j < 0 ) j = filename.lastIndexOf('\\') ; if ( j >= 0 ) { path = filename.substring(0, j) ; fn = filename.substring(j+1) ; } return Tuple.createTuple(path, fn) ; }
public static <X> Tuple<X> createTuple(/* @SuppressWarnings("unchecked") */X... elements) { X[] els = elements ; // ArrayUtils.copy(elements) ; return create(els) ; }
/** Apply to a <em>mapped</em> tuple to get the i'th slot as it appears after mapping : SPO->POS : 0'th slot is S from POS */ public <T> T mapSlot(int idx, Tuple<T> tuple) { idx = insertOrder[idx] ; return tuple.get(idx) ; }
/** Split a file name into path, basename and extension. Nulls returned if don't make sense. */ public static Tuple<String> splitDirBaseExt(String filename) { String path = null ; String basename = filename ; String ext = null ; int j = filename.lastIndexOf('/') ; if ( j < 0 ) j = filename.lastIndexOf('\\') ; if ( j >= 0 ) { path = filename.substring(0, j) ; basename = filename.substring(j+1) ; } int i = basename.lastIndexOf('.') ; if ( i > -1 ) { ext = basename.substring(i+1) ; basename = basename.substring(0, i) ; } return Tuple.createTuple(path, basename, ext) ; }
@Override public Tuple<T> convert(Tuple<T> tuple) { T[] x = ArrayUtils.copy(tuple.tuple, 0, prefixLength) ; return Tuple.create(x) ; } } ;
@Override public T convert(Tuple<T> tuple) { return tuple.get(slot) ; } } ;
@SuppressWarnings("unchecked") public static Tuple<Set<Var>> mentionedVarsByPosition(Op... ops) { Set<Var> graphAcc = collector() ; Set<Var> subjAcc = collector() ; Set<Var> predAcc = collector() ; Set<Var> objAcc = collector() ; Set<Var> unknownAcc = collector() ; OpVarsPatternWithPositions visitor = new OpVarsPatternWithPositions(graphAcc, subjAcc, predAcc, objAcc, unknownAcc, false); for (Op op : ops) OpWalker.walk(op, visitor); return Tuple.createTuple(graphAcc, subjAcc, predAcc, objAcc, unknownAcc); }
public Tuple<T> build() { @SuppressWarnings("unchecked") T[] elts = (T[])new Object[x.size()] ; // Copy contents, should not create a new array because elts // is created with the right size so elts == elts2 T[] elts2 = x.toArray(elts) ; return new Tuple<T>(elts2) ; } }
if (varsByPosition.size() != 5) return false; safeVars.addAll(varsByPosition.get(0)); safeVars.addAll(varsByPosition.get(1)); safeVars.addAll(varsByPosition.get(2)); Set<Var> unsafeVars = new HashSet<Var>(); unsafeVars.addAll(varsByPosition.get(3)); unsafeVars.addAll(varsByPosition.get(4)); boolean lhsSafe = true, rhsSafe = true; if (unsafeVars.size() > 0) {
@SuppressWarnings("unchecked") public static Tuple<Set<Var>> mentionedVarsByPosition(Op op) { Set<Var> graphAcc = collector() ; Set<Var> subjAcc = collector() ; Set<Var> predAcc = collector() ; Set<Var> objAcc = collector() ; Set<Var> unknownAcc = collector() ; OpVarsPatternWithPositions visitor = new OpVarsPatternWithPositions(graphAcc, subjAcc, predAcc, objAcc, unknownAcc, false); OpWalker.walk(op, visitor); return Tuple.createTuple(graphAcc, subjAcc, predAcc, objAcc, unknownAcc); }
if (varsByPosition.size() != 5) return false; safeVars.addAll(varsByPosition.get(0)); safeVars.addAll(varsByPosition.get(1)); safeVars.addAll(varsByPosition.get(2)); Set<Var> unsafeVars = new HashSet<Var>(); unsafeVars.addAll(varsByPosition.get(3)); unsafeVars.addAll(varsByPosition.get(4)); boolean lhsSafe = true, rhsSafe = true; if (unsafeVars.size() > 0) {