List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize)
From source file:com.thinkbiganalytics.feedmgr.service.UserPropertyTransform.java
/** * Transforms the specified Metadata user-defined properties to Feed Manager user-defined properties. * * @param properties map of property names to values * @param userFields the user-defined field descriptors * @return the set of Feed Manager user-defined properties *///from www.j av a2s.c o m @Nonnull @SafeVarargs public static Set<UserProperty> toUserProperties(@Nonnull final Map<String, String> properties, @Nonnull final Set<UserFieldDescriptor>... userFields) { // Map field names and order int order = 0; int size = Arrays.stream(userFields).collect(Collectors.summingInt(Set::size)); final Map<String, UserFieldDescriptor> userFieldMap = Maps.newHashMapWithExpectedSize(size); final Map<String, Integer> userFieldOrder = Maps.newHashMapWithExpectedSize(size); for (final Set<UserFieldDescriptor> set : userFields) { final Iterator<UserFieldDescriptor> sorted = set.stream() .sorted((f1, f2) -> Integer.compare(f1.getOrder(), f2.getOrder())).iterator(); while (sorted.hasNext()) { final UserFieldDescriptor field = sorted.next(); if (!userFieldMap.containsKey(field.getSystemName())) { userFieldMap.put(field.getSystemName(), field); userFieldOrder.put(field.getSystemName(), order++); } } } // Convert from Metadata to Feed Manager format final Stream<UserProperty> newProperties = userFieldMap.values().stream() .filter(field -> !properties.containsKey(field.getSystemName())).map(field -> { final UserProperty property = new UserProperty(); property.setDescription(field.getDescription()); property.setDisplayName(field.getDisplayName()); property.setLocked(true); property.setOrder(userFieldOrder.get(field.getSystemName())); property.setRequired(field.isRequired()); property.setSystemName(field.getSystemName()); return property; }); final Stream<UserProperty> existingProperties = properties.entrySet().stream().map(entry -> { // Create the Feed Manager property final UserProperty property = new UserProperty(); property.setLocked(false); property.setSystemName(entry.getKey()); property.setValue(entry.getValue()); // Set additional Metadata attributes final UserFieldDescriptor field = userFieldMap.get(entry.getKey()); if (field != null) { property.setDescription(field.getDescription()); property.setDisplayName(field.getDisplayName()); property.setLocked(true); property.setOrder(userFieldOrder.get(entry.getKey())); property.setRequired(field.isRequired()); } // Return the Feed Manager property return property; }); return Stream.concat(newProperties, existingProperties) .collect(Collectors.toCollection(LinkedHashSet::new)); }
From source file:org.gradoop.flink.algorithms.fsm.transactional.tle.functions.ToFSMGraph.java
/** * Transforms a graph's vertices./*from ww w . j a va 2 s.c o m*/ * * @param graph graph * @param vertexIdMap mapping of Gradoop ids to integers * @return vertices represented by a integer-label map */ protected Map<Integer, String> transformVertices(GraphTransaction graph, Map<GradoopId, Integer> vertexIdMap) { Map<Integer, String> fsmVertices = Maps.newHashMapWithExpectedSize(graph.getVertices().size()); int vertexId = 0; for (Vertex vertex : graph.getVertices()) { vertexIdMap.put(vertex.getId(), vertexId); fsmVertices.put(vertexId, vertex.getLabel()); vertexId++; } return fsmVertices; }
From source file:org.gradoop.flink.algorithms.fsm.transactional.tle.functions.ToCCSGraph.java
@Override public CCSGraph map(GraphTransaction graph) throws Exception { String category = graph.getGraphHead().getPropertyValue(CategoryCharacteristicSubgraphs.CATEGORY_KEY) .toString();//from w ww.j a v a2 s . c o m Map<GradoopId, Integer> vertexIdMap = Maps.newHashMapWithExpectedSize(graph.getVertices().size()); Map<Integer, String> fsmVertices = transformVertices(graph, vertexIdMap); Map<Integer, FSMEdge> fsmEdges = transformEdges(graph, vertexIdMap); return new CCSGraph(category, graph.getGraphHead().getId(), fsmVertices, fsmEdges); }
From source file:org.datacleaner.util.InputStreamToPropertiesMapFunc.java
@Override public Map<String, String> apply(final InputStream in) { final Properties properties = new Properties(); try {//from w ww . j a v a2 s. c o m properties.load(in); } catch (final IOException ex) { throw new RuntimeException(ex); } final HashMap<String, String> map = Maps.newHashMapWithExpectedSize(properties.size()); for (final Entry<?, ?> e : properties.entrySet()) { final String key = (String) e.getKey(); final String value = (String) e.getValue(); map.put(key, value); } return map; }
From source file:org.infoscoop.request.OAuth2Message.java
public OAuth2Message() { this.params = Maps.newHashMapWithExpectedSize(5); this.unparsedProperties = Maps.newHashMapWithExpectedSize(0); }
From source file:tachyon.master.rawtable.journal.UpdateMetadataEntry.java
@Override public Map<String, Object> getParameters() { Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(2); parameters.put("id", mId); parameters.put("metadata", mMetadata); return parameters; }
From source file:com.google.template.soy.data.internal.AugmentedParamStore.java
public AugmentedParamStore(@Nullable SoyRecord backingStore, int expectedKeys) { this.backingStore = backingStore; this.localStore = Maps.newHashMapWithExpectedSize(expectedKeys); }
From source file:com.opengamma.language.value.AvailableOutputsConverter.java
protected AvailableOutputsConverter() { conversion(TypeMap.ZERO_LOSS, AVAILABLE_OUTPUTS, MAP, new Action<AvailableOutputs, Map>() { @Override//from w w w . ja va 2s .c o m protected Map convert(final AvailableOutputs value) { final Set<AvailableOutput> outputs = value.getOutputs(); final Map<String, ValueProperties> map = Maps.newHashMapWithExpectedSize(outputs.size()); for (AvailableOutput output : outputs) { map.put(output.getValueName(), output.getProperties()); } return map; } }); }
From source file:tachyon.master.file.journal.InodeDirectoryIdGeneratorEntry.java
@Override public Map<String, Object> getParameters() { Map<String, Object> parameters = Maps.newHashMapWithExpectedSize(2); parameters.put("containerId", mContainerId); parameters.put("sequenceNumber", mSequenceNumber); return parameters; }
From source file:com.google.devtools.build.lib.skyframe.TreeArtifactValue.java
/** * Returns a TreeArtifactValue out of the given Artifact-relative path fragments * and their corresponding FileArtifactValues. *//* w w w .j a v a 2 s . c o m*/ static TreeArtifactValue create(Map<TreeFileArtifact, FileArtifactValue> childFileValues) { Map<String, Metadata> digestBuilder = Maps.newHashMapWithExpectedSize(childFileValues.size()); for (Map.Entry<TreeFileArtifact, FileArtifactValue> e : childFileValues.entrySet()) { digestBuilder.put(e.getKey().getParentRelativePath().getPathString(), new Metadata(e.getValue().getDigest())); } return new TreeArtifactValue(DigestUtils.fromMetadata(digestBuilder).getDigestBytesUnsafe(), ImmutableMap.copyOf(childFileValues)); }