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

The following are Jave code examples for showing how to use min() 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.
Example 1
Project: ProjectAres   File: RaindropListener.java   Source Code and License Vote up 5 votes
private int calculateRaindrops(MatchPlayerState player, int count, boolean scaled, double percent) {
    if(scaled) {
        final Match match = player.getMatch();
        count += (int) ((double) match.getParticipatingPlayers().size() / match.getMaxPlayers() * RaindropConstants.MATCH_FULLNESS_BONUS);

        if(player.getParty() instanceof Team) {
            count += Ints.min((int) (Math.sqrt(((Team) player.getParty()).getCumulativeParticipation(player.getPlayerId()).getSeconds()) / RaindropConstants.PLAY_TIME_BONUS), RaindropConstants.PLAY_TIME_BONUS_CUTOFF);
        }
    }

    return RaindropUtil.calculateRaindrops(player.getPlayerId(), (int) (count * percent), true);
}
 
Example 2
Project: Thermionics   File: HeatStorage.java   Source Code and License Vote up 5 votes
@Override
public int receiveHeat(int amount, boolean simulate) {
	int toReceive = Ints.min(amount, max-cur, maxReceive);
	if (toReceive<minReceive) toReceive = 0;
	if (!simulate) {
		cur += toReceive;
		markDirty();
	}
	
	return toReceive;
}
 
Example 3
Project: Thermionics   File: HeatStorage.java   Source Code and License Vote up 5 votes
@Override
public int extractHeat(int amount, boolean simulate) {
	int toExtract = Ints.min(amount, cur, maxExtract);
	if (!simulate) {
		cur -= toExtract;
		markDirty();
	}
	return toExtract;
}
 
Example 4
Project: Thermionics   File: TileEntityOven.java   Source Code and License Vote up 4 votes
@Override
public void update() {
	if (progress>=H_PER_SMELT) {
		//We're finished. Don't do *anything* until we can kick the item into the output slot.
		//Note: By now the "work-slot" has always already been replaced by a smelting result.
		
		if (itemStorage.getStackInSlot(StandardMachineSlots.WORK).isEmpty()) {
			//Invalid state! Kick us back into a valid state.
			progress = 0;
			this.markDirty();
			return;
		}
		
		//System.out.println("Smelt end step. workslot:"+itemStorage.getStackInSlot(SLOT_WORK)+" outputslot:"+itemStorage.getStackInSlot(MachineItemStorageView.SLOT_MACHINE_OUTPUT));
		
		ItemStack result = itemStorage.insertItem(StandardMachineSlots.OUTPUT, itemStorage.getStackInSlot(StandardMachineSlots.WORK), false);
		itemStorage.setStackInSlot(StandardMachineSlots.WORK, result);
		//System.out.println("End End step. workslot:"+itemStorage.getStackInSlot(SLOT_WORK)+" outputslot:"+itemStorage.getStackInSlot(MachineItemStorageView.SLOT_MACHINE_OUTPUT));
		
		if (result==null || result.isEmpty()) {
			//Good! Kill our progress. We can resume work next tick
			progress = 0;
			this.markDirty();
			this.markActive(false);
		} else {
			//We're still stalled :(
			
			//System.out.println("Continue stall.");
		}
		return;
	}
	
	int heatNeeded = H_PER_SMELT - progress;
	
	int heatAvailable = heatStorage.getHeatStored();
	int heatToConsume = Ints.min(heatAvailable, HEAT_EFFICIENCY, heatNeeded);
	
	if (itemStorage.getStackInSlot(StandardMachineSlots.INPUT).isEmpty()) {
		if (progress>0) {
			progress = 0;
			markDirty();
		}
		return;
	}
	
	if (heatToConsume<=0) {
		//Backpedal progress
		if (progress>0) {
			progress--;
			markDirty();
		}
	} else {
		//Apply progress
		progress += heatStorage.extractHeat(heatToConsume, false);
		markActive(true);
		if (progress>=H_PER_SMELT) {
			doSmelt();
		}
	}
}
 
Example 5
Project: guava-mock   File: HashCode.java   Source Code and License Vote up 3 votes
/**
 * Copies bytes from this hash code into {@code dest}.
 *
 * @param dest the byte array into which the hash code will be written
 * @param offset the start offset in the data
 * @param maxLength the maximum number of bytes to write
 * @return the number of bytes written to {@code dest}
 * @throws IndexOutOfBoundsException if there is not enough room in {@code dest}
 */
@CanIgnoreReturnValue
public int writeBytesTo(byte[] dest, int offset, int maxLength) {
  maxLength = Ints.min(maxLength, bits() / 8);
  Preconditions.checkPositionIndexes(offset, offset + maxLength, dest.length);
  writeBytesToImpl(dest, offset, maxLength);
  return maxLength;
}
 
Example 6
Project: googles-monorepo-demo   File: HashCode.java   Source Code and License Vote up 3 votes
/**
 * Copies bytes from this hash code into {@code dest}.
 *
 * @param dest the byte array into which the hash code will be written
 * @param offset the start offset in the data
 * @param maxLength the maximum number of bytes to write
 * @return the number of bytes written to {@code dest}
 * @throws IndexOutOfBoundsException if there is not enough room in {@code dest}
 */
@CanIgnoreReturnValue
public int writeBytesTo(byte[] dest, int offset, int maxLength) {
  maxLength = Ints.min(maxLength, bits() / 8);
  Preconditions.checkPositionIndexes(offset, offset + maxLength, dest.length);
  writeBytesToImpl(dest, offset, maxLength);
  return maxLength;
}