Java 类com.google.common.collect.MapConstraint 实例源码

项目:guava-libraries    文件:ArbitraryInstancesTest.java   
public void testGet_misc() {
  assertNotNull(ArbitraryInstances.get(CharMatcher.class));
  assertNotNull(ArbitraryInstances.get(Currency.class).getCurrencyCode());
  assertNotNull(ArbitraryInstances.get(Locale.class));
  ArbitraryInstances.get(Joiner.class).join(ImmutableList.of("a"));
  ArbitraryInstances.get(Splitter.class).split("a,b");
  assertFalse(ArbitraryInstances.get(Optional.class).isPresent());
  ArbitraryInstances.get(Stopwatch.class).start();
  assertNotNull(ArbitraryInstances.get(Ticker.class));
  assertNotNull(ArbitraryInstances.get(MapConstraint.class));
  assertFreshInstanceReturned(Random.class);
  assertEquals(ArbitraryInstances.get(Random.class).nextInt(),
      ArbitraryInstances.get(Random.class).nextInt());
}
项目:benayn    文件:Mapper.java   
/**
 * Add a constraint that verifies that neither the key nor the value is
 * null. If either is null, a {@link NullPointerException} is thrown.
     * 
 * @return
 */
@SuppressWarnings("unchecked")
public Mapper<K, V> keyAndValueNotNull() {
    return addConstraint((MapConstraint<K, V>) MapConstraints.notNull());
}
项目:benayn    文件:Mapper.java   
/**
 * Add a constraint that verifies that the key is
 * null. If is null, a {@link NullPointerException} is thrown.
 * 
 * @return
 */
@SuppressWarnings("unchecked")
public Mapper<K, V> keyNotNull() {
    return addConstraint((MapConstraint<K, V>) KeyNotNullRestraint.INSTANCE);
}
项目:benayn    文件:Mapper.java   
/**
 * Add a constraint that verifies that the value is
 * null. If is null, a {@link NullPointerException} is thrown.
 * 
 * @return
 */
@SuppressWarnings("unchecked")
public Mapper<K, V> valueNotNull() {
    return addConstraint((MapConstraint<K, V>) ValueNotNullRestraint.INSTANCE);
}
项目:benayn    文件:Mapper.java   
/**
 * Add a constrained view of the delegate map, using the specified constraint
 * 
 * @param constraint
 * @return
 */
private Mapper<K, V> addConstraint(MapConstraint<K, V> constraint) {
    this.delegate = Optional.of(MapConstraints.constrainedMap(delegate.get(), constraint));
    return this;
}