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.apache.rocketmq.jms.util.URISpecParser.java

/**
 * ConnectionUrl spec is broker://ip:port?key1=value1&key2=value2
 *
 * @param uri Just like broker://ip:port?key1=value1&key2=value2
 * @return The parameters' map/*from   w  w  w . j  a  va2  s  . c om*/
 */
public static Map<String, String> parseURI(String uri) {
    Preconditions.checkArgument(null != uri && !uri.trim().isEmpty(), "Uri can not be empty!");

    Map<String, String> results = Maps.newHashMap();
    String broker = uri.substring(0, uri.indexOf(":"));
    results.put(CommonConstant.PROVIDER, broker);

    if (broker.equals(DEFAULT_BROKER)) {
        //Special handle for alibaba inner mq broker
        String queryStr = uri.substring(uri.indexOf("?") + 1, uri.length());
        if (StringUtils.isNotEmpty(queryStr)) {
            String[] params = queryStr.split("&");
            for (String param : params) {
                if (param.contains("=")) {
                    String[] values = param.split("=", 2);
                    results.put(values[0], values[1]);
                }
            }
        }
    } else {
        throw new IllegalArgumentException("Broker must be rocketmq");
    }
    return results;
}

From source file:org.auraframework.throwable.quickfix.CreateThemeDefQuickFix.java

private static Map<String, Object> createMap(DefDescriptor<?> descriptor) {
    Map<String, Object> ret = Maps.newHashMap();
    ret.put("descriptor", descriptor);
    return ret;/* w  w w .j a v a2 s. c om*/
}

From source file:org.apache.kylin.common.QueryContext.java

private static void setString(String key, String value) {
    Map<String, String> context = _queryContext.get();
    if (context == null) {
        Map<String, String> newMap = Maps.newHashMap();
        newMap.put(key, value);//  w w w .j  a va2  s  .co  m
        _queryContext.set(newMap);
    } else {
        context.put(key, value);
    }
}

From source file:org.springside.examples.showcase.log.AppenderUtils.java

/**
 * ?Map, MapKey???./*from  ww  w .  j a  va2 s. c  om*/
 */
public static Map<String, Object> convertEventToMap(LoggingEvent event) {
    Map<String, Object> map = Maps.newHashMap();
    map.put(MESSAGE, event.getMessage());
    map.put(LEVEL, event.getLevel().toString());
    map.put(LOGGER_NAME, event.getLoggerName());
    map.put(THREAD_NAME, event.getThreadName());
    map.put(LOG_TIME, new Date(event.getTimeStamp()));
    return map;
}

From source file:org.eclipse.sirius.table.business.internal.metamodel.operations.DColumnOperations.java

/**
 * Sort the column cells considering their index and return them.
 *
 * @param column/*from www .  j  av a  2s  .  co  m*/
 *            column.
 * @return a sorted set of cells.
 */
public static Collection<DCell> getOrderedCells(final DColumn column) {
    final Map<DLine, Integer> lineIndices = Maps.newHashMap();
    fillIndices(column.getTable(), lineIndices, 0);
    Ordering<DCell> ordering = Ordering.from(new Comparator<DCell>() {
        @Override
        public int compare(DCell a, DCell b) {
            int result = 0;
            DLine lineA = a.getLine();
            DLine lineB = b.getLine();
            if (lineA == null) {
                result = -1;
            } else if (lineB == null) {
                result = 1;
            } else {
                Integer aIndex = lineIndices.get(lineA);
                Integer bIndex = lineIndices.get(lineB);
                if (aIndex == null || bIndex == null) {
                    throw new RuntimeException(Messages.Table_UnexpectedExceptionMessage);
                }
                return aIndex - bIndex;
            }
            return result;
        }
    });
    List<DCell> result = ordering.sortedCopy(column.getCells());
    return result;
}

From source file:de.flapdoodle.mongoom.mapping.index.IndexParser.java

public static Map<String, EntityIndexDef> getIndexGroupMap(Class<?> entityClass) {
    Map<String, EntityIndexDef> map = Maps.newHashMap();
    IndexGroup[] indexGroups = getIndexGroups(entityClass);
    for (IndexGroup ig : indexGroups) {
        IndexOption options = ig.options();
        String name = ig.name();//from   w ww .  ja  v a2 s  .  c  o  m
        if (name.length() == 0)
            name = null;
        map.put(ig.group(), new EntityIndexDef(name, options.unique(), options.dropDups(), options.sparse()));
    }
    return map;
}

From source file:org.guicerecipes.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;
        }//  ww w  .  j  ava 2  s .  c  om

        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.atlasapi.output.rdf.BeanIntrospector.java

public static Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> beanType)
        throws IntrospectionException {
    Map<String, PropertyDescriptor> result = Maps.newHashMap();

    BeanIntrospector.getPropertiesInternal(beanType, "", result);

    return result;
}

From source file:org.apache.tajo.ws.rs.resources.outputs.RestOutputFactory.java

private static Map<String, String> load() {
    Map<String, String> outputClasses = Maps.newHashMap();
    Set<Class> restOutputClasses = ClassUtil.findClasses(AbstractStreamingOutput.class,
            "org.apache.tajo.ws.rs.resources.outputs");

    for (Class eachClass : restOutputClasses) {
        if (eachClass.isInterface() || Modifier.isAbstract(eachClass.getModifiers())) {
            continue;
        }/*from   w  w  w .j a va 2s .  c  o m*/

        AbstractStreamingOutput streamingOutput = null;
        try {
            streamingOutput = (AbstractStreamingOutput) eachClass
                    .getDeclaredConstructor(
                            new Class[] { NonForwardQueryResultScanner.class, Integer.class, Integer.class })
                    .newInstance(null, 0, 0);
        } catch (Exception e) {
            LOG.warn(eachClass + " cannot instantiate Function class because of " + e.getMessage(), e);
            continue;
        }
        String className = streamingOutput.getClass().getCanonicalName();
        String headerType = streamingOutput.getClass().getAnnotation(RestReturnType.class).mimeType();

        if (StringUtils.isNotEmpty(headerType)) {
            outputClasses.put(headerType, className);
        }
    }

    return outputClasses;
}

From source file:com.sk89q.worldguard.protection.flags.FlagUtil.java

/**
 * Marshal a value of flag values into a map of raw values.
 *
 * @param values The unmarshalled flag values map
 * @return The raw values map//from  w w w .j  a  v  a 2 s. c o m
 */
public static Map<String, Object> marshal(Map<Flag<?>, Object> values) {
    checkNotNull(values, "values");

    Map<String, Object> rawValues = Maps.newHashMap();
    for (Entry<Flag<?>, Object> entry : values.entrySet()) {
        try {
            rawValues.put(entry.getKey().getName(), marshal(entry.getKey(), entry.getValue()));
        } catch (Exception e) {
            log.log(Level.WARNING,
                    "Failed to marshal flag value for " + entry.getKey() + "; value is " + entry.getValue(), e);
        }
    }

    return rawValues;
}