Example usage for com.google.common.primitives Ints min

List of usage examples for com.google.common.primitives Ints min

Introduction

In this page you can find the example usage for com.google.common.primitives Ints min.

Prototype

public static int min(int... array) 

Source Link

Document

Returns the least value present in array .

Usage

From source file:org.eclipse.recommenders.jayes.transformation.AbstractDecomposition.java

private AbstractFactor reorderFactor(AbstractFactor f) {
    int[] dimensions = f.getDimensions();
    int min = Ints.min(dimensions);
    int minIndex = Ints.lastIndexOf(dimensions, min);

    if (minIndex == dimensions.length - 1)
        return f;
    int[] nDim = rotateRight(dimensions, dimensions.length - 1 - minIndex);
    int[] nIDs = rotateRight(f.getDimensionIDs(), dimensions.length - 1 - minIndex);

    AbstractFactor f2 = new DenseFactor();
    f2.setDimensionIDs(nIDs);//from w w  w .  j a v  a  2s .co m
    f2.setDimensions(nDim);
    f2.fill(1);
    f2.multiplyCompatible(f);

    return f2;
}

From source file:org.nla.tarotdroid.biz.MapPlayersScores.java

/**
 * Returns the minimum score.//  w w  w  .  j av a2 s.  com
 * @return the minimum score.
 */
public int getMinScore() {
    return Ints.min(Ints.toArray(this.mapPlayersScores.values()));
}

From source file:edu.mit.streamjit.impl.compiler2.CompositionAllocationStrategy.java

@Override
public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) {
    if (group.isStateful()) {
        int minStatefulId = Integer.MAX_VALUE;
        for (Actor a : group.actors())
            if (a instanceof WorkerActor && ((WorkerActor) a).archetype().isStateful())
                minStatefulId = Math.min(minStatefulId, a.id());
        Configuration.SwitchParameter<Integer> param = config.getParameter("Group" + minStatefulId + "Core",
                Configuration.SwitchParameter.class, Integer.class);
        cores.get(param.getValue() % cores.size()).allocate(group, iterations);
        return;//w w  w . j  a va 2  s. co  m
    }

    Configuration.CompositionParameter param = config.getParameter("Group" + group.id() + "Cores",
            Configuration.CompositionParameter.class);
    assert iterations.lowerBoundType() == BoundType.CLOSED && iterations.upperBoundType() == BoundType.OPEN;
    int totalAvailable = iterations.upperEndpoint() - iterations.lowerEndpoint();
    int[] allocations = new int[cores.size()];
    int totalAllocated = 0;
    for (int i = 0; i < param.getLength() && i < allocations.length; ++i) {
        int allocation = DoubleMath.roundToInt(param.getValue(i) * totalAvailable, RoundingMode.HALF_EVEN);
        allocations[i] = allocation;
        totalAllocated += allocation;
    }
    //If we allocated more than we have, remove from the cores with the least.
    //Need a loop here because we might not have enough on the least core.
    while (totalAllocated > totalAvailable) {
        int least = Ints.indexOf(allocations, Ints.max(allocations));
        for (int i = 0; i < allocations.length; ++i)
            if (allocations[i] > 0 && allocations[i] < allocations[least])
                least = i;
        int toRemove = Math.min(allocations[least], totalAllocated - totalAvailable);
        allocations[least] -= toRemove;
        totalAllocated -= toRemove;
    }
    //If we didn't allocate enough, allocate on the cores with the most.
    if (totalAllocated < totalAvailable) {
        int most = Ints.indexOf(allocations, Ints.min(allocations));
        for (int i = 0; i < allocations.length; ++i)
            if (allocations[i] > allocations[most])
                most = i;
        allocations[most] += totalAvailable - totalAllocated;
        totalAllocated += totalAvailable - totalAllocated;
    }
    assert totalAllocated == totalAvailable : totalAllocated + " " + totalAvailable;

    int lower = iterations.lowerEndpoint();
    for (int i = 0; i < allocations.length; ++i)
        if (allocations[i] > 0) {
            cores.get(i).allocate(group, Range.closedOpen(lower, lower + allocations[i]));
            lower += allocations[i];
        }
}

From source file:net.minecraftforge.fluids.BlockFluidClassic.java

protected boolean[] getOptimalFlowDirections(World world, BlockPos pos) {
    for (int side = 0; side < 4; side++) {
        flowCost[side] = 1000;//  ww w  .j av a2  s  .  c om

        BlockPos pos2 = pos.offset(SIDES.get(side));

        if (!canFlowInto(world, pos2) || isSourceBlock(world, pos2)) {
            continue;
        }

        if (canFlowInto(world, pos2.up(densityDir))) {
            flowCost[side] = 0;
        } else {
            flowCost[side] = calculateFlowCost(world, pos2, 1, side);
        }
    }

    int min = Ints.min(flowCost);
    for (int side = 0; side < 4; side++) {
        isOptimalFlowDirection[side] = flowCost[side] == min;
    }
    return isOptimalFlowDirection;
}

From source file:org.nla.tarotdroid.biz.GameSetScores.java

/**
 * @param player/*from ww  w .j  a v a  2 s. c om*/
 * @return
 */
public int getMinScoreEverForPlayer(final Player player) {
    if (player == null) {
        throw new IllegalArgumentException("player is null");
    }

    if (this.gameScores.size() == 0) {
        return 0;
    }

    List<Integer> allPlayerScoreValues = newArrayList();
    for (int i = 0; i < this.gameScores.size(); ++i) {
        allPlayerScoreValues.add(this.getResultsAtGameOfIndex(i).get(player));
    }
    allPlayerScoreValues.add(0);

    return Ints.min(Ints.toArray(allPlayerScoreValues));
}

From source file:org.nla.tarotdroid.biz.GameSetScores.java

/**
 * Returns the minimum score of all games.
 * @return the minimum score of all games.
 *///  w  w  w. j a  v a2 s.com
public int getMinScoreEver() {
    if (this.gameScores.size() == 0) {
        return 0;
    }

    List<Integer> allScoreValues = newArrayList();
    for (int i = 0; i < this.gameScores.size(); ++i) {
        allScoreValues.addAll(this.getResultsAtGameOfIndex(i).values());
    }
    allScoreValues.add(0);

    return Ints.min(Ints.toArray(allScoreValues));
}