List of usage examples for java.util LinkedHashMap putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Builds a lookup table of settings * @param mapping - the mapping to use/*w w w .ja v a 2 s .c om*/ * @param type - if the index has a specific type, lookup that and _default_ ; otherwise just _default * @return */ public static LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode> parseDefaultMapping( final JsonNode mapping, final Optional<String> type, final Optional<DataSchemaBean.SearchIndexSchemaBean> maybe_search_index_schema, final Optional<DataSchemaBean.DocumentSchemaBean> maybe_document_schema, final SearchIndexSchemaDefaultBean search_index_schema_override, final ObjectMapper mapper) { //(see similar code in createComplexStringLookups) final boolean tokenize_by_default = maybe_search_index_schema.map(schema -> schema.tokenize_by_default()) .orElse(true); final boolean dual_tokenize_by_default = Optional .ofNullable(search_index_schema_override.dual_tokenize_by_default()).orElse(false); final JsonNode default_string_mapping = ((ObjectNode) (ElasticsearchIndexUtils.getMapping( Tuples._2T(tokenize_by_default, dual_tokenize_by_default), search_index_schema_override, mapper, true))).put(TYPE_MATCH_NAME, "string").put(PATH_MATCH_NAME, "*"); // (this is always not tokenized but inherits dual tokenization) final ObjectNode not_analyzed_field = ((ObjectNode) (ElasticsearchIndexUtils.getMapping( Tuples._2T(false, dual_tokenize_by_default), search_index_schema_override, mapper, true))) .put(TYPE_MATCH_NAME, "string"); final LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode> ret = Optional .ofNullable(mapping.get("mappings")).map(m -> { if (!m.isObject()) throw new RuntimeException("mappings must be object"); return m; }) .map(m -> Optional.ofNullable(m.get(type.orElse("_default_"))) .map(mm -> !mm.isNull() ? mm : m.get("_default_")).orElse(m.get("_default_"))) .filter(m -> !m.isNull()).map(i -> { if (!i.isObject()) throw new RuntimeException(type + " must be object"); return i; }).map(i -> { // OK so I have a list of dynamic_templates, and a list of properties - and then a set of string defaults to apply // 1) want to leave the properties alone // 2) then the tokenization overrides from createComplexStringLookups // 3) then the existing templates final Map<Either<String, Tuple2<String, String>>, JsonNode> override_props = createComplexStringLookups( maybe_search_index_schema, search_index_schema_override, mapper); // ensure string doc fields aren't analyzed final Map<Either<String, Tuple2<String, String>>, String> type_override = maybe_search_index_schema .map(s -> s.type_override()).map(m -> buildTypeMap(m)).orElse(Collections.emptyMap()); final Map<Either<String, Tuple2<String, String>>, JsonNode> doc_props = maybe_document_schema .map(ds -> ds.deduplication_fields()) .<Map<Either<String, Tuple2<String, String>>, JsonNode>>map(fields -> { return fields.stream().filter(f -> !override_props.containsKey(Either.left(f))) .filter(f -> !override_props.containsKey(Either.right(Tuples._2T(f, "*")))) .filter(f -> !type_override.containsKey(Either.left(f))) .filter(f -> !type_override.containsKey(Either.right(Tuples._2T(f, "*")))) .<Tuple2<Either<String, Tuple2<String, String>>, JsonNode>>map( f -> Tuples._2T(Either.right(Tuples._2T(f, "string")), not_analyzed_field.deepCopy().put(PATH_MATCH_NAME, f))) .collect(Collectors.toMap( (Tuple2<Either<String, Tuple2<String, String>>, JsonNode> t2) -> t2 ._1(), t2 -> t2._2())); }).orElse(Collections.emptyMap()); final LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode> props = new LinkedHashMap<>(); props.putAll(doc_props); // (put these first - though actually i'm fixing the order with an explicit sort in the columnar section) props.putAll(override_props); // extra mappings and extra templates Optionals.of(() -> search_index_schema_override.extra_field_mappings()) .map(o -> mapper.convertValue(o, JsonNode.class)).ifPresent(j -> { props.putAll(getTemplates(j, default_string_mapping, props.keySet())); props.putAll(getProperties(j)); }); // full mappings at the end props.putAll(getTemplates(i, default_string_mapping, props.keySet())); props.putAll(getProperties(i)); return props; }).orElse(new LinkedHashMap<>()); return ret; }
From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyParameterSensitivity.java
/** * Create a copy of the sensitivity and add a given named sensitivity to it. If the name / currency pair is in the map, the two sensitivity matrices are added. * Otherwise, a new entry is put into the map * @param nameCcy The name and the currency, not null * @param sensitivity The sensitivity to add, not null * @return The total sensitivity.//w ww.j av a 2s . co m */ public MultipleCurrencyParameterSensitivity plus(final Pair<String, Currency> nameCcy, final DoubleMatrix1D sensitivity) { ArgumentChecker.notNull(nameCcy, "Name/currency"); ArgumentChecker.notNull(sensitivity, "Matrix"); final MatrixAlgebra algebra = MatrixAlgebraFactory.COMMONS_ALGEBRA; final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<>(); result.putAll(_sensitivity); if (result.containsKey(nameCcy)) { result.put(nameCcy, (DoubleMatrix1D) algebra.add(result.get(nameCcy), sensitivity)); } else { result.put(nameCcy, sensitivity); } return new MultipleCurrencyParameterSensitivity(result); }
From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyParameterSensitivity.java
/** * Create a copy of the sensitivity and add a given sensitivity to it. * @param other The sensitivity to add.//from w w w . j a v a 2s.c o m * @return The total sensitivity. */ public MultipleCurrencyParameterSensitivity plus(final MultipleCurrencyParameterSensitivity other) { ArgumentChecker.notNull(other, "Sensitivity to add"); final MatrixAlgebra algebra = MatrixAlgebraFactory.COMMONS_ALGEBRA; final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<>(); result.putAll(_sensitivity); for (final Map.Entry<Pair<String, Currency>, DoubleMatrix1D> entry : other.getSensitivities().entrySet()) { final Pair<String, Currency> nameCcy = entry.getKey(); if (result.containsKey(nameCcy)) { result.put(nameCcy, (DoubleMatrix1D) algebra.add(result.get(nameCcy), entry.getValue())); } else { result.put(nameCcy, entry.getValue()); } } return new MultipleCurrencyParameterSensitivity(result); }
From source file:com.espertech.esper.pattern.EvalEveryDistinctStateExpireKeyNode.java
public final void evaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, boolean isQuitted) { // determine if this evaluation has been seen before from the same node Object matchEventKey = PatternExpressionUtil.getKeys(matchEvent, everyNode); boolean haveSeenThis = false; LinkedHashMap<Object, Long> keysFromNode = spawnedNodes.get(fromNode); if (keysFromNode != null) { // Clean out old keys Iterator<Map.Entry<Object, Long>> it = keysFromNode.entrySet().iterator(); long currentTime = everyNode.getContext().getPatternContext().getTimeProvider().getTime(); for (; it.hasNext();) { Map.Entry<Object, Long> entry = it.next(); if (currentTime - entry.getValue() >= everyNode.getFactoryNode().getMsecToExpire()) { it.remove();/*from ww w .j a v a 2 s. c o m*/ } else { break; } } if (keysFromNode.containsKey(matchEventKey)) { haveSeenThis = true; } else { keysFromNode.put(matchEventKey, currentTime); } } if (isQuitted) { spawnedNodes.remove(fromNode); } // See explanation in EvalFilterStateNode for the type check if (fromNode.isFilterStateNode()) { // We do not need to newState new listeners here, since the filter state node below this node did not quit } else { // Spawn all nodes below this EVERY node // During the start of a child we need to use the temporary evaluator to catch any event created during a start // Such events can be raised when the "not" operator is used. EvalEveryStateSpawnEvaluator spawnEvaluator = new EvalEveryStateSpawnEvaluator( everyNode.getContext().getPatternContext().getStatementName()); EvalStateNode spawned = everyNode.getChildNode().newState(spawnEvaluator, null, 0L); spawned.start(beginState); // If the whole spawned expression already turned true, quit it again if (spawnEvaluator.isEvaluatedTrue()) { spawned.quit(); } else { LinkedHashMap<Object, Long> keyset = new LinkedHashMap<Object, Long>(); if (keysFromNode != null) { keyset.putAll(keysFromNode); } spawnedNodes.put(spawned, keyset); spawned.setParentEvaluator(this); } } if (!haveSeenThis) { this.getParentEvaluator().evaluateTrue(matchEvent, this, false); } }
From source file:io.wcm.caravan.io.http.response.Response.java
private Response(int status, String reason, Map<String, Collection<String>> headers, Body body) { checkState(status >= 200, "Invalid status code: %s", status); this.status = status; this.reason = checkNotNull(reason, "reason"); LinkedHashMap<String, Collection<String>> copyOf = new LinkedHashMap<String, Collection<String>>(); copyOf.putAll(checkNotNull(headers, "headers")); this.headers = Collections.unmodifiableMap(copyOf); this.body = body; //nullable }
From source file:com.opengamma.analytics.financial.interestrate.capletstripping.CapletStrippingJacobian.java
@Override public DoubleMatrix2D evaluate(final DoubleMatrix1D x) { final LinkedHashMap<String, Interpolator1DDataBundle> db = _dataBundleBuilder.evaluate(x); //TODO merge these - they do the same work! final LinkedHashMap<String, InterpolatedDoublesCurve> curves = _curveBuilder.evaluate(x); // set any known (i.e. fixed) curves if (_knownParameterTermSturctures != null) { curves.putAll(_knownParameterTermSturctures); }/*from w w w . ja v a 2 s. c o m*/ //TODO make this general - not SABR specific final Curve<Double, Double> cAlpha = curves.get(ALPHA); final Curve<Double, Double> cBeta = curves.get(BETA); final Curve<Double, Double> cRho = curves.get(RHO); final Curve<Double, Double> cNu = curves.get(NU); final VolatilityModel1D volModel = new SABRTermStructureParameters(cAlpha, cBeta, cRho, cNu); final int nCaps = _capPricers.size(); final int m = x.getNumberOfElements(); final double[][] jac = new double[nCaps][m]; double f, k, t; for (int i = 0; i < nCaps; i++) { //outer loop over caps final CapFloorPricer capPricer = _capPricers.get(i); final double vega = capPricer.vega(volModel); final int nCaplets = capPricer.getNumberCaplets(); final double[][] greeks = new double[nCaplets][]; //the sensitivity of vol to the model parameters final double[] capletVega = new double[nCaplets]; final double[] capletExpiries = capPricer.getExpiries(); final double[] capletFwds = capPricer.getForwards(); final double[] capletDF = capPricer.getDiscountFactors(); final double[][][] nodeSens = new double[_parameterNames.size()][nCaplets][]; //Sensitivity to the nodes of a particular curve at a particular time k = capPricer.getStrike(); //TODO There will be much repeated calculations here, as many of the caplets are shared across caps for (int tIndex = 0; tIndex < nCaplets; tIndex++) { f = capletFwds[tIndex]; t = capletExpiries[tIndex]; final EuropeanVanillaOption option = new EuropeanVanillaOption(k, t, true); //TODO again this is SABR specific final SABRFormulaData data = new SABRFormulaData(cAlpha.getYValue(t), cBeta.getYValue(t), cRho.getYValue(t), cNu.getYValue(t)); greeks[tIndex] = SABR.getVolatilityAdjoint(option, f, data); //2nd and 3rd entries are forward & strike sensitivity which we don't use capletVega[tIndex] = capletDF[tIndex] * BlackFormulaRepository.vega(f, k, t, greeks[tIndex][0]); int parmIndex = 0; for (final String name : _parameterNames) { final Interpolator1D itrp = _interpolators.get(name); nodeSens[parmIndex++][tIndex] = itrp.getNodeSensitivitiesForValue(db.get(name), t); } } final double[] res = new double[x.getNumberOfElements()]; for (int tIndex = 0; tIndex < nCaplets; tIndex++) { int index = 0; for (int parmIndex = 0; parmIndex < _parameterNames.size(); parmIndex++) { final double temp = capletVega[tIndex] * greeks[tIndex][parmIndex + 3]; //1st 3 are vol, dForward & dStrike final double[] ns = nodeSens[parmIndex][tIndex]; for (final double element : ns) { res[index] += element * temp; index++; } } } for (int j = 0; j < res.length; j++) { jac[i][j] = res[j] / vega; } } return new DoubleMatrix2D(jac); }
From source file:org.ohmage.reminders.types.time.TimeTrigDesc.java
public LinkedHashMap<String, Boolean> getRepeat() { LinkedHashMap<String, Boolean> ret = new LinkedHashMap<String, Boolean>(); ret.putAll(mRepeatList); return ret;/*from ww w. ja v a 2 s . com*/ }
From source file:org.graylog2.inputs.transports.UdpTransportTest.java
private UdpTransport launchTransportForBootStrapTest(final ChannelHandler channelHandler) throws MisfireException { final UdpTransport transport = new UdpTransport(CONFIGURATION, throughputCounter, new LocalMetricRegistry()) { @Override//from w ww. ja v a 2 s .c om protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers( MessageInput input) { final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>(); handlers.put("counter", Callables.returning(channelHandler)); handlers.putAll(super.getFinalChannelHandlers(input)); return handlers; } }; final MessageInput messageInput = mock(MessageInput.class); when(messageInput.getId()).thenReturn("TEST"); when(messageInput.getName()).thenReturn("TEST"); transport.launch(messageInput); return transport; }
From source file:com.tdclighthouse.commons.simpleform.html.FormItemGroup.java
public Map<String, FormItem> getItemsMap() { LinkedHashMap<String, FormItem> result = new LinkedHashMap<String, FormItem>(); Iterator<String> iterator = this.subgroups.keySet().iterator(); while (iterator.hasNext()) { FormItemGroup formItemGroup = this.subgroups.get(iterator.next()); result.putAll(formItemGroup.getItemsMap()); }//from ww w .jav a2 s.c o m result.putAll(this.items); return result; }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
public LinkedHashMap<String, StatusBarNotification> getNotificationMap() { LinkedHashMap<String, StatusBarNotification> map = new LinkedHashMap<>(archivedNotificationMap); map.putAll(notificationMap); return map;/*from ww w. j a v a 2 s . c o m*/ }