Java Code Examples for com.google.common.collect.Ranges#greaterThan()
The following examples show how to use
com.google.common.collect.Ranges#greaterThan() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostgreSQLGuavaRangeType.java From hibernate-types with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static <T extends Comparable> Range<T> ofString(String str, Function<String, T> converter, Class<T> cls) { BoundType lowerBound = str.charAt(0) == '[' ? BoundType.CLOSED : BoundType.OPEN; BoundType upperBound = str.charAt(str.length() - 1) == ']' ? BoundType.CLOSED : BoundType.OPEN; int delim = str.indexOf(','); if (delim == -1) { throw new IllegalArgumentException("Cannot find comma character"); } String lowerStr = str.substring(1, delim); String upperStr = str.substring(delim + 1, str.length() - 1); T lower = null; T upper = null; if (lowerStr.length() > 0) { lower = converter.apply(lowerStr); } if (upperStr.length() > 0) { upper = converter.apply(upperStr); } if (lower == null && upper == null) { throw new IllegalArgumentException("Cannot find bound type"); } if (lowerStr.length() == 0) { return upperBound == BoundType.CLOSED ? Ranges.atMost(upper) : Ranges.lessThan(upper); } else if (upperStr.length() == 0) { return lowerBound == BoundType.CLOSED ? Ranges.atLeast(lower) : Ranges.greaterThan(lower); } else { return Ranges.range(lower, lowerBound, upper, upperBound); } }
Example 2
Source File: PostgreSQLGuavaRangeType.java From hibernate-types with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static <T extends Comparable> Range<T> ofString(String str, Function<String, T> converter, Class<T> cls) { BoundType lowerBound = str.charAt(0) == '[' ? BoundType.CLOSED : BoundType.OPEN; BoundType upperBound = str.charAt(str.length() - 1) == ']' ? BoundType.CLOSED : BoundType.OPEN; int delim = str.indexOf(','); if (delim == -1) { throw new IllegalArgumentException("Cannot find comma character"); } String lowerStr = str.substring(1, delim); String upperStr = str.substring(delim + 1, str.length() - 1); T lower = null; T upper = null; if (lowerStr.length() > 0) { lower = converter.apply(lowerStr); } if (upperStr.length() > 0) { upper = converter.apply(upperStr); } if (lower == null && upper == null) { throw new IllegalArgumentException("Cannot find bound type"); } if (lowerStr.length() == 0) { return upperBound == BoundType.CLOSED ? Ranges.atMost(upper) : Ranges.lessThan(upper); } else if (upperStr.length() == 0) { return lowerBound == BoundType.CLOSED ? Ranges.atLeast(lower) : Ranges.greaterThan(lower); } else { return Ranges.range(lower, lowerBound, upper, upperBound); } }
Example 3
Source File: PostgreSQLGuavaRangeType.java From hibernate-types with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static <T extends Comparable> Range<T> ofString(String str, Function<String, T> converter, Class<T> cls) { BoundType lowerBound = str.charAt(0) == '[' ? BoundType.CLOSED : BoundType.OPEN; BoundType upperBound = str.charAt(str.length() - 1) == ']' ? BoundType.CLOSED : BoundType.OPEN; int delim = str.indexOf(','); if (delim == -1) { throw new IllegalArgumentException("Cannot find comma character"); } String lowerStr = str.substring(1, delim); String upperStr = str.substring(delim + 1, str.length() - 1); T lower = null; T upper = null; if (lowerStr.length() > 0) { lower = converter.apply(lowerStr); } if (upperStr.length() > 0) { upper = converter.apply(upperStr); } if (lower == null && upper == null) { throw new IllegalArgumentException("Cannot find bound type"); } if (lowerStr.length() == 0) { return upperBound == BoundType.CLOSED ? Ranges.atMost(upper) : Ranges.lessThan(upper); } else if (upperStr.length() == 0) { return lowerBound == BoundType.CLOSED ? Ranges.atLeast(lower) : Ranges.greaterThan(lower); } else { return Ranges.range(lower, lowerBound, upper, upperBound); } }