/** * * @param from inclusive start point for range * @param to inclusive end point for range * @param hitLimit This tells how many results you want included from this range as a minimum. * You might get less if there are not enough, or you might get more. It will use the dictionary and * include enough entries to satisfy your request. * Positive number will start from left (@from) and work right. * Negative number will start from right and work its way left. * 0 means no limit. * @param indexName the index to search for this range * @param isFromQuery Indicate if this stems directly from the user given query, * or if you have constructed it at will. */ public RangeItem(Number from, Number to, int hitLimit, String indexName, boolean isFromQuery) { this(new Limit(from, true), new Limit(to, true), hitLimit, indexName, isFromQuery); }
@NonNull private IntItem instantiateRangeItem(Number lowerBound, Number upperBound, String field, boolean bounds_left_open, boolean bounds_right_open) { Preconditions.checkArgument(lowerBound != null && upperBound != null && field != null, "Expected 3 NonNull-arguments"); if (!bounds_left_open && !bounds_right_open) { return new RangeItem(lowerBound, upperBound, field); } else { Limit from; Limit to; if (bounds_left_open && bounds_right_open) { from = new Limit(lowerBound, false); to = new Limit(upperBound, false); } else if (bounds_left_open) { from = new Limit(lowerBound, false); to = new Limit(upperBound, true); } else { from = new Limit(lowerBound, true); to = new Limit(upperBound, false); } return new IntItem(from, to, field); } }
private void parseAndAssignLimits(String e) { if (e.startsWith("<") && ! e.contains(";")) { from = Limit.NEGATIVE_INFINITY; to = new Limit(asNumber(e.substring(1)), false); } else if (e.startsWith(">")) { from = new Limit(asNumber(e.substring(1)), false); to = Limit.POSITIVE_INFINITY; } else if (e.startsWith("[") || e.startsWith("<")) { if ( ! (e.endsWith("]") || e.endsWith(">"))) throw new IllegalArgumentException("No closing bracket"); boolean inclusiveStart = e.startsWith("["); boolean inclusiveEnd = e.startsWith("["); String[] limits = e.substring(1, e.length()-1).split(";"); if (limits.length < 1 || limits.length > 3) throw new IllegalArgumentException("Unexpected bracket content"); Limit from = new Limit(getOr(Double.NEGATIVE_INFINITY, 0, limits), inclusiveStart); Limit to = new Limit(getOr(Double.POSITIVE_INFINITY, 1, limits), inclusiveEnd); setLimits(from, to); hitLimit = getOr(0, 2, limits).intValue(); } else { to = from = new Limit(asNumber(e), true); } }
Limit to; if (BOUNDS_OPEN.equals(bounds)) { from = new Limit(lowerArg, false); to = new Limit(upperArg, false); } else if (BOUNDS_LEFT_OPEN.equals(bounds)) { from = new Limit(lowerArg, false); to = new Limit(upperArg, true); } else if (BOUNDS_RIGHT_OPEN.equals(bounds)) { from = new Limit(lowerArg, true); to = new Limit(upperArg, false); } else { throw newUnexpectedArgumentException(bounds, BOUNDS_OPEN,