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:com.cloudera.kitten.appmaster.util.HDFSFileFinder.java

public static Map<String, Long> getNumBytesOfGlobHeldByDatanodes(Path p, Configuration conf)
        throws IOException {
    FileSystem fs = p.getFileSystem(conf);

    HashMap<String, Long> bytesHeld = Maps.newHashMap();
    for (FileStatus f : fs.globStatus(p)) {
        BlockLocation[] bls = fs.getFileBlockLocations(p, 0, f.getLen());
        if (bls.length > 0) {
            for (BlockLocation bl : bls) {
                long l = bl.getLength();
                for (String name : bl.getNames()) {
                    if (bytesHeld.containsKey(name))
                        bytesHeld.put(name, bytesHeld.get(name) + l);
                    else
                        bytesHeld.put(name, l);
                }// ww w .j a v a2 s.co m
            }
        }
    }

    return bytesHeld;
}

From source file:com.example.helloworld.dao.PolicyDAO.java

public Collection<Policy> findPoliciesByContactId(Long contactId) {
    Map<Long, Policy> result = Maps.newHashMap();
    for (JoinRow row : runFindPoliciesByContactIdQuery(contactId)) {
        if (!result.containsKey(row.getId())) {
            result.put(row.getId(), new Policy(row.getId(), row.getExternalPolicyId(), row.getContactId(),
                    row.getProductDescription()));
        }//from w  w w .  ja v  a  2  s  . c o m
        result.get(row.getId()).addCover(row.getCoverDescription());
    }

    return result.values();
}

From source file:com.thinker.arch.platform.common.maintain.editor.web.controller.utils.OnlineEditorUtils.java

public static Map<Object, Object> extractFileInfoMap(File currentFile, String rootPath)
        throws UnsupportedEncodingException {
    Map<Object, Object> info = Maps.newHashMap();
    String name = currentFile.getName();
    info.put("name", name);
    info.put("path",
            URLEncoder.encode(currentFile.getAbsolutePath().replace(rootPath, ""), Constants.ENCODING));
    info.put("canEdit", canEdit(name));
    info.put("hasParent", !currentFile.getPath().equals(rootPath));
    info.put("isParent", hasSubFiles(currentFile));
    info.put("isDirectory", currentFile.isDirectory());
    info.put("root", info.get("path").equals(""));
    info.put("open", info.get("path").equals(""));
    info.put("iconSkin", currentFile.isDirectory() ? CSS_DIRECTORY : CSS_FILE);
    info.put("size", currentFile.length());
    Date modifiedDate = new Date(currentFile.lastModified());
    info.put("lastModified", DateFormatUtils.format(modifiedDate, DATE_PATTERN));
    info.put("lastModifiedForLong", currentFile.lastModified());
    return info;//w  w  w.j  a v a  2 s  .  c  o m
}

From source file:com.netflix.suro.routing.FilterTestUtil.java

public static MessageContainer makeMessageContainer(String routingKey, String path, Object value)
        throws Exception {
    MessageContainer container = mock(MessageContainer.class);
    when(container.getRoutingKey()).thenReturn(routingKey);

    if (path == null) {
        return container;
    }/*from w  w  w .j ava  2s .c  om*/
    List<String> steps = Lists.newArrayList(PATH_SPLITTER.split(path));
    Map<String, Object> map = Maps.newHashMap();
    Map<String, Object> current = map;

    for (int i = 0; i < steps.size() - 1; i++) {
        String step = steps.get(i);
        Map<String, Object> obj = Maps.newHashMap();
        current.put(step, obj);
        current = obj;
    }
    current.put(steps.get(steps.size() - 1), value);

    when(container.getEntity(Map.class)).thenReturn(map);

    return container;
}

From source file:domainapp.integtests.bootstrap.DomainAppSystemInitializer.java

