List of usage examples for com.google.common.collect Maps newLinkedHashMap
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(Map<? extends K, ? extends V> map)
From source file:org.jclouds.blobstore.domain.internal.BlobBuilderImpl.java
@Override public BlobBuilder userMetadata(Map<String, String> userMetadata) { if (userMetadata != null) this.userMetadata = Maps.newLinkedHashMap(userMetadata); return this; }
From source file:org.jpmml.evaluator.OutputUtil.java
/** * Evaluates the {@link Output} element. * * @param predictions Map of {@link Evaluator#getTargetFields() target field} values. * * @return Map of {@link Evaluator#getTargetFields() target field} values together with {@link Evaluator#getOutputFields() output field} values. *//*from w w w. j a v a 2s .c o m*/ @SuppressWarnings(value = { "fallthrough" }) static public Map<FieldName, ?> evaluate(Map<FieldName, ?> predictions, ModelEvaluationContext context) { ModelEvaluator<?> modelEvaluator = context.getModelEvaluator(); Output output = modelEvaluator.getOutput(); if (output == null) { return predictions; } Map<FieldName, Object> result = Maps.newLinkedHashMap(predictions); List<OutputField> outputFields = output.getOutputFields(); outputFields: for (OutputField outputField : outputFields) { Map<FieldName, ?> segmentPredictions = predictions; String segmentId = outputField.getSegmentId(); if (segmentId != null) { MiningModelEvaluationContext miningModelContext = (MiningModelEvaluationContext) context; segmentPredictions = miningModelContext.getResult(segmentId); } // End if // "If there is no Segment matching segmentId or if the predicate of the matching Segment evaluated to false, then the result delivered by this OutputField is missing" if (segmentPredictions == null) { continue outputFields; } // "Attribute targetField is required in case the model has multiple target fields" FieldName targetField = outputField.getTargetField(); if (targetField == null) { targetField = modelEvaluator.getTargetField(); } Object value = null; ResultFeatureType resultFeature = getResultFeatureType(outputField); // Load the mining result switch (resultFeature) { case ENTITY_ID: { if (isSegmentId(segmentPredictions, outputField)) { break; } } // Falls through case PREDICTED_VALUE: case PREDICTED_DISPLAY_VALUE: case PROBABILITY: case RESIDUAL: case CLUSTER_ID: case AFFINITY: case ENTITY_AFFINITY: case CLUSTER_AFFINITY: case REASON_CODE: case RULE_VALUE: case ANTECEDENT: case CONSEQUENT: case RULE: case RULE_ID: case CONFIDENCE: case SUPPORT: case LIFT: case LEVERAGE: { if (!segmentPredictions.containsKey(targetField)) { throw new MissingFieldException(targetField, outputField); } // A target value could be either simple or complex values value = segmentPredictions.get(targetField); // If the target value is missing, then the result delivered by this OutputField is missing if (value == null) { continue outputFields; } } break; default: break; } // End switch // Perform the requested computation on the mining result switch (resultFeature) { case PREDICTED_VALUE: { value = getPredictedValue(value); } break; case PREDICTED_DISPLAY_VALUE: { Target target = modelEvaluator.getTarget(targetField); DataField dataField = modelEvaluator.getDataField(targetField); value = getPredictedDisplayValue(value, target, dataField); } break; case TRANSFORMED_VALUE: case DECISION: { if (segmentId != null) { throw new UnsupportedFeatureException(outputField); } Expression expression = outputField.getExpression(); if (expression == null) { throw new InvalidFeatureException(outputField); } value = FieldValueUtil.getValue(ExpressionUtil.evaluate(expression, context)); } break; case PROBABILITY: { value = getProbability(value, outputField); } break; case RESIDUAL: { FieldValue expectedValue = context.getField(targetField); if (expectedValue == null) { throw new MissingFieldException(targetField, outputField); } DataField dataField = modelEvaluator.getDataField(targetField); OpType opType = dataField.getOptype(); switch (opType) { case CONTINUOUS: value = getContinuousResidual(value, expectedValue); break; case CATEGORICAL: value = getCategoricalResidual(value, expectedValue); break; default: throw new UnsupportedFeatureException(dataField, opType); } } break; case ENTITY_ID: { // "Result feature entityId returns the id of the winning segment" if (isSegmentId(segmentPredictions, outputField)) { SegmentResultMap segmentResult = (SegmentResultMap) segmentPredictions; value = segmentResult.getId(); break; } value = getEntityId(value, outputField); } break; case CLUSTER_ID: { value = getClusterId(value); } break; case AFFINITY: case ENTITY_AFFINITY: { value = getAffinity(value, outputField); } break; case CLUSTER_AFFINITY: { value = getClusterAffinity(value); } break; case REASON_CODE: { value = getReasonCode(value, outputField); } break; case RULE_VALUE: { value = getRuleValue(value, outputField); } break; case ANTECEDENT: { value = getRuleValue(value, outputField, RuleFeatureType.ANTECEDENT); } break; case CONSEQUENT: { value = getRuleValue(value, outputField, RuleFeatureType.CONSEQUENT); } break; case RULE: { value = getRuleValue(value, outputField, RuleFeatureType.RULE); } break; case RULE_ID: { value = getRuleValue(value, outputField, RuleFeatureType.RULE_ID); } break; case CONFIDENCE: { value = getRuleValue(value, outputField, RuleFeatureType.CONFIDENCE); } break; case SUPPORT: { value = getRuleValue(value, outputField, RuleFeatureType.SUPPORT); } break; case LIFT: { value = getRuleValue(value, outputField, RuleFeatureType.LIFT); } break; case LEVERAGE: { value = getRuleValue(value, outputField, RuleFeatureType.LEVERAGE); } break; case WARNING: { value = context.getWarnings(); } break; default: throw new UnsupportedFeatureException(outputField, resultFeature); } // The result of one output field becomes available to other other output fields context.declare(outputField.getName(), FieldValueUtil.create(outputField, value)); result.put(outputField.getName(), value); } return result; }
From source file:oculus.aperture.icons.IconResourceRequest.java
/** * Parses icon request parameters from the specified resource *//*from w w w .ja v a 2 s . com*/ public IconResourceRequest(Resource resource) { final Map<String, Object> typePath = resource.getRequest().getAttributes(); // now get the type specifier type = (String) typePath.get("type"); if (type == null) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Must specify an icon type"); } // start with a copy of attributes. attributes = Maps.newLinkedHashMap(resource.getQuery().getValuesMap()); // then remove the code attribute. code = attributes.remove("code"); // different default if code to show. if (code != null && !code.isEmpty()) { codeHeight = 9; } // then remove the raster attributes. final String scode = attributes.remove("codeHeight"); final String swidth = attributes.remove("iconWidth"); final String sheight = attributes.remove("iconHeight"); final String sformat = attributes.remove("iconFormat"); // parse any attributes which were supplied. if (scode != null) { try { codeHeight = Integer.parseInt(scode); } catch (Exception e) { } } if (swidth != null) { try { width = Integer.parseInt(swidth); } catch (Exception e) { } } if (sheight != null) { try { height = Integer.parseInt(sheight) - codeHeight; } catch (Exception e) { } } if (sformat != null) { try { format = ImageType.valueOf(sformat.toUpperCase()); } catch (Exception e) { } } }
From source file:org.apache.shindig.common.uri.Uri.java
Uri(UriBuilder builder) { scheme = builder.getScheme();/*from w w w . j a v a 2 s . c o m*/ authority = builder.getAuthority(); path = builder.getPath(); query = builder.getQuery(); fragment = builder.getFragment(); queryParameters = Collections.unmodifiableMap(Maps.newLinkedHashMap(builder.getQueryParameters())); fragmentParameters = Collections.unmodifiableMap(Maps.newLinkedHashMap(builder.getFragmentParameters())); StringBuilder out = new StringBuilder(); if (scheme != null) { out.append(scheme).append(':'); } if (authority != null) { out.append("//").append(authority); // insure that there's a separator between authority/path if (path != null && path.length() > 1 && !path.startsWith("/")) { out.append('/'); } } if (path != null) { out.append(path); } if (query != null) { out.append('?').append(query); } if (fragment != null) { out.append('#').append(fragment); } text = out.toString(); }
From source file:org.smartdeveloperhub.curator.connector.io.ConversionContext.java
public ConversionContext withNamespacePrefix(final String namespace, final String prefix) { Preconditions.checkNotNull(namespace, "Namespace cannot be null"); Preconditions.checkNotNull(prefix, "Prefix cannot be null"); final Map<String, String> newNamespacePrefixes = Maps.newLinkedHashMap(this.namespacePrefixes); newNamespacePrefixes.put(namespace, prefix); return new ConversionContext(this.base, newNamespacePrefixes); }
From source file:org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor.java
public TypeParameterSubstitutor(Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> typeParameterMapping, ITypeReferenceOwner owner) {//from www. j av a 2s. c o m this.owner = owner; this.typeParameterMapping = Maps.newLinkedHashMap(typeParameterMapping); }
From source file:io.norberg.h2client.benchmarks.ProgressMeter.java
public MetricGroup group(final String name) { MetricGroup group = groups.get(name); if (group == null) { synchronized (this) { group = groups.get(name);//w w w .j a va 2 s . c o m if (group == null) { final Map<String, MetricGroup> newGroups = Maps.newLinkedHashMap(groups); group = new MetricGroup(); newGroups.put(name, group); groups = unmodifiableMap(newGroups); } } } return group; }
From source file:com.android.builder.internal.testing.CustomTestRunListener.java
@Override protected Map<String, String> getPropertiesAttributes() { Map<String, String> propertiesAttributes = Maps.newLinkedHashMap(super.getPropertiesAttributes()); propertiesAttributes.put("device", mDeviceName); propertiesAttributes.put("flavor", mFlavorName); propertiesAttributes.put("project", mProjectName); return ImmutableMap.copyOf(propertiesAttributes); }
From source file:com.greensopinion.swagger.jaxrsgen.model.ApiModel.java
ApiModel(String name, String description, List<String> required, LinkedHashMap<String, Property> properties) { this.name = checkNotNull(name); this.id = name; this.description = Strings.emptyToNull(description); this.required = ImmutableList.copyOf(checkNotNull(required)); this.properties = Maps.newLinkedHashMap(checkNotNull(properties)); }
From source file:com.exoplatform.iversion.Merge.java
public <M, T extends Version<K, V, M>> Merge(Iterable<VersionNode<K, V, M, T>> versions) { checkNotNull(versions, "versions"); Iterator<VersionNode<K, V, M, T>> iter = versions.iterator(); // No versions if (!iter.hasNext()) { mergedProperties = ImmutableMap.of(); revisions = ImmutableSet.of();/* w w w . j a va 2 s.com*/ conflicts = ImmutableMultimap.of(); } else { VersionNode<K, V, M, T> versionNode = next(iter); // One version if (!iter.hasNext()) { mergedProperties = versionNode.getProperties(); revisions = ImmutableSet.of(versionNode.getRevision()); conflicts = ImmutableMultimap.of(); } // More than one version -> merge! else { Map<K, VersionProperty<V>> mergedProperties = Maps.newLinkedHashMap(versionNode.getProperties()); Set<Long> heads = Sets.newHashSet(versionNode.getRevision()); ImmutableMultimap.Builder<K, VersionProperty<V>> conflicts = ImmutableMultimap.builder(); Set<Long> mergedRevisions = Sets.newHashSet(versionNode.getRevisions()); do { versionNode = next(iter); // Version already merged? if (!mergedRevisions.contains(versionNode.getRevision())) { for (Map.Entry<K, VersionProperty<V>> entry : versionNode.getProperties().entrySet()) { K key = entry.getKey(); VersionProperty<V> nextValue = entry.getValue(); // nextValue derives from common ancestor? if (!mergedRevisions.contains(nextValue.revision)) { VersionProperty<V> previousValue = mergedProperties.get(key); // New value if (previousValue == null) { mergedProperties.put(key, nextValue); } // Conflicting value? else if (!equal(previousValue.value, nextValue.value)) { conflicts.put(key, nextValue); } } } mergedRevisions.addAll(versionNode.getRevisions()); heads.removeAll(versionNode.getRevisions()); heads.add(versionNode.getRevision()); } } while (iter.hasNext()); this.mergedProperties = unmodifiableMap(mergedProperties); this.revisions = unmodifiableSet(heads); this.conflicts = conflicts.build(); } } }