Example usage for com.google.common.collect ImmutableTable.Builder put

List of usage examples for com.google.common.collect ImmutableTable.Builder put

Introduction

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

Prototype

@Deprecated
@Override
public final V put(R rowKey, C columnKey, V value) 

Source Link

Document

Guaranteed to throw an exception and leave the table unmodified.

Usage

From source file:org.dishevelled.analysis.AnalysisUtils.java

/**
 * Convert the specified binary key map to an immutable table.
 *
 * @param <N> binary key map key type and table row and column key type
 * @param <E> binary key map value type and table value type
 * @param binaryKeyMap binary key map to convert, must be not null
 * @return the specified binary key map converted to an immutable table
 *///from  w w  w.j  a v  a  2 s.  c om
public static <N, E> ImmutableTable<N, N, E> toImmutableTable(final BinaryKeyMap<N, N, E> binaryKeyMap) {
    if (binaryKeyMap == null) {
        throw new IllegalArgumentException("binaryKeyMap must not be null");
    }
    ImmutableTable.Builder<N, N, E> builder = ImmutableTable.builder();
    for (Map.Entry<BinaryKey<N, N>, E> entry : binaryKeyMap.entrySet()) {
        N row = entry.getKey().getFirstKey();
        N column = entry.getKey().getSecondKey();
        E value = entry.getValue();
        builder.put(row, column, value);
    }
    return builder.build();
}

From source file:uk.ac.open.kmi.iserve.discovery.api.impl.AbstractMatcher.java

/**
 * Obtain all the matching resources with the URIs of {@code origin} within the range of MatchTypes provided, both inclusive.
 *
 * @param origins URIs to match/*  w  ww .j  av a  2 s. c o m*/
 * @param minType the minimum MatchType we want to obtain
 * @param maxType the maximum MatchType we want to obtain
 * @return a {@link com.google.common.collect.Table} with the result of the matching indexed by origin URI and then destination URI.
 */
@Override
public Table<URI, URI, MatchResult> listMatchesWithinRange(Set<URI> origins, MatchType minType,
        MatchType maxType) {

    ImmutableTable.Builder<URI, URI, MatchResult> builder = ImmutableTable.builder();
    Map<URI, MatchResult> matches;
    for (URI origin : origins) {
        matches = this.listMatchesWithinRange(origin, minType, maxType);
        for (Map.Entry<URI, MatchResult> match : matches.entrySet()) {
            builder.put(origin, match.getKey(), match.getValue());
        }
    }
    return builder.build();
}

From source file:at.ac.univie.isc.asio.sql.ConvertToTable.java

private Table<Integer, String, String> convert(final Iterable<String[]> rows, final String[] header) {
    final ImmutableTable.Builder<Integer, String, String> table = ImmutableTable.builder();
    int rowIndex = 0;
    for (String[] row : rows) {
        assert row.length == header.length : "row length mismatch with header @" + Arrays.toString(row);
        for (int columnIndex = 0; columnIndex < row.length; columnIndex++) {
            final String value = normalize(row[columnIndex]);
            table.put(rowIndex, header[columnIndex], value);
        }/* w  w  w  .  j a v a2  s. c  o  m*/
        rowIndex++;
    }
    return table.build();
}

From source file:com.opengamma.strata.report.cashflow.CashFlowReportRunner.java

private ImmutableTable<Integer, Integer, Object> getData(List<ExplainMap> flatMap, List<ExplainKey<?>> keys) {
    ImmutableTable.Builder<Integer, Integer, Object> builder = ImmutableTable.builder();

    for (int rowIdx = 0; rowIdx < flatMap.size(); rowIdx++) {
        ExplainMap rowMap = flatMap.get(rowIdx);

        for (int colIdx = 0; colIdx < keys.size(); colIdx++) {
            builder.put(rowIdx, colIdx, rowMap.get(keys.get(colIdx)));
        }//from w ww .  j  a  v  a2s .  c o m
    }
    return builder.build();
}

From source file:com.google.template.soy.shared.internal.DelTemplateSelector.java

