Java Code Examples for com.google.common.collect.BoundType.OPEN

The following are Jave code examples for showing how to use OPEN of the com.google.common.collect.BoundType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-pulsar   File: NamespaceBundleTest.java   Source Code and License Vote up 6 votes
@Test
public void testIncludes() throws Exception {
    DestinationName dn = DestinationName.get("persistent://pulsar/use/ns1/topic-1");
    Long hashKey = factory.getLongHashCode(dn.toString());
    Long upper = Math.max(hashKey + 1, NamespaceBundles.FULL_UPPER_BOUND);
    BoundType upperType = upper.equals(NamespaceBundles.FULL_UPPER_BOUND) ? BoundType.CLOSED : BoundType.OPEN;
    NamespaceBundle bundle = factory.getBundle(dn.getNamespaceObject(),
            Range.range(hashKey / 2, BoundType.CLOSED, upper, upperType));
    assertTrue(bundle.includes(dn));
    bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"),
            Range.range(upper, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
    assertTrue(!bundle.includes(dn));

    NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"),
            Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(!otherBundle.includes(dn));
}
 
Example 2
Project: jiplib   File: IPAddresses.java   Source Code and License Vote up 6 votes
static Range<IPAddress> canonical(final Range<IPAddress> range,
    final LongDiscreteDomain<IPAddress> domain) {
  if (range.isEmpty()) {
    return null;
  }
  final boolean l = range.lowerBoundType() == BoundType.OPEN;
  final boolean u = range.upperBoundType() == BoundType.OPEN;
  final IPAddress s = range.lowerEndpoint();
  final IPAddress e = range.upperEndpoint();
  if (l && u) {
    Range.closed(domain.next(s), domain.previous(e));
  } else if (l) {
    return Range.closed(domain.next(s), e);
  } else if (u) {
    return Range.closed(s, domain.previous(e));
  }
  return range;
}
 
Example 3
Project: tcl-regex-java   File: RuntimeColorMap.java   Source Code and License Vote up 6 votes
private void computeBmp(RangeMap<Integer, Short> fullMap) {
    for (Map.Entry<Range<Integer>, Short> me : fullMap.asMapOfRanges().entrySet()) {
        Range<Integer> range = me.getKey();
        int min = range.lowerEndpoint();
        if (range.lowerBoundType() == BoundType.OPEN) {
            min++;
        }
        if (min < Character.MAX_VALUE) {
            int rmax = range.upperEndpoint();
            if (range.upperBoundType() == BoundType.OPEN) {
                rmax--;
            }
            int max = Math.min(Character.MAX_VALUE, rmax);
            for (int x = min; x <= max; x++) {
                this.bmpMap[x] = me.getValue();
            }
        }
    }
}
 
Example 4
Project: variation-cytoscape3-app   File: Ranges.java   Source Code and License Vote up 6 votes
/**
 * Return true if the specified range is strictly less than the specified value.
 *
 * @param <C> range endpoint type
 * @param range range, must not be null
 * @param value value, must not be null
 * @return true if the specified range is strictly less than the specified value
 */
public static <C extends Comparable> boolean isLessThan(final Range<C> range, final C value)
{
    checkNotNull(range);
    checkNotNull(value);

    if (!range.hasUpperBound())
    {
        return false;
    }
    if (range.upperBoundType() == BoundType.OPEN && range.upperEndpoint().equals(value))
    {
        return true;
    }
    return range.upperEndpoint().compareTo(value) < 0;
}
 
Example 5
Project: incubator-pulsar   File: ServiceUnitZkUtils.java   Source Code and License Vote up 5 votes
private static Range<Long> getHashRange(String rangePathPart) {
    String[] endPoints = rangePathPart.split("_");
    checkArgument(endPoints.length == 2, "Malformed bundle hash range path part:" + rangePathPart);
    Long startLong = Long.decode(endPoints[0]);
    Long endLong = Long.decode(endPoints[1]);
    BoundType endType = (endPoints[1].equals(LAST_BOUNDARY)) ? BoundType.CLOSED : BoundType.OPEN;
    return Range.range(startLong, BoundType.CLOSED, endLong, endType);
}
 
Example 6
Project: r01fb   File: Range.java   Source Code and License Vote up 5 votes
public Range(final com.google.common.collect.Range<T> range) {
	_range = range;
	_upperBound = range.hasUpperBound() ? range.upperEndpoint() : null;
	_lowerBound = range.hasLowerBound() ? range.lowerEndpoint() : null;
	
	_upperBoundType = range.hasUpperBound() ? range.upperBoundType() : BoundType.OPEN;
	_lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : BoundType.OPEN;
}
 
Example 7
Project: r01fb   File: Range.java   Source Code and License Vote up 5 votes
public Range(final T lower,final BoundType lowerBoundType,
			 final T upper,final BoundType upperBoundType) {
	// store the lower and upper bounds
	_lowerBound = lower;
	_upperBound = upper;
	
	_lowerBoundType = lowerBoundType;
	_upperBoundType = upperBoundType;
	
	// Create the delegate
	if (_lowerBound != null && _upperBound != null) {
		if (lowerBoundType == BoundType.OPEN && upperBoundType == BoundType.OPEN) { 
			_range = com.google.common.collect.Range.open(_lowerBound,_upperBound);
		} else if (lowerBoundType == BoundType.OPEN && upperBoundType == BoundType.CLOSED) {
			_range = com.google.common.collect.Range.openClosed(_lowerBound,_upperBound);
		} else if (lowerBoundType == BoundType.CLOSED && upperBoundType == BoundType.CLOSED) {
			_range = com.google.common.collect.Range.closed(_lowerBound,_upperBound);
		} else if (lowerBoundType == BoundType.CLOSED && upperBoundType == BoundType.OPEN) {
			_range = com.google.common.collect.Range.closedOpen(_lowerBound,_upperBound);
		} else {
			throw new IllegalArgumentException("Both lower and upper bound types MUST be provided!");
		}
	} else if (_lowerBound != null) {
		if (lowerBoundType == BoundType.OPEN) {
			_range = com.google.common.collect.Range.greaterThan(_lowerBound);
		} else {
			_range = com.google.common.collect.Range.atLeast(_lowerBound);
		}
	} else if (_upperBound != null) {
		if (upperBoundType == BoundType.OPEN) {
			_range = com.google.common.collect.Range.lessThan(_upperBound);
		} else {
			_range = com.google.common.collect.Range.atMost(_upperBound);
		}
	} else {
		throw new IllegalArgumentException("Cannot create range, at least lower or upper bound SHOULD be not null");
	}
}
 
Example 8
Project: gondola   File: BucketManager.java   Source Code and License Vote up 5 votes
public ShardState lookupBucketTable(Range<Integer> range) {
    Map<Range<Integer>, ShardState> rangeMaps = bucketMap.subRangeMap(range).asMapOfRanges();
    if (rangeMaps.size() > 1) {
        boolean same = true;
        ShardState prev = null;
        for (Map.Entry<Range<Integer>, ShardState> e : rangeMaps.entrySet()) {
            Range<Integer> r = e.getKey();
            if (r.upperEndpoint() - r.lowerEndpoint() <= 1 && r.lowerBoundType() == BoundType.OPEN
                && r.upperBoundType() == BoundType.OPEN) {
                continue;
            }
            if (prev != null && !prev.equals(e.getValue())) {
                same = false;
                break;

            }
            prev = e.getValue();
        }
        if (!same) {
            throw new IllegalStateException(
                "Overlapped range found - inputRange=" + range + " ranges=" + rangeMaps.toString());
        }
        return prev;
    } else if (rangeMaps.size() == 0) {
        return null;
    }
    return rangeMaps.values().stream().findFirst().get();
}
 
Example 9
Project: activitystreams   File: Parameter.java   Source Code and License Vote up 5 votes
public <O extends Comparable<? super O>>Range<O> bounds() {
  O mini = minInclusive();
  O mine = minExclusive();
  O maxi = maxInclusive();
  O maxe = maxExclusive();
  Ordering<O> ordering = Ordering.<O>natural();
  O min = ordering.nullsLast().min(mini,mine);
  O max = ordering.nullsFirst().max(maxi,maxe);
  BoundType lower = 
    min == null ? null :
    min == mini ? BoundType.CLOSED :
      BoundType.OPEN;
  BoundType upper = 
    max == null ? null : 
    max == maxi ? BoundType.CLOSED :
      BoundType.OPEN;
  if (lower == null && upper == null)
    return Range.<O>all();
  else if (lower != null && upper == null) 
    return lower == BoundType.CLOSED ? 
      Range.atLeast(min) : 
      Range.greaterThan(min);
  else if (lower == null && upper != null)
    return upper == BoundType.CLOSED ?
      Range.atMost(max) :
      Range.lessThan(max);
  else {
    return Range.range(min, lower, max, upper);
  }
}
 
Example 10
Project: jiplib   File: AddressIterable.java   Source Code and License Vote up 5 votes
/**
 * @param range
 *          the address range
 * @param domain
 *          addressing domain
 */
public AddressIterable(final Range<IPAddress> range) {
  this();
  this.range = range;
  this.domain = (LongDiscreteDomain<IPAddress>) range.lowerEndpoint()
      .getDomain();
  this.current = range.lowerEndpoint();
  if (range.lowerBoundType() == BoundType.OPEN) {
    this.current = this.domain.next(this.current);
  }
}
 
Example 11
Project: jiplib   File: AddressIterable.java   Source Code and License Vote up 5 votes
/**
 * @return size of the address range
 */
public BigInteger size() {
  BigInteger result = this.domain.distance(this.range.lowerEndpoint(),
      this.range.upperEndpoint());
  result = result.add(BigInteger.ONE);
  if (this.range.upperBoundType() == BoundType.OPEN) {
    result = result.subtract(BigInteger.ONE);
  }
  if (this.range.lowerBoundType() == BoundType.OPEN) {
    result = result.subtract(BigInteger.ONE);
  }
  return result;
}
 
Example 12
Project: calcite   File: RexSimplify.java   Source Code and License Vote up 5 votes
private <C extends Comparable<C>> RexNode simplifyUsingPredicates(RexNode e,
    Class<C> clazz) {
  final Comparison comparison = Comparison.of(e);
  // Check for comparison with null values
  if (comparison == null
      || comparison.kind == SqlKind.NOT_EQUALS
      || comparison.literal.getValue() == null) {
    return e;
  }
  final C v0 = comparison.literal.getValueAs(clazz);
  final Range<C> range = range(comparison.kind, v0);
  final Range<C> range2 =
      residue(comparison.ref, range, predicates.pulledUpPredicates,
          clazz);
  if (range2 == null) {
    // Term is impossible to satisfy given these predicates
    return rexBuilder.makeLiteral(false);
  } else if (range2.equals(range)) {
    // no change
    return e;
  } else if (range2.equals(Range.all())) {
    // Term is always satisfied given these predicates
    return rexBuilder.makeLiteral(true);
  } else if (range2.lowerEndpoint().equals(range2.upperEndpoint())) {
    if (range2.lowerBoundType() == BoundType.OPEN
        || range2.upperBoundType() == BoundType.OPEN) {
      // range is a point, but does not include its endpoint, therefore is
      // effectively empty
      return rexBuilder.makeLiteral(false);
    }
    // range is now a point; it's worth simplifying
    return rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, comparison.ref,
        rexBuilder.makeLiteral(range2.lowerEndpoint(),
            comparison.literal.getType(), comparison.literal.getTypeName()));
  } else {
    // range has been reduced but it's not worth simplifying
    return e;
  }
}
 
