Ops { public static boolean in(TemplateContext ctx, Object o, Object in) { if (in == null) { return false; } if (in instanceof LongRange) { return ((LongRange) in).in(Types.toLong(ctx, o)); } if (in instanceof DoubleRange) { return ((DoubleRange) in).in(Types.toDouble(ctx, o)); } if (in instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) in; return map.containsKey(o) || map.containsKey(Types.toString(ctx, o)); } if (Types.isString(ctx, in)) { return Types.toString(ctx, in).contains(Types.toString(ctx, o)); } if (in instanceof Iterable<?> || Types.isArray(ctx, in)) { Iterator<?> it = Types.toIterator(ctx, in); while (it.hasNext()) { Object item = it.next(); if (CompareOps.eq(ctx, o, item)) { return true; } } return false; } return false; }  static Object and(TemplateContext ctx, Object value1, final Object value2); static Object or(TemplateContext ctx, Object value1, final Object value2); static Object iand(TemplateContext ctx, Object value1, final Object value2); static Object ior(TemplateContext ctx, Object value1, final Object value2); static Object xor(TemplateContext ctx, Object value1, final Object value2); static Object div(TemplateContext ctx, Object value1, final Object value2); static Object mul(TemplateContext ctx, Object value1, final Object value2); static Object mod(TemplateContext ctx, Object value1, final Object value2); static Object binaryPlus(TemplateContext ctx, Object value1, final Object value2); static Object binaryMinus(TemplateContext ctx, Object value1, final Object value2); static Object unaryMinus(TemplateContext ctx, Object value); static Object unaryPlus(TemplateContext ctx, Object value); static long bitwiseNot(TemplateContext ctx, Object value); static boolean booleanNot(TemplateContext ctx, Object value); static long lshift(TemplateContext ctx, Object value, Object count); static long rshift(TemplateContext ctx, Object value, Object count); static Object slice(TemplateContext ctx, Object target, Object startObject, Object endObject, Object strideObject); static Object dot(TemplateContext ctx, Object target, Object child); static Object qdot(TemplateContext ctx, Object target, Object child); static Object pipe(TemplateContext ctx, Object target, Object filterName, Object[] params); static Object invoke(TemplateContext ctx, Object target, Object methodName, Object[] params); static Object newRange(TemplateContext ctx, Object from, Object to); static Object newRangeBy(TemplateContext ctx, Object from, Object to, Object by); static boolean in(TemplateContext ctx, Object o, Object in);  }
@Test public void testIn() { assertTrue(Ops.in(null, 1, new LongRange(1, 2))); assertTrue(Ops.in(null, 1, new DoubleRange(1, 2))); assertFalse(Ops.in(null, 0, new LongRange(1, 2))); assertFalse(Ops.in(null, 0, new DoubleRange(1, 2))); assertTrue(Ops.in(null, "a", "cat")); assertTrue(Ops.in(null, "a", 'a')); assertFalse(Ops.in(null, "a", "boo")); assertFalse(Ops.in(null, "a", 'o')); assertTrue(Ops.in(null, 1, Arrays.asList(1, 2, 3))); assertTrue(Ops.in(null, 1L, Arrays.asList(1, 2, 3))); assertFalse(Ops.in(null, 10, Arrays.asList(1, 2, 3))); assertFalse(Ops.in(null, 10L, Arrays.asList(1, 2, 3))); assertTrue(Ops.in(null, 1, new Object[] { 1, 2, 3 })); assertTrue(Ops.in(null, 1, new int[] { 1, 2, 3 })); assertTrue(Ops.in(null, 1, new long[] { 1, 2, 3 })); assertTrue(Ops.in(null, 1L, new Object[] { 1, 2, 3 })); assertTrue(Ops.in(null, 1L, new int[] { 1, 2, 3 })); assertTrue(Ops.in(null, 1L, new long[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10, new Object[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10, new int[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10, new long[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10L, new Object[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10L, new int[] { 1, 2, 3 })); assertFalse(Ops.in(null, 10L, new long[] { 1, 2, 3 })); Map<Object, Object> map = Maps.newHashMap(); map.put("a", "b"); assertTrue(Ops.in(null, "a", map)); assertTrue(Ops.in(null, 'a', map)); assertFalse(Ops.in(null, "b", map)); assertFalse(Ops.in(null, 'b', map)); }