private DelTemplateSelector(Builder<T> builder) {
    ImmutableTable.Builder<String, String, Group<T>> nameAndVariantBuilder = ImmutableTable.builder();
    ImmutableListMultimap.Builder<String, T> delTemplateNameToValuesBuilder = ImmutableListMultimap.builder();
    for (Table.Cell<String, String, Group.Builder<T>> entry : builder.nameAndVariantToGroup.cellSet()) {
        Group<T> group = entry.getValue().build();
        nameAndVariantBuilder.put(entry.getRowKey(), entry.getColumnKey(), group);
        String delTemplateName = entry.getRowKey();
        if (group.defaultValue != null) {
            delTemplateNameToValuesBuilder.put(delTemplateName, group.defaultValue);
        }//from   ww  w .j  a  va 2  s.  com
        delTemplateNameToValuesBuilder.putAll(delTemplateName, group.delpackageToValue.values());
    }
    this.nameAndVariantToGroup = nameAndVariantBuilder.build();
    this.delTemplateNameToValues = delTemplateNameToValuesBuilder.build();
}

From source file:net.awairo.mcmod.spawnchecker.client.common.MultiServerWorldSeedConfig.java

private static ImmutableTable<String, Integer, Long> load(String[] worldSeeds) {
    final Pattern pattern = Pattern.compile("^\"([^\"]+)\"$");
    final Splitter keyValue = Splitter.on('=');
    final Splitter hostPort = Splitter.on(':');

    final ImmutableTable.Builder<String, Integer, Long> builder = ImmutableTable.builder();
    for (String seedConfig : worldSeeds) {
        final Matcher m = pattern.matcher(seedConfig);
        if (!m.matches()) {
            LOGGER.warn("removed {} from world seed configurations. (illegal format)", seedConfig);
            continue;
        }/*  w w  w.j a  v  a2s  .  c o m*/

        final Iterator<String> kv = keyValue.split(m.group(1)).iterator();

        if (!kv.hasNext()) {
            LOGGER.warn("removed {} from world seed configurations. (illegal address)", seedConfig);
            continue;
        }

        final Iterator<String> hp = hostPort.split(kv.next()).iterator();
        if (!kv.hasNext()) {
            LOGGER.warn("removed {} from world seed configurations. (illegal seed)", seedConfig);
            continue;
        }
        if (!hp.hasNext()) {
            LOGGER.warn("removed {} from world seed configurations. (illegal address)", seedConfig);
            continue;
        }

        final Long seed = Longs.tryParse(kv.next());
        if (seed == null) {
            LOGGER.warn("removed {} from world seed configurations. (illegal seed value)", seedConfig);
            continue;
        }

        final String host = hp.next();
        final Integer port = hp.hasNext() ? Ints.tryParse(hp.next()) : DEFAULT_PORT;

        builder.put(host, port, seed);
    }

    return builder.build();
}

From source file:su.opencode.shuffler.MarkovBuildingVisitor.java

private Table<String, String, Double> probabilityTable(Table<String, String, Integer> chainTable) {

    ImmutableTable.Builder<String, String, Double> builder = ImmutableTable.builder();

    for (Map.Entry<String, Map<String, Integer>> row : chainTable.rowMap().entrySet()) {
        if (row.getValue().isEmpty())
            continue;

        double total = 0;

        for (Map.Entry<String, Integer> cell : row.getValue().entrySet()) {
            total += cell.getValue();/*from   ww w  . j a v a 2 s. c om*/
        }

        for (Map.Entry<String, Integer> cell : row.getValue().entrySet()) {
            double prob = cell.getValue() / total;
            builder.put(row.getKey(), cell.getKey(), prob);
        }
    }

    builder.orderRowsBy(StringComparator.INSTANCE);
    builder.orderColumnsBy(StringComparator.INSTANCE);

    return builder.build();
}

From source file:net.minecrell.quartz.launch.mappings.Mappings.java

