Example usage for com.google.common.collect Maps newHashMap

List of usage examples for com.google.common.collect Maps newHashMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newHashMap.

Prototype

public static <K, V> HashMap<K, V> newHashMap() 

Source Link

Document

Creates a mutable, empty HashMap instance.

Usage

From source file:vazkii.tinkerer.common.block.tile.peripheral.PeripheralAspectContainer.java

public static Map<Double, Map<String, Object>> aspectsToMap(IAspectContainer container) {
    Map<Double, Map<String, Object>> aspects = Maps.newHashMap();
    AspectList aspectList = container.getAspects();
    if (aspectList == null)
        return aspects;
    int i = 1;/*from ww w  . j ava 2s  .c  o  m*/
    for (Aspect aspect : aspectList.getAspects()) {
        if (aspect == null)
            continue;
        appendAspectEntry(aspects, i++, aspect, aspectList.getAmount(aspect));
    }
    return aspects;
}

From source file:com.enonic.cms.core.portal.datasource.handler.DataSourceRequest.java

public DataSourceRequest() {
    this.paramMap = Maps.newHashMap();
}

From source file:ai.grakn.graql.internal.util.Partition.java

/**
 * Constructs a new partition of singletons
 *//*w ww  .j  a  v a 2s  . c  om*/
public static <T> Partition<T> singletons(Collection<T> nodes) {
    final Map<T, T> parents = Maps.newHashMap();
    final Map<T, Integer> ranks = Maps.newHashMap();
    for (T node : nodes) {
        parents.put(node, node); // each node is its own head
        ranks.put(node, 0); // every node has depth 0 to start
    }
    return new Partition<T>(parents, ranks);
}

From source file:org.eclipse.mylyn.internal.wikitext.html.core.BlockStrategies.java

private static Map<BlockType, List<BlockType>> createBlockTypeToAlternatives() {
    Map<BlockType, List<BlockType>> alternatives = Maps.newHashMap();
    addAlternatives(alternatives, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.BULLETED_LIST, BlockType.NUMERIC_LIST);
    addAlternatives(alternatives, BlockType.NUMERIC_LIST, BlockType.BULLETED_LIST);
    addAlternatives(alternatives, BlockType.CODE, BlockType.PREFORMATTED, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.DEFINITION_LIST, BlockType.NUMERIC_LIST, BlockType.BULLETED_LIST);
    addAlternatives(alternatives, BlockType.DIV, BlockType.PARAGRAPH);
    addAlternatives(alternatives, BlockType.FOOTNOTE, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.INFORMATION, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.LIST_ITEM, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.DEFINITION_ITEM, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.DEFINITION_TERM, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.NOTE, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.PANEL, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.PREFORMATTED, BlockType.CODE, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.QUOTE, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.TABLE_CELL_HEADER, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.TABLE_CELL_NORMAL, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.TIP, BlockType.PARAGRAPH, BlockType.DIV);
    addAlternatives(alternatives, BlockType.WARNING, BlockType.PARAGRAPH, BlockType.DIV);
    return ImmutableMap.copyOf(alternatives);
}

From source file:com.topekalabs.algos.discrete.Permutations.java

public static <L, V> Set<Map<L, V>> labeledPermutations(Map<L, Set<V>> valuesMap) {
    Set<Map<L, V>> permutations = Sets.newHashSet();

    if (valuesMap.isEmpty()) {
        return permutations;
    }/*from  ww w. ja v  a2s.c om*/

    Map.Entry<L, Set<V>> mapEntry = CollectionUtils.getSingleElement(valuesMap.entrySet());
    L label = mapEntry.getKey();
    Set<V> values = mapEntry.getValue();

    if (valuesMap.size() == 1) {
        for (V value : values) {
            Map<L, V> permutation = Maps.newHashMap();
            permutation.put(label, value);
            permutations.add(permutation);
        }

        return permutations;
    }

    Map<L, Set<V>> reducedValuesMap = Maps.newHashMap(valuesMap);
    reducedValuesMap.remove(label);

    Set<Map<L, V>> reducedPermutations = labeledPermutations(reducedValuesMap);

    for (Map<L, V> reducedPermutation : reducedPermutations) {
        for (V value : values) {
            Map<L, V> permutation = Maps.newHashMap(reducedPermutation);
            permutation.put(label, value);
            permutations.add(permutation);
        }
    }

    return permutations;
}

