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:presto.android.gui.JimpleUtil.java

public static JimpleUtil v(Hierarchy hier) {
    if (instance == null) {
        instance = new JimpleUtil();
        instance.s2m = Maps.newHashMap();
        instance.exprToStmt = Maps.newHashMap();
        instance.hier = hier;/*from w  w w.j a va 2s  .  co  m*/
    }
    return instance;
}

From source file:org.apache.kylin.cube.gridtable.CubeGridTable.java

public static Map<TblColRef, Dictionary<String>> getDimensionToDictionaryMap(CubeSegment cubeSeg,
        long cuboidId) {
    CubeDesc cubeDesc = cubeSeg.getCubeDesc();
    CubeManager cubeMgr = CubeManager.getInstance(cubeSeg.getCubeInstance().getConfig());

    // build a dictionary map
    Map<TblColRef, Dictionary<String>> dictionaryMap = Maps.newHashMap();
    List<TblColRef> dimCols = Cuboid.findById(cubeDesc, cuboidId).getColumns();
    for (TblColRef col : dimCols) {
        Dictionary<String> dictionary = cubeMgr.getDictionary(cubeSeg, col);
        if (dictionary != null) {
            dictionaryMap.put(col, dictionary);
        }//from   w ww  .  j  a  v  a  2 s  .c  o m
    }

    return dictionaryMap;
}

From source file:com.dotweblabs.friendscube.rest.guice.GuiceServletModule.java

private static Map<String, String> map(String... params) {
    Preconditions.checkArgument(params.length % 2 == 0, "You have to have a n even number of map params");
    Map<String, String> map = Maps.newHashMap();
    for (int i = 0; i < params.length; i += 2) {
        map.put(params[i], params[i + 1]);
    }//  w  w w.  j a  va  2s .  c om
    return map;
}

From source file:com.palantir.common.collect.Maps2.java

public static <K, V> Map<K, V> createConstantValueMap(Iterable<K> keys, V v) {
    Map<K, V> ret = Maps.newHashMap();
    for (K k : keys) {
        ret.put(k, v);//  www.  j a v  a  2s  . co  m
    }
    return ret;
}

From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java

/**
 * Set environment variable "kafkaServer" to the host and port specified by
 * docker// w w w.j a  v  a 2  s  . c  o  m
 */
public static void setKafkaEnvironment(DockerComposeRule docker) {
    DockerPort kafka = docker.containers().container("kafka").port(9092);
    Map<String, String> newEnv = Maps.newHashMap();
    newEnv.put(ServiceProperties.KAFKA_SERVER_KEY, kafka.inFormat("$HOST:$EXTERNAL_PORT"));
    newEnv.putAll(System.getenv());
    setEnv(newEnv);
}

From source file:com.fanmei.pay4j.util.ConvertUtil.java

public static Map<String, String> convert2Map(@Nonnull Map<String, String[]> sourceMap) {
    Map<String, String> params = Maps.newHashMap();
    for (Map.Entry<String, String[]> entry : sourceMap.entrySet()) {
        String key = entry.getKey();
        List<String> values = Arrays.asList(entry.getValue());
        if (values == null || values.isEmpty()) {
            continue;
        }/* ww  w  .  j a  v a 2s.  c om*/
        params.put(key, Joiner.on(",").join(values));
    }
    return params;
}

From source file:at.molindo.notify.model.Message.java

public static Message parse(String str, IRenderService.Type type) throws RenderException {

    Set<String> required = Sets.newHashSet(REQUIRED_FIELDS);
    Map<String, String> fieldValues = Maps.newHashMap();

    Message rendered = new Message();
    rendered.setType(type);/*ww w . ja v a 2s . c o m*/

    StringBuilder body = null;
    for (String line : StringUtils.split(str, "\n")) {
        if (body == null) {
            if (StringUtils.empty(StringUtils.trim(line))) {
                body = new StringBuilder();
            } else {
                int split = line.indexOf(':');
                if (split < 0) {
                    throw new RenderException("illegal line: " + line);
                }
                String fieldName = line.substring(0, split).trim();
                String fieldValue = line.substring(split + 1).trim();

                if (!SUPPORTED_FIELDS.contains(fieldName)) {
                    throw new RenderException("unknown field: " + fieldName);
                }

                fieldValues.put(fieldName, fieldValue);
            }
        } else if (body.length() > 0 || !StringUtils.empty(StringUtils.trim(line))) {
            body.append(line).append("\n");
        }
    }

    required.removeAll(fieldValues.keySet());
    if (required.size() > 0) {
        throw new RenderException("missing fields: " + required);
    }

    if (body == null || body.length() == 0) {
        throw new RenderException("empty body");
    }
    // remove trailing \n
    body.setLength(body.length() - 1);

    rendered.setSubject(fieldValues.get(FIELD_SUBJECT));
    rendered.setMessage(body.toString());

    return rendered;
}

From source file:com.shz.foundation.service.dynamic.SearchFilter.java

/**
 * searchParamskey?OPERATOR_FIELDNAME/*  w ww  .  j ava 2 s.  co  m*/
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = names[1];
        Operator operator = Operator.fromString(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:org.apache.gobblin.util.DownloadUtils.java

/**
 * Download jar through {@link Grape} given an org, module and version
 * It is assumed that an ivy settings file exists on the classpath
 *//*  www.  j  a v  a  2 s.c  o  m*/
public static URI[] downloadJar(String org, String module, String version, boolean transitive)
        throws IOException {
    Map<String, Object> artifactMap = Maps.newHashMap();
    artifactMap.put("org", org);
    artifactMap.put("module", module);
    artifactMap.put("version", version);
    artifactMap.put("transitive", transitive);
    return downloadJar(artifactMap);
}

From source file:com.jyzn.wifi.validate.platforminterface.SmsInterfaceImpl.java

@Override
public Map HttpSendSms(String postUrl, String postData) {
    String result = "";
    Map resultMap = Maps.newHashMap();
    try {//from w  w  w  . j ava 2s  . c  om
        //??POST
        URL url = new URL(postUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setUseCaches(false);
        conn.setDoOutput(true);
        conn.setRequestProperty("Content-Length", "" + postData.length());

        try {
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            out.write(postData);
            out.flush();//?
        } catch (IOException e) {
        }

        //???
        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            System.out.println("connect failed!");
            resultMap.put("status", "fail");
            //return "fail";
        }

        //??
        String line;
        try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
            while ((line = in.readLine()) != null) {
                result += line + "\n";
            }
        }
        resultMap.put("status", "sucess");
        resultMap.put("result", result);
    } catch (IOException e) {
        e.printStackTrace(System.out);
    }
    return resultMap;
}