protected Mappings(List<ClassNode> mappingClasses) {
    requireNonNull(mappingClasses, "mappingClasses");
    if (mappingClasses.isEmpty()) {
        this.classes = ImmutableBiMap.of();
        this.methods = ImmutableTable.of();
        this.fields = ImmutableTable.of();
        this.constructors = ImmutableMultimap.of();
        this.accessMappings = ImmutableTable.of();
        return;/*from  www.j ava  2  s.  c  o  m*/
    }

    ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder();

    for (ClassNode classNode : mappingClasses) {
        ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, MAPPING);
        checkState(annotation != null, "Class %s is missing the @Mapping annotation", classNode.name);
        String mapping = annotation.getString("value", "");
        if (!mapping.isEmpty()) {
            classes.put(mapping, classNode.name);
        }
    }

    this.classes = classes.build();

    // We need to remap the descriptors of the fields and methods, use ASM for convenience
    Remapper remapper = new Remapper() {

        @Override
        public String map(String className) {
            return unmap(className);
        }
    };

    // Load field, method and access mappings
    ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder();
    ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder();
    ImmutableMultimap.Builder<String, MethodNode> constructors = ImmutableMultimap.builder();
    ImmutableTable.Builder<String, String, AccessMapping> accessMappings = ImmutableTable.builder();

    for (ClassNode classNode : mappingClasses) {
        String className = classNode.name.replace('/', '.');
        String internalName = unmap(classNode.name);

        ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, ACCESSIBLE);
        if (annotation != null) {
            accessMappings.put(className, "", AccessMapping.of(classNode));
        }

        for (MethodNode methodNode : classNode.methods) {
            Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(methodNode);

            annotation = annotations.get(CONSTRUCTOR);
            if (annotation != null) {
                // Generate constructor call code
                Methods.visitConstructor(methodNode, classNode.name);
                constructors.put(className, methodNode);
                continue;
            }

            // TODO: Validation
            annotation = annotations.get(MAPPING);
            if (annotation != null) {
                String mapping = annotation.getString("value", "");
                if (!mapping.isEmpty()) {
                    methods.put(internalName, mapping + remapper.mapMethodDesc(methodNode.desc),
                            methodNode.name);
                }
            }

            annotation = annotations.get(ACCESSIBLE);
            if (annotation != null) {
                accessMappings.put(className, methodNode.name + methodNode.desc, AccessMapping.of(methodNode));
            }
        }

        for (FieldNode fieldNode : classNode.fields) {
            Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(fieldNode);

            // TODO: Validation
            annotation = annotations.get(MAPPING);
            if (annotation != null) {
                String mapping = annotation.getString("value", "");
                if (!mapping.isEmpty()) {
                    fields.put(internalName, mapping + ':' + remapper.mapDesc(fieldNode.desc), fieldNode.name);
                }
            }

            annotation = annotations.get(ACCESSIBLE);
            if (annotation != null) {
                accessMappings.put(className, fieldNode.name, AccessMapping.of(fieldNode));
            }
        }
    }

    this.methods = methods.build();
    this.fields = fields.build();
    this.constructors = constructors.build();
    this.accessMappings = accessMappings.build();
}

From source file:org.lanternpowered.server.block.state.LanternBlockStateMap.java