From source file:com.twitter.ambrose.model.hadoop.CounterGroup.java

/**
 * Constructs map of counter groups by name from Hadoop Counters instance.
 *
 * @param counters counters./*  ww w. ja  va2s.  c o  m*/
 * @return map of counter groups by name.
 */
public static Map<String, CounterGroup> counterGroupsByName(Counters counters) {
    Map<String, CounterGroup> counterGroupsByName = Maps.newHashMap();
    if (counters != null) {
        for (Counters.Group group : counters) {
            CounterGroup counterGroup = new CounterGroup(group);
            counterGroupsByName.put(counterGroup.getGroupName(), counterGroup);
        }
    }
    return counterGroupsByName;
}

From source file:com.flaptor.indextank.storage.RecordMerger.java

public static List<LogRecord> compactAndSort(Iterator<LogRecord> source) {
    Map<String, LogRecord> target = Maps.newHashMap();
    while (source.hasNext()) {
        LogRecord record = source.next();
        LogRecord compacted = target.get(record.get_docid());
        if (compacted == null) {
            target.put(record.get_docid(), new LogRecord(record));
        } else {/*from  www . j  av a  2  s  . c  o  m*/
            mergeRecordInto(record, compacted);
        }
    }
    List<LogRecord> records = Lists.newArrayList(target.values());
    Collections.sort(records, RecordMerger.MERGE_ORDER);
    return records;
}

From source file:nl.knaw.huygens.timbuctoo.model.PersonNameBuilder.java

private static Map<MultiKey, String> createSeparatorMap() {
    Map<MultiKey, String> map = Maps.newHashMap();
    map.put(new MultiKey(PersonNameComponent.Type.SURNAME, PersonNameComponent.Type.FORENAME), COMMA);
    map.put(new MultiKey(PersonNameComponent.Type.SURNAME, PersonNameComponent.Type.GEN_NAME), COMMA);
    map.put(new MultiKey(PersonNameComponent.Type.SURNAME, PersonNameComponent.Type.ADD_NAME), COMMA);
    map.put(new MultiKey(PersonNameComponent.Type.SURNAME, PersonNameComponent.Type.NAME_LINK), COMMA);
    map.put(new MultiKey(PersonNameComponent.Type.FORENAME, PersonNameComponent.Type.ADD_NAME), COMMA);
    map.put(new MultiKey(PersonNameComponent.Type.GEN_NAME, PersonNameComponent.Type.ADD_NAME), COMMA);
    return map;/*from   w w w .java  2 s.c o  m*/
}

From source file:ru.runa.wfe.commons.web.WebUtils.java

public static String getFormComponentScript(String javascript, Map<String, String> substitutions) {
    if (substitutions == null) {
        substitutions = Maps.newHashMap();
    }//from ww w . j ava 2s .c  o  m
    for (Map.Entry<String, String> entry : substitutions.entrySet()) {
        javascript = javascript.replaceAll(Pattern.quote(entry.getKey()),
                Matcher.quoteReplacement(entry.getValue()));
    }
    return getScript(javascript);
}

From source file:org.eclipse.incquery.runtime.localsearch.planner.util.CompilerHelper.java

public static Map<PVariable, Integer> createVariableMapping(SubPlan plan) {
    Map<PVariable, Integer> variableMapping = Maps.newHashMap();

    int variableNumber = 0;

    // Important note: this list might contain duplications when parameters are made equal inside the pattern
    // This is the expected and normal behavior
    List<PVariable> symbolicParameterVariables = plan.getBody().getSymbolicParameterVariables();
    for (PVariable pVariable : symbolicParameterVariables) {
        variableMapping.put(pVariable, variableNumber++);
    }//from w  w  w . j  ava 2  s. co m

    // Reason for complexity here: not all variables were given back for call plan.getAllDeducedVariables();
    Set<PVariable> allVariables = Sets.newHashSet();
    Set<PConstraint> allEnforcedConstraints = plan.getAllEnforcedConstraints();
    for (PConstraint pConstraint : allEnforcedConstraints) {
        allVariables.addAll(pConstraint.getAffectedVariables());
    }
    for (PVariable pVariable : allVariables) {
        if (!variableMapping.containsKey(pVariable)) {
            variableMapping.put(pVariable, variableNumber++);
        }
    }

    return variableMapping;
}