Example usage for com.google.common.collect Table put

List of usage examples for com.google.common.collect Table put

Introduction

In this page you can find the example usage for com.google.common.collect Table put.

Prototype

@Nullable
V put(R rowKey, C columnKey, V value);

Source Link

Document

Associates the specified value with the specified keys.

Usage

From source file:org.auraframework.impl.css.flavor.FlavorIncludeDefImpl.java

@Override
public Table<DefDescriptor<ComponentDef>, String, FlavorOverrideLocation> computeOverrides()
        throws QuickFixException {
    // component / flavor (might be multiple per cmp) / override location (should only be one per cmp/flavor combo)
    Table<DefDescriptor<ComponentDef>, String, FlavorOverrideLocation> table = HashBasedTable.create();

    for (DefDescriptor<FlavoredStyleDef> style : getDefs()) {
        DefDescriptor<ComponentDef> cmp = Flavors.toComponentDescriptor(style);
        Map<String, FlavorAnnotation> annotations = style.getDef().getFlavorAnnotations();
        for (FlavorAnnotation annotation : annotations.values()) {
            table.put(cmp, annotation.getFlavorName(),
                    new FlavorOverrideLocationImpl(style, annotation.getOverridesIf().orElse(null)));
        }//from   w  w w  .j  ava 2 s  .c  o m
    }

    return table;
}

From source file:prm4j.indexing.model.ParametricPropertyModel.java

/**
 * Returns a mapping (X, X') -> monitorSetId where X,X' are parameter sets. X identifies the node and X' identifies
 * the parameter set of the receiving instance.
 * //from w w  w .  j a v  a 2s. com
 * @return mapping (X, X') -> monitorSetId
 */
public Table<Set<Parameter<?>>, Set<Parameter<?>>, Integer> getMonitorSetIds() {
    final Table<Set<Parameter<?>>, Set<Parameter<?>>, Integer> monitorSetIds = HashBasedTable.create();
    for (Set<Parameter<?>> parameterSet : getMonitorSetSpecs().keys()) {
        int i = 0;
        for (Tuple<Set<Parameter<?>>, Boolean> tuple : toOrderedTupleListByLeftSize(
                getMonitorSetSpecs().get(parameterSet))) {
            monitorSetIds.put(parameterSet, tuple._1(), i++);
        }
    }
    return monitorSetIds;
}

From source file:net.librec.recommender.cf.rating.FMALSRecommender.java

@Override
protected void setup() throws LibrecException {
    super.setup();

    // init Q//  w  ww .java  2s .  c  om
    Q = new DenseMatrix(n, k);

    // construct training appender matrix
    Table<Integer, Integer, Double> trainTable = HashBasedTable.create();
    for (int i = 0; i < n; i++) {
        int[] ratingKeys = trainTensor.keys(i);
        int colPrefix = 0;
        for (int j = 0; j < ratingKeys.length; j++) {
            int indexOfFeatureVector = colPrefix + ratingKeys[j];
            colPrefix += trainTensor.dimensions[j];
            trainTable.put(i, indexOfFeatureVector, 1.0);
        }
    }
    trainFeatureMatrix = new SparseMatrix(n, p, trainTable);
}

From source file:org.joda.beans.ser.GuavaSerIteratorFactory.java

/**
 * Gets an iterable wrapper for {@code Table}.
 * //from  w  w  w  . j  ava2 s.c  om
 * @param rowType  the row type, not null
 * @param colType  the column type, not null
 * @param valueType  the value type, not null
 * @param valueTypeTypes  the generic parameters of the value type
 * @return the iterable, not null
 */
public static final SerIterable table(final Class<?> rowType, final Class<?> colType, final Class<?> valueType,
        final List<Class<?>> valueTypeTypes) {
    final Table<Object, Object, Object> table = HashBasedTable.create();
    return new SerIterable() {
        @Override
        public SerIterator iterator() {
            return table(table, Object.class, rowType, colType, valueType, valueTypeTypes);
        }

        @Override
        public void add(Object row, Object column, Object value, int count) {
            if (row == null) {
                throw new IllegalArgumentException("Missing row");
            }
            if (column == null) {
                throw new IllegalArgumentException("Missing column");
            }
            if (count != 1) {
                throw new IllegalArgumentException("Unexpected count");
            }
            table.put(row, column, value);
        }

        @Override
        public Object build() {
            return table;
        }

        @Override
        public SerCategory category() {
            return SerCategory.TABLE;
        }

        @Override
        public Class<?> keyType() {
            return rowType;
        }

        @Override
        public Class<?> columnType() {
            return colType;
        }

        @Override
        public Class<?> valueType() {
            return valueType;
        }

        @Override
        public List<Class<?>> valueTypeTypes() {
            return valueTypeTypes;
        }
    };
}

From source file:com.ngdata.hbaseindexer.indexer.Indexer.java

/**
 * groups a map of (id->document) pairs by shard
 * (consider moving this to a BaseSharder class)
 *///from  ww  w .ja  va  2s . c  om
