List of usage examples for com.google.common.collect Maps newHashMap
public static <K, V> HashMap<K, V> newHashMap()
From source file:edu.byu.nlp.al.simulation.GoldLabelProvider.java
public static GoldLabelProvider<SparseFeatureVector, Integer> from(Dataset dataset) { Map<String, Integer> goldLabels = Maps.newHashMap(); for (DatasetInstance inst : dataset) { goldLabels.put(inst.getInfo().getRawSource(), inst.getLabel()); }//from w w w . ja va2s .co m return new GoldLabelProvider<SparseFeatureVector, Integer>(goldLabels); }
From source file:com.opentable.config.ConfigMagicDynamicMBean.java
private static Map<String, Object> toMap(Object configBean) { PropertyDescriptor[] props = ReflectUtils.getBeanGetters(configBean.getClass()); Map<String, Object> result = Maps.newHashMap(); for (PropertyDescriptor prop : props) { if (CONFIG_MAGIC_CALLBACKS_NAME.equals(prop.getName())) { continue; }//w w w. j a va 2 s .c o m try { result.put(prop.getName(), ObjectUtils.toString(prop.getReadMethod().invoke(configBean), null)); } catch (Exception e) { LOG.error(String.format("For class %s, unable to find config property %s", configBean.getClass(), prop), e); } } return result; }
From source file:org.sakaiproject.kernel.util.MapUtils.java
/** * Converts a name value string delimited with = and ; into an immutable map. * * @param values// w ww . j a va 2 s . c om * the contents of the map * @return an immutable map. */ public static Map<String, String> convertToImmutableMap(String values) { Map<String, String> m = Maps.newHashMap(); String[] templates = StringUtils.split(values, ';'); if (templates != null) { for (String template : templates) { String[] nv = StringUtils.split(template, "=", 2); m.put(nv[0].trim(), nv[1].trim()); } } return ImmutableMap.copyOf(m); }
From source file:edu.byu.nlp.al.simulation.DatasetGoldLabelProvider.java
public static DatasetGoldLabelProvider<SparseFeatureVector, Integer> from(Dataset dataset) { Map<String, Integer> goldLabels = Maps.newHashMap(); for (DatasetInstance inst : dataset) { goldLabels.put(inst.getInfo().getRawSource(), inst.getLabel()); }/*from w w w . j a v a 2 s . c o m*/ return new DatasetGoldLabelProvider<SparseFeatureVector, Integer>(goldLabels); }
From source file:org.apache.shindig.social.opensocial.jpa.spi.SPIUtils.java
/** * @param userIds/*from w w w . ja v a 2 s . co m*/ * @param token * @return */ public static List<String> getUserList(Set<UserId> userIds, SecurityToken token) { // TODO What's the use of userIdMap? HashMap<String, String> userIdMap = Maps.newHashMap(); List<String> paramList = Lists.newArrayList(); for (UserId u : userIds) { try { String uid = u.getUserId(token); if (uid != null) { userIdMap.put(uid, uid); paramList.add(uid); } } catch (IllegalStateException istate) { // ignore the user id. } } return paramList; }
From source file:org.apache.bookkeeper.mledger.offload.OffloadUtils.java
public static Map<String, String> getOffloadDriverMetadata(LedgerInfo ledgerInfo) { Map<String, String> metadata = Maps.newHashMap(); if (ledgerInfo.hasOffloadContext()) { OffloadContext ctx = ledgerInfo.getOffloadContext(); if (ctx.hasDriverMetadata()) { OffloadDriverMetadata driverMetadata = ctx.getDriverMetadata(); if (driverMetadata.getPropertiesCount() > 0) { driverMetadata.getPropertiesList().forEach(kv -> metadata.put(kv.getKey(), kv.getValue())); }/* ww w .j a v a 2 s . co m*/ } } return metadata; }
From source file:com.turn.sorcerer.util.TypedDictionary.java
public TypedDictionary() { map = Maps.newHashMap(); }
From source file:org.mayocat.addons.store.dbi.AddonsHelper.java
public static <T extends Identifiable & HasAddons> List<T> withAddons(List<T> entities, AddonsDAO dao) { Collection<UUID> ids = Collections2.transform(entities, new Function<T, UUID>() { @Override/* w w w . ja v a 2 s . c o m*/ public UUID apply(final T entity) { return entity.getId(); } }); if (ids.size() <= 0) { return entities; } List<AddonGroup> addons = dao.findAllAddonsForIds(new ArrayList(ids)); Map<UUID, List<AddonGroup>> addonsForEntity = Maps.newHashMap(); for (AddonGroup addon : addons) { if (!addonsForEntity.containsKey(addon.getEntityId())) { addonsForEntity.put(addon.getEntityId(), new ArrayList<AddonGroup>()); } addonsForEntity.get(addon.getEntityId()).add(addon); } for (T entity : entities) { if (addonsForEntity.containsKey(entity.getId())) { entity.setAddons(asMap(addonsForEntity.get(entity.getId()))); } } return entities; }
From source file:org.apache.isis.security.shiro.util.Util.java
public static Map<String, List<String>> parse(String permissionsByRoleStr) { Map<String, List<String>> perms = Maps.newHashMap(); for (String roleAndPermsStr : Splitter.on(";").split(permissionsByRoleStr)) { final Iterable<String> split = Splitter.on("=").split(roleAndPermsStr); final String[] roleAndPerms = Iterables.toArray(split, String.class); if (roleAndPerms.length != 2) { continue; }/*ww w . ja va 2s. c o m*/ final String role = roleAndPerms[0].trim(); final String permStr = roleAndPerms[1].trim(); perms.put(role, Lists.newArrayList(Iterables.transform(Splitter.on(",").split(permStr), TRIM))); } return perms; }
From source file:com.palantir.atlasdb.keyvalue.partition.util.RowResultUtil.java
public static Map<Cell, Value> getNewestValue(RowResult<Value> row) { Map<Cell, Value> result = Maps.newHashMap(); for (Map.Entry<Cell, Value> e : row.getCells()) { final Cell cell = e.getKey(); final Value val = e.getValue(); if (!result.containsKey(cell) || result.get(cell).getTimestamp() < val.getTimestamp()) { result.put(cell, val); }//from www. ja va 2 s . c om } return result; }