@SuppressWarnings("rawtypes")
public LanternBlockStateMap(LanternBlockType blockType, Iterable<BlockTrait<?>> blockTraits) {
    this.blockType = blockType;

    // There are no block traits
    if (!blockTraits.iterator().hasNext()) {
        final LanternBlockState blockState = new LanternBlockState(this, ImmutableMap.of());
        blockState.propertyValueTable = ImmutableTable.of();
        this.blockStates = ImmutableList.of(blockState);
        this.blockTraits = ImmutableMap.of();
        this.keys = ImmutableSet.of();
        return;//from  w  ww . j a  v a  2 s.co  m
    }

    // Convert to a list so it can be sorted
    final List<BlockTrait<?>> list = Lists.newArrayList(blockTraits);

    // Sort the traits by the name
    list.sort(Comparator.comparing(BlockTrait::getName));

    // The builder for the name to trait lookup
    final ImmutableMap.Builder<String, BlockTrait<?>> builder = ImmutableMap.builder();
    final ImmutableSet.Builder<Key<?>> keys = ImmutableSet.builder();

    // All the sets with all the allowed values
    final List<Set<Comparable<?>>> allowedValues = new ArrayList<>();

    for (BlockTrait<?> trait : list) {
        allowedValues.add(new HashSet<>(trait.getPossibleValues()));
        keys.add(((LanternBlockTrait) trait).getKey());
        builder.put(trait.getName(), trait);
    }

    // Build the lookups
    this.blockTraits = builder.build();
    this.keys = keys.build();

    // A map with as the key the trait values map and as value the state
    final LinkedHashMap<Map<?, ?>, BlockState> stateByValuesMap = new LinkedHashMap<>();

    // The block states
    final ImmutableList.Builder<BlockState> blockStates = ImmutableList.builder();

    // Do the cartesian product to get all the possible combinations
    for (List<Comparable<?>> comparables : Sets.cartesianProduct(allowedValues)) {
        final Iterator<Comparable<?>> objectsIt = comparables.iterator();

        final ImmutableMap.Builder<BlockTrait<?>, Comparable<?>> traitValuesBuilder = ImmutableMap.builder();
        for (BlockTrait<?> trait : list) {
            traitValuesBuilder.put(trait, objectsIt.next());
        }

        final ImmutableMap<BlockTrait<?>, Comparable<?>> traitValues = traitValuesBuilder.build();
        final LanternBlockState blockState = new LanternBlockState(this, traitValues);
        stateByValuesMap.put(traitValues, blockState);
        blockStates.add(blockState);
    }

    this.blockStates = blockStates.build();
    this.blockStates.stream().map(state -> (LanternBlockState) state).forEach(state -> {
        final ImmutableTable.Builder<BlockTrait<?>, Comparable<?>, BlockState> tableBuilder = ImmutableTable
                .builder();
        list.forEach(trait -> trait.getPossibleValues().stream()
                .filter(value -> value != state.getTraitValue(trait).get()).forEach(value -> {
                    final Map<BlockTrait<?>, Comparable<?>> valueByTrait = new HashMap<>();
                    valueByTrait.putAll(state.traitValues);
                    valueByTrait.put(trait, value);
                    tableBuilder.put(trait, value, stateByValuesMap.get(valueByTrait));
                }));
        state.propertyValueTable = tableBuilder.build();
    });

    int internalId = 0;
    for (BlockState blockState : this.blockStates) {
        final LanternBlockState blockState1 = (LanternBlockState) blockState;
        blockState1.extended = blockType.getExtendedBlockStateProvider().remove(blockState) != blockState;
        blockState1.internalId = internalId++;
    }
}

From source file:com.proofpoint.reporting.ReportCollector.java

private void collectData() {
    final long lastSystemTimeMillis = bucketIdProvider.getLastSystemTimeMillis();
    ImmutableTable.Builder<ObjectName, String, Number> builder = ImmutableTable.builder();
    int numAtributes = 0;
    for (Entry<ObjectName, ReportedBean> reportedBeanEntry : reportedBeanRegistry.getReportedBeans()
            .entrySet()) {//from   ww  w. j a  va2 s.co  m
        for (ReportedBeanAttribute attribute : reportedBeanEntry.getValue().getAttributes()) {
            Number value = null;

            try {
                value = attribute.getValue(null);
            } catch (AttributeNotFoundException | MBeanException | ReflectionException ignored) {
            }

            if (isReportable(value)) {
                ++numAtributes;
                builder.put(reportedBeanEntry.getKey(), attribute.getName(), value);
            }
        }
    }
    builder.put(REPORT_COLLECTOR_OBJECT_NAME, "NumMetrics", numAtributes);
    final Table<ObjectName, String, Number> collectedData = builder.build();
    clientExecutorService.submit(new Runnable() {
        @Override
        public void run() {
            reportClient.report(lastSystemTimeMillis, collectedData);
        }
    });
}