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

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

Introduction

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

Prototype

void putAll(Table<? extends R, ? extends C, ? extends V> table);

Source Link

Document

Copies all mappings from the specified table to this table.

Usage

From source file:com.google.devtools.build.android.resources.RClassGenerator.java

private static Table<String, String, SymbolEntry> getAllSymbols(Collection<SymbolLoader> symbolLoaders)
        throws IOException {
    Table<String, String, SymbolEntry> symbols = HashBasedTable.create();
    for (SymbolLoader symbolLoader : symbolLoaders) {
        symbols.putAll(getSymbols(symbolLoader));
    }// w ww. j  a  v  a  2 s .c om
    return symbols;
}

From source file:org.opendaylight.groupbasedpolicy.util.SubjectResolverUtils.java

private static Policy resolvePolicy(Tenant contractTenant, Contract contract, Policy merge,
        Table<EndpointConstraint, EndpointConstraint, List<Subject>> subjectMap) {
    Table<EndpointConstraint, EndpointConstraint, List<RuleGroup>> ruleMap = HashBasedTable.create();
    if (merge != null) {
        ruleMap.putAll(merge.getRuleMap());
    }/* w  ww .j  av  a 2s  .  co m*/
    for (Cell<EndpointConstraint, EndpointConstraint, List<Subject>> entry : subjectMap.cellSet()) {
        List<RuleGroup> rules = new ArrayList<>();
        EndpointConstraint consEpConstraint = entry.getRowKey();
        EndpointConstraint provEpConstraint = entry.getColumnKey();
        List<RuleGroup> oldrules = ruleMap.get(consEpConstraint, provEpConstraint);
        if (oldrules != null) {
            rules.addAll(oldrules);
        }
        for (Subject s : entry.getValue()) {
            if (s.getRule() == null)
                continue;

            RuleGroup rg = new RuleGroup(s.getRule(), s.getOrder(), contractTenant, contract, s.getName());
            rules.add(rg);
        }
        Collections.sort(rules);
        ruleMap.put(consEpConstraint, provEpConstraint, Collections.unmodifiableList(rules));
    }
    return new Policy(ruleMap);
}

From source file:com.google.devtools.build.android.resources.ResourceSymbols.java

public static ResourceSymbols merge(Collection<ResourceSymbols> symbolTables) {
    final Table<String, String, RTxtSymbolEntry> mergedTable = HashBasedTable.create();
    for (ResourceSymbols symbolTableProvider : symbolTables) {
        mergedTable.putAll(symbolTableProvider.asTable());
    }//from   w w  w. j a  va2  s. c  o m
    return from(mergedTable);
}

From source file:com.android.builder.internal.SymbolWriter.java

private Table<String, String, SymbolEntry> getAllSymbols() {
    Table<String, String, SymbolEntry> symbols = HashBasedTable.create();

    for (SymbolLoader symbolLoader : mSymbols) {
        symbols.putAll(symbolLoader.getSymbols());
    }/*from  w  w w.j a v  a2  s  . c  o  m*/

    return symbols;
}

From source file:com.przemo.etl.transformations.MovingAverageTransformation.java

/**
 * Calculates moving average on the values of the given column in the table. The table has to be sorted to give correct results.
 * The values in the column must be of a numeric type.
 * @param column//from   w ww. j  a  va2  s.c om
 * @param period 
 */
public MovingAverageTransformation(final String column, final int period) {
    this.calculatedColumn = column;
    this.transformation = new Function() {

        @Override
        public Object apply(Object f) {
            if (f instanceof Table && ((Table) f).containsColumn(column)) {
                Table t = (Table) f;
                if (t.column(column).size() >= period) {
                    Table tr = calculateMovingAverage(t, period, column);
                    if (tr != null) {
                        t.putAll(tr);
                    }
                }
            }
            return f;
        }
    };
}

From source file:com.google.devtools.build.android.resources.RClassWriter.java

private Table<String, String, SymbolEntry> getAllSymbols() throws IOException {
    Table<String, String, SymbolEntry> symbols = HashBasedTable.create();
    for (SymbolLoader symbolLoader : symbolTables) {
        symbols.putAll(getSymbols(symbolLoader));
    }/*from  w w  w .  j av a2 s. co  m*/
    return symbols;
}

From source file:com.google.devtools.build.android.resources.ResourceSymbols.java

/**
 * Writes the java sources for a given package.
 *
 * @param sourceOut The directory to write the java package structures and sources to.
 * @param packageName The name of the package to write.
 * @param packageSymbols The symbols defined in the given package.
 * @throws IOException when encountering an error during writing.
 *///from   ww  w  . j av  a2s  .c o  m
