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.mousephenotype.dcc.exportlibrary.exporter.dbloading.Loader.java

public CentreSpecimenSet getValidBaselines() throws ConfigurationException, HibernateException {
    String printFile = FileReader.printFile(VALID_BASELINES);
    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 w w w .j  av  a 2  s  .  com*/
        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;
}

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

public CentreSpecimenSet getSingleColonyID() throws ConfigurationException, HibernateException {
    String printFile = FileReader.printFile(SINGLE_COLONYID);
    CentreSpecimenSet centreSpecimenSet = new CentreSpecimenSet();
    List<Specimen> specimens = this.hibernateManager.nativeQuery(printFile, Specimen.class);
    logger.trace("{} specimens retrieved", specimens.size());
    if (specimens != null && !specimens.isEmpty()) {
        CentreSpecimen aux = null;//w w  w  .j av a2  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.trace("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;
}

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

@Override
public Table<Actor, Action, ActionProfilingData> asTable() {
    Table<Actor, Action, ActionProfilingData> table = HashBasedTable.create();
    for (ActorProfilingData actorData : getActorsData()) {
        for (ActionProfilingData actionData : actorData.getActionsData()) {
            table.put(actorData.getActor(), actionData.getAction(), actionData);
        }/*  w ww . j  a v  a 2 s . c o  m*/
    }

    return table;
}

From source file:co.cask.cdap.internal.app.AbstractInMemoryProgramRunner.java

/**
 * Starts all instances of a Program component.
 *
 * @param program The program to run/*from   ww  w.j a v a2 s . c o m*/
 * @param name Name of the component
 * @param instances Number of instances to start
 * @param runId The runId
 * @param options System and User runtime arguments
 * @param components A Table for storing the resulting ProgramControllers
 * @param type Type of ProgramRunnerFactory
 */
private void startComponent(Program program, String name, int instances, RunId runId, ProgramOptions options,
        Table<String, Integer, ProgramController> components, ProgramRunnerFactory.Type type) {
    for (int instanceId = 0; instanceId < instances; instanceId++) {
        ProgramOptions componentOptions = createComponentOptions(name, instanceId, instances, runId, options);
        ProgramController controller = programRunnerFactory.create(type).run(program, componentOptions);
        components.put(name, instanceId, controller);
    }
}

From source file:org.eclipse.incquery.tooling.core.project.PluginXmlModifier.java

private void addExtensionToMap(ExtensionData data, Table<String, String, List<ExtensionData>> table) {
    String id = data.getId();/*from w ww .ja  va  2s.  c  om*/
    String point = data.getPoint();
    if (Strings.isNullOrEmpty(id) || Strings.isNullOrEmpty(point)) {
        return;
    }
    List<ExtensionData> extensions = null;
    if (table.contains(id, point)) {
        extensions = table.get(id, point);
    } else {
        extensions = Lists.newArrayList();
        table.put(id, point, extensions);
    }
    extensions.add(data);
}

From source file:org.terasology.rendering.nui.skin.UISkinBuilder.java

private UIStyleFamily buildFamily(String family, UIStyle defaultStyle) {
    UIStyle baseStyle = new UIStyle(defaultStyle);
    if (!family.isEmpty()) {
        UIStyleFragment fragment = baseStyles.get(family);
        fragment.applyTo(baseStyle);/* w  w  w .ja v  a 2s.  c  om*/
    }

    Map<Class<? extends UIWidget>, Table<String, String, UIStyle>> familyStyles = Maps.newHashMap();
    Map<StyleKey, UIStyleFragment> styleLookup = elementStyles.row(family);
    Map<StyleKey, UIStyleFragment> baseStyleLookup = (family.isEmpty())
            ? Maps.<StyleKey, UIStyleFragment>newHashMap()
            : elementStyles.row("");
    for (StyleKey styleKey : Sets.union(styleLookup.keySet(), baseStyleKeys)) {
        UIStyle elementStyle = new UIStyle(baseStyle);
        List<Class<? extends UIWidget>> inheritanceTree = ReflectionUtil.getInheritanceTree(styleKey.element,
                UIWidget.class);
        applyStylesForInheritanceTree(inheritanceTree, "", "", elementStyle, styleLookup, baseStyleLookup);

        if (!styleKey.part.isEmpty()) {
            applyStylesForInheritanceTree(inheritanceTree, styleKey.part, "", elementStyle, styleLookup,
                    baseStyleLookup);
        }

        if (!styleKey.mode.isEmpty()) {
            applyStylesForInheritanceTree(inheritanceTree, styleKey.part, styleKey.mode, elementStyle,
                    styleLookup, baseStyleLookup);
        }

        Table<String, String, UIStyle> elementTable = familyStyles.get(styleKey.element);
        if (elementTable == null) {
            elementTable = HashBasedTable.create();
            familyStyles.put(styleKey.element, elementTable);
        }
        elementTable.put(styleKey.part, styleKey.mode, elementStyle);
    }
    return new UIStyleFamily(baseStyle, familyStyles);
}

From source file:co.cask.cdap.internal.app.runtime.service.InMemoryServiceRunner.java

private Table<String, Integer, ProgramController> createRunnables(Program program, RunId runId,
        ServiceSpecification serviceSpec) {
    Table<String, Integer, ProgramController> runnables = HashBasedTable.create();

    try {//from w  w w  .ja  v a2 s . c om
        for (Map.Entry<String, RuntimeSpecification> entry : serviceSpec.getRunnables().entrySet()) {
            int instanceCount = entry.getValue().getResourceSpecification().getInstances();
            for (int instanceId = 0; instanceId < instanceCount; instanceId++) {
                runnables.put(entry.getKey(), instanceId, startRunnable(program,
                        createRunnableOptions(entry.getKey(), instanceId, instanceCount, runId)));
            }
        }
    } catch (Throwable t) {
        // Need to stop all started runnable here.
        try {
            Futures.successfulAsList(Iterables.transform(runnables.values(),
                    new Function<ProgramController, ListenableFuture<ProgramController>>() {
                        @Override
                        public ListenableFuture<ProgramController> apply(ProgramController input) {
                            return input.stop();
                        }
                    })).get();
        } catch (Exception e) {
            LOG.error("Failed to stop all the runnables");
        }
        throw Throwables.propagate(t);
    }
    return runnables;
}

From source file:org.sonar.server.measure.ws.ComponentTreeDataLoader.java

private Table<String, MetricDto, Measure> searchMeasuresByComponentUuidAndMetric(DbSession dbSession,
        ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components,
        List<MetricDto> metrics, @Nullable Long developerId) {

    Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
    MeasureTreeQuery measureQuery = MeasureTreeQuery.builder()
            .setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name()))
            .setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery())
            .setQualifiers(componentTreeQuery.getQualifiers()).setPersonId(developerId)
            .setMetricIds(new ArrayList<>(metricsById.keySet())).build();

    Table<String, MetricDto, Measure> measuresByComponentUuidAndMetric = HashBasedTable
            .create(components.size(), metrics.size());
    dbClient.measureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery, result -> {
        MeasureDto measureDto = (MeasureDto) result.getResultObject();
        measuresByComponentUuidAndMetric.put(measureDto.getComponentUuid(),
                metricsById.get(measureDto.getMetricId()), Measure.createFromMeasureDto(measureDto));
    });// w  w  w  .j  ava  2 s. c o  m

    addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);

    return measuresByComponentUuidAndMetric;
}

