Java Code Examples for com.google.common.primitives.Ints.MAX_POWER_OF_TWO

The following are Jave code examples for showing how to use MAX_POWER_OF_TWO of the com.google.common.primitives.Ints class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: guava-mock   File: Maps.java   View Source Code Vote up 5 votes
/**
 * Returns a capacity that is sufficient to keep the map from being resized as long as it grows no
 * larger than expectedSize and the load factor is ≥ its default (0.75).
 */
static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 2
Project: googles-monorepo-demo   File: Maps.java   View Source Code Vote up 5 votes
/**
 * Returns a capacity that is sufficient to keep the map from being resized as long as it grows no
 * larger than expectedSize and the load factor is ≥ its default (0.75).
 */
static int capacity(int expectedSize) {
  if (expectedSize < 3) {
    checkNonnegative(expectedSize, "expectedSize");
    return expectedSize + 1;
  }
  if (expectedSize < Ints.MAX_POWER_OF_TWO) {
    // This is the calculation used in JDK8 to resize when a putAll
    // happens; it seems to be the most conservative calculation we
    // can make.  0.75 is the default load factor.
    return (int) ((float) expectedSize / 0.75F + 1.0F);
  }
  return Integer.MAX_VALUE; // any large value
}
 
Example 3
Project: guava-mock   File: Striped.java   View Source Code Vote up 4 votes
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}
 
Example 4
Project: googles-monorepo-demo   File: Striped.java   View Source Code Vote up 4 votes
PowerOfTwoStriped(int stripes) {
  Preconditions.checkArgument(stripes > 0, "Stripes must be positive");
  this.mask = stripes > Ints.MAX_POWER_OF_TWO ? ALL_SET : ceilToPowerOfTwo(stripes) - 1;
}