/** * Selects the maximum value found in an Iterable. * * @param items a Collection * @return the maximum value * @since 2.2.0 */ public static <T> T max(Iterable<T> items) { T answer = null; for (T value : items) { if (value != null) { if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) { answer = value; } } } return answer; }
@Override public boolean hasNext() { fetchNextIfNeeded(); return (next != null) && (isAscending ? (range.inclusive ? compareLessThanEqual(next, range.getTo()) : compareLessThan(next, range.getTo())) : (range.inclusive ? compareGreaterThanEqual(next, range.getFrom()) : compareGreaterThan(next, range.getFrom()))); }
private static boolean areReversed(Number from, Number to) { try { return compareGreaterThan(from, to); } catch (ClassCastException cce) { throw new IllegalArgumentException("Unable to create range due to incompatible types: " + from.getClass().getSimpleName() + ".." + to.getClass().getSimpleName() + " (possible missing brackets around range?)", cce); } }
public void testGreaterThan() { assertTrue(ScriptBytecodeAdapter.compareGreaterThan(new Integer(3), new Integer(2))); assertTrue(ScriptBytecodeAdapter.compareGreaterThanEqual(new Integer(2), new Integer(2))); }
private static boolean areReversed(Comparable from, Comparable to) { try { return ScriptBytecodeAdapter.compareGreaterThan(from, to); } catch (IllegalArgumentException iae) { throw new IllegalArgumentException("Unable to create range due to incompatible types: " + from.getClass().getSimpleName() + ".." + to.getClass().getSimpleName() + " (possible missing brackets around range?)", iae); } }
public static List createRange(Object from, Object to, boolean inclusive) throws Throwable { if (from instanceof Integer && to instanceof Integer) { int ifrom = (Integer) from; int ito = (Integer) to; if (inclusive || ifrom != ito) { return new IntRange(inclusive, ifrom, ito); } // else fall through for EmptyRange } if (!inclusive && compareEqual(from, to)) { return new EmptyRange((Comparable) from); } if (from instanceof Number && to instanceof Number) { return new NumberRange(comparableNumber((Number) from), comparableNumber((Number) to), inclusive); } if (!inclusive) { if (compareGreaterThan(from, to)) { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "next"); } else { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "previous"); } } return new ObjectRange((Comparable) from, (Comparable) to); }
/** * Selects the maximum value found in a collection * * @param items a Collection * @return the maximum value */ public static <T> T max(Collection<T> items) { T answer = null; for (T value : items) { if (value != null) { if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) { answer = value; } } } return answer; }
/** * Selects the maximum value found in a collection * * @param items a Collection * @return the maximum value */ public static <T> T max(Collection<T> items) { T answer = null; for (T value : items) { if (value != null) { if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) { answer = value; } } } return answer; }
/** * Selects the maximum value found in a collection * * @param items a Collection * @return the maximum value */ public static Object max(Collection items) { Object answer = null; for (Iterator iter = items.iterator(); iter.hasNext();) { Object value = iter.next(); if (value != null) { if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) { answer = value; } } } return answer; }
/** * Selects the maximum value found in a collection * * @param items a Collection * @return the maximum value */ public static Object max(Collection items) { Object answer = null; for (Iterator iter = items.iterator(); iter.hasNext();) { Object value = iter.next(); if (value != null) { if (answer == null || ScriptBytecodeAdapter.compareGreaterThan(value, answer)) { answer = value; } } } return answer; }
public static List createRange(Object from, Object to, boolean inclusive) throws Throwable { if (!inclusive) { if (compareEqual(from, to)) { return new EmptyRange((Comparable) from); } if (compareGreaterThan(from, to)) { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "next"); } else { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "previous"); } } if (from instanceof Integer && to instanceof Integer) { return new IntRange(DefaultTypeTransformation.intUnbox(from), DefaultTypeTransformation.intUnbox(to)); } else { return new ObjectRange((Comparable) from, (Comparable) to); } }
/** * Creates a new {@link ObjectRange}. Creates a reversed range if * <code>from</code> < <code>to</code>. * * @param from the first value in the range. * @param to the last value in the range. */ public ObjectRange(Comparable from, Comparable to) { if (from == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range"); } if (to == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'to' index in a Range"); } try { this.reverse = ScriptBytecodeAdapter.compareGreaterThan(from, to); } catch (ClassCastException cce) { throw new IllegalArgumentException("Unable to create range due to incompatible types: " + from.getClass().getSimpleName() + ".." + to.getClass().getSimpleName() + " (possible missing brackets around range?)", cce); } if (this.reverse) { constructorHelper(to, from); } else { constructorHelper(from, to); } }
/** * Creates a new {@link ObjectRange}. Creates a reversed range if * <code>from</code> < <code>to</code>. * * @param from the first value in the range. * @param to the last value in the range. */ public ObjectRange(Comparable from, Comparable to) { if (from == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range"); } if (to == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'to' index in a Range"); } this.reverse = ScriptBytecodeAdapter.compareGreaterThan(from, to); if (this.reverse) { constructorHelper(to, from); } else { constructorHelper(from, to); } }
/** * Creates a new {@link ObjectRange}. Creates a reversed range if * <code>from</code> < <code>to</code>. * * @param from the first value in the range. * @param to the last value in the range. */ public ObjectRange(Comparable from, Comparable to) { if (from == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range"); } if (to == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'to' index in a Range"); } this.reverse = ScriptBytecodeAdapter.compareGreaterThan(from, to); if (this.reverse) { constructorHelper(to, from); } else { constructorHelper(from, to); } }
/** * Creates a new {@link ObjectRange}. Creates a reversed range if * <code>from</code> < <code>to</code>. * * @param from the first value in the range. * @param to the last value in the range. */ public ObjectRange(Comparable from, Comparable to) { if (from == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range"); } if (to == null) { throw new IllegalArgumentException("Must specify a non-null value for the 'to' index in a Range"); } this.reverse = ScriptBytecodeAdapter.compareGreaterThan(from, to); if (this.reverse) { constructorHelper(to, from); } else { constructorHelper(from, to); } }
return new EmptyRange((Comparable) from); if (compareGreaterThan(from, to)) { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "next"); } else {
return new EmptyRange((Comparable) from); if (compareGreaterThan(from, to)) { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "next"); } else {
return new EmptyRange((Comparable) from); if (compareGreaterThan(from, to)) { to = invokeMethod0(ScriptBytecodeAdapter.class, to, "next"); } else {