target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test(expected = NullPointerException.class) public void test_comparator_indexOf_null_arguments() { indexOf(null, new String[] {null}, String.CASE_INSENSITIVE_ORDER); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_comparator_indexOf_null_arguments_null_comparator() { indexOf(null, new String[] {null}, null); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_comparator_indexOf_illegal_arg() { indexOf(10, null, null); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_bounded_comparator_indexOf() { String[] ary = new String[] {"a", "b", "c", "d", "B"}; assertEquals(1, indexOf("B", ary, 0, 5, String.CASE_INSENSITIVE_ORDER)); assertEquals(4, indexOf("b", ary, 2, 5, String.CASE_INSENSITIVE_ORDER)); assertEquals(-1, indexOf("b", ary, 2, 4, String.CASE_INSENSITIVE_ORDER)); assertEquals(-1, indexOf("b", ary, 0, 0, String.CASE_INSENSITIVE_ORDER)); assertEquals(-1, indexOf("b", ary, 5, 5, String.CASE_INSENSITIVE_ORDER)); assertEquals(-1, indexOf("e", ary, 0, 5, String.CASE_INSENSITIVE_ORDER)); assertEquals(1, indexOf("b", ary, 0, 5, null)); assertEquals(4, indexOf("B", ary, 0, 5, null)); assertEquals(-1, indexOf("b", ary, 2, 5, null)); assertEquals(-1, indexOf("b", ary, 2, 4, null)); assertEquals(-1, indexOf("b", ary, 0, 0, null)); assertEquals(-1, indexOf("b", ary, 5, 5, null)); assertEquals(-1, indexOf("e", ary, 0, 5, null)); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_bounded_comparator_indexOf_illegal_arg() { String[] ary = new String[] {"a", "b", "c", "d", "B"}; try { indexOf("b", null, 2, 1, null); fail(); } catch (NullPointerException ignored) {} try { indexOf("b", ary, -2, -1, null); fail(); } catch (IndexOutOfBoundsException ignored) {} try { indexOf("b", ary, -1, 0, null); fail(); } catch (IndexOutOfBoundsException ignored) {} try { indexOf("b", ary, 5, 6, null); fail(); } catch (IndexOutOfBoundsException ignored) {} try { indexOf("b", ary, 2, 1, null); fail(); } catch (IllegalArgumentException ignored) {} } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_bounded_comparator_indexOf_null_arguments() { indexOf(null, new String[] {null}, 0, 1, String.CASE_INSENSITIVE_ORDER); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_bounded_comparator_indexOf_null_arguments_null_comparator() { indexOf(null, new String[] {null}, 0, 1, null); } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_lastIndexOf() { Integer[] ary = new Integer[] {10, 11, 12, 13, null, 10, 11, 12, 13, null}; assertEquals(9, lastIndexOf(null, ary)); assertEquals(6, lastIndexOf(11, ary)); assertEquals(-1, lastIndexOf(42, ary)); assertEquals(-1, lastIndexOf(null, new Integer[] {1, 2, 3})); } | public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_lastIndexOf_illegal_arg() { lastIndexOf(10, null); } | public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int lastIndexOf(T element, T[] array) { if (element == null) { for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { return i; } } } else { for (int i = array.length - 1; i >= 0; i--) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_collectProperties_composite_type_with_diamond() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(C.class); assertEquals(3, result.size()); assertEquals("c", result.get(0).getName()); assertEquals("a", result.get(1).getName()); assertEquals("b", result.get(2).getName()); result = collectProperties(E.class); assertEquals(5, result.size()); assertEquals("e", result.get(0).getName()); assertEquals("c", result.get(1).getName()); assertEquals("d", result.get(2).getName()); assertEquals("a", result.get(3).getName()); assertEquals("b", result.get(4).getName()); } | static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } |
@Test public void test_check_range() { checkRange(0, 0, 2); checkRange(0, 2, 2); checkRange(2, 2, 2); try { checkRange(-1, 2, 2); fail(); } catch (IndexOutOfBoundsException ignored) {} try { checkRange( 0, 3, 2); fail(); } catch (IndexOutOfBoundsException ignored) {} try { checkRange( 7, 6, 2); fail(); } catch (IndexOutOfBoundsException ignored) {} try { checkRange( 1, 0, 2); fail(); } catch (IllegalArgumentException ignored) {} } | public static void checkRange(int fromIndex, int toIndex, int length) { if (fromIndex < 0 || toIndex > length) { throw new IndexOutOfBoundsException( String.format("range [%d, %d) is outside bounds [%d, %d)", fromIndex, toIndex, 0, length)); } if (fromIndex > toIndex) { throw new IllegalArgumentException( String.format("fromIndex %d cannot be greater than toIndex %d", fromIndex, toIndex)); } } | ArrayTools { public static void checkRange(int fromIndex, int toIndex, int length) { if (fromIndex < 0 || toIndex > length) { throw new IndexOutOfBoundsException( String.format("range [%d, %d) is outside bounds [%d, %d)", fromIndex, toIndex, 0, length)); } if (fromIndex > toIndex) { throw new IllegalArgumentException( String.format("fromIndex %d cannot be greater than toIndex %d", fromIndex, toIndex)); } } } | ArrayTools { public static void checkRange(int fromIndex, int toIndex, int length) { if (fromIndex < 0 || toIndex > length) { throw new IndexOutOfBoundsException( String.format("range [%d, %d) is outside bounds [%d, %d)", fromIndex, toIndex, 0, length)); } if (fromIndex > toIndex) { throw new IllegalArgumentException( String.format("fromIndex %d cannot be greater than toIndex %d", fromIndex, toIndex)); } } private ArrayTools(); } | ArrayTools { public static void checkRange(int fromIndex, int toIndex, int length) { if (fromIndex < 0 || toIndex > length) { throw new IndexOutOfBoundsException( String.format("range [%d, %d) is outside bounds [%d, %d)", fromIndex, toIndex, 0, length)); } if (fromIndex > toIndex) { throw new IllegalArgumentException( String.format("fromIndex %d cannot be greater than toIndex %d", fromIndex, toIndex)); } } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static void checkRange(int fromIndex, int toIndex, int length) { if (fromIndex < 0 || toIndex > length) { throw new IndexOutOfBoundsException( String.format("range [%d, %d) is outside bounds [%d, %d)", fromIndex, toIndex, 0, length)); } if (fromIndex > toIndex) { throw new IllegalArgumentException( String.format("fromIndex %d cannot be greater than toIndex %d", fromIndex, toIndex)); } } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_sort() { Integer[] a = new Integer[] {3, 2, 1}; assertArrayEquals(new Integer[] {1, 2, 3}, sort(a)); assertSame(a, sort(a)); } | public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_sort_nulls() { Integer[] a = new Integer[] {null, null}; sort(a); } | public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_sort_comparator() { Integer[] a = new Integer[] {2, 1, 3}; assertArrayEquals(new Integer[] {1, 2, 3}, sort(a, null)); assertSame(a, sort(a, null)); assertArrayEquals(new Integer[] {3, 2, 1}, sort(a, Collections.reverseOrder())); assertSame(a, sort(a, Collections.reverseOrder())); } | public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test(expected = NullPointerException.class) public void test_sort_comparator_nulls() { String[] a = new String[] {null, null}; sort(a, String.CASE_INSENSITIVE_ORDER); } | public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> T[] sort(T[] a) { Arrays.sort(a); return a; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_indexOf_bad_types() { final Object[] EMPTY = new Object[0]; final Object notComparable = new Object(); @SuppressWarnings("unchecked") Comparator<Object> comparator = (Comparator)String.CASE_INSENSITIVE_ORDER; assertEquals(-1, indexOf(notComparable, EMPTY, null)); assertEquals(-1, indexOf(null, EMPTY, null)); assertEquals(-1, indexOf(notComparable, EMPTY, comparator)); assertEquals(-1, indexOf(null, EMPTY, comparator)); try { indexOf(notComparable, new Object[] {"a"}, null); fail(); } catch (ClassCastException ignored) {} try { indexOf(null, new Object[] {"a"}, null); fail(); } catch (NullPointerException ignored) {} try { indexOf(notComparable, new Object[] {"a"}, comparator); fail(); } catch (ClassCastException ignored) {} try { indexOf(null, new Object[] {"a"}, comparator); fail(); } catch (NullPointerException ignored) {} } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_indexOf_range_bad_types() { final Object[] items = new Object[] {"a", "b", "c"}; final Object notComparable = new Object(); @SuppressWarnings("unchecked") Comparator<Object> comparator = (Comparator)String.CASE_INSENSITIVE_ORDER; assertEquals(-1, indexOf(notComparable, items, 1, 1, null)); assertEquals(-1, indexOf(null, items, 1, 1, null)); assertEquals(-1, indexOf(notComparable, items, 1, 1, comparator)); assertEquals(-1, indexOf(null, items, 1, 1, comparator)); try { indexOf(notComparable, items, 1, 2, null); fail(); } catch (ClassCastException ignored) {} try { indexOf(null, items, 1, 2, null); fail(); } catch (NullPointerException ignored) {} try { indexOf(notComparable, items, 1, 2, comparator); fail(); } catch (ClassCastException ignored) {} try { indexOf(null, items, 1, 2, comparator); fail(); } catch (NullPointerException ignored) {} } | public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); } | ArrayTools { public static <T> int indexOf(T element, T[] array) { if (element == null) { for (int i = 0; i < array.length; i++) { if (array[i] == null) { return i; } } } else { for (int i = 0; i < array.length; i++) { if (element.equals(array[i])) { return i; } } } return -1; } private ArrayTools(); static int indexOf(T element, T[] array); static int indexOf(T element, T[] array, int fromIndex, int toIndex); static int indexOf(T element, T[] array, Comparator<? super T> comparator); static int indexOf(T element, T[] array, int fromIndex, int toIndex, Comparator<? super T> comparator); static int lastIndexOf(T element, T[] array); static void checkRange(int fromIndex, int toIndex, int length); static T[] sort(T[] a); static T[] sort(T[] a, Comparator<? super T> c); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; static final Type[] EMPTY_TYPE_ARRAY; } |
@Test public void test_daemon_thread_factory() { Runnable r = mock(Runnable.class); Thread thread = new Thread(r); thread.setDaemon(false); ThreadFactory factory = mock(ThreadFactory.class); when(factory.newThread(any(Runnable.class))).thenReturn(thread); assertSame(thread, newDaemonThreadFactory(factory).newThread(r)); assertTrue(thread.isDaemon()); verify(factory).newThread(r); } | public static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); if (!t.isDaemon()) { t.setDaemon(true); } return t; } }; } | ThreadTools { public static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); if (!t.isDaemon()) { t.setDaemon(true); } return t; } }; } } | ThreadTools { public static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); if (!t.isDaemon()) { t.setDaemon(true); } return t; } }; } private ThreadTools(); } | ThreadTools { public static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); if (!t.isDaemon()) { t.setDaemon(true); } return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } | ThreadTools { public static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); if (!t.isDaemon()) { t.setDaemon(true); } return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } |
@Test public void test_naming_thread_factory() { Runnable r = mock(Runnable.class); Thread thread = new Thread(r); thread.setName("Foo"); ThreadFactory factory = mock(ThreadFactory.class); when(factory.newThread(any(Runnable.class))).thenReturn(thread); assertSame(thread, newNamingThreadFactory("#%d %s", factory).newThread(r)); assertEquals("#0 Foo", thread.getName()); verify(factory).newThread(r); } | public static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped) { String.format(format, 0, "test name"); Objects.requireNonNull(wrapped); final AtomicInteger threadNumber = new AtomicInteger(0); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setName(String.format(format, threadNumber.getAndIncrement(), t.getName())); return t; } }; } | ThreadTools { public static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped) { String.format(format, 0, "test name"); Objects.requireNonNull(wrapped); final AtomicInteger threadNumber = new AtomicInteger(0); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setName(String.format(format, threadNumber.getAndIncrement(), t.getName())); return t; } }; } } | ThreadTools { public static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped) { String.format(format, 0, "test name"); Objects.requireNonNull(wrapped); final AtomicInteger threadNumber = new AtomicInteger(0); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setName(String.format(format, threadNumber.getAndIncrement(), t.getName())); return t; } }; } private ThreadTools(); } | ThreadTools { public static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped) { String.format(format, 0, "test name"); Objects.requireNonNull(wrapped); final AtomicInteger threadNumber = new AtomicInteger(0); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setName(String.format(format, threadNumber.getAndIncrement(), t.getName())); return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } | ThreadTools { public static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped) { String.format(format, 0, "test name"); Objects.requireNonNull(wrapped); final AtomicInteger threadNumber = new AtomicInteger(0); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setName(String.format(format, threadNumber.getAndIncrement(), t.getName())); return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } |
@Test public void test_context_thread_factory() { Runnable r = mock(Runnable.class); Thread thread = new Thread(r); ThreadFactory factory = mock(ThreadFactory.class); when(factory.newThread(any(Runnable.class))).thenReturn(thread); ClassLoader cl = new URLClassLoader(new URL[] {}); assertSame(thread, newContextThreadFactory(cl, factory).newThread(r)); assertSame(cl, thread.getContextClassLoader()); verify(factory).newThread(r); } | public static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setContextClassLoader(classLoader); return t; } }; } | ThreadTools { public static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setContextClassLoader(classLoader); return t; } }; } } | ThreadTools { public static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setContextClassLoader(classLoader); return t; } }; } private ThreadTools(); } | ThreadTools { public static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setContextClassLoader(classLoader); return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } | ThreadTools { public static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped) { Objects.requireNonNull(wrapped); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = wrapped.newThread(r); t.setContextClassLoader(classLoader); return t; } }; } private ThreadTools(); static ThreadFactory newDaemonThreadFactory(final ThreadFactory wrapped); static ThreadFactory newNamingThreadFactory(final String format, final ThreadFactory wrapped); static ThreadFactory newContextThreadFactory(final ClassLoader classLoader, final ThreadFactory wrapped); } |
@Test public void test_collectProperties_with_duplicate_property_names() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(R.class); assertEquals(3, result.size()); assertEquals(R.class, result.get(0).getType()); assertEquals(P.class, result.get(1).getType()); assertEquals(Q.class, result.get(2).getType()); } | static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } |
@Test public void test_capitalize() { assertEquals("HellO", capitalize("hellO")); assertEquals("HellO", capitalize("HellO")); assertEquals("A", capitalize("a")); assertEquals("", capitalize("")); assertNull(capitalize(null)); } | public static String capitalize(String s) { return s == null || s.isEmpty() ? s : s.substring(0, 1).toUpperCase(Locale.ENGLISH) + s.substring(1); } | StringTools { public static String capitalize(String s) { return s == null || s.isEmpty() ? s : s.substring(0, 1).toUpperCase(Locale.ENGLISH) + s.substring(1); } } | StringTools { public static String capitalize(String s) { return s == null || s.isEmpty() ? s : s.substring(0, 1).toUpperCase(Locale.ENGLISH) + s.substring(1); } private StringTools(); } | StringTools { public static String capitalize(String s) { return s == null || s.isEmpty() ? s : s.substring(0, 1).toUpperCase(Locale.ENGLISH) + s.substring(1); } private StringTools(); static String capitalize(String s); } | StringTools { public static String capitalize(String s) { return s == null || s.isEmpty() ? s : s.substring(0, 1).toUpperCase(Locale.ENGLISH) + s.substring(1); } private StringTools(); static String capitalize(String s); } |
@Test public void test_coalesce() { Object x = new Object(); Object y = new Object(); assertSame(x, coalesce(x, y)); assertSame(x, coalesce(x, null)); assertNull(coalesce(null, null)); assertSame(y, coalesce(null, y)); } | public static <T> T coalesce(T x, T y) { return x != null ? x : y; } | ObjectTools { public static <T> T coalesce(T x, T y) { return x != null ? x : y; } } | ObjectTools { public static <T> T coalesce(T x, T y) { return x != null ? x : y; } private ObjectTools(); } | ObjectTools { public static <T> T coalesce(T x, T y) { return x != null ? x : y; } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } | ObjectTools { public static <T> T coalesce(T x, T y) { return x != null ? x : y; } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } |
@Test public void test_compare() { assertEquals( 0, compare(1, 1, null)); assertEquals(-1, compare(0, 1, null)); assertEquals( 1, compare(1, 0, null)); assertEquals( 0, compare(1, 1, Collections.reverseOrder())); assertEquals( 1, compare(0, 1, Collections.reverseOrder())); assertEquals(-1, compare(1, 0, Collections.reverseOrder())); } | public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } |
@Test public void test_compare_nulls() { @SuppressWarnings("unchecked") Comparator<Object> c = (Comparator<Object>)mock(Comparator.class); when(c.compare(any(), any())).thenReturn(5); assertEquals(5, compare(null, null, c)); } | public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } |
@Test(expected = NullPointerException.class) public void test_natural_compare_nulls() { compare(null, 5, null); } | public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } |
@Test(expected = ClassCastException.class) public void test_compare_not_comparable() { compare(int.class, int.class, null); } | public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } | ObjectTools { public static <T> int compare(T left, T right, Comparator<? super T> comparator) { if (comparator == null) { @SuppressWarnings("unchecked") Comparable<T> leftComparable = (Comparable<T>)left; return leftComparable.compareTo(right); } return comparator.compare(left, right); } private ObjectTools(); static T coalesce(T x, T y); static int compare(T left, T right, Comparator<? super T> comparator); } |
@Test public void test_recursive_type_variable() { compare(MY_ENUM.getE(), new LateTypeVariable<Class>("E", MyEnum.class, MY_ENUM.getE().getBounds()[0])); } | @Override public Type[] getBounds() { if (bounds != null) { return bounds.clone(); } throw new IllegalStateException("bounds have not yet been assigned"); } | LateTypeVariable implements TypeVariable<D> { @Override public Type[] getBounds() { if (bounds != null) { return bounds.clone(); } throw new IllegalStateException("bounds have not yet been assigned"); } } | LateTypeVariable implements TypeVariable<D> { @Override public Type[] getBounds() { if (bounds != null) { return bounds.clone(); } throw new IllegalStateException("bounds have not yet been assigned"); } LateTypeVariable(String name, D genericDeclaration, Type... bounds); } | LateTypeVariable implements TypeVariable<D> { @Override public Type[] getBounds() { if (bounds != null) { return bounds.clone(); } throw new IllegalStateException("bounds have not yet been assigned"); } LateTypeVariable(String name, D genericDeclaration, Type... bounds); static LateTypeVariable<D> copyOf(TypeVariable<D> tv); @Override String getName(); @Override D getGenericDeclaration(); @Override Type[] getBounds(); synchronized void assignBounds(Type... bounds); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateTypeVariable implements TypeVariable<D> { @Override public Type[] getBounds() { if (bounds != null) { return bounds.clone(); } throw new IllegalStateException("bounds have not yet been assigned"); } LateTypeVariable(String name, D genericDeclaration, Type... bounds); static LateTypeVariable<D> copyOf(TypeVariable<D> tv); @Override String getName(); @Override D getGenericDeclaration(); @Override Type[] getBounds(); synchronized void assignBounds(Type... bounds); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_equality() { TypeToken<Set<String>> setOfString1 = new TypeToken<Set<String>>(){}; TypeToken<Set<String>> setOfString2 = new TypeToken<Set<String>>(){}; TypeToken<Set<Long>> setOfLong = new TypeToken<Set<Long>>(){}; assertEquals(setOfString1, setOfString2); assertEquals(setOfString1.hashCode(), setOfString2.hashCode()); assertNotEquals(setOfString1, setOfLong); assertNotEquals(setOfString1.hashCode(), setOfLong.hashCode()); assertNotEquals(setOfString1, new Object()); } | @Override public final int hashCode() { return type.hashCode(); } | TypeToken { @Override public final int hashCode() { return type.hashCode(); } } | TypeToken { @Override public final int hashCode() { return type.hashCode(); } protected TypeToken(); } | TypeToken { @Override public final int hashCode() { return type.hashCode(); } protected TypeToken(); final Type asType(); final T asNull(); @Override final boolean equals(Object that); @Override final int hashCode(); @Override final String toString(); } | TypeToken { @Override public final int hashCode() { return type.hashCode(); } protected TypeToken(); final Type asType(); final T asNull(); @Override final boolean equals(Object that); @Override final int hashCode(); @Override final String toString(); } |
@Test public void test_typed_null() { TypeToken<Long> token = new TypeToken<Long>(){}; assertEquals(42, invoke(token.asNull())); } | public final T asNull() { return null; } | TypeToken { public final T asNull() { return null; } } | TypeToken { public final T asNull() { return null; } protected TypeToken(); } | TypeToken { public final T asNull() { return null; } protected TypeToken(); final Type asType(); final T asNull(); @Override final boolean equals(Object that); @Override final int hashCode(); @Override final String toString(); } | TypeToken { public final T asNull() { return null; } protected TypeToken(); final Type asType(); final T asNull(); @Override final boolean equals(Object that); @Override final int hashCode(); @Override final String toString(); } |
@Test public void test_nested_print() { assertEquals( "net.nullschool.reflect.Outer<java.lang.Short>.Inner1<java.lang.Integer>.Inner2<java.lang.Long>", new TypeToken<Outer<Short>.Inner1<Integer>.Inner2<Long>>(){}.asType().toString()); assertEquals( "net.nullschool.reflect.Outer.$Inner3<java.lang.Integer>", new TypeToken<Outer.$Inner3<Integer>>(){}.asType().toString()); assertEquals( "net.nullschool.reflect.Outer.$Inner3<java.lang.Integer>.$Inner4<java.lang.Long>", new TypeToken<Outer.$Inner3<Integer>.$Inner4<Long>>(){}.asType().toString()); } | @Override public String toString() { return print(this); } | LateParameterizedType implements ParameterizedType { @Override public String toString() { return print(this); } } | LateParameterizedType implements ParameterizedType { @Override public String toString() { return print(this); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { @Override public String toString() { return print(this); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { @Override public String toString() { return print(this); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_collectProperties_with_narrowest_type_in_upper_level() throws IntrospectionException { List<GrainProperty> result; result = collectProperties(W.class); assertEquals(3, result.size()); assertEquals(Object.class, result.get(0).getType()); assertEquals(Integer.class, result.get(1).getType()); assertEquals(Number.class, result.get(2).getType()); } | static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } | SymbolTable { static List<GrainProperty> collectProperties(Type type) throws IntrospectionException { List<GrainProperty> results = new ArrayList<>(); Set<Type> visited = new HashSet<>(); visited.add(null); visited.add(Object.class); Deque<Type> workList = new LinkedList<>(); workList.add(type); while (!workList.isEmpty()) { Type current = workList.removeFirst(); if (visited.contains(current)) { continue; } visited.add(current); results.addAll(collectDeclaredProperties(current)); workList.add(genericSuperclassOf(current)); Collections.addAll(workList, genericInterfacesOf(current)); } return results; } SymbolTable(Class<?> schema, TypeTable typeTable, TypePrinterFactory printerFactory, Member typePolicyMember); } |
@Test public void test_resolve() throws Exception { LateParameterizedType lpc = new LateParameterizedType(Map.class, null, String.class, Integer.class); Method putMethod = Map.class.getMethod("put", Object.class, Object.class); assertEquals(Integer.class, lpc.resolve(putMethod.getGenericReturnType())); assertArrayEquals(new Type[] {String.class, Integer.class}, lpc.resolve(putMethod.getGenericParameterTypes())); assertArrayEquals(new Type[] {String.class, Integer.class}, lpc.resolve(Map.class.getTypeParameters())); assertEquals(Long.class, lpc.resolve(Long.class)); Method putAllMethod = Map.class.getMethod("putAll", Map.class); Type mapParam = putAllMethod.getGenericParameterTypes()[0]; assertEquals(new TypeToken<Map<? extends String, ? extends Integer>>(){}.asType(), lpc.resolve(mapParam)); assertEquals( new LateWildcardType("? super", String.class), lpc.resolve(new LateWildcardType("? super", new LateTypeVariable<Class>("K", Map.class)))); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_recursive_resolve() throws Exception { LateParameterizedType lpc = new LateParameterizedType(Map.class, null, String.class, Integer.class); assertEquals(lpc, lpc.resolve(new LateParameterizedType(Map.class, null, Map.class.getTypeParameters()))); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_resolve_uninstantiated_type() throws Exception { TypeVariable<?>[] typeVars = Map.class.getTypeParameters(); LateParameterizedType lpc = new LateParameterizedType(Map.class, null, Map.class.getTypeParameters()); Method m = Map.class.getMethod("put", Object.class, Object.class); assertEquals(typeVars[1], lpc.resolve(m.getGenericReturnType())); assertArrayEquals(typeVars, lpc.resolve(m.getGenericParameterTypes())); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_resolve_partially_instantiated_type() throws Exception { TypeVariable<?>[] typeVars = Map.class.getTypeParameters(); LateParameterizedType lpc = new LateParameterizedType(Map.class, null, String.class, typeVars[1]); Method m = Map.class.getMethod("put", Object.class, Object.class); assertEquals(typeVars[1], lpc.resolve(m.getGenericReturnType())); assertArrayEquals(new Type[] {String.class, typeVars[1]}, lpc.resolve(m.getGenericParameterTypes())); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_resolve_causes_concrete_array_instantiation() throws Exception { TypeVariable<?> E = List.class.getTypeParameters()[0]; LateParameterizedType lpc = new LateParameterizedType(List.class, null, Integer.class); LateGenericArrayType arrayOfE = new LateGenericArrayType(E); LateGenericArrayType arrayOfArrayOfE = new LateGenericArrayType(arrayOfE); LateParameterizedType setOfArrayOfE = new LateParameterizedType(Set.class, null, arrayOfE); LateParameterizedType setOfArrayOfArrayOfE = new LateParameterizedType(Set.class, null, arrayOfArrayOfE); LateGenericArrayType arrayOfSetOfArrayOfE = new LateGenericArrayType(setOfArrayOfE); assertEquals(Integer[].class, lpc.resolve(arrayOfE)); assertEquals(Integer[][].class, lpc.resolve(arrayOfArrayOfE)); assertEquals( new LateParameterizedType(Set.class, null, Integer[].class), lpc.resolve(setOfArrayOfE)); assertEquals( new LateParameterizedType(Set.class, null, Integer[][].class), lpc.resolve(setOfArrayOfArrayOfE)); assertEquals( new LateGenericArrayType(new LateParameterizedType(Set.class, null, Integer[].class)), lpc.resolve(arrayOfSetOfArrayOfE)); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_generic_method_shadows_enclosing_type_parameter() throws Exception { LateParameterizedType lpc = new LateParameterizedType(Foo.class, null, Integer.class); Method m = Foo.class.getMethod("bar", Object.class); assertEquals(m.getGenericReturnType(), lpc.resolve(m.getGenericReturnType())); assertArrayEquals(m.getGenericParameterTypes(), lpc.resolve(m.getGenericParameterTypes())); } | public Type resolve(Type type) { return resolver.apply(type); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type resolve(Type type) { return resolver.apply(type); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_superclass() { LateParameterizedType lpc = new LateParameterizedType(ArrayList.class, null, Long.class); compare( new JavaToken<AbstractList<Long>>(){}.asParameterizedType(), lpc = (LateParameterizedType)lpc.getSuperclass()); compare( new JavaToken<AbstractCollection<Long>>(){}.asParameterizedType(), lpc = (LateParameterizedType)lpc.getSuperclass()); assertSame(Object.class, lpc.getSuperclass()); LateParameterizedType listOfLong = new LateParameterizedType(List.class, null, Long.class); assertNull(listOfLong.getSuperclass()); } | public Type getSuperclass() { return resolve(rawType.getGenericSuperclass()); } | LateParameterizedType implements ParameterizedType { public Type getSuperclass() { return resolve(rawType.getGenericSuperclass()); } } | LateParameterizedType implements ParameterizedType { public Type getSuperclass() { return resolve(rawType.getGenericSuperclass()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type getSuperclass() { return resolve(rawType.getGenericSuperclass()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type getSuperclass() { return resolve(rawType.getGenericSuperclass()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_interfaces() { LateParameterizedType lpc = new LateParameterizedType(ArrayList.class, null, Long.class); Type[] result = lpc.getInterfaces(); assertEquals(4, result.length); compare(new JavaToken<List<Long>>(){}.asParameterizedType(), lpc = (LateParameterizedType)result[0]); assertSame(RandomAccess.class, result[1]); assertSame(Cloneable.class, result[2]); assertSame(Serializable.class, result[3]); result = lpc.getInterfaces(); assertEquals(1, result.length); compare(new JavaToken<Collection<Long>>(){}.asParameterizedType(), lpc = (LateParameterizedType)result[0]); result = lpc.getInterfaces(); assertEquals(1, result.length); compare(new JavaToken<Iterable<Long>>(){}.asParameterizedType(), lpc = (LateParameterizedType)result[0]); result = lpc.getInterfaces(); assertEquals(0, result.length); } | public Type[] getInterfaces() { return resolve(rawType.getGenericInterfaces()); } | LateParameterizedType implements ParameterizedType { public Type[] getInterfaces() { return resolve(rawType.getGenericInterfaces()); } } | LateParameterizedType implements ParameterizedType { public Type[] getInterfaces() { return resolve(rawType.getGenericInterfaces()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); } | LateParameterizedType implements ParameterizedType { public Type[] getInterfaces() { return resolve(rawType.getGenericInterfaces()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateParameterizedType implements ParameterizedType { public Type[] getInterfaces() { return resolve(rawType.getGenericInterfaces()); } LateParameterizedType(Type rawType, Type ownerType, Type... actualTypeArguments); static LateParameterizedType copyOf(ParameterizedType pt); @Override Class<?> getRawType(); @Override Type getOwnerType(); @Override Type[] getActualTypeArguments(); Type resolve(Type type); Type[] resolve(Type[] types); Type getSuperclass(); Type[] getInterfaces(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_buildArrayType() { assertSame(int[].class, buildArrayType(int.class)); assertSame(int[][].class, buildArrayType(int[].class)); assertSame(Integer[].class, buildArrayType(Integer.class)); assertSame(Map[].class, buildArrayType(Map.class)); } | public static Class<?> buildArrayType(Class<?> componentType) { return Array.newInstance(componentType, 0).getClass(); } | TypeTools { public static Class<?> buildArrayType(Class<?> componentType) { return Array.newInstance(componentType, 0).getClass(); } } | TypeTools { public static Class<?> buildArrayType(Class<?> componentType) { return Array.newInstance(componentType, 0).getClass(); } private TypeTools(); } | TypeTools { public static Class<?> buildArrayType(Class<?> componentType) { return Array.newInstance(componentType, 0).getClass(); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { public static Class<?> buildArrayType(Class<?> componentType) { return Array.newInstance(componentType, 0).getClass(); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_erasure() { assertSame(int.class, erase(int.class)); assertSame(Object.class, erase(Object.class)); assertSame(Object[].class, erase(Object[].class)); assertSame(Set[].class, erase(new JavaToken<Set<?>[]>(){}.asGenericArrayType())); assertSame(Object.class, erase(new JavaToken<Set<?>>(){}.asWildcardType())); assertSame(Object.class, erase(new JavaToken<Set<? super Comparable>>(){}.asWildcardType())); assertSame(Comparable.class, erase(new JavaToken<Set<? extends Comparable>>(){}.asWildcardType())); assertSame(Map.class, erase(new LateWildcardType("? extends", Map.class, HashMap.class))); assertSame(Set.class, erase(new JavaToken<Set<Integer>>(){}.asParameterizedType())); assertSame(Set.class, erase(new JavaToken<Set<?>>(){}.asParameterizedType())); assertSame(Object.class, erase(new LateTypeVariable<Class>("E", Set.class))); assertSame(Map.class, erase(new LateTypeVariable<Class>("E", Set.class, Map.class))); assertSame(Map.class, erase(new LateTypeVariable<Class>("E", Set.class, Map.class, HashMap.class))); assertNull(erase(null)); try { erase(new Type(){}); fail(); } catch (IllegalArgumentException expected) {} } | public static Class<?> erase(Type type) { return Eraser.INSTANCE.apply(type); } | TypeTools { public static Class<?> erase(Type type) { return Eraser.INSTANCE.apply(type); } } | TypeTools { public static Class<?> erase(Type type) { return Eraser.INSTANCE.apply(type); } private TypeTools(); } | TypeTools { public static Class<?> erase(Type type) { return Eraser.INSTANCE.apply(type); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { public static Class<?> erase(Type type) { return Eraser.INSTANCE.apply(type); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_immutify_known_immutable_types() { assertSame(boolean.class, immutify(boolean.class)); assertSame(byte.class, immutify(byte.class)); assertSame(short.class, immutify(short.class)); assertSame(int.class, immutify(int.class)); assertSame(long.class, immutify(long.class)); assertSame(float.class, immutify(float.class)); assertSame(double.class, immutify(double.class)); assertSame(char.class, immutify(char.class)); assertSame(Boolean.class, immutify(Boolean.class)); assertSame(Byte.class, immutify(Byte.class)); assertSame(Short.class, immutify(Short.class)); assertSame(Integer.class, immutify(Integer.class)); assertSame(Long.class, immutify(Long.class)); assertSame(BigInteger.class, immutify(BigInteger.class)); assertSame(BigDecimal.class, immutify(BigDecimal.class)); assertSame(Float.class, immutify(Float.class)); assertSame(Double.class, immutify(Double.class)); assertSame(Character.class, immutify(Character.class)); assertSame(String.class, immutify(String.class)); } | Immutify(TypeTable typeTable) { this.typeTable = typeTable; } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } |
@Test public void test_print() { assertEquals("java.util.List", print(List.class)); assertEquals("java.util.List[]", print(List[].class)); assertEquals( "java.util.List<? extends java.lang.Integer>", print(new JavaToken<List<? extends Integer>>(){}.asType())); assertEquals( "java.util.List<? extends java.lang.Integer>[][]", print(new JavaToken<List<? extends Integer>[][]>(){}.asType())); assertEquals("java.util.Map.Entry", print(Map.Entry.class)); assertEquals("int", print(int.class)); assertEquals("int[]", print(int[].class)); } | public static String print(Type type) { return print(type, new FullNamePrinter()); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_print_with_custom_printer() { assertEquals("~List", print(List.class, new PrependTildePrinter())); assertEquals("~List[]", print(List[].class, new PrependTildePrinter())); assertEquals( "~List<? extends ~Integer>", print(new JavaToken<List<? extends Integer>>(){}.asType(), new PrependTildePrinter())); assertEquals( "~List<? extends ~Integer>[][]", print(new JavaToken<List<? extends Integer>[][]>(){}.asType(), new PrependTildePrinter())); assertEquals("~Map.Entry", print(Map.Entry.class, new PrependTildePrinter())); assertEquals("~int", print(int.class, new PrependTildePrinter())); assertEquals("~int[]", print(int[].class, new PrependTildePrinter())); } | public static String print(Type type) { return print(type, new FullNamePrinter()); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { public static String print(Type type) { return print(type, new FullNamePrinter()); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_apply() { @SuppressWarnings("unchecked") TypeOperator<Type> operator = (TypeOperator<Type>)mock(TypeOperator.class); when(operator.apply((Type)String.class)).thenReturn(Character.class); when(operator.apply((Type)Integer.class)).thenReturn(Byte.class); Type[] result = apply(operator, new Type[] {String.class, Integer.class}); assertArrayEquals(new Type[] {Character.class, Byte.class}, result); } | public static Type[] apply(TypeOperator<? extends Type> operator, Type[] types) { Type[] result = types.length > 0 ? new Type[types.length] : types; for (int i = 0; i < types.length; i++) { result[i] = operator.apply(types[i]); } return result; } | TypeTools { public static Type[] apply(TypeOperator<? extends Type> operator, Type[] types) { Type[] result = types.length > 0 ? new Type[types.length] : types; for (int i = 0; i < types.length; i++) { result[i] = operator.apply(types[i]); } return result; } } | TypeTools { public static Type[] apply(TypeOperator<? extends Type> operator, Type[] types) { Type[] result = types.length > 0 ? new Type[types.length] : types; for (int i = 0; i < types.length; i++) { result[i] = operator.apply(types[i]); } return result; } private TypeTools(); } | TypeTools { public static Type[] apply(TypeOperator<? extends Type> operator, Type[] types) { Type[] result = types.length > 0 ? new Type[types.length] : types; for (int i = 0; i < types.length; i++) { result[i] = operator.apply(types[i]); } return result; } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { public static Type[] apply(TypeOperator<? extends Type> operator, Type[] types) { Type[] result = types.length > 0 ? new Type[types.length] : types; for (int i = 0; i < types.length; i++) { result[i] = operator.apply(types[i]); } return result; } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_copyOf() { assertEquals(Class.class, copyOf(Object.class).getClass()); assertEquals(LateParameterizedType.class, copyOf(new JavaToken<Set<Byte>>(){}.asParameterizedType()).getClass()); assertEquals(LateGenericArrayType.class, copyOf(new JavaToken<Set<Byte>[]>(){}.asGenericArrayType()).getClass()); assertEquals(LateWildcardType.class, copyOf(new JavaToken<Set<?>>(){}.asWildcardType()).getClass()); } | static Type copyOf(Type type) { return LateTypeConverter.INSTANCE.apply(type); } | TypeTools { static Type copyOf(Type type) { return LateTypeConverter.INSTANCE.apply(type); } } | TypeTools { static Type copyOf(Type type) { return LateTypeConverter.INSTANCE.apply(type); } private TypeTools(); } | TypeTools { static Type copyOf(Type type) { return LateTypeConverter.INSTANCE.apply(type); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } | TypeTools { static Type copyOf(Type type) { return LateTypeConverter.INSTANCE.apply(type); } private TypeTools(); static boolean isInnerClass(Class<?> clazz); static Class<?> buildArrayType(Class<?> componentType); static Class<?> erase(Type type); static String print(Type type); static String print(Type type, TypePrinter printer); static Type[] apply(TypeOperator<? extends Type> operator, Type[] types); static Class<?> publicInterfaceOf(Class<?> type); } |
@Test public void test_extra_linguistic_wildcard_bounds() { assertEquals( "? extends java.io.Serializable & java.lang.Comparable", new LateWildcardType("? extends", Serializable.class, Comparable.class).toString()); assertEquals( "? extends java.lang.Class & java.lang.Class", new LateWildcardType("? extends", Class.class, Class.class).toString()); assertEquals( "? super java.io.Serializable & java.lang.Comparable", new LateWildcardType("? super", Serializable.class, Comparable.class).toString()); } | @Override public String toString() { return print(this); } | LateWildcardType implements WildcardType { @Override public String toString() { return print(this); } } | LateWildcardType implements WildcardType { @Override public String toString() { return print(this); } private LateWildcardType(Type[] upperBounds, Type[] lowerBounds); LateWildcardType(String keyword, Type... bounds); } | LateWildcardType implements WildcardType { @Override public String toString() { return print(this); } private LateWildcardType(Type[] upperBounds, Type[] lowerBounds); LateWildcardType(String keyword, Type... bounds); static LateWildcardType copyOf(WildcardType wt); @Override Type[] getUpperBounds(); @Override Type[] getLowerBounds(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } | LateWildcardType implements WildcardType { @Override public String toString() { return print(this); } private LateWildcardType(Type[] upperBounds, Type[] lowerBounds); LateWildcardType(String keyword, Type... bounds); static LateWildcardType copyOf(WildcardType wt); @Override Type[] getUpperBounds(); @Override Type[] getLowerBounds(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); } |
@Test public void test_eraser() { Eraser eraser = Eraser.INSTANCE; assertSame(Object.class, eraser.apply(Object.class)); assertSame(Object[].class, eraser.apply(Object[].class)); assertSame(Set[].class, eraser.apply(new JavaToken<Set<?>[]>(){}.asGenericArrayType())); assertSame(Object.class, eraser.apply(new LateWildcardType("?"))); assertSame(Object.class, eraser.apply(new LateWildcardType("? super", Comparable.class))); assertSame(Comparable.class, eraser.apply(new LateWildcardType("? extends", Comparable.class))); assertSame(Map.class, eraser.apply(new LateWildcardType("? extends", Map.class, HashMap.class))); assertSame(Set.class, eraser.apply(new JavaToken<Set<Integer>>(){}.asParameterizedType())); assertSame(Object.class, eraser.apply(new LateTypeVariable<Class>("E", Set.class))); assertSame(Map.class, eraser.apply(new LateTypeVariable<Class>("E", Set.class, Map.class))); assertSame(Map.class, eraser.apply(new LateTypeVariable<Class>("E", Set.class, Map.class, HashMap.class))); assertSame(Object.class, eraser.apply((Type)Object.class)); assertSame(Object[].class, eraser.apply((Type)Object[].class)); assertSame(Set[].class, eraser.apply(new JavaToken<Set<?>[]>(){}.asType())); assertSame(Object.class, eraser.apply((Type)new LateWildcardType("?"))); assertSame(Object.class, eraser.apply((Type)new LateWildcardType("? super", Comparable.class))); assertSame(Comparable.class, eraser.apply((Type)new LateWildcardType("? extends", Comparable.class))); assertSame(Map.class, eraser.apply((Type)new LateWildcardType("? extends", Map.class, HashMap.class))); assertSame(Set.class, eraser.apply(new JavaToken<Set<Integer>>(){}.asType())); assertSame(Object.class, eraser.apply((Type)new LateTypeVariable<Class>("E", Set.class))); assertSame(Map.class, eraser.apply((Type)new LateTypeVariable<Class>("E", Set.class, Map.class))); assertSame(Map.class, eraser.apply((Type)new LateTypeVariable<Class>("E", Set.class, Map.class, HashMap.class))); assertNull(eraser.apply((Type)null)); } | @Override public Class<?> apply(Class<?> clazz) { return clazz; } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } @Override Class<?> apply(Class<?> clazz); @Override Class<?> apply(ParameterizedType pt); @Override Class<?> apply(GenericArrayType gat); @Override Class<?> apply(WildcardType wt); @Override Class<?> apply(TypeVariable<?> tv); } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } @Override Class<?> apply(Class<?> clazz); @Override Class<?> apply(ParameterizedType pt); @Override Class<?> apply(GenericArrayType gat); @Override Class<?> apply(WildcardType wt); @Override Class<?> apply(TypeVariable<?> tv); } |
@Test(expected = IllegalArgumentException.class) public void test_eraser_unknown() { Eraser.INSTANCE.apply(new Type(){}); } | @Override public Class<?> apply(Class<?> clazz) { return clazz; } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } @Override Class<?> apply(Class<?> clazz); @Override Class<?> apply(ParameterizedType pt); @Override Class<?> apply(GenericArrayType gat); @Override Class<?> apply(WildcardType wt); @Override Class<?> apply(TypeVariable<?> tv); } | Eraser extends AbstractTypeOperator<Class<?>> { @Override public Class<?> apply(Class<?> clazz) { return clazz; } @Override Class<?> apply(Class<?> clazz); @Override Class<?> apply(ParameterizedType pt); @Override Class<?> apply(GenericArrayType gat); @Override Class<?> apply(WildcardType wt); @Override Class<?> apply(TypeVariable<?> tv); } |
@Test public void test_invoke() { TypeOperator<?> operator = mock(AbstractTypeOperator.class); given(operator.apply(any(Type.class))).willCallRealMethod(); operator.apply((Type)Object.class); operator.apply((Type)new LateParameterizedType(Set.class, null, Integer.class)); operator.apply((Type)new LateGenericArrayType(new LateTypeVariable<Class>("E", Set.class))); operator.apply((Type)new LateWildcardType("?")); operator.apply((Type)new LateTypeVariable<Class>("E", Set.class)); assertNull(operator.apply((Type)null)); verify(operator, times(1)).apply(any(Class.class)); verify(operator, times(1)).apply(any(ParameterizedType.class)); verify(operator, times(1)).apply(any(GenericArrayType.class)); verify(operator, times(1)).apply(any(WildcardType.class)); verify(operator, times(1)).apply(any(TypeVariable.class)); verify(operator, times(6)).apply(any(Type.class)); } | @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } @Override T apply(Type type); } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } @Override T apply(Type type); } |
@Test(expected = IllegalArgumentException.class) public void test_invoke_unknown() { TypeOperator<?> operator = mock(AbstractTypeOperator.class); given(operator.apply(any(Type.class))).willCallRealMethod(); operator.apply(new Type(){}); } | @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } @Override T apply(Type type); } | AbstractTypeOperator implements TypeOperator<T> { @Override public T apply(Type type) { if (type instanceof Class) { return apply((Class<?>)type); } else if (type instanceof ParameterizedType) { return apply((ParameterizedType)type); } else if (type instanceof WildcardType) { return apply((WildcardType)type); } else if (type instanceof GenericArrayType) { return apply((GenericArrayType)type); } else if (type instanceof TypeVariable) { return apply((TypeVariable<?>)type); } else if (type == null) { return null; } throw new IllegalArgumentException("Unsupported Type implementation: " + type.getClass()); } @Override T apply(Type type); } |
@Test public void test_with() { compare_lists(Arrays.asList(1, 1), new BasicList1<>(1).with(1)); compare_lists(Arrays.asList(1, null), new BasicList1<>(1).with(null)); } | @Override public ConstList<E> with(E e) { return listOf(e0, e); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_arrays_not_immutable() { try { immutify(char[].class); fail(); } catch (IllegalArgumentException expected) {} try { immutify(String[].class); fail(); } catch (IllegalArgumentException expected) {} } | Immutify(TypeTable typeTable) { this.typeTable = typeTable; } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } |
@Test public void test_with_index() { compare_lists(Arrays.asList(2, 1), new BasicList1<>(1).with(0, 2)); compare_lists(Arrays.asList(1, 2), new BasicList1<>(1).with(1, 2)); } | @Override public ConstList<E> with(E e) { return listOf(e0, e); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test(expected = IndexOutOfBoundsException.class) public void test_with_index_out_of_bounds() { new BasicList1<>(1).with(2, 1); } | @Override public ConstList<E> with(E e) { return listOf(e0, e); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> with(E e) { return listOf(e0, e); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_withAll() { ConstList<Integer> list = new BasicList1<>(1); compare_lists(Arrays.asList(1, 1, 2, 3), list.withAll(Arrays.asList(1, 2, 3))); assertSame(list, list.withAll(Collections.<Integer>emptyList())); } | @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test(expected = NullPointerException.class) public void test_withAll_throws() { new BasicList1<>(1).withAll(null); } | @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_withAll_index() { ConstList<Integer> list = new BasicList1<>(0); compare_lists(Arrays.asList(1, 2, 3, 0), list.withAll(0, Arrays.asList(1, 2, 3))); compare_lists(Arrays.asList(0, 1, 2, 3), list.withAll(1, Arrays.asList(1, 2, 3))); assertSame(list, list.withAll(0, Collections.<Integer>emptyList())); } | @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test(expected = IndexOutOfBoundsException.class) public void test_withAll_index_out_of_bounds() { new BasicList1<>(1).withAll(2, Collections.<Integer>emptyList()); } | @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test(expected = NullPointerException.class) public void test_withAll_index_throws() { new BasicList1<>(1).withAll(0, null); } | @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> withAll(Collection<? extends E> c) { return c.isEmpty() ? this : BasicCollections.<E>condenseToList(insert(c.toArray(), 0, e0)); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_replace() { compare_lists(Collections.singletonList(9), new BasicList1<>(1).replace(0, 9)); } | @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test(expected = IndexOutOfBoundsException.class) public void test_replace_out_of_bounds() { new BasicList1<>(1).replace(1, 1); } | @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> replace(int index, E e) { if (index == 0) { return listOf(e); } throw new IndexOutOfBoundsException(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_without() { ConstList<Integer> list = new BasicList1<>(1); assertSame(BasicList0.instance(), list.without(1)); assertSame(list, list.without(2)); assertSame(list, list.without(null)); } | @Override public ConstList<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptyList(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptyList(); } } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptyList(); } @SuppressWarnings("unchecked") BasicList1(Object e0); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptyList(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } | BasicList1 extends BasicConstList<E> { @Override public ConstList<E> without(Object o) { return !contains(o) ? this : BasicCollections.<E>emptyList(); } @SuppressWarnings("unchecked") BasicList1(Object e0); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override E get(int index); @Override Object[] toArray(); @Override ConstList<E> with(E e); @Override ConstList<E> with(int index, E e); @Override ConstList<E> withAll(Collection<? extends E> c); @Override ConstList<E> withAll(int index, Collection<? extends E> c); @Override ConstList<E> replace(int index, E e); @Override ConstList<E> without(Object o); @Override ConstList<E> delete(int index); @Override ConstList<E> withoutAll(Collection<?> c); @Override ConstList<E> subList(int fromIndex, int toIndex); @Override boolean equals(Object that); @Override int hashCode(); } |
@Test public void test_immutify_enum() { assertEquals(new TypeToken<Enum>(){}.asType(), immutify(Enum.class)); assertSame(Color.class, immutify(Color.class)); } | Immutify(TypeTable typeTable) { this.typeTable = typeTable; } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } | Immutify extends AbstractTypeOperator<Type> { Immutify(TypeTable typeTable) { this.typeTable = typeTable; } Immutify(TypeTable typeTable); @Override Class<?> apply(Class<?> clazz); @Override Type apply(ParameterizedType pt); @Override Type apply(GenericArrayType gat); @Override Type apply(WildcardType wt); @Override Type apply(TypeVariable<?> tv); } |
@Test public void suspectBehaviour() throws Exception { GraphDatabaseService db = createDatabase(); EmailQueries queries = new EmailQueries( db, new PrintingExecutionEngineWrapper( db, "email", name ) ); ExecutionResult result = queries.suspectBehaviour(); Iterator<Map<String, Object>> iterator = result.iterator(); Map<String, Object> next = iterator.next(); assertEquals( "1", next.get( "email.id" )); assertFalse( iterator.hasNext() ); db.shutdown(); } | public ExecutionResult suspectBehaviour() { String query = "MATCH (bob:User {username:'Bob'})-[:SENT]->(email)-[:CC]->(alias),\n" + " (alias)-[:ALIAS_OF]->(bob)\n" + "RETURN email.id"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | EmailQueries { public ExecutionResult suspectBehaviour() { String query = "MATCH (bob:User {username:'Bob'})-[:SENT]->(email)-[:CC]->(alias),\n" + " (alias)-[:ALIAS_OF]->(bob)\n" + "RETURN email.id"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | EmailQueries { public ExecutionResult suspectBehaviour() { String query = "MATCH (bob:User {username:'Bob'})-[:SENT]->(email)-[:CC]->(alias),\n" + " (alias)-[:ALIAS_OF]->(bob)\n" + "RETURN email.id"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | EmailQueries { public ExecutionResult suspectBehaviour() { String query = "MATCH (bob:User {username:'Bob'})-[:SENT]->(email)-[:CC]->(alias),\n" + " (alias)-[:ALIAS_OF]->(bob)\n" + "RETURN email.id"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } | EmailQueries { public ExecutionResult suspectBehaviour() { String query = "MATCH (bob:User {username:'Bob'})-[:SENT]->(email)-[:CC]->(alias),\n" + " (alias)-[:ALIAS_OF]->(bob)\n" + "RETURN email.id"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } |
@Test public void friendOfAFriendWithMultipleInterest() throws Exception { ExecutionResult results = queries.friendOfAFriendWithMultipleInterest( "Arnold", 5, "Art", "Design" ); Iterator<Map<String, Object>> iterator = results.iterator(); Map<String, Object> result = iterator.next(); assertEquals( "Emily", result.get( "name" ) ); assertEquals( 2L, result.get( "score" ) ); assertEquals( 2L, result.get( "distance" ) ); assertEquals( asList( "Art", "Design" ), result.get( "interests" ) ); assertFalse( iterator.hasNext() ); } | public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); static final Label USER; static final Label TOPIC; } |
@Test public void friendOfAFriendWithMultipleInterestShouldOrderByScore() throws Exception { ExecutionResult results = queries.friendOfAFriendWithMultipleInterest( "Sarah", 5, "Java", "Travel", "Medicine" ); Iterator<Map<String, Object>> iterator = results.iterator(); Map<String, Object> result = iterator.next(); assertEquals( "Arnold", result.get( "name" ) ); assertEquals( 2L, result.get( "score" ) ); assertEquals( 2L, result.get( "distance" ) ); assertEquals( asList( "Java", "Travel" ), result.get( "interests" ) ); result = iterator.next(); assertEquals( "Charlie", result.get( "name" ) ); assertEquals( 1L, result.get( "score" ) ); assertEquals( 1L, result.get( "distance" ) ); assertEquals( asList( "Medicine" ), result.get( "interests" ) ); assertFalse( iterator.hasNext() ); } | public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); } | SocialNetworkQueries { public ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH p=(subject)-[:WORKED_ON]->()-[:WORKED_ON*0..2]-()\n" + " <-[:WORKED_ON]-(person)-[:INTERESTED_IN]->(interest)\n" + "WHERE person<>subject AND interest.name IN {interests}\n" + "WITH person, interest, min(length(p)) as pathLength\n" + "ORDER BY interest.name\n"+ "RETURN person.name AS name,\n" + " count(interest) AS score,\n" + " collect(interest.name) AS interests,\n" + " ((pathLength - 1)/2) AS distance\n" + "ORDER BY score DESC\n" + "LIMIT {resultLimit}"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); params.put( "interests", interestLabels ); params.put( "resultLimit", limit ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); static final Label USER; static final Label TOPIC; } |
@Test public void shouldCreateNewWorkedWithRelationships() throws Exception { String cypher = "MATCH (sarah:User {name:'Sarah'}),\n" + " (ben:User {name:'Ben'})\n" + "CREATE sarah-[:WORKED_WITH]->ben"; createFromCypher( db, "Enriched Social Network", cypher ); ExecutionResult results = queries.createWorkedWithRelationships( "Sarah" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); Map<String, Object> result = iterator.next(); assertEquals( "Emily", result.get( "endName" ) ); result = iterator.next(); assertEquals( "Charlie", result.get( "endName" ) ); result = iterator.next(); assertEquals( "Kate", result.get( "endName" ) ); assertFalse( iterator.hasNext() ); } | public ExecutionResult createWorkedWithRelationships( String userName ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH (subject)-[:WORKED_ON]->()<-[:WORKED_ON]-(person)\n" + "WHERE NOT((subject)-[:WORKED_WITH]-(person))\n" + "WITH DISTINCT subject, person\n" + "CREATE UNIQUE (subject)-[:WORKED_WITH]-(person)\n" + "RETURN subject.name AS startName, person.name AS endName"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); return executionEngineWrapper.execute( query, params ); } | SocialNetworkQueries { public ExecutionResult createWorkedWithRelationships( String userName ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH (subject)-[:WORKED_ON]->()<-[:WORKED_ON]-(person)\n" + "WHERE NOT((subject)-[:WORKED_WITH]-(person))\n" + "WITH DISTINCT subject, person\n" + "CREATE UNIQUE (subject)-[:WORKED_WITH]-(person)\n" + "RETURN subject.name AS startName, person.name AS endName"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); return executionEngineWrapper.execute( query, params ); } } | SocialNetworkQueries { public ExecutionResult createWorkedWithRelationships( String userName ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH (subject)-[:WORKED_ON]->()<-[:WORKED_ON]-(person)\n" + "WHERE NOT((subject)-[:WORKED_WITH]-(person))\n" + "WITH DISTINCT subject, person\n" + "CREATE UNIQUE (subject)-[:WORKED_WITH]-(person)\n" + "RETURN subject.name AS startName, person.name AS endName"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | SocialNetworkQueries { public ExecutionResult createWorkedWithRelationships( String userName ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH (subject)-[:WORKED_ON]->()<-[:WORKED_ON]-(person)\n" + "WHERE NOT((subject)-[:WORKED_WITH]-(person))\n" + "WITH DISTINCT subject, person\n" + "CREATE UNIQUE (subject)-[:WORKED_WITH]-(person)\n" + "RETURN subject.name AS startName, person.name AS endName"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); } | SocialNetworkQueries { public ExecutionResult createWorkedWithRelationships( String userName ) { String query = "MATCH (subject:User {name:{name}})\n" + "MATCH (subject)-[:WORKED_ON]->()<-[:WORKED_ON]-(person)\n" + "WHERE NOT((subject)-[:WORKED_WITH]-(person))\n" + "WITH DISTINCT subject, person\n" + "CREATE UNIQUE (subject)-[:WORKED_WITH]-(person)\n" + "RETURN subject.name AS startName, person.name AS endName"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "name", userName ); return executionEngineWrapper.execute( query, params ); } SocialNetworkQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult sharedInterestsSameCompany( String userName ); ExecutionResult sharedInterestsAllCompanies( String userName, int limit ); ExecutionResult sharedInterestsAlsoInterestedInTopic( String userName, String topicLabel ); ExecutionResult friendOfAFriendWithInterest( String userName, String topicLabel, int limit ); Collection<Node> friendOfAFriendWithInterestTraversalFramework( String userName,
final String topicLabel,
int limit ); ExecutionResult friendOfAFriendWithMultipleInterest( String userName, int limit, String... interestLabels ); ExecutionResult friendWorkedWithFriendWithInterests( String userName, int limit, String... interestLabels ); ExecutionResult createWorkedWithRelationships( String userName ); ExecutionResult getAllUsers(); static final Label USER; static final Label TOPIC; } |
@Test public void allowedWithInheritTrueGivesAccessToSubcompaniesAndAccounts() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleResources( "Ben" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Account-1", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-2", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-3", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-6", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-4", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-5", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-7", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void deniedExcludesCompanyFromPermissionsTree() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleResources( "Sarah" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Account-4", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-5", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-1", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-2", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertEquals( "Account-3", ((Path) iterator.next().get( "paths" )).endNode().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleResources( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-(employee)-[:HAS_ACCOUNT]->(account)\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account)\n" + "RETURN paths"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH paths=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()" + "<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN paths"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldGetAccessibleCompaniesForAdmin() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleCompanies( "Sarah" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Startup", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertEquals( "Acme", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldGetAccessibleCompaniesForAdminWhereNoAllowedInheritFalse() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleCompanies( "Ben" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Acme", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertEquals( "Spinoff", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertEquals( "Startup", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertEquals( "Skunkworkz", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void moreComplexShouldGetAccessibleCompaniesForAdmin() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleCompanies( "Liz" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "BigCompany", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertEquals( "One-ManShop", ((Node) iterator.next().get( "company" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleCompanies( String adminName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0..3]-company\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-company)\n" + "RETURN company"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}})\n" + "MATCH admin-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN company"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAccessibleAccountsForAdminAndCompany() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleAccountsForCompany( "Sarah", "Startup" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Account-4", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertEquals( "Account-5", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void moreComplexShouldFindAccessibleAccountsForAdminAndCompany() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleAccountsForCompany( "Liz", "BigCompany" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Account-8", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void suspectBehaviour2() throws Exception { GraphDatabaseService db = createDatabase2(); EmailQueries queries = new EmailQueries( db, new PrintingExecutionEngineWrapper( db, "email", name ) ); ExecutionResult result = queries.suspectBehaviour2(); Iterator<Map<String, Object>> iterator = result.iterator(); Map<String, Object> next = iterator.next(); assertEquals( 1L, next.get( "depth" ) ); assertEquals( "Davina", next.get( "replier" ) ); next = iterator.next(); assertEquals( 1L, next.get( "depth" ) ); assertEquals( "Bob", next.get( "replier" ) ); next = iterator.next(); assertEquals( 2L, next.get( "depth" ) ); assertEquals( "Charlie", next.get( "replier" ) ); next = iterator.next(); assertEquals( 3L, next.get( "depth" ) ); assertEquals( "Bob", next.get( "replier" ) ); assertFalse( iterator.hasNext() ); db.shutdown(); } | public ExecutionResult suspectBehaviour2() { String query = "MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-()<-[:SENT]-(replier)\n" + "RETURN replier.username AS replier, length(p) - 1 AS depth ORDER BY depth"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | EmailQueries { public ExecutionResult suspectBehaviour2() { String query = "MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-()<-[:SENT]-(replier)\n" + "RETURN replier.username AS replier, length(p) - 1 AS depth ORDER BY depth"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | EmailQueries { public ExecutionResult suspectBehaviour2() { String query = "MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-()<-[:SENT]-(replier)\n" + "RETURN replier.username AS replier, length(p) - 1 AS depth ORDER BY depth"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | EmailQueries { public ExecutionResult suspectBehaviour2() { String query = "MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-()<-[:SENT]-(replier)\n" + "RETURN replier.username AS replier, length(p) - 1 AS depth ORDER BY depth"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } | EmailQueries { public ExecutionResult suspectBehaviour2() { String query = "MATCH p=(email:Email {id:'6'})<-[:REPLY_TO*1..4]-()<-[:SENT]-(replier)\n" + "RETURN replier.username AS replier, length(p) - 1 AS depth ORDER BY depth"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } |
@Test public void shouldFindAccessibleAccountsForAdminAndCompanyWhenNoAllowedWithInheritFalse() throws Exception { QueryUnionExecutionResult results = queries.findAccessibleAccountsForCompany( "Ben", "Startup" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Account-4", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertEquals( "Account-5", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertEquals( "Account-7", ((Node) iterator.next().get( "account" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName, String companyName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:CHILD_OF*0." + ".3]-subcompany<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT]->account\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0." + ".3]-subcompany)\n" + "RETURN account"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company:Company{name:{companyName}})\n" + "MATCH admin-[:MEMBER_OF]->group-[permission:ALLOWED]->company<-[:WORKS_FOR]-employee-[:HAS_ACCOUNT" + "]->account\n" + "WHERE (permission.inherit=false)\n" + "RETURN account"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForAccountResourceWhereAllowedInheritAndAllowedNotInherit() throws Exception { QueryUnionExecutionResult results = queries.findAdminForResource( "Account-10" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Phil", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertEquals( "Liz", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForEmployeeResourceWhereAllowedInheritAndDenied() throws Exception { QueryUnionExecutionResult results = queries.findAdminForResource( "Kate" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Ben", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForResource( String resourceName ) { String inheritedQuery = "MATCH (resource:Resource {name:{resourceName}}) \n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (resource:Resource{name:{resourceName}})\n" + "MATCH p=resource-[:WORKS_FOR|HAS_ACCOUNT*1..2]-company<-[permission:ALLOWED]-()" + "<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForCompanyWithAllowedInherit() throws Exception { QueryUnionExecutionResult results = queries.findAdminForCompany( "BigCompany" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Liz", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForCompanyWithDenied() throws Exception { QueryUnionExecutionResult results = queries.findAdminForCompany( "AcquiredLtd" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForCompanyWithAllowedInheritAndAllowedDoNotInheritTooLowInTree() throws Exception { QueryUnionExecutionResult results = queries.findAdminForCompany( "Subsidiary" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Phil", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldFindAdminForCompanyWithAllowedInheritAndAllowedAllowedDoNotInherit() throws Exception { QueryUnionExecutionResult results = queries.findAdminForCompany( "One-ManShop" ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "Phil", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertEquals( "Liz", ((Node) iterator.next().get( "admin" )).getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult findAdminForCompany( String companyName ) { String inheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company-[:CHILD_OF*0..3]->()<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=true) AND NOT (admin-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-company)\n" + "RETURN DISTINCT admin, p"; String notInheritedQuery = "MATCH (company:Company{name:{companyName}})\n" + "MATCH p=company<-[permission:ALLOWED]-()<-[:MEMBER_OF]-admin\n" + "WHERE (permission.inherit=false)\n" + "RETURN DISTINCT admin, p"; Map<String, Object> params = new HashMap<>(); params.put( "companyName", companyName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void shouldDetermineWhetherAdminHasAccessToResource() throws Exception { Map<String, List<Long>> testData = new HashMap<String, List<Long>>(); testData.put( "Alistair", asList( 1L, 0L ) ); testData.put( "Account-8", asList( 1L, 0L ) ); testData.put( "Eve", asList( 0L, 0L ) ); testData.put( "Account-9", asList( 0L, 0L ) ); testData.put( "Mary", asList( 0L, 0L ) ); testData.put( "Account-12", asList( 0L, 0L ) ); testData.put( "Gary", asList( 0L, 0L ) ); testData.put( "Account-11", asList( 0L, 0L ) ); testData.put( "Bill", asList( 0L, 1L ) ); testData.put( "Account-10", asList( 0L, 1L ) ); for ( String resourceName : testData.keySet() ) { List<Long> expectedResults = testData.get( resourceName ); Iterator<Long> expectedResultsIterator = expectedResults.iterator(); QueryUnionExecutionResult results = queries.hasAccessToResource( "Liz", resourceName ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( resourceName + " inherited", expectedResultsIterator.next(), iterator.next().get( "accessCount" ) ); assertEquals( resourceName + " not inherited", expectedResultsIterator.next(), iterator.next().get( "accessCount" ) ); assertFalse( iterator.hasNext() ); assertFalse( expectedResultsIterator.hasNext() ); } } | public QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0." + ".3]-(company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource)\n" + "WHERE (permission.inherit=true) AND NOT (admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company)\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=admin-[:MEMBER_OF]->()-[permission:ALLOWED]->company-[:WORKS_FOR|HAS_ACCOUNT*1..2]-resource\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0." + ".3]-(company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource)\n" + "WHERE (permission.inherit=true) AND NOT (admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company)\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=admin-[:MEMBER_OF]->()-[permission:ALLOWED]->company-[:WORKS_FOR|HAS_ACCOUNT*1..2]-resource\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0." + ".3]-(company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource)\n" + "WHERE (permission.inherit=true) AND NOT (admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company)\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=admin-[:MEMBER_OF]->()-[permission:ALLOWED]->company-[:WORKS_FOR|HAS_ACCOUNT*1..2]-resource\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0." + ".3]-(company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource)\n" + "WHERE (permission.inherit=true) AND NOT (admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company)\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=admin-[:MEMBER_OF]->()-[permission:ALLOWED]->company-[:WORKS_FOR|HAS_ACCOUNT*1..2]-resource\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->()<-[:CHILD_OF*0." + ".3]-(company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource)\n" + "WHERE (permission.inherit=true) AND NOT (admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company)\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (resource:Resource{name:{resourceName}})\n" + "MATCH p=admin-[:MEMBER_OF]->()-[permission:ALLOWED]->company-[:WORKS_FOR|HAS_ACCOUNT*1..2]-resource\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test @Ignore("does not work conceptually") public void shouldDetermineWhetherAdminHasAccessToIndexedResource() throws Exception { Map<String, List<Long>> testData = new LinkedHashMap<>(); testData.put( "Alistair", asList( 1L, 0L ) ); testData.put( "Account-8", asList( 1L, 0L ) ); testData.put( "Eve", asList( 0L, 0L ) ); testData.put( "Account-9", asList( 0L, 0L ) ); testData.put( "Mary", asList( 0L, 0L ) ); testData.put( "Account-12", asList( 0L, 0L ) ); testData.put( "Gary", asList( 0L, 0L ) ); testData.put( "Account-11", asList( 0L, 0L ) ); testData.put( "Bill", asList( 0L, 1L ) ); testData.put( "Account-10", asList( 0L, 1L ) ); for ( String resourceName : testData.keySet() ) { List<Long> expectedResults = testData.get( resourceName ); Iterator<Long> expectedResultsIterator = expectedResults.iterator(); QueryUnionExecutionResult results = queries.hasAccessToIndexedResource( "Liz", resourceName ); Iterator<Map<String, Object>> iterator = results.iterator(); assertTrue( iterator.hasNext() ); assertEquals( resourceName + " inherited", expectedResultsIterator.next(), iterator.next().get( "accessCount" ) ); assertEquals( resourceName + " not inherited", expectedResultsIterator.next(), iterator.next().get( "accessCount" ) ); assertFalse( iterator.hasNext() ); assertFalse( expectedResultsIterator.hasNext() ); } } | public QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=true) AND NOT ((admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company))\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=true) AND NOT ((admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company))\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=true) AND NOT ((admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company))\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=true) AND NOT ((admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company))\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } | AccessControlWithRelationshipPropertiesQueries { public QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ) { String inheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=true) AND NOT ((admin)-[:MEMBER_OF]->()-[:DENIED]->()<-[:CHILD_OF*0..3]-(company))\n" + "RETURN COUNT(p) AS accessCount"; String notInheritedQuery = "MATCH (admin:Administrator {name:{adminName}}),\n" + " (company)<-[:CHILD_OF*0..3]-(:Company)-[:WORKS_FOR|HAS_ACCOUNT*1..2]-(resource:Resource {name:{resourceName}})\n" + "MATCH p=(admin)-[:MEMBER_OF]->()-[permission:ALLOWED]->(company)\n" + "WHERE (permission.inherit=false)\n" + "RETURN COUNT(p) AS accessCount"; Map<String, Object> params = new HashMap<>(); params.put( "adminName", adminName ); params.put( "resourceName", resourceName ); return executionEngine.execute( params, inheritedQuery, notInheritedQuery ); } AccessControlWithRelationshipPropertiesQueries( ExecutionEngineWrapper executionEngine ); QueryUnionExecutionResult findAccessibleResources( String adminName ); QueryUnionExecutionResult findAccessibleCompanies( String adminName ); QueryUnionExecutionResult findAccessibleAccountsForCompany( String adminName,
String companyName ); QueryUnionExecutionResult findAdminForResource( String resourceName ); QueryUnionExecutionResult findAdminForCompany( String companyName ); QueryUnionExecutionResult hasAccessToResource( String adminName, String resourceName ); QueryUnionExecutionResult hasAccessToIndexedResource( String adminName, String resourceName ); } |
@Test public void theatreCityBard() throws Exception { try ( Transaction tx = db.beginTx() ) { assertTheatreCityBard( queries.theatreCityBard() ); assertTheatreCityBard( queries2.theatreCityBard() ); assertTheatreCityBard( queriesUsingAutoIndexes.theatreCityBard() ); tx.success(); } } | public ExecutionResult theatreCityBard() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "RETURN theater.name AS theater, newcastle.name AS city, bard.lastname AS bard"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | ShakespeareQueries { public ExecutionResult theatreCityBard() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "RETURN theater.name AS theater, newcastle.name AS city, bard.lastname AS bard"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | ShakespeareQueries { public ExecutionResult theatreCityBard() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "RETURN theater.name AS theater, newcastle.name AS city, bard.lastname AS bard"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); } | ShakespeareQueries { public ExecutionResult theatreCityBard() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "RETURN theater.name AS theater, newcastle.name AS city, bard.lastname AS bard"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } | ShakespeareQueries { public ExecutionResult theatreCityBard() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "RETURN theater.name AS theater, newcastle.name AS city, bard.lastname AS bard"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } |
@Test public void suspectBehaviour3() throws Exception { GraphDatabaseService db = createDatabase3(); EmailQueries queries = new EmailQueries( db, new PrintingExecutionEngineWrapper( db, "email", name ) ); ExecutionResult result = queries.suspectBehaviour3(); Iterator<Object> objectIterator = result.columnAs( "count(f)" ); assertEquals( 2L, objectIterator.next() ); assertFalse( objectIterator.hasNext() ); db.shutdown(); } | public ExecutionResult suspectBehaviour3() { String query = "MATCH (email:Email {id:'11'})<-[f:FORWARD_OF*]-() \n" + "RETURN count(f)"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | EmailQueries { public ExecutionResult suspectBehaviour3() { String query = "MATCH (email:Email {id:'11'})<-[f:FORWARD_OF*]-() \n" + "RETURN count(f)"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | EmailQueries { public ExecutionResult suspectBehaviour3() { String query = "MATCH (email:Email {id:'11'})<-[f:FORWARD_OF*]-() \n" + "RETURN count(f)"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | EmailQueries { public ExecutionResult suspectBehaviour3() { String query = "MATCH (email:Email {id:'11'})<-[f:FORWARD_OF*]-() \n" + "RETURN count(f)"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } | EmailQueries { public ExecutionResult suspectBehaviour3() { String query = "MATCH (email:Email {id:'11'})<-[f:FORWARD_OF*]-() \n" + "RETURN count(f)"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } |
@Test public void exampleOfWith() throws Exception { try ( Transaction tx = db.beginTx() ) { assertExampleOfWith( queries.exampleOfWith() ); assertExampleOfWith( queries2.exampleOfWith() ); assertExampleOfWith( queriesUsingAutoIndexes.exampleOfWith() ); tx.success(); } } | public ExecutionResult exampleOfWith() { String query = "MATCH (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (bard)-[w:WROTE_PLAY]->(play)\n" + "WITH play \n" + "ORDER BY w.year DESC \n" + "RETURN collect(play.title) AS plays"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | ShakespeareQueries { public ExecutionResult exampleOfWith() { String query = "MATCH (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (bard)-[w:WROTE_PLAY]->(play)\n" + "WITH play \n" + "ORDER BY w.year DESC \n" + "RETURN collect(play.title) AS plays"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | ShakespeareQueries { public ExecutionResult exampleOfWith() { String query = "MATCH (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (bard)-[w:WROTE_PLAY]->(play)\n" + "WITH play \n" + "ORDER BY w.year DESC \n" + "RETURN collect(play.title) AS plays"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); } | ShakespeareQueries { public ExecutionResult exampleOfWith() { String query = "MATCH (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (bard)-[w:WROTE_PLAY]->(play)\n" + "WITH play \n" + "ORDER BY w.year DESC \n" + "RETURN collect(play.title) AS plays"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } | ShakespeareQueries { public ExecutionResult exampleOfWith() { String query = "MATCH (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (bard)-[w:WROTE_PLAY]->(play)\n" + "WITH play \n" + "ORDER BY w.year DESC \n" + "RETURN collect(play.title) AS plays"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } |
@Test public void shouldReturnAllPlays() throws Exception { try ( Transaction tx = db.beginTx() ) { assertAllPlays( queries.allPlays() ); assertAllPlays( queries2.allPlays() ); assertAllPlays( queriesUsingAutoIndexes.allPlays() ); } } | public ExecutionResult allPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)\n" + " <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->\n" + " (play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | ShakespeareQueries { public ExecutionResult allPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)\n" + " <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->\n" + " (play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | ShakespeareQueries { public ExecutionResult allPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)\n" + " <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->\n" + " (play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); } | ShakespeareQueries { public ExecutionResult allPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)\n" + " <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->\n" + " (play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } | ShakespeareQueries { public ExecutionResult allPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)\n" + " <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->\n" + " (play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } |
@Test public void shouldReturnLatePeriodPlays() throws Exception { try ( Transaction tx = db.beginTx() ) { assertLatePeriodPlays( queries.latePeriodPlays() ); assertLatePeriodPlays( queries2.latePeriodPlays() ); assertLatePeriodPlays( queriesUsingAutoIndexes.latePeriodPlays() ); tx.success(); } } | public ExecutionResult latePeriodPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[w:WROTE_PLAY]-(bard)\n" + "WHERE w.year > 1608\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | ShakespeareQueries { public ExecutionResult latePeriodPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[w:WROTE_PLAY]-(bard)\n" + "WHERE w.year > 1608\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | ShakespeareQueries { public ExecutionResult latePeriodPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[w:WROTE_PLAY]-(bard)\n" + "WHERE w.year > 1608\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); } | ShakespeareQueries { public ExecutionResult latePeriodPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[w:WROTE_PLAY]-(bard)\n" + "WHERE w.year > 1608\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } | ShakespeareQueries { public ExecutionResult latePeriodPlays() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[w:WROTE_PLAY]-(bard)\n" + "WHERE w.year > 1608\n" + "RETURN DISTINCT play.title AS play"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } |
@Test public void orderedByPerformance() throws Exception { try ( Transaction tx = db.beginTx() ) { assertOrderedByPerformance( queries.orderedByPerformance() ); assertOrderedByPerformance( queries2.orderedByPerformance() ); assertOrderedByPerformance( queriesUsingAutoIndexes.orderedByPerformance() ); tx.success(); } } | public ExecutionResult orderedByPerformance() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN play.title AS play, count(p) AS performance_count \n" + "ORDER BY performance_count DESC"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | ShakespeareQueries { public ExecutionResult orderedByPerformance() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN play.title AS play, count(p) AS performance_count \n" + "ORDER BY performance_count DESC"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | ShakespeareQueries { public ExecutionResult orderedByPerformance() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN play.title AS play, count(p) AS performance_count \n" + "ORDER BY performance_count DESC"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); } | ShakespeareQueries { public ExecutionResult orderedByPerformance() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN play.title AS play, count(p) AS performance_count \n" + "ORDER BY performance_count DESC"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } | ShakespeareQueries { public ExecutionResult orderedByPerformance() { String query = "MATCH (theater:Venue {name:'Theatre Royal'}), \n" + " (newcastle:City {name:'Newcastle'}), \n" + " (bard:Author {lastname:'Shakespeare'})\n" + "MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()\n" + " -[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard)\n" + "RETURN play.title AS play, count(p) AS performance_count \n" + "ORDER BY performance_count DESC"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } ShakespeareQueries( ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult theatreCityBard(); ExecutionResult allPlays(); ExecutionResult latePeriodPlays(); ExecutionResult orderedByPerformance(); ExecutionResult exampleOfWith(); } |
@Test public void parcelRoutingUsingParcelRouteCalculator() throws Exception { DateTime startDtm = interval1.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); Iterable<Node> results = queries.findShortestPathWithParcelRouteCalculator( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Node> iterator = results.iterator(); assertEquals( "DeliveryArea-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-2", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-2", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-2", iterator.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", iterator.next().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void parcelRoutingUsingParcelRouteCalculatorChoosesShortestRouteBetweenDeliveryBases() throws Exception { DateTime startDtm = interval2.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); Iterable<Node> results = queries.findShortestPathWithParcelRouteCalculator( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Node> iterator = results.iterator(); assertEquals( "DeliveryArea-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-2", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-2", iterator.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", iterator.next().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void parcelRoutingUsingParcelRouteCalculatorRespectsIntervals() throws Exception { DateTime startDtm = interval3.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); Iterable<Node> results = queries.findShortestPathWithParcelRouteCalculator( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Node> iterator = results.iterator(); assertEquals( "DeliveryArea-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", iterator.next().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void parcelRoutingUsingSimpleParcelRouteCalculatorRespectsIntervals() throws Exception { DateTime startDtm = interval3.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); Iterable<Node> results = queries.findShortestPathWithSimpleParcelRouteCalculator( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Node> iterator = results.iterator(); assertEquals( "DeliveryArea-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-3", iterator.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", iterator.next().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ) { return simpleParcelRouteCalculator.calculateRoute( start, end, interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ) { return simpleParcelRouteCalculator.calculateRoute( start, end, interval ); } } | LogisticsQueries { public Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ) { return simpleParcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ) { return simpleParcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ) { return simpleParcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void withinScopeOfSingleParcelCentreParcelRouteCalculator() throws Exception { DateTime startDtm = interval2.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); Iterable<Node> results = queries.findShortestPathWithParcelRouteCalculator( "DeliveryArea-1", "DeliverySegment-8", queryInterval ); Iterator<Node> iterator = results.iterator(); assertEquals( "DeliveryArea-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", iterator.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-1", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-2", iterator.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-4", iterator.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-8", iterator.next().getProperty( "name" ) ); assertFalse( iterator.hasNext() ); } | public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ) { return parcelRouteCalculator.calculateRoute( start, end, interval ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void parcelRoutingUsingCypherReduce() throws Exception { DateTime startDtm = interval1.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); ExecutionResult result = queries.findShortestPathWithCypherReduce( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Iterable<Node>> rows = result.columnAs( "n" ); Iterator<Node> nodes = rows.next().iterator(); assertEquals( "DeliveryArea-1", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", nodes.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-1", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-2", nodes.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-2", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-2", nodes.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", nodes.next().getProperty( "name" ) ); assertFalse( nodes.hasNext() ); } | public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
@Test public void lossyDb() throws Exception { GraphDatabaseService db = createDatabase4(); EmailQueries queries = new EmailQueries( db, new PrintingExecutionEngineWrapper( db, "email", name ) ); ExecutionResult result = queries.lossyDb(); assertEquals(1, count(result.iterator())); db.shutdown(); } | public ExecutionResult lossyDb() { String query = "MATCH (bob:User {username:'Bob'})-[e:EMAILED]->(charlie:User {username:'Charlie'})\n" + "RETURN e"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } | EmailQueries { public ExecutionResult lossyDb() { String query = "MATCH (bob:User {username:'Bob'})-[e:EMAILED]->(charlie:User {username:'Charlie'})\n" + "RETURN e"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } } | EmailQueries { public ExecutionResult lossyDb() { String query = "MATCH (bob:User {username:'Bob'})-[e:EMAILED]->(charlie:User {username:'Charlie'})\n" + "RETURN e"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | EmailQueries { public ExecutionResult lossyDb() { String query = "MATCH (bob:User {username:'Bob'})-[e:EMAILED]->(charlie:User {username:'Charlie'})\n" + "RETURN e"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } | EmailQueries { public ExecutionResult lossyDb() { String query = "MATCH (bob:User {username:'Bob'})-[e:EMAILED]->(charlie:User {username:'Charlie'})\n" + "RETURN e"; Map<String, Object> params = new HashMap<String, Object>(); return executionEngineWrapper.execute( query, params ); } EmailQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); ExecutionResult suspectBehaviour(); ExecutionResult suspectBehaviour2(); ExecutionResult suspectBehaviour3(); ExecutionResult lossyDb(); } |
@Test public void parcelRoutingUsingCypherReduceChoosesShortestRouteBetweenDeliveryBases() throws Exception { DateTime startDtm = interval2.getStart().plusDays( 2 ); Interval queryInterval = new Interval( startDtm, startDtm.plusDays( 1 ) ); ExecutionResult result = queries.findShortestPathWithCypherReduce( "DeliveryArea-1", "DeliverySegment-3", queryInterval ); Iterator<Iterable<Node>> rows = result.columnAs( "n" ); Iterator<Node> nodes = rows.next().iterator(); assertEquals( "DeliveryArea-1", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-1", nodes.next().getProperty( "name" ) ); assertEquals( "ParcelCentre-2", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryBase-3", nodes.next().getProperty( "name" ) ); assertEquals( "DeliveryArea-2", nodes.next().getProperty( "name" ) ); assertEquals( "DeliverySegment-3", nodes.next().getProperty( "name" ) ); assertFalse( nodes.hasNext() ); } | public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } | LogisticsQueries { public ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ) { String query = "MATCH (s:Location {name:{startLocation}}),\n" + " (e:Location {name:{endLocation}})\n" + "MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)\n" + "WHERE all(r in relationships(upLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH e, upLeg, db1\n" + "MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)\n" + "WHERE all(r in relationships(downLeg)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH db1, db2, upLeg, downLeg\n" + "MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)\n" + "WHERE all(r in relationships(topRoute)\n" + " WHERE r.start_date <= {intervalStart}\n" + " AND r.end_date >= {intervalEnd})\n" + "WITH upLeg, downLeg, topRoute,\n" + " reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score\n" + " ORDER BY score ASC\n" + " LIMIT 1\n" + "RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS n"; Map<String, Object> params = new HashMap<String, Object>(); params.put( "startLocation", start ); params.put( "endLocation", end ); params.put( "intervalStart", interval.getStartMillis() ); params.put( "intervalEnd", interval.getEndMillis() ); return executionEngineWrapper.execute( query, params ); } LogisticsQueries( GraphDatabaseService db, ExecutionEngineWrapper executionEngineWrapper ); Iterable<Node> findShortestPathWithParcelRouteCalculator( String start, String end, Interval interval ); Iterable<Node> findShortestPathWithSimpleParcelRouteCalculator( String start, String end, Interval interval ); ExecutionResult findShortestPathWithCypherReduce( String start, String end, Interval interval ); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.