public static void initIsft() {
    IsisSystemForTest isft = IsisSystemForTest.getElseNull();
    if(isft == null) {
        isft = new IsisSystemForTest.Builder()
                .withLoggingAt(org.apache.log4j.Level.INFO)
                .with(new DomainAppAppManifest() {
                    @Override//from ww  w.ja v a 2s  .  c o m
                    public Map<String, String> getConfigurationProperties() {
                        final Map<String, String> map = Maps.newHashMap();
                        Util.withJavaxJdoRunInMemoryProperties(map);
                        Util.withDataNucleusProperties(map);
                        Util.withIsisIntegTestProperties(map);
                        return map;
                    }
                })
                .build();
        isft.setUpSystem();
        IsisSystemForTest.set(isft);
    }
}

From source file:com.framework.demo.service.push.PushApiImpl.java

public void pushUnreadMessage(final Long userId, Long unreadMessageCount) {
    Map<String, Object> data = Maps.newHashMap();
    data.put("unreadMessageCount", unreadMessageCount);
    pushService.push(userId, data);/*from w w w . ja  v a2  s.  c o m*/
}

From source file:org.apache.flume.instrumentation.util.JMXPollUtil.java

public static Map<String, Map<String, String>> getAllMBeans() {
    Map<String, Map<String, String>> mbeanMap = Maps.newHashMap();
    Set<ObjectInstance> queryMBeans = null;
    try {//  w  w  w  . jav  a  2 s .  c o m
        queryMBeans = mbeanServer.queryMBeans(null, null);
    } catch (Exception ex) {
        LOG.error("Could not get Mbeans for monitoring", ex);
        Throwables.propagate(ex);
    }
    for (ObjectInstance obj : queryMBeans) {
        try {
            if (!obj.getObjectName().toString().startsWith("org.apache.flume")) {
                continue;
            }
            MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes();
            String strAtts[] = new String[attrs.length];
            for (int i = 0; i < strAtts.length; i++) {
                strAtts[i] = attrs[i].getName();
            }
            AttributeList attrList = mbeanServer.getAttributes(obj.getObjectName(), strAtts);
            String component = obj.getObjectName().toString()
                    .substring(obj.getObjectName().toString().indexOf('=') + 1);
            Map<String, String> attrMap = Maps.newHashMap();

            for (Object attr : attrList) {
                Attribute localAttr = (Attribute) attr;
                if (localAttr.getName().equalsIgnoreCase("type")) {
                    component = localAttr.getValue() + "." + component;
                }
                attrMap.put(localAttr.getName(), localAttr.getValue().toString());
            }
            mbeanMap.put(component, attrMap);
        } catch (Exception e) {
            LOG.error("Unable to poll JMX for metrics.", e);
        }
    }
    return mbeanMap;
}

From source file:co.cask.cdap.api.common.RuntimeArguments.java

/**
 * Converts a POSIX compliant program argument array to a String-to-String Map.
 * @param args Array of Strings where each element is a POSIX compliant program argument (Ex: "--os=Linux" ).
 * @return Map of argument Keys and Values (Ex: Key = "os" and Value = "Linux").
 *//*from  w w  w  .  ja  v  a2  s  .c  o m*/
public static Map<String, String> fromPosixArray(String[] args) {
    Map<String, String> kvMap = Maps.newHashMap();
    for (String arg : args) {
        kvMap.putAll(Splitter.on("--").omitEmptyStrings().trimResults().withKeyValueSeparator("=").split(arg));
    }
    return kvMap;
}

From source file:org.obiba.mica.micaConfig.domain.ProjectConfig.java

public Map<String, LocalizedString> getProperties() {
    return properties == null ? properties = Maps.newHashMap() : properties;
}

From source file:org.napile.compiler.lang.types.SubstitutionUtils.java

/**
 * Builds a context with all the supertypes' parameters substituted
 *//*from   w  w  w  .  ja v a  2 s .c o  m*/
@NotNull
public static TypeSubstitutor buildDeepSubstitutor(@NotNull NapileType type) {
    Map<TypeConstructor, NapileType> substitution = Maps.newHashMap();
    TypeSubstitutor typeSubstitutor = TypeSubstitutor.create(substitution);
    // we use the mutability of the map here
    fillInDeepSubstitutor(type, typeSubstitutor, substitution, null);
    return typeSubstitutor;
}