List of usage examples for com.google.common.collect Maps newLinkedHashMap
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap()
From source file:org.pshdl.model.types.builtIn.busses.BusGenSideFiles.java
private static AuxiliaryContent wrapperFile(HDLUnit unit, String unitName, String dirName, String version, int regCount, int memCount, String type, String rootDir, boolean withDate) { final String wrapperName = unitName + WRAPPER_APPENDIX; final String relPath = dirName + "/hdl/vhdl/" + wrapperName + ".vhd"; final Map<String, String> options = Maps.newLinkedHashMap(); options.put("{NAME}", unitName); options.put("{DIRNAME}", dirName); options.put("{WRAPPERNAME}", wrapperName); options.put("{VERSION}", version.replaceAll("_", ".")); if (withDate) { options.put("{DATE}", new Date().toString()); }/* ww w . j a v a 2 s . c o m*/ options.put("{REGCOUNT}", Integer.toString(regCount)); final StringBuilder memGenerics = new StringBuilder(); // {MEM_GENERICS} final StringBuilder memArray = new StringBuilder(); // {MEM_ARRAY} final StringBuilder memCes = new StringBuilder(); // {MEM_CES} for (int i = 0; i < memCount; i++) { memGenerics.append( " C_MEM" + i + "_BASEADDR : std_logic_vector := X\"FFFFFFFF\";\n"); memGenerics .append(" C_MEM" + i + "_HIGHADDR : std_logic_vector := X\"00000000\";"); memArray.append(" ,ZERO_ADDR_PAD & C_MEM" + i + "_BASEADDR -- user logic memory space " + i + " base address\n"); memArray.append(" ,ZERO_ADDR_PAD & C_MEM" + i + "_HIGHADDR -- user logic memory space " + i + " high address\n"); memCes.append(",").append(i + 1).append(" => 1\n"); } options.put("{MEM_GENERICS}", memGenerics.toString()); options.put("{MEM_ARRAY}", memArray.toString()); options.put("{MEM_CES}", memCes.toString()); String memPortMap; if (memCount > 0) { memPortMap = " Bus2IP_Addr => ipif_Bus2IP_Addr,\n" + // "Bus2IP_CS => ipif_Bus2IP_CS(1 to " + memCount + "),\n" + // "Bus2IP_RNW => ipif_Bus2IP_RNW,"; } else { memPortMap = ""; } options.put("{MEM_PORTMAP}", memPortMap); final HDLInterface asInterface = unit.asInterface(); final StringBuilder generics = new StringBuilder(); final StringBuilder genericsMap = new StringBuilder(); final StringBuilder ports = new StringBuilder(); final StringBuilder portMap = new StringBuilder(); for (final HDLVariableDeclaration vhd : asInterface.getPorts()) { if (vhd.getAnnotation(HDLBuiltInAnnotationProvider.HDLBuiltInAnnotations.genSignal) != null) { continue; } StringBuilder targetMap = null; StringBuilder target = null; final HDLDirection direction = vhd.getDirection(); String dir = direction.toString(); switch (direction) { case PARAMETER: targetMap = genericsMap; target = generics; dir = ""; break; case IN: case OUT: targetMap = portMap; target = ports; break; default: continue; } for (final HDLVariable v : vhd.getVariables()) { target.append('\t').append(v.getName()).append("\t:\t").append(dir).append(" "); switch (vhd.getPrimitive().getType()) { case BIT: target.append("std_logic"); break; case BITVECTOR: target.append("std_logic_vector"); target.append("(").append(vhd.getPrimitive().getWidth()).append("-1 downto 0)"); break; case UINT: target.append("unsigned"); target.append("(").append(vhd.getPrimitive().getWidth()).append("-1 downto 0)"); break; case INT: target.append("signed"); target.append("(").append(vhd.getPrimitive().getWidth()).append("-1 downto 0)"); break; case NATURAL: target.append("NATURAL"); break; case INTEGER: target.append("INTEGER"); break; default: } if ((vhd.getDirection() == HDLDirection.PARAMETER) && (v.getDefaultValue() != null)) { target.append(":=").append(v.getDefaultValue()); } target.append(';'); targetMap.append('\t').append(v.getName()).append(" => ").append(v.getName()).append(",\n"); } } options.put("{PORTS}", ports.toString()); options.put("{PORTMAP}", portMap.toString()); options.put("{GENERICS}", generics.toString()); options.put("{GENERICSMAP}", genericsMap.toString()); try { return new AuxiliaryContent(rootDir + relPath, Helper.processFile(BusGenSideFiles.class, type + "_wrapper.vhd", options), true); } catch (final IOException e) { e.printStackTrace(); } return null; }
From source file:com.cinchapi.concourse.server.storage.db.PrimaryRecord.java
/** * Return a log of revisions to the field mapped from {@code key}. * /*ww w . j a va 2 s. co m*/ * @param key * @return the revision log */ public Map<Long, String> audit(Text key) { read.lock(); try { Map<Long, String> audit = Maps.newLinkedHashMap(); List<CompactRevision<Value>> revisions = history.get(key); /* Authorized */ if (revisions != null) { Iterator<CompactRevision<Value>> it = revisions.iterator(); while (it.hasNext()) { CompactRevision<Value> revision = it.next(); audit.put(revision.getVersion(), revision.toString(locator, key)); } } return audit; } finally { read.unlock(); } }
From source file:org.jclouds.ibmdev.xml.LocationHandler.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("ID")) { id = currentText.toString().trim(); } else if (qName.equalsIgnoreCase("Name")) { name = currentText.toString().trim(); } else if (qName.equalsIgnoreCase("Description")) { description = currentText.toString().trim(); if (description.equals("")) description = null;// w ww .j a v a2 s. c om } else if (qName.equalsIgnoreCase("Value")) { capabilities.get(capabilityName).put(capabilityKey, currentText.toString().trim()); } else if (qName.equalsIgnoreCase("Location")) { if (currentText.toString().trim().equals("")) { this.loc = new Location(id, name, description, location, capabilities); id = null; name = null; description = null; location = null; capabilities = Maps.newLinkedHashMap(); capabilityKey = null; capabilityName = null; } else { location = currentText.toString().trim(); } } currentText = new StringBuilder(); }
From source file:com.google.api.tools.framework.aspects.http.RestAnalyzer.java
/** * Finalizes rest analysis, delivering the collections used. *///from w ww. j a v a2s . c om List<CollectionAttribute> finalizeAndGetCollections() { // Compute the resource types for each collection. We need to have all collections fully // built before this can be done. // // In the first pass, we walk over all messages and collect information from the // resource attribute as derived from a doc instruction. In the second pass, for those // collections which still have no resource, we run a heuristic to identify the resource. Map<String, TypeRef> definedResources = Maps.newLinkedHashMap(); for (TypeRef type : aspect.getModel().getSymbolTable().getDeclaredTypes()) { if (!type.isMessage()) { continue; } MessageType message = type.getMessageType(); List<ResourceAttribute> definitions = message.getAttribute(ResourceAttribute.KEY); if (definitions != null) { for (ResourceAttribute definition : definitions) { definedResources.put(definition.collection(), type); } } } ImmutableList.Builder<CollectionAttribute> result = ImmutableList.builder(); for (CollectionAttribute collection : collectionMap.values()) { TypeRef type = definedResources.get(collection.getFullName()); if (type == null) { // No defined resource association, run heuristics. type = new ResourceTypeSelector(aspect.getModel(), collection.getMethods()) .getCandiateResourceType(); } collection.setResourceType(type); result.add(collection); } return result.build(); }
From source file:org.jclouds.ohai.functions.NestSlashKeys.java
private Map<String, JsonBall> mergeSameKeys(Multimap<String, Supplier<JsonBall>> from) { Map<String, JsonBall> merged = Maps.newLinkedHashMap(); for (Entry<String, Supplier<JsonBall>> entry : from.entries()) { if (merged.containsKey(entry.getKey())) { mergeAsPeer(entry.getKey(), entry.getValue().get(), merged); } else {/*from w w w. j a v a 2s.c o m*/ merged.put(entry.getKey(), entry.getValue().get()); } } return merged; }
From source file:cc.kave.episodes.statistics.EpisodesStatistics.java
private Map<Double, Integer> initBd(Set<Episode> episodes, int freqThresh) { Map<Double, Integer> initializer = Maps.newLinkedHashMap(); for (Episode ep : episodes) { int epFreq = ep.getFrequency(); if (epFreq < freqThresh) { continue; }//from ww w . java 2 s. c o m double bd = ep.getBidirectMeasure(); double reoundBd = Precision.round(bd, ROUNDVALUE); if (!initializer.containsKey(reoundBd)) { initializer.put(reoundBd, 0); } } return initializer; }
From source file:org.gradle.model.dsl.internal.transform.ClosureBackedRuleFactory.java
public <T> DeferredModelAction toAction(final Class<T> subjectType, final Closure<?> closure) { final TransformedClosure transformedClosure = (TransformedClosure) closure; SourceLocation sourceLocation = ruleLocationExtractor.transform(transformedClosure); final ModelRuleDescriptor descriptor = sourceLocation.asDescriptor(); return new DeferredModelAction() { @Override//from w w w. j av a 2 s. c om public ModelRuleDescriptor getDescriptor() { return descriptor; } @Override public void execute(MutableModelNode node, ModelActionRole role) { final boolean supportsNestedRules = node.canBeViewedAs(MANAGED_INSTANCE_TYPE); InputReferences inputs = transformedClosure.inputReferences(); List<InputReference> inputReferences = supportsNestedRules ? inputs.getOwnReferences() : inputs.getAllReferences(); final Map<String, PotentialInput> inputValues = Maps.newLinkedHashMap(); List<ModelReference<?>> inputModelReferences = Lists.newArrayList(); for (InputReference inputReference : inputReferences) { String description = String.format("@ line %d", inputReference.getLineNumber()); String path = inputReference.getPath(); if (!inputValues.containsKey(path)) { inputValues.put(path, new PotentialInput(inputModelReferences.size())); inputModelReferences.add(ModelReference.untyped(ModelPath.path(path), description)); } } node.applyToSelf(role, InputUsingModelAction.of(ModelReference.of(node.getPath(), subjectType), descriptor, inputModelReferences, new BiAction<T, List<ModelView<?>>>() { @Override public void execute(T t, List<ModelView<?>> modelViews) { // Make a copy of the closure, attach inputs and execute Closure<?> cloned = closure.rehydrate(null, closure.getThisObject(), closure.getThisObject()); ((TransformedClosure) cloned).makeRule(new PotentialInputs(modelViews, inputValues), supportsNestedRules ? ClosureBackedRuleFactory.this : null); ClosureBackedAction.execute(t, cloned); } })); } }; }
From source file:brooklyn.networking.AttributeMunger.java
public void transformSensorStringReplacingWithPublicAddressAndPort( final EntityAndAttribute<String> targetToUpdate, final Optional<EntityAndAttribute<Integer>> optionalTargetPort, final Iterable<? extends AttributeSensor<String>> targetsToMatch, final EntityAndAttribute<String> replacementSource) { SensorPropagaterWithReplacement mapper = new SensorPropagaterWithReplacement(targetToUpdate, false, new Function<String, String>() { @Override//from www . j a va2 s. c o m public String apply(String sensorVal) { if (sensorVal == null) return null; String input = targetToUpdate.get(); String replacementText = replacementSource.get(); log.debug("sensor mapper transforming address in " + targetToUpdate + ", with " + replacementText + " (old value is " + input + ")"); String suffix = ""; if (optionalTargetPort.isPresent()) { Integer port = optionalTargetPort.get().get(); if (port == null) { log.warn("no map-from port available for sensor mapper replacing addresses in " + targetToUpdate + " (listening on " + optionalTargetPort + ")"); return input; } suffix = ":" + port; } Map<AttributeSensor<String>, String> targetValsToMatch = Maps.newLinkedHashMap(); for (AttributeSensor<String> targetToMatch : targetsToMatch) { targetValsToMatch.put(targetToMatch, targetToUpdate.getEntity().getAttribute(targetToMatch)); } String output = input; for (String targetValToMatch : targetValsToMatch.values()) { output = replaceIfNotNull(output, targetValToMatch + suffix, replacementText); } log.debug("sensor mapper transforming address in " + targetToUpdate + ": " + "input=" + input + "; output=" + output + "; suffix=" + suffix + "; replacementSource=" + replacementSource + "; replacementText=" + replacementText + "; targetValsToMatch=" + targetValsToMatch); return output; } }); // TODO Should we subscribe to each of targetsToMatch? // And should we subscribe to optionalTargetPort? for (AttributeSensor<String> targetToMatch : targetsToMatch) { subscribe(targetToUpdate.getEntity(), targetToMatch, mapper); } subscribe(targetToUpdate.getEntity(), targetToUpdate.getAttribute(), mapper); subscribe(replacementSource.getEntity(), replacementSource.getAttribute(), mapper); // assume hostname and port are set before the above subscription String newval = mapper.apply(targetToUpdate.get()); if (newval != null) { setAttributeIfChanged(targetToUpdate, newval); } }
From source file:org.jclouds.googlecloudstorage.domain.templates.ObjectTemplate.java
public ObjectTemplate customMetadata(String key, String value) { if (this.metadata == null) { this.metadata = Maps.newLinkedHashMap(); }/* w ww . ja va2 s . co m*/ this.metadata.put(key, value); return this; }
From source file:nl.knaw.huygens.facetedsearch.ElaborateSearchParameters.java
@JsonIgnore public Map<String, String> getTextFieldsToSearch() { Map<String, String> map = Maps.newLinkedHashMap(); String textlayerPrefix = isCaseSensitive() ? SolrFields.TEXTLAYERCS_PREFIX : SolrFields.TEXTLAYER_PREFIX; String annotationPrefix = isCaseSensitive() ? SolrFields.ANNOTATIONCS_PREFIX : SolrFields.ANNOTATION_PREFIX; for (String textLayer : textLayers) { String fieldname = SolrUtils.normalize(textLayer); if (getSearchInTranscriptions()) { map.put(textlayerPrefix + fieldname, textLayer); }// w w w .j av a2 s . c o m if (getSearchInAnnotations()) { map.put(annotationPrefix + fieldname, textLayer + " annotations"); } } return map; }