Java Code Examples for com.google.common.primitives.Ints.max()

The following are Jave code examples for showing how to use max() 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: ditb   File: BucketAllocator.java   View Source Code Vote up 6 votes
BucketAllocator(long availableSpace, int[] bucketSizes)
    throws BucketAllocatorException {
  this.bucketSizes = bucketSizes == null ? DEFAULT_BUCKET_SIZES : bucketSizes;
  Arrays.sort(this.bucketSizes);
  this.bigItemSize = Ints.max(this.bucketSizes);
  this.bucketCapacity = FEWEST_ITEMS_IN_BUCKET * bigItemSize;
  buckets = new Bucket[(int) (availableSpace / bucketCapacity)];
  if (buckets.length < this.bucketSizes.length)
    throw new BucketAllocatorException(
        "Bucket allocator size too small - must have room for at least "
            + this.bucketSizes.length + " buckets");
  bucketSizeInfos = new BucketSizeInfo[this.bucketSizes.length];
  for (int i = 0; i < this.bucketSizes.length; ++i) {
    bucketSizeInfos[i] = new BucketSizeInfo(i);
  }
  for (int i = 0; i < buckets.length; ++i) {
    buckets[i] = new Bucket(bucketCapacity * i);
    bucketSizeInfos[i < this.bucketSizes.length ? i : this.bucketSizes.length - 1]
        .instantiateBucket(buckets[i]);
  }
  this.totalSize = ((long) buckets.length) * bucketCapacity;
}
 
Example 2
Project: Thermionics   File: BigExplosion.java   View Source Code Vote up 5 votes
/**
 * Casts a ray from origin to target, destroying blocks along the way and diminishing power.
 * 
 * <li>Does not alter origin or target vector.
 * <li>Destroys blocks
 * <li>Returns unused power to store back in the cylinder map
 */
public float raycast(World world, MutableVector origin, MutableVector target, float power) {
	IBlockState air = Blocks.AIR.getDefaultState();
	float x = origin.x + 0.5f;
	float y = origin.y + 0.5f;
	float z = origin.z + 0.5f;
	float dx = target.x - origin.x;
	float dy = target.y - origin.y;
	float dz = target.z - origin.z;
	int d = Ints.max((int)Math.abs(dx), (int)Math.abs(dy), (int)Math.abs(dz));
	dx /= (float)d;
	dy /= (float)d;
	dz /= (float)d;
	float curPower = power;
	for(int i=0; i<=d; i++) {
		BlockPos here = new BlockPos((int)x, (int)y, (int)z);
		IBlockState state = world.getBlockState(here);
		if (state!=air) {
			//curPower = 
			float remaining = explodeBlock(world, here, curPower);
			if (remaining<=0) return 0;
			//if (curPower<=0) return 0;
			curPower = remaining;
			
		}
		
		x += dx;
		y += dy;
		z += dz;
	}
	
	return curPower;
}