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:heros.solver.IDESolver.java

private void addEndSummary(N sP, D d1, N eP, D d2, EdgeFunction<V> f) {
    Table<N, D, EdgeFunction<V>> summaries = endSummary.get(sP, d1);
    if (summaries == null) {
        summaries = HashBasedTable.create();
        endSummary.put(sP, d1, summaries);
    }/* ww w .j  a  v  a2  s .co  m*/
    summaries.put(eP, d2, f);
}

From source file:com.android.tools.idea.uibuilder.property.NlProperties.java

@NotNull
private Table<String, String, NlPropertyItem> getPropertiesWithReadLock(@NotNull AndroidFacet facet,
        @NotNull List<NlComponent> components, @NotNull GradleDependencyManager dependencyManager) {
    ResourceManager localResourceManager = facet.getLocalResourceManager();
    ResourceManager systemResourceManager = facet.getSystemResourceManager();
    if (systemResourceManager == null) {
        Logger.getInstance(NlProperties.class)
                .error("No system resource manager for module: " + facet.getModule().getName());
        return ImmutableTable.of();
    }// ww w.  j a  va2s. c o m

    AttributeDefinitions localAttrDefs = localResourceManager.getAttributeDefinitions();
    AttributeDefinitions systemAttrDefs = systemResourceManager.getAttributeDefinitions();

    Table<String, String, NlPropertyItem> combinedProperties = null;

    for (NlComponent component : components) {
        XmlTag tag = component.getTag();
        if (!tag.isValid()) {
            return ImmutableTable.of();
        }

        XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(tag);
        if (elementDescriptor == null) {
            return ImmutableTable.of();
        }

        XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
        Table<String, String, NlPropertyItem> properties = HashBasedTable.create(3, descriptors.length);

        for (XmlAttributeDescriptor desc : descriptors) {
            String namespace = getNamespace(desc, tag);
            AttributeDefinitions attrDefs = NS_RESOURCES.equals(namespace) ? systemAttrDefs : localAttrDefs;
            AttributeDefinition attrDef = attrDefs == null ? null : attrDefs.getAttrDefByName(desc.getName());
            NlPropertyItem property = NlPropertyItem.create(components, desc, namespace, attrDef);
            properties.put(StringUtil.notNullize(namespace), property.getName(), property);
        }

        // Exceptions:
        switch (tag.getName()) {
        case AUTO_COMPLETE_TEXT_VIEW:
            // An AutoCompleteTextView has a popup that is created at runtime.
            // Properties for this popup can be added to the AutoCompleteTextView tag.
            properties.put(ANDROID_URI, ATTR_POPUP_BACKGROUND, NlPropertyItem.create(components,
                    new AndroidAnyAttributeDescriptor(ATTR_POPUP_BACKGROUND), ANDROID_URI,
                    systemAttrDefs != null ? systemAttrDefs.getAttrDefByName(ATTR_POPUP_BACKGROUND) : null));
            break;
        }

        combinedProperties = combine(properties, combinedProperties);
    }

    // The following properties are deprecated in the support library and can be ignored by tools:
    assert combinedProperties != null;
    combinedProperties.remove(AUTO_URI, ATTR_PADDING_START);
    combinedProperties.remove(AUTO_URI, ATTR_PADDING_END);
    combinedProperties.remove(AUTO_URI, ATTR_THEME);

    setUpDesignProperties(combinedProperties);
    setUpSrcCompat(combinedProperties, facet, components, dependencyManager);

    initStarState(combinedProperties);

    //noinspection ConstantConditions
    return combinedProperties;
}

From source file:co.turnus.profiling.util.ProfilingDataAnalyser.java