Example 13
Project: tcl-regex-java   File: ColorMap.java   Source Code and License Vote up 5 votes
/**
 * subrange - allocate new subcolors to this range of chars, fill in arcs.
 * The range will overlap existing ranges; even in the simplest case,
 * it will overlap the initial WHITE range. For each existing range that
 * it overlaps, allocate a new color, mark the range as mapping to that color,
 * and add an arc between the states for that color.
 */
void subrange(int from, int to, State lp, State rp) throws RegexException {
    /* Avoid one call to map.get() for each character in the range.
     * This map will usually contain one item, but in complex cases more.
     * For example, if we had [a-f][g-h] and then someone asked for [f-g], there
     * would be two. Each of these new ranges will get a new color via subcolor.
     */
    Map<Range<Integer>, Short> curColors = map.subRangeMap(Range.closed(from, to)).asMapOfRanges();
    /*
     * To avoid concurrent mod problems, we need to copy the ranges we are working from.
     */
    List<Range<Integer>> ranges = Lists.newArrayList(curColors.keySet());
    for (Range<Integer> rangeToProcess : ranges) {
        // bound management here irritating.
        int start = rangeToProcess.lowerEndpoint();
        if (rangeToProcess.lowerBoundType() == BoundType.OPEN) {
            start++;
        }
        int end = rangeToProcess.upperEndpoint();
        if (rangeToProcess.upperBoundType() == BoundType.CLOSED) {
            end++;
        }
        // allocate a new subcolor and account it owning the entire range.
        short color = subcolor(start, end - start);
        compiler.getNfa().newarc(Compiler.PLAIN, color, lp, rp);
    }
}
 