From source file:de.uni_potsdam.hpi.asg.logictool.synthesis.table.ComplexGateTableSynthesis.java

@Override
protected void fillTable(int num, String[] inputs, Table<EspressoTerm, String, EspressoValue> table) {
    for (State state : stategraph.getStates()) {
        BitSet x = state.getBinaryRepresentationNormalised(stategraph.getAllSignals());
        EspressoTerm t = new EspressoTerm(BitSetHelper.formatBitset(x, num), inputs);
        for (Signal sig : stategraph.getAllSignals()) {
            if (sig.getType() == SignalType.output || sig.getType() == SignalType.internal) {
                switch (state.getStateValues().get(sig)) {
                case high:
                case rising:
                    table.put(t, sig.getName(), EspressoValue.one);
                    break;
                case falling:
                case low:
                    table.put(t, sig.getName(), EspressoValue.zero);
                    break;
                }//from  w  ww  .j  a va 2  s .co  m
            }
        }
    }
}

From source file:net.librec.data.splitter.LOOCVDataSplitter.java

/**
 * Split ratings into two parts where one rating per item is preserved as
 * the test set and the remaining data as the training set.
 *//*from w  w w  .  j  ava2s.c  om*/
public void getLOOByItems() {
    trainMatrix = new SparseMatrix(preferenceMatrix);

    Table<Integer, Integer, Double> dataTable = HashBasedTable.create();
    Multimap<Integer, Integer> colMap = HashMultimap.create();

    for (int i = 0, im = preferenceMatrix.numColumns(); i < im; i++) {
        List<Integer> users = preferenceMatrix.getRows(i);

        int randId = (int) (users.size() * Randoms.uniform());
        int u = users.get(randId);

        trainMatrix.set(u, i, 0);
        dataTable.put(u, i, preferenceMatrix.get(u, i));
        colMap.put(i, u);
    }

    SparseMatrix.reshape(trainMatrix);
    testMatrix = new SparseMatrix(preferenceMatrix.numRows(), preferenceMatrix.numColumns(), dataTable, colMap);
}