public void writeTo(Path sourceOut, String packageName, Collection<ResourceSymbols> packageSymbols)
        throws IOException {

    Table<String, String, RTxtSymbolEntry> symbols = HashBasedTable.create();
    for (ResourceSymbols packageSymbol : packageSymbols) {
        symbols.putAll(packageSymbol.asTable());
    }

    Path packageOut = sourceOut.resolve(packageName.replace('.', File.separatorChar));
    Files.createDirectories(packageOut);

    Path file = packageOut.resolve(SdkConstants.FN_RESOURCE_CLASS);

    try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8,
            StandardOpenOption.CREATE_NEW)) {

        writer.write("/* AUTO-GENERATED FILE.  DO NOT MODIFY.\n");
        writer.write(" *\n");
        writer.write(" * This class was automatically generated by the\n");
        writer.write(" * aapt tool from the resource data it found.  It\n");
        writer.write(" * should not be modified by hand.\n");
        writer.write(" */\n");

        writer.write("package ");
        writer.write(packageName);
        writer.write(";\n\npublic final class R {\n");

        Set<String> rowSet = symbols.rowKeySet();
        List<String> rowList = new ArrayList<>(rowSet);
        Collections.sort(rowList);

        for (String row : rowList) {
            writer.write("\tpublic static final class ");
            writer.write(row);
            writer.write(" {\n");

            Map<String, RTxtSymbolEntry> rowMap = symbols.row(row);
            Set<String> symbolSet = rowMap.keySet();
            List<String> symbolList = new ArrayList<>(symbolSet);
            Collections.sort(symbolList);

            for (String symbolName : symbolList) {
                // get the matching SymbolEntry from the values Table.
                RTxtSymbolEntry value = values.get(row, symbolName);
                if (value != null) {
                    writer.write("\t\tpublic static final ");
                    writer.write(value.getType());
                    writer.write(" ");
                    writer.write(value.getName());
                    writer.write(" = ");
                    writer.write(value.getValue());
                    writer.write(";\n");
                }
            }

            writer.write("\t}\n");
        }

        writer.write("}\n");
    }
}

From source file:com.infinities.keystone4j.common.Config.java

public Table<Type, String, Option> getTable() {
    Table<Type, String, Option> table = HashBasedTable.create();
    table.putAll(FILE_OPTIONS);
    return table;
}

From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.GenericLogicDiscoverer.java

/**
 * Generic implementation for finding all the Services or Operations that have ALL the given types as inputs or outputs.
 *
 * @param entityType   the MSM URI of the type of entity we are looking for. Only supports Service and Operation.
 * @param relationship the MSM URI of the relationship we are looking for. Only supports hasInput and hasOutput.
 * @param types        the input/output types (modelReferences that is) we are looking for
 * @return a Map mapping operation/services URIs to MatchResults.
 *//*from   w w  w  .  j av  a  2 s  .  c  o  m*/
private Map<URI, MatchResult> findAll(URI entityType, URI relationship, Set<URI> types) {

    // Ensure that we have been given correct parameters
    if (types == null || types.isEmpty()
            || (!entityType.toASCIIString().equals(MSM.Service.getURI())
                    && !entityType.toASCIIString().equals(MSM.Operation.getURI()))
            || (!relationship.toASCIIString().equals(MSM.hasInput.getURI())
                    && !entityType.toASCIIString().equals(MSM.hasOutput.getURI())
                    && !relationship.toASCIIString().equals(SAWSDL.modelReference.getURI()))) {

        return ImmutableMap.of();
    }

    // Expand the input types to get all that match enough to be consumed
    // The structure is: <OriginalType, MatchingType, MatchResult>
    Table<URI, URI, MatchResult> expandedTypes;
    if (relationship.toASCIIString().equals(SAWSDL.modelReference.getURI())) {
        expandedTypes = HashBasedTable.create();
        for (URI type : types) {
            expandedTypes.putAll(this.conceptMatcher.listMatchesAtMostOfType(ImmutableSet.of(type),
                    LogicConceptMatchType.Subsume));
            expandedTypes.putAll(
                    this.conceptMatcher.listMatchesOfType(ImmutableSet.of(type), LogicConceptMatchType.Exact));
        }
    } else {
        expandedTypes = this.conceptMatcher.listMatchesAtLeastOfType(types, LogicConceptMatchType.Plugin);
    }

    // Track all the results in a multimap to push the details up the stack
    ListMultimap<URI, MatchResult> result = ArrayListMultimap.create();

    // Do the intersection of those operations that can consume each of the inputs separately
    boolean firstTime = true;
    Map<URI, MatchResult> intermediateMatches;
    Map<URI, Map<URI, MatchResult>> rowMap = expandedTypes.rowMap();
    // For each original type
    for (URI inputType : rowMap.keySet()) {
        // obtain those entities that match any of the expanded matching types
        intermediateMatches = findSome(entityType, relationship, rowMap.get(inputType).keySet());
        if (firstTime) {
            // Add all entries
            firstTime = false;
            for (Map.Entry<URI, MatchResult> entry : intermediateMatches.entrySet()) {
                result.put(entry.getKey(), entry.getValue());
            }
        } else {
            // Put all the values from the intersection
            Set<URI> intersection = Sets.intersection(result.keySet(), intermediateMatches.keySet());
            for (URI opUri : intersection) {
                result.put(opUri, intermediateMatches.get(opUri));
            }

            // Drop all the values from the difference
            // Use an immutable copy since the views will be changed
            Set<URI> difference = Sets.difference(result.keySet(), intermediateMatches.keySet())
                    .immutableCopy();
            for (URI opUri : difference) {
                result.removeAll(opUri);
            }
        }
    }

    // Merge the results into a single map using Union
    return Maps.transformValues(result.asMap(), MatchResultsMerger.INTERSECTION);

}