Example 14
Project: ngs   File: Ranges.java   Source Code and License Vote up 5 votes
/**
 * Return true if the specified range is strictly less than the specified value.
 *
 * @param <C> range endpoint type
 * @param range range, must not be null
 * @param value value, must not be null
 * @return true if the specified range is strictly less than the specified value
 */
public static <C extends Comparable> boolean isLessThan(final Range<C> range, final C value) {
    checkNotNull(range);
    checkNotNull(value);

    if (!range.hasUpperBound()) {
        return false;
    }
    if (range.upperBoundType() == BoundType.OPEN && range.upperEndpoint().equals(value)) {
        return true;
    }
    return range.upperEndpoint().compareTo(value) < 0;
}
 
Example 15
Project: ngs   File: Ranges.java   Source Code and License Vote up 5 votes
/**
 * Return true if the specified range is strictly greater than the specified value.
 *
 * @param <C> range endpoint type
 * @param range range, must not be null
 * @param value value, must not be null
 * @return true if the specified range is strictly greater than the specified value
 */
public static <C extends Comparable> boolean isGreaterThan(final Range<C> range, final C value) {
    checkNotNull(range);
    checkNotNull(value);

    if (!range.hasLowerBound()) {
        return false;
    }
    if (range.lowerBoundType() == BoundType.OPEN && range.lowerEndpoint().equals(value)) {
        return true;
    }
    return range.lowerEndpoint().compareTo(value) > 0;
}
 