@SuppressWarnings("unchecked")
public <T> Table<T, Action, ComData> getSortedComData(Class<T> type, Key key, Order order) {
    if (type.isAssignableFrom(Actor.class)) {
        // create a temporary table
        Table<Actor, Action, ComData> table = HashBasedTable.create();
        for (Cell<Actor, Action, ActionProfilingData> cell : data.asTable().cellSet()) {
            table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
        }//ww  w  .ja  v a  2 s.c  o m

        // sort the table
        tableComComparator.setSorting(key, order);
        ImmutableTable.Builder<Actor, Action, ComData> sortedBuilder = ImmutableTable.builder(); // preserves insertion order
        for (Table.Cell<Actor, Action, ComData> cell : tableComComparator.sortedCopy(table.cellSet())) {
            sortedBuilder.put(cell);
        }

        // return a sorted table
        return (Table<T, Action, ComData>) sortedBuilder.build();
    } else if (type.isAssignableFrom(ActorClass.class)) {
        // create a temporary table
        Table<ActorClass, Action, ComData> table = HashBasedTable.create();
        for (Cell<Actor, Action, ActionProfilingData> cell : data.asTable().cellSet()) {
            ActorClass clazz = cell.getRowKey().getActorClass();
            Action action = cell.getColumnKey();
            ComData actionData = table.get(clazz, action);
            if (actionData == null) {
                actionData = cell.getValue();
            } else {
                actionData = ProfilingDataUtil.sum(actionData, cell.getValue());
            }
            table.put(clazz, action, actionData);
        }

        // sort the table
        tableComComparator.setSorting(key, order);
        ImmutableTable.Builder<ActorClass, Action, ComData> sortedBuilder = ImmutableTable.builder(); // preserves insertion order
        for (Table.Cell<ActorClass, Action, ComData> cell : tableComComparator.sortedCopy(table.cellSet())) {
            sortedBuilder.put(cell);
        }

        // return a sorted table
        return (Table<T, Action, ComData>) sortedBuilder.build();
    }
    return null;
}

From source file:co.turnus.profiling.util.ProfilingDataAnalyser.java

@SuppressWarnings("unchecked")
public <T> Table<T, Action, ExtendExecData> getSortedExecData(Class<T> type, Key key, Order order) {
    if (type.isAssignableFrom(Actor.class)) {
        // create a temporary table
        Table<Actor, Action, ExtendExecData> table = HashBasedTable.create();
        for (Cell<Actor, Action, ActionProfilingData> cell : data.asTable().cellSet()) {
            table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
        }// w  w  w. ja  v a  2 s.c om

        // sort the table
        tableExecComparator.setSorting(key, order);
        ImmutableTable.Builder<Actor, Action, ExtendExecData> sortedBuilder = ImmutableTable.builder(); // preserves insertion order
        for (Table.Cell<Actor, Action, ExtendExecData> cell : tableExecComparator.sortedCopy(table.cellSet())) {
            sortedBuilder.put(cell);
        }

        // return a sorted table
        return (Table<T, Action, ExtendExecData>) sortedBuilder.build();
    } else if (type.isAssignableFrom(ActorClass.class)) {
        // create a temporary table
        Table<ActorClass, Action, ExtendExecData> table = HashBasedTable.create();
        for (Cell<Actor, Action, ActionProfilingData> cell : data.asTable().cellSet()) {
            ActorClass clazz = cell.getRowKey().getActorClass();
            Action action = cell.getColumnKey();
            ExtendExecData actionData = table.get(clazz, action);
            if (actionData == null) {
                actionData = cell.getValue();
            } else {
                actionData = ProfilingDataUtil.sum(actionData, cell.getValue());
            }
            table.put(clazz, action, actionData);
        }

        // sort the table
        tableExecComparator.setSorting(key, order);
        ImmutableTable.Builder<ActorClass, Action, ExtendExecData> sortedBuilder = ImmutableTable.builder(); // preserves insertion order
        for (Table.Cell<ActorClass, Action, ExtendExecData> cell : tableExecComparator
                .sortedCopy(table.cellSet())) {
            sortedBuilder.put(cell);
        }

        // return a sorted table
        return (Table<T, Action, ExtendExecData>) sortedBuilder.build();
    }
    return null;
}

From source file:co.cask.tigon.internal.app.queue.SimpleQueueSpecificationGenerator.java

/**
 * Given a {@link FlowSpecification}.//from  w  w  w .j a v  a2s .  c om
 *
 * @param input {@link FlowSpecification}
 * @return A {@link com.google.common.collect.Table}
 */
@Override
public Table<Node, String, Set<QueueSpecification>> create(FlowSpecification input) {
    Table<Node, String, Set<QueueSpecification>> table = HashBasedTable.create();

    String flow = input.getName();
    Map<String, FlowletDefinition> flowlets = input.getFlowlets();

    // Iterate through connections of a flow.
    for (FlowletConnection connection : input.getConnections()) {
        final String source = connection.getSourceName();
        final String target = connection.getTargetName();
        final Node sourceNode = new Node(connection.getSourceType(), source);

        Set<QueueSpecification> queueSpec = generateQueueSpecification(flow, connection,
                flowlets.get(target).getInputs(), flowlets.get(source).getOutputs());

        Set<QueueSpecification> queueSpecifications = table.get(sourceNode, target);
        if (queueSpecifications == null) {
            queueSpecifications = Sets.newHashSet();
            table.put(sourceNode, target, queueSpecifications);
        }
        queueSpecifications.addAll(queueSpec);
    }
    return table;
}

From source file:eu.itesla_project.modules.offline.CsvMetricsDb.java

@Override
public synchronized void exportCsv(String workflowId, Writer writer, char delimiter) {
    Objects.requireNonNull(workflowId);
    Objects.requireNonNull(writer);
    try {/*from   w  w w  .  j a v a  2s  . co m*/
        flush(workflowId);

        Table<String, String, String> table = HashBasedTable.create();
        try (BufferedReader metricsReader = Files.newBufferedReader(toMetricsCsvFile(workflowId),
                StandardCharsets.UTF_8)) {
            String line;
            while ((line = metricsReader.readLine()) != null) {
                String[] tokens = line.split(Character.toString(CSV_SEPARATOR));
                if (tokens.length != 4) {
                    LOGGER.warn("Invalid line '{}'", line);
                    continue;
                }
                String target = tokens[0];
                String moduleName = tokens[1];
                String metricName = tokens[2];
                String metricValue = tokens[3];
                table.put(target, (moduleName.length() > 0 ? moduleName + ":" : "") + metricName, metricValue);
            }
        }
        writer.write("target");
        writer.write(delimiter);
        List<String> columnKeys = new ArrayList<>(new TreeSet<>(table.columnKeySet()));
        for (String columnKey : columnKeys) {
            writer.write(columnKey);
            writer.write(delimiter);
        }
        writer.write("\n");
        for (Map.Entry<String, Map<String, String>> entry : table.rowMap().entrySet()) {
            String target = entry.getKey();
            Map<String, String> metrics = entry.getValue();
            writer.write(target);
            writer.write(delimiter);
            for (String columnKey : columnKeys) {
                String value = metrics.get(columnKey);
                if (value != null) {
                    writer.write(value);
                }
                writer.write(delimiter);
            }
            writer.write("\n");
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

/**
 * manifestbundleLocation// ww  w  .  j a va 2 s.  c o  m
 *
 * @param document
 * @param libManifestMap
 * @param manifestOptions
 * @throws DocumentException
 */
private static void addBundleLocationToDestManifest(Document document, Map<String, File> libManifestMap,
        Multimap<String, File> libDependenciesMaps, ManifestOptions manifestOptions) throws DocumentException {
    Table<String, String, String> bundleInfoTable = HashBasedTable.create();
    Map<String, String> packageNameMap = new HashMap<String, String>();
    for (Map.Entry<String, File> entry : libManifestMap.entrySet()) {
        File libManifest = entry.getValue();
        if (libManifest.exists()) {
            SAXReader reader = new SAXReader();
            Document libDocument = reader.read(libManifest);// ?XML
            Element libRoot = libDocument.getRootElement();// 
            String packageName = libRoot.attributeValue("package");
            packageNameMap.put(entry.getKey(), packageName);
            List<? extends Node> nodes = libRoot.selectNodes("//activity|//service|//receiver");
            for (Node node : nodes) {
                Element e = (Element) node;
                String name = e.attributeValue("name");
                String type = e.getName();
                bundleInfoTable.put(type, name, packageName);
            }
        }
    }

    // ??manifest?
    for (String key : libDependenciesMaps.keySet()) {
        Collection<File> libManifests = libDependenciesMaps.get(key);
        for (File libManifest : libManifests) {
            if (libManifest.exists()) {
                SAXReader reader = new SAXReader();
                Document libDocument = reader.read(libManifest);// ?XML
                Element libRoot = libDocument.getRootElement();// 
                String packageName = packageNameMap.get(key);
                List<? extends Node> nodes = libRoot.selectNodes("//activity|//service|//receiver");
                for (Node node : nodes) {
                    Element e = (Element) node;
                    String name = e.attributeValue("name");
                    String type = e.getName();
                    bundleInfoTable.put(type, name, packageName);
                }
            }
        }
    }

    Element root = document.getRootElement();// 
    List<? extends Node> nodes = root.selectNodes("//activity|//service|//receiver");
    for (Node node : nodes) {
        Element e = (Element) node;
        String name = e.attributeValue("name");
        String type = e.getName();
        String packageName = bundleInfoTable.get(type, name);
        if (null != packageName) {
            Element metaData = e.addElement("meta-data");
            metaData.addAttribute("android:name", "bundleLocation");
            metaData.addAttribute("android:value", packageName);
        }
    }
}

From source file:matrix.SparseMatrix.java

/**
 * @return the data table of this matrix as (row, column, value) cells
 *///from  w w w.j  a v  a 2 s  .  co  m
public Table<Integer, Integer, Float> getDataTable() {
    Table<Integer, Integer, Float> res = HashBasedTable.create();

    for (MatrixEntry me : this) {
        if (me.get() != 0)
            res.put(me.row(), me.column(), me.get());
    }

    return res;
}

From source file:com.urey.flume.source.taildir.ReliableTaildirEventReader.java

/**
 * Create a ReliableTaildirEventReader to watch the given directory.
 *///from w  w  w .j av  a2 s. com
private ReliableTaildirEventReader(Map<String, String> filePaths, Table<String, String, String> headerTable,
        String positionFilePath, boolean skipToEnd, boolean addByteOffset, boolean recursiveDirectorySearch,
        boolean annotateYarnApplicationId, boolean annotateYarnContainerId, boolean annotateFileName,
        String fileNameHeader) throws IOException {
    // Sanity checks
    Preconditions.checkNotNull(filePaths);
    Preconditions.checkNotNull(positionFilePath);

    if (logger.isDebugEnabled()) {
        logger.debug("Initializing {} with directory={}, metaDir={}",
                new Object[] { ReliableTaildirEventReader.class.getSimpleName(), filePaths });
    }

    Table<String, File, Pattern> tailFileTable = HashBasedTable.create();
    for (Entry<String, String> e : filePaths.entrySet()) {
        File f = new File(e.getValue());
        File parentDir = f.getParentFile();
        Preconditions.checkState(parentDir.exists(),
                "Directory does not exist: " + parentDir.getAbsolutePath());
        Pattern fileNamePattern = Pattern.compile(f.getName());
        tailFileTable.put(e.getKey(), parentDir, fileNamePattern);
    }
    logger.info("tailFileTable: " + tailFileTable.toString());
    logger.info("headerTable: " + headerTable.toString());

    this.tailFileTable = tailFileTable;
    this.headerTable = headerTable;
    this.addByteOffset = addByteOffset;

    this.recursiveDirectorySearch = recursiveDirectorySearch;
    this.annotateYarnApplicationId = annotateYarnApplicationId;
    this.annotateYarnContainerId = annotateYarnContainerId;

    this.annotateFileName = annotateFileName;
    this.fileNameHeader = fileNameHeader;

    updateTailFiles(skipToEnd);

    logger.info("Updating position from position file: " + positionFilePath);
    loadPositionFile(positionFilePath);
}

From source file:org.expretio.maven.plugins.capnp.CapnProtoMojo.java

private void doHandleNativesDependency() throws MojoExecutionException {
    String classifier;/*  ww  w.j a  v a2 s. co m*/

    if (nativeDependencyClassifier.equals(AUTO_CLASSIFIER_DEFAULT)) {
        Table<String, String, String> indexTable = HashBasedTable.create();

        try {
            XMLConfiguration index = new XMLConfiguration();

            index.load(resolve(createNativesIndexArtifact()));

            for (HierarchicalConfiguration indexEntry : index.configurationsAt("entry")) {
                String osName = indexEntry.getString("os-name");
                String archNames = indexEntry.getString("arch-names");
                String mavenClassifier = indexEntry.getString("maven-classifier");

                for (String archName : Splitter.on(',').omitEmptyStrings().trimResults().split(archNames)) {
                    indexTable.put(osName.toUpperCase(), getCanonicalArchitecture(archName), mavenClassifier);
                }
            }

            classifier = indexTable.get(JavaPlatform.getCurrentOs().toString(),
                    getCanonicalArchitecture(JavaPlatform.getCurrentArch()));
        } catch (Exception e) {
            throw new NativesManagerException(e);
        }
    } else {
        classifier = nativeDependencyClassifier;
    }

    nativesManager.addResourceUrl(resolve(createNativesArtifact(classifier)));
}