private Map<Integer, Map<String, SolrInputDocument>> shardByMapKey(
        Map<String, SolrInputDocument> documentsToAdd) throws SharderException {
    Table<Integer, String, SolrInputDocument> table = HashBasedTable.create();

    for (Map.Entry<String, SolrInputDocument> entry : documentsToAdd.entrySet()) {
        table.put(sharder.getShard(entry.getKey()), entry.getKey(), entry.getValue());
    }

    return table.rowMap();
}

From source file:com.dangdang.ddframe.rdb.sharding.jdbc.ShardingStatement.java

private Table<Integer, Integer, Object> subTable(final int[] columnIndexes) {
    Table<Integer, Integer, Object> result = TreeBasedTable.create();
    for (int each : columnIndexes) {
        for (Map.Entry<Integer, Object> eachEntry : generatedKeyContext.getValueTable().column(each - 1)
                .entrySet()) {//  w w  w.  ja va 2s  . c  o m
            result.put(eachEntry.getKey(), each - 1, eachEntry.getValue());
        }
    }
    return result;
}

From source file:co.turnus.profiling.impl.ProfilingWeightsImpl.java

@Override
public Table<Actor, Action, ActionProfilingWeights> asTable() {
    Table<Actor, Action, ActionProfilingWeights> table = HashBasedTable.create();
    for (ActorProfilingWeights actorWeights : getActorsWeights()) {
        for (ActionProfilingWeights actionWeights : actorWeights.getActionsWeights()) {
            table.put(actorWeights.getActor(), actionWeights.getAction(), actionWeights);
        }//from   ww  w .  ja va  2  s .  c o  m
    }
    return table;
}

From source file:com.amd.gerrit.plugins.manifestsubscription.VersionedManifests.java

static void traverseManifestAndApplyOp(GitRepositoryManager gitRepoManager,
        List<com.amd.gerrit.plugins.manifestsubscription.manifest.Project> projects, String defaultRef,
        ManifestOp op, Table<String, String, String> lookup) throws GitAPIException, IOException {

    String ref;// ww w .  ja v  a  2s.c om
    String hash;
    String projectName;
    Project.NameKey p;
    for (com.amd.gerrit.plugins.manifestsubscription.manifest.Project project : projects) {
        projectName = project.getName();
        ref = project.getRevision();

        ref = (ref == null) ? defaultRef : ref;

        if (ref != null) {
            if (lookup != null) {
                hash = lookup.get(projectName, ref);
            } else {
                hash = null;
            }

            if (hash == null) {
                p = new Project.NameKey(projectName);
                try (Repository db = gitRepoManager.openRepository(p)) {
                    hash = db.resolve(ref).getName();
                } catch (IOException | NullPointerException e) {
                    log.warn("Cannot resolve ref: " + ref + "\n\t" + projectName + "\n\t" + defaultRef + "\n\t"
                            + Arrays.toString(e.getStackTrace()));
                }
            }

            if (hash != null) {
                if (lookup != null)
                    lookup.put(projectName, ref, hash);
                op.apply(project, hash, ref, gitRepoManager);
            }
        }

        if (project.getProject().size() > 0) {
            traverseManifestAndApplyOp(gitRepoManager, project.getProject(), defaultRef, op, lookup);
        }
    }
}

From source file:com.lyndir.omicron.cli.view.MapView.java

