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:org.brocalc.domain.RangeConstraintMapUtil.java

public static <T extends Comparable<?>> Map<Range<T>, BrokerageScheduleComponent> createRangeConstrainedMap(
        final String rangeName) {
    final Map<Range<T>, BrokerageScheduleComponent> baseMap = Maps.newHashMap();
    Map<Range<T>, BrokerageScheduleComponent> constrainedMap = MapConstraints.constrainedMap(baseMap,
            new MapConstraint<Range<T>, BrokerageScheduleComponent>() {

                @Override//from   w  w w.j  a  va 2 s  .  co  m
                public void checkKeyValue(Range<T> newKey,
                        BrokerageScheduleComponent brokerageScheduleComponent) {
                    baseMap.keySet();
                    for (Range<T> existingKey : baseMap.keySet()) {
                        if (existingKey.isConnected(newKey) && !existingKey.intersection(newKey).isEmpty()) {
                            throw new RangeOverlapException(
                                    rangeName + " " + newKey + " overlaps with " + existingKey);
                        }
                    }
                }
            });
    return constrainedMap;
}

From source file:org.guiceyfruit.support.Reflectors.java

/** Returns all the methods on the given type ignoring overloaded methods */
public static List<Method> getAllMethods(TypeLiteral<?> startType) {
    List<Method> answer = Lists.newArrayList();
    Map<MethodKey, Method> boundMethods = Maps.newHashMap();
    while (true) {
        Class<?> type = startType.getRawType();
        if (type == Object.class) {
            break;
        }//from   w  w w  . j  a  va  2s  .co  m

        Method[] methods = type.getDeclaredMethods();
        for (final Method method : methods) {
            MethodKey key = new MethodKey(method);
            if (boundMethods.get(key) == null) {
                boundMethods.put(key, method);
                answer.add(method);
            }
        }

        //startType = startType.getSupertype(type);
        Class<?> supertype = type.getSuperclass();
        if (supertype == Object.class) {
            break;
        }
        startType = startType.getSupertype(supertype);
    }
    return answer;
}

From source file:org.apache.pig.backend.hadoop.executionengine.tez.util.TezRuntimeUtil.java

public static Map<Object, Pair<Integer, Integer>> readReduceMapFromSample(TupleFactory tf) {
    Map<Object, Pair<Integer, Integer>> reducerMap = Maps.newHashMap();
    Map<String, Object> distMap = null;
    if (PigProcessor.sampleMap != null) {
        // We've collected sampleMap in PigProcessor
        distMap = PigProcessor.sampleMap;
    } else {//from www  . java  2s  .co m
        LOG.info("Key distribution map is empty");
        return reducerMap;
    }

    long start = System.currentTimeMillis();

    try {
        reducerMap = Maps.newHashMap();
        // The distMap is structured as (key, min, max) where min, max
        // being the index of the reducers
        DataBag partitionList = (DataBag) distMap.get(PartitionSkewedKeys.PARTITION_LIST);
        int totalReducers = Integer.valueOf("" + distMap.get(PartitionSkewedKeys.TOTAL_REDUCERS));
        Iterator<Tuple> it = partitionList.iterator();
        while (it.hasNext()) {
            Tuple idxTuple = it.next();
            Integer maxIndex = (Integer) idxTuple.get(idxTuple.size() - 1);
            Integer minIndex = (Integer) idxTuple.get(idxTuple.size() - 2);
            // Used to replace the maxIndex with the number of reducers
            if (maxIndex < minIndex) {
                maxIndex = totalReducers + maxIndex;
            }

            Tuple keyT;
            // if the join is on more than 1 key
            if (idxTuple.size() > 3) {
                // remove the last 2 fields of the tuple, i.e: minIndex and maxIndex and store
                // it in the reducer map
                Tuple keyTuple = tf.newTuple();
                for (int i = 0; i < idxTuple.size() - 2; i++) {
                    keyTuple.append(idxTuple.get(i));
                }
                keyT = keyTuple;
            } else {
                keyT = tf.newTuple(1);
                keyT.set(0, idxTuple.get(0));
            }
            // number of reducers
            Integer cnt = maxIndex - minIndex;
            // 1 is added to account for the 0 index
            reducerMap.put(keyT, new Pair<Integer, Integer>(minIndex, cnt));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    LOG.info("Initialized reducerMap. Time taken: " + (System.currentTimeMillis() - start));
    return reducerMap;
}

From source file:org.auraframework.docs.DocsController.java

@AuraEnabled
public static Component getDemo(@Key("demo") String demo) throws QuickFixException {
    Map<String, Object> attributes = Maps.newHashMap();
    attributes.put("demo", demo);
    return Aura.getInstanceService().getInstance("auradocs:demoPanel", ComponentDef.class, attributes);
}

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

private ParameterBeanMapper(final Class<T> type, final String dsName) {
    this.type = type;
    this.dsName = dsName;
    this.fields = Maps.newHashMap();
    initializeMappings();/*  w w  w.j  av a 2  s .com*/
}

From source file:com.chenchengzhi.windtalkers.core.BindingMap.java

public BindingMap() {
    values = Maps.newHashMap();
}

From source file:org.yakindu.sct.examples.wizard.drop.ExampleURLHandler.java

/**
 * Copied from {@link org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.parseQuery(String)}
 *//*from w  w w  . ja v a2 s . c o  m*/
private static Map<String, String> parseQuery(String url) {
    String query;
    try {
        query = new URL(url).getQuery();
    } catch (MalformedURLException e) {
        return Maps.newHashMap();
    }
    if (query == null) {
        return Maps.newHashMap();
    }
    Map<String, String> values = new LinkedHashMap<String, String>();
    String[] params = query.split(SPLIT_REGEX);
    for (String param : params) {
        String[] keyValue = param.split(EQUALS_REGEX);
        if (keyValue.length == 2) {
            String key = keyValue[0];
            String value = keyValue[1];
            values.put(key, value);
        }
    }
    return values;
}

From source file:org.opendaylight.groupbasedpolicy.jsonrpc.RpcMessageMap.java

public RpcMessageMap() {
    messageMap = Maps.newHashMap();
}

From source file:org.onos.yangtools.checkstyle.CheckCodingStyleTestClass.java

public CheckCodingStyleTestClass() {
    Comparator<String> string = CASE_INSENSITIVE_ORDER;

    Map<String, String> map = Maps.newHashMap();
}

From source file:com.ibm.og.json.FailingConditionsConfig.java

public FailingConditionsConfig() {
    this.operations = 0;
    this.runtime = 0.0;
    this.runtimeUnit = TimeUnit.SECONDS;
    this.concurrentRequests = 2000;
    this.statusCodes = Maps.newHashMap();
}