Example 16
Project: magenta   File: RandomLong.java   Source Code and License Vote up 5 votes
/**
 * Generate a {@code long} within the intersection formed by the specified {@code range} and this instance own range.
 *
 * @param range the specfied range
 * @return a generated {@code long}
 */
public long any(final Range<Long> range) {

  Range<Long> r = range.intersection(constraint);

  if (r.isEmpty()) {
    throw new IllegalStateException(String.format(
        "The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
  }

  long upperBound = r.hasUpperBound() ? r.upperEndpoint() : Long.MAX_VALUE;
  long lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Long.MIN_VALUE;

  if (r.hasUpperBound() && BoundType.CLOSED == r.upperBoundType()) {
    upperBound++;
  }

  if (r.hasLowerBound() && BoundType.OPEN == r.lowerBoundType()) {
    lowerBound++;
  }

  long delta = Math.abs(upperBound - lowerBound);

  long randomLong = ((( Math.abs(this.random.nextLong()) % (delta / resolution))) * resolution) + lowerBound ;

  return randomLong;
}
 
Example 17
Project: magenta   File: RandomShort.java   Source Code and License Vote up 5 votes
/**
 * Generate a random short within the intersection of the specified
 * <code>range</code> and this instance current range.
 *
 * @param range
 *          the desired range
 * @return a randomly generated integer
 */
public short any(final Range<Short> range) {

  Range<Short> r = range.intersection(constraint);

  if (r.isEmpty()) {
    throw new IllegalStateException(String.format(
        "The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
  }

  short upperBound = r.hasUpperBound() ? r.upperEndpoint() : Short.MAX_VALUE;
  short lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Short.MIN_VALUE;

  if (BoundType.CLOSED == r.upperBoundType()) {
    // upperBound is not included in the random.nextInt() method
    upperBound++;
  }

  if (BoundType.OPEN == r.lowerBoundType()) {
    // lowerBound is included in the random.nextInt() method
    lowerBound++;
  }

  short delta = (short) Math.abs(upperBound - lowerBound);

  short anyIntRange = (short) ((this.random.nextInt(delta / resolution) * resolution) + lowerBound);

  return anyIntRange;
}
 
Example 18
Project: magenta   File: RandomInteger.java   Source Code and License Vote up 5 votes
/**
 * Generate a random integer within the intersection of the specified
 * <code>range</code> and this instance current range.
 *
 * @param range
 *          the desired range
 * @return a randomly generated integer
 */
public int any(final Range<Integer> range) {

  Range<Integer> r = range.intersection(constraint);

  if (r.isEmpty()) {
    throw new IllegalStateException(String.format(
        "The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
  }

  int upperBound = r.hasUpperBound() ? r.upperEndpoint() : Integer.MAX_VALUE;
  int lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Integer.MIN_VALUE;

  if (r.hasUpperBound() && BoundType.CLOSED == r.upperBoundType()) {
    // upperBound is not included in the random.nextInt() method
    upperBound++;
  }

  if (r.hasLowerBound() && BoundType.OPEN == r.lowerBoundType()) {
    // lowerBound is included in the random.nextInt() method
    lowerBound++;
  }

  int delta = Math.abs(upperBound - lowerBound);

  int anyIntegerRange = (this.random.nextInt(delta / resolution) * resolution) + lowerBound ;

  return anyIntegerRange;
}
 
Example 19
Project: magenta   File: RandomDouble.java   Source Code and License Vote up 5 votes
/**
 * Return any double in the intersection of the specified range and this class
 * own defined range.
 *
 * @param range
 *          the desired range
 * @return a random double
 */
public double any(final Range<Double> range) {
  Range<Double> r = range.intersection(constraint);

  if (r.isEmpty()) {
    throw new IllegalStateException(String.format(
        "The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
  }

  double upperBound = r.hasUpperBound() ? r.upperEndpoint() : 1.0E7D;
  double lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : -1.0E7D;

  if (r.hasUpperBound() && BoundType.CLOSED == r.upperBoundType()) {
    upperBound = upperBound + lowestIncrement;
  }

  if (r.hasLowerBound() && BoundType.OPEN == r.lowerBoundType()) {
    lowerBound = lowerBound + lowestIncrement;
  }

  if(Double.isInfinite(lowerBound * scale)){
    lowerBound = lowerBound / scale;
  }

  if(Double.isInfinite(upperBound * scale)){
    upperBound = upperBound / scale;
  }

  double delta = Math.abs(upperBound - lowerBound);

  double anyDoubleRange = (Math.floor((this.random.nextDouble() * delta * scale) + (lowerBound * scale)) / scale);

  return anyDoubleRange;
}
 
Example 20
Project: variation-cytoscape3-app   File: Ranges.java   Source Code and License Vote up 5 votes
/**
 * Return true if the specified range is strictly greater than the specified value.
 *
 * @param <C> range endpoint type
 * @param range range, must not be null
 * @param value value, must not be null
 * @return true if the specified range is strictly greater than the specified value
 */
public static <C extends Comparable> boolean isGreaterThan(final Range<C> range, final C value) {
    checkNotNull(range);
    checkNotNull(value);

    if (!range.hasLowerBound())
    {
        return false;
    }
    if (range.lowerBoundType() == BoundType.OPEN && range.lowerEndpoint().equals(value))
    {
        return true;
    }
    return range.lowerEndpoint().compareTo(value) > 0;
}
 
Example 21
Project: ProjectAres   File: XMLUtils.java   Source Code and License Vote up 4 votes
/**
 * Parse a range in the standard mathematical format e.g.
 *
 *     [0, 1) for a closed-open range from 0 to 1.
 *
 * Can also parse single numbers as a closed range e.g.
 *
 *     5 for a closed-closed range from 5 to 5.
 */
public static <T extends Number & Comparable<T>> Range<T> parseNumericRange(Node node, Class<T> type) throws InvalidXMLException {
    String value = node.getValue();

    Matcher matcher = RANGE_RE.matcher(value);
    if(!matcher.matches()) {
        T number = parseNumber(node, value, type, (T) null);
        if(number != null) {
            return Range.singleton(number);
        }
        throw new InvalidXMLException("Invalid " + type.getSimpleName().toLowerCase() + " range '" + value + "'", node);
    }

    T lower = parseNumber(node, matcher.group(2), type, true);
    T upper = parseNumber(node, matcher.group(3), type, true);

    BoundType lowerType = null, upperType = null;
    if(!Double.isInfinite(lower.doubleValue())) {
        lowerType = "(".equals(matcher.group(1)) ? BoundType.OPEN : BoundType.CLOSED;
    }
    if(!Double.isInfinite(upper.doubleValue())) {
        upperType = ")".equals(matcher.group(4)) ? BoundType.OPEN : BoundType.CLOSED;
    }

    if(lower.compareTo(upper) == 1) {
        throw new InvalidXMLException("range lower bound (" + lower + ") cannot be greater than upper bound (" + upper + ")", node);
    }

    if(lowerType == null) {
        if(upperType == null) {
            return Range.all();
        } else {
            return Range.upTo(upper, upperType);
        }
    } else {
        if(upperType == null) {
            return Range.downTo(lower, lowerType);
        } else {
            return Range.range(lower, lowerType, upper, upperType);
        }
    }
}
 
Example 22
Project: ProjectAres   File: XMLUtils.java   Source Code and License Vote up 4 votes
public static <T extends Number & Comparable<T>> Range<T> parseNumericRange(Element el, Class<T> type, Range<T> def) throws InvalidXMLException {
    Attribute lt = el.getAttribute("lt");
    Attribute lte = getAttribute(el, "lte", "max");
    Attribute gt = el.getAttribute("gt");
    Attribute gte = getAttribute(el, "gte", "min");

    if(lt != null && lte != null) throw new InvalidXMLException("Conflicting upper bound for numeric range", el);
    if(gt != null && gte != null) throw new InvalidXMLException("Conflicting lower bound for numeric range", el);

    BoundType lowerBoundType, upperBoundType;
    T lowerBound, upperBound;

    if(gt != null) {
        lowerBound = parseNumber(gt, type, (T) null);
        lowerBoundType = BoundType.OPEN;
    } else {
        lowerBound = parseNumber(gte, type, (T) null);
        lowerBoundType = BoundType.CLOSED;
    }

    if(lt != null) {
        upperBound = parseNumber(lt, type, (T) null);
        upperBoundType = BoundType.OPEN;
    } else {
        upperBound = parseNumber(lte, type, (T) null);
        upperBoundType = BoundType.CLOSED;
    }

    if(lowerBound == null) {
        if(upperBound == null) {
            return def;
        } else {
            return Range.upTo(upperBound, upperBoundType);
        }
    } else {
        if(upperBound == null) {
            return Range.downTo(lowerBound, lowerBoundType);
        } else {
            return Range.range(lowerBound, lowerBoundType, upperBound, upperBoundType);
        }
    }
}
 
Example 23
Project: scylla-tools-java   File: TokenFilter.java   Source Code and License Vote up 4 votes
private static BoundType toBoundType(boolean inclusive)
{
    return inclusive ? BoundType.CLOSED : BoundType.OPEN;
}
 
Example 24
Project: ngs   File: Interval.java   Source Code and License Vote up 4 votes
private BoundType reverse(final BoundType type) {
    return this.range.upperBoundType() == BoundType.OPEN ? BoundType.CLOSED
                                                         : BoundType.OPEN;
}
 
Example 25
Project: assertj-guava   File: RangeAssert.java   Source Code and License Vote up 3 votes
/**
 * Verifies that the actual {@link com.google.common.collect.Range} lower bound is opened.<br>
 * <p>
 * Example :
 *
 * <pre><code class='java'> Range&lt;Integer&gt; range = Range.open(1, 2);
 *
 * assertThat(range).hasOpenedLowerBound();</code></pre>
 *
 * @return this {@link OptionalAssert} for assertions chaining.
 * @throws AssertionError if the actual {@link com.google.common.collect.Range} is {@code null}.
 * @throws AssertionError if the actual {@link com.google.common.collect.Range} lower bound is closed.
 */
public RangeAssert<T> hasOpenedLowerBound() throws AssertionError {
  Objects.instance().assertNotNull(info, actual);

  if (actual.lowerBoundType() != BoundType.OPEN) {
    throw failures.failure(info, shouldHaveOpenedLowerBound(actual));
  }

  return this;
}
 
Example 26
Project: assertj-guava   File: RangeAssert.java   Source Code and License Vote up 3 votes
/**
 * Verifies that the actual {@link com.google.common.collect.Range} upper bound is opened.<br>
 * <p>
 * Example :
 *
 * <pre><code class='java'> Range&lt;Integer&gt; range = Range.open(10, 12);
 *
 * assertThat(range).hasOpenedUpperBound();</code></pre>
 *
 * @return this {@link OptionalAssert} for assertions chaining.
 * @throws AssertionError if the actual {@link com.google.common.collect.Range} is {@code null}.
 * @throws AssertionError if the actual {@link com.google.common.collect.Range} upper bound is closed.
 */
public RangeAssert<T> hasOpenedUpperBound() throws AssertionError {
  Objects.instance().assertNotNull(info, actual);

  if (actual.upperBoundType() != BoundType.OPEN) {
    throw failures.failure(info, shouldHaveOpenedUpperBound(actual));
  }

  return this;
}
 
Example 27
Project: r01fb   File: Range.java   Source Code and License Vote up 2 votes
/**
 * Creates an OPEN range from its bounds
 * @param lower
 * @param upper
 * @return
 */
public static <T extends Comparable<T>> Range<T> open(final T lower,final T upper) {
	if (lower == null || upper == null) throw new IllegalArgumentException("Both lower and upper bounds must be not null in an open Range");
	return new Range<T>(lower,BoundType.OPEN,
						upper,BoundType.OPEN);
}
 
Example 28
Project: r01fb   File: Range.java   Source Code and License Vote up 2 votes
/**
 * Creates an OPEN on the lower end and CLOSED on the upper end range from its bounds
 * @param lower
 * @param upper
 * @return
 */
public static <T extends Comparable<T>> Range<T> openClosed(final T lower,final T upper) {
	if (lower == null || upper == null) throw new IllegalArgumentException("Both lower and upper bounds must be not null in an open Range");
	return new Range<T>(lower,BoundType.OPEN,
						upper,BoundType.CLOSED);
}
 
Example 29
Project: r01fb   File: Range.java   Source Code and License Vote up 2 votes
/**
 * Creates an CLOSED on the lower end and OPEN on the upper end range from its bounds
 * @param lower
 * @param upper
 * @return
 */
public static <T extends Comparable<T>> Range<T> closedOpen(final T lower,final T upper) {
	if (lower == null || upper == null) throw new IllegalArgumentException("Both lower and upper bounds must be not null in an open Range");
	return new Range<T>(lower,BoundType.CLOSED,
						upper,BoundType.OPEN);
}
 
Example 30
Project: r01fb   File: Range.java   Source Code and License Vote up 2 votes
/**
 * Creates a greaterThan (>) range from its lower bound
 * @param lower
 * @param upper
 * @return
 */
public static <T extends Comparable<T>> Range<T> greaterThan(final T lower) {
	if (lower == null) throw new IllegalArgumentException("lower bound must be not null in an greaterThan Range");
	return new Range<T>(lower,BoundType.OPEN,
						null,null);
}
 
Example 31
Project: r01fb   File: Range.java   Source Code and License Vote up 2 votes
/**
 * Creates a lessThan (<) range from the upper bound
 * @param lower
 * @param upper
 * @return
 */
public static <T extends Comparable<T>> Range<T> lessThan(final T upper) {
	if (upper == null) throw new IllegalArgumentException("upper bound must be not null in an greaterThan Range");
	return new Range<T>(null,null,
						upper,BoundType.OPEN);
}