@Override
protected void drawForeground(final Screen screen) {
    super.drawForeground(screen);

    Optional<IGameController> gameController = OmicronCLI.get().getGameController();
    if (!gameController.isPresent())
        return;//from   w w  w  .  j  av  a  2  s .  co  m

    Optional<IPlayer> localPlayerOptional = OmicronCLI.get().getLocalPlayer();
    if (!localPlayerOptional.isPresent())
        return;
    IPlayer localPlayer = localPlayerOptional.get();

    // Create an empty grid.
    Size levelSize = gameController.get().getGame().getLevel(getLevelType()).getSize();
    Table<Integer, Integer, ITile> grid = HashBasedTable.create(levelSize.getHeight(), levelSize.getWidth());

    // Iterate observable tiles and populate the grid.
    localPlayer.observableTiles().forEach(tile -> {
        Vec2 coordinate = positionToMapCoordinate(tile.getPosition());
        grid.put(coordinate.getY(), coordinate.getX(), tile);
    });

    // Draw grid in view.
    Box contentBox = getContentBoxOnScreen();
    for (int screenX = contentBox.getLeft(); screenX <= contentBox.getRight(); ++screenX)
        for (int screenY = contentBox.getTop(); screenY <= contentBox.getBottom(); ++screenY) {
            int tileY = screenY - contentBox.getTop() + getOffset().getY();
            int tileX = screenX - contentBox.getLeft() + getOffset().getX();
            if (!levelSize.isInBounds(Vec2.create(tileX, tileY)))
                continue;

            ITile tile = grid.get(tileY, tileX);
            Maybe<? extends IGameObject> contents;
            Terminal.Color bgColor = getBackgroundColor();
            if (tile == null)
                contents = Maybe.empty();
            else {
                contents = tile.getContents();
                bgColor = levelTypeColors.get(tile.getLevel().getType());

                for (final ResourceType resourceType : ResourceType.values()) {
                    Maybe<Integer> resourceQuantity = tile.getResourceQuantity(resourceType);
                    if (resourceQuantity.presence() == Maybe.Presence.PRESENT)
                        bgColor = resourceTypeColors.get(resourceType);
                }
            }

            screen.putString(screenX + (screenY % 2 == 0 ? 0 : 1), screenY,
                    contents.presence() == Maybe.Presence.PRESENT
                            ? contents.get().getType().getTypeName().substring(0, 1)
                            : " ",
                    getMapColor(), bgColor, ScreenCharacterStyle.Bold);
            // Draw off-screen warning labels.
        }

    Inset offScreen = new Inset(Math.max(0, getOffset().getY()),
            Math.max(0, levelSize.getWidth() - contentBox.getSize().getWidth() - getOffset().getX() + 1),
            Math.max(0, levelSize.getHeight() - contentBox.getSize().getHeight() - getOffset().getY() - 1),
            Math.max(0, getOffset().getX()));
    int centerX = contentBox.getLeft() + (levelSize.getWidth() - offScreen.getHorizontal()) / 2
            - getOffset().getX() + offScreen.getLeft();
    int centerY = contentBox.getTop() + (levelSize.getHeight() - offScreen.getVertical()) / 2
            - getOffset().getY() + offScreen.getTop();
    centerX = Math.min(contentBox.getRight() - 3, Math.max(contentBox.getLeft(), centerX));
    centerY = Math.min(contentBox.getBottom() - 1, Math.max(contentBox.getTop() + 1, centerY));
    if (offScreen.getTop() > 0)
        screen.putString(centerX, contentBox.getTop(), //
                String.format("%+d", offScreen.getTop()), getInfoTextColor(), getInfoBackgroundColor());
    if (offScreen.getRight() > 0) {
        String label = String.format("%+d", offScreen.getRight());
        screen.putString(contentBox.getRight() - label.length(), centerY, //
                label, getInfoTextColor(), getInfoBackgroundColor());
    }
    if (offScreen.getBottom() > 0)
        screen.putString(centerX, contentBox.getBottom(), //
                String.format("%+d", offScreen.getBottom()), getInfoTextColor(), getInfoBackgroundColor());
    if (offScreen.getLeft() > 0)
        screen.putString(contentBox.getLeft(), centerY, //
                String.format("%+d", offScreen.getLeft()), getInfoTextColor(), getInfoBackgroundColor());
}

From source file:org.mousephenotype.dcc.exportlibrary.exporter.dbloading.Loader.java

public CentreSpecimenSet getValidMutants() throws ConfigurationException, HibernateException {
    String printFile = FileReader.printFile(VALID_MUTANTS);
    CentreSpecimenSet centreSpecimenSet = new CentreSpecimenSet();
    List<Specimen> specimens = this.hibernateManager.nativeQuery(printFile, Specimen.class);
    logger.info("{} specimens retrieved", specimens.size());
    if (specimens != null && !specimens.isEmpty()) {
        CentreSpecimen aux = null;/*from ww w  .j  a v a  2  s .c  o m*/
        Table<String, Class, Object> parameters = HashBasedTable.create();

        Map<String, org.hibernate.type.Type> scalars = ImmutableMap.<String, org.hibernate.type.Type>builder()
                .put("centreID", StringType.INSTANCE).build();
        logger.info("linking to ");
        for (Specimen specimen : specimens) {
            parameters.put("specimenHJID", Long.class, specimen.getHjid());
            List<String> nativeQuery = this.hibernateManager.nativeQuery(
                    "select CENTRESPECIMEN.CENTREID as centreID from phenodcc_raw.CENTRESPECIMEN join phenodcc_raw.SPECIMEN on CENTRESPECIMEN.HJID = SPECIMEN.MOUSEOREMBRYO_CENTRESPECIMEN_0 where SPECIMEN.HJID = :specimenHJID",
                    scalars, parameters);
            if (nativeQuery != null && !nativeQuery.isEmpty()) {
                logger.trace("{} centre for specimenID {}", nativeQuery.get(0), specimen.getSpecimenID());
                aux = this.getCentreSpecimen(centreSpecimenSet, CentreILARcode.valueOf(nativeQuery.get(0)));
                if (aux == null) {
                    aux = new CentreSpecimen();
                    aux.setCentreID(CentreILARcode.valueOf(nativeQuery.get(0)));
                    centreSpecimenSet.getCentre().add(aux);
                }
                aux.getMouseOrEmbryo().add(specimen);
            } else {
                logger.error("specimen HJID {} is not part of a centreSpecimen", specimen.getHjid());
            }
        }
    }
    return centreSpecimenSet;
}