From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.GenericLogicDiscoverer.java

/**
 * Generic implementation for finding all the Services or Operations that have SOME of the given types as inputs or outputs.
 *
 * @param entityType   the MSM URI of the type of entity we are looking for. Only supports Service and Operation.
 * @param relationship the MSM URI of the relationship we are looking for. Only supports hasInput and hasOutput.
 * @param types        the input/output types (modelReferences that is) we are looking for
 * @return a Map mapping operation/services URIs to MatchResults.
 *//*from   w ww  .  java 2  s  .c om*/
private Map<URI, MatchResult> findSome(URI entityType, URI relationship, Set<URI> types) {

    // Ensure that we have been given correct parameters
    if (types == null || types.isEmpty()
            || (!entityType.toASCIIString().equals(MSM.Service.getURI())
                    && !entityType.toASCIIString().equals(MSM.Operation.getURI()))
            || (!relationship.toASCIIString().equals(MSM.hasInput.getURI())
                    && !entityType.toASCIIString().equals(MSM.hasOutput.getURI())
                    && !relationship.toASCIIString().equals(SAWSDL.modelReference.getURI()))) {

        return ImmutableMap.of();
    }

    // Expand the input types to get all that match enough to be consumed
    // TODO: The leastOfType should be configurable
    Table<URI, URI, MatchResult> expandedTypes;
    if (relationship.toASCIIString().equals(SAWSDL.modelReference.getURI())) {
        expandedTypes = HashBasedTable.create();
        //TODO: fix this properly
        for (URI type : types) {
            expandedTypes.putAll(this.conceptMatcher.listMatchesAtMostOfType(ImmutableSet.of(type),
                    LogicConceptMatchType.Subsume));
            expandedTypes.putAll(
                    this.conceptMatcher.listMatchesOfType(ImmutableSet.of(type), LogicConceptMatchType.Exact));
        }

    } else {
        expandedTypes = this.conceptMatcher.listMatchesAtLeastOfType(types, LogicConceptMatchType.Plugin);
    }

    // Track all the results in a multimap to push the details up the stack
    Multimap<URI, MatchResult> result = ArrayListMultimap.create();

    // Find all the entities with modelReferences to the expanded types
    // The column view is the one with all the possible matches since a class will always match itself
    Map<URI, Map<URI, MatchResult>> columnMap = expandedTypes.columnMap();
    for (URI type : columnMap.keySet()) {
        Set<URI> entities = ImmutableSet.of();
        if (relationship.toASCIIString().equals(SAWSDL.modelReference.getURI())) {
            entities = listEntitesWithModelReference(entityType, type);
        } else if (relationship.toASCIIString().equals(MSM.hasInput.getURI())
                || relationship.toASCIIString().equals(MSM.hasOutput.getURI())) {
            entities = listEntitiesWithType(entityType, relationship, type);
        }

        for (URI entity : entities) {
            result.putAll(entity, columnMap.get(type).values());
        }
    }

    // Merge the results into a single map using Union
    return Maps.transformValues(result.asMap(), MatchResultsMerger.UNION);

}