Example usage for com.google.common.collect ArrayTable create

List of usage examples for com.google.common.collect ArrayTable create

Introduction

In this page you can find the example usage for com.google.common.collect ArrayTable create.

Prototype

public static <R, C, V> ArrayTable<R, C, V> create(Table<R, C, V> table) 

Source Link

Document

Creates an ArrayTable with the mappings in the provided table.

Usage

From source file:com.sk89q.worldedit.world.block.BlockState.java

private void populate(Map<Map<Property<?>, Object>, BlockState> stateMap) {
    final Table<Property<?>, Object, BlockState> states = HashBasedTable.create();

    for (final Map.Entry<Property<?>, Object> entry : this.values.entrySet()) {
        final Property<Object> property = (Property<Object>) entry.getKey();

        property.getValues().forEach(value -> {
            if (value != entry.getValue()) {
                BlockState modifiedState = stateMap.get(this.withValue(property, value));
                if (modifiedState != null) {
                    states.put(property, value, modifiedState);
                } else {
                    System.out.println(stateMap);
                    WorldEdit.logger.warn("Found a null state at " + this.withValue(property, value));
                }/*from  w w  w. j a  va2s. c o m*/
            }
        });
    }

    this.states = states.isEmpty() ? states : ArrayTable.create(states);
}

From source file:eu.lp0.cursus.scoring.scores.impl.AveragingRacePointsData.java

@Override
protected Map<Pilot, Integer> calculateRacePoints(Race race) {
    Table<Pilot, Race, Integer> racePoints = ArrayTable.create(scoresBeforeAveraging.getRacePoints());

    if (method != AveragingMethod.SET_NULL) {
        for (Pilot pilot : scores.getPilots()) {
            // Calculate an average score using the other races
            if (racePoints.row(pilot).get(race) == null) {
                Set<Race> otherRaces = getOtherRacesForPilot(pilot, race, true);

                // Add the scores from the other races
                int points = 0;
                for (Race otherRace : otherRaces) {
                    points += racePoints.row(pilot).get(otherRace);
                }//from  w  w  w .j  a v  a  2s  .  c  o m

                // Calculate and apply the average
                points = BigDecimal.valueOf(points).divide(BigDecimal.valueOf(otherRaces.size()), rounding)
                        .intValue();
                racePoints.row(pilot).put(race, points);
            }
        }
    } else {
        // Do nothing, the scores for those pilots will be null
    }

    return racePoints.column(race);
}