List of usage examples for java.util LinkedHashMap put
V put(K key, V value);
From source file:com.opengamma.analytics.financial.curve.sensitivity.ParameterUnderlyingSensitivityBlockCalculator.java
public ParameterSensitivity pointToParameterSensitivity(final Currency ccy, final InterestRateCurveSensitivity sensitivity, final Set<String> fixedCurves, final YieldCurveBundle bundle) { Set<String> curveNamesSet = bundle.getAllNames(); int nbCurve = curveNamesSet.size(); String[] curveNamesArray = new String[nbCurve]; int loopname = 0; LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>(); for (final String name : curveNamesSet) { // loop over all curves (by name) curveNamesArray[loopname] = name; curveNum.put(name, loopname++); }//from ww w . java 2 s .c o m int[] nbNewParameters = new int[nbCurve]; // Implementation note: nbNewParameters - number of new parameters in the curve, parameters not from an underlying curve which is another curve of the bundle. int[][] indexOther = new int[nbCurve][]; // Implementation note: indexOther - the index of the underlying curves, if any. loopname = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) final YieldAndDiscountCurve curve = bundle.getCurve(name); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); nbNewParameters[loopname] = curve.getNumberOfParameters(); List<Integer> indexOtherList = new ArrayList<Integer>(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { indexOtherList.add(i); nbNewParameters[loopname] -= nbNewParameters[i]; } } indexOther[loopname] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0])); loopname++; } loopname = 0; for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { loopname++; } } int nbSensitivityCurve = loopname; int[] nbNewParamSensiCurve = new int[nbSensitivityCurve]; // Implementation note: nbNewParamSensiCurve int[][] indexOtherSensiCurve = new int[nbSensitivityCurve][]; // Implementation note: indexOtherSensiCurve - // int[] startCleanParameter = new int[nbSensitivityCurve]; // Implementation note: startCleanParameter - for each curve for which the sensitivity should be computed, the index in the total sensitivity vector at which that curve start. int[][] startDirtyParameter = new int[nbSensitivityCurve][]; // Implementation note: startDirtyParameter - for each curve for which the sensitivity should be computed, the indexes of the underlying curves. int nbCleanParameters = 0; int currentDirtyStart = 0; loopname = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { int num = curveNum.get(name); final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Integer> startDirtyParameterList = new ArrayList<Integer>(); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[i]; } } startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[loopname]; startDirtyParameter[loopname] = ArrayUtils .toPrimitive(startDirtyParameterList.toArray(new Integer[0])); nbNewParamSensiCurve[loopname] = nbNewParameters[num]; indexOtherSensiCurve[loopname] = indexOther[num]; // startCleanParameter[loopname] = nbCleanParameters; nbCleanParameters += nbNewParamSensiCurve[loopname]; loopname++; } } final List<Double> sensiDirtyList = new ArrayList<Double>(); for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); Double[] oneCurveSensitivity = pointToParameterSensitivity(sensitivity.getSensitivities().get(name), curve); sensiDirtyList.addAll(Arrays.asList(oneCurveSensitivity)); } } double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0])); double[][] sensiClean = new double[nbSensitivityCurve][]; for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { sensiClean[loopcurve] = new double[nbNewParamSensiCurve[loopcurve]]; } for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { for (int loopo = 0; loopo < indexOtherSensiCurve[loopcurve].length; loopo++) { if (!fixedCurves.contains(curveNamesArray[indexOtherSensiCurve[loopcurve][loopo]])) { for (int loops = 0; loops < nbNewParamSensiCurve[indexOtherSensiCurve[loopcurve][loopo]]; loops++) { sensiClean[indexOtherSensiCurve[loopcurve][loopo]][loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops]; } } } for (int loops = 0; loops < nbNewParamSensiCurve[loopcurve]; loops++) { sensiClean[loopcurve][loops] += sensiDirty[startDirtyParameter[loopcurve][indexOtherSensiCurve[loopcurve].length] + loops]; } } final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D>(); for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { result.put(new ObjectsPair<String, Currency>(curveNamesArray[loopcurve], ccy), new DoubleMatrix1D(sensiClean[loopcurve])); } return new ParameterSensitivity(result); }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcMetastoreUtil.java
public static LinkedHashMap<String, JdbcTypeInfo> convertRecordToJdbcType(Record record, String precisionAttribute, String scaleAttribute, JdbcSchemaWriter schemaWriter) throws OnRecordErrorException, JdbcStageCheckedException { if (!record.get().getType().isOneOf(Field.Type.MAP, Field.Type.LIST_MAP)) { throw new OnRecordErrorException(record, JdbcErrors.JDBC_300, record.getHeader().getSourceId(), record.get().getType().toString()); }//from ww w. j a va 2s. co m LinkedHashMap<String, JdbcTypeInfo> columns = new LinkedHashMap<>(); Map<String, Field> list = record.get().getValueAsMap(); for (Map.Entry<String, Field> pair : list.entrySet()) { if (StringUtils.isEmpty(pair.getKey())) { throw new OnRecordErrorException(record, JdbcErrors.JDBC_301, "Field name is empty"); } String fieldPath = pair.getKey(); Field currField = pair.getValue(); // Some types requires special checks or alterations JdbcType jdbcType = JdbcType.getJdbcTypeforFieldType(currField.getType()); JdbcTypeInfo jdbcTypeInfo; if (jdbcType == JdbcType.DECIMAL) { int precision = resolveScaleOrPrecisionExpression("precision", currField, precisionAttribute, fieldPath); int scale = resolveScaleOrPrecisionExpression("scale", currField, scaleAttribute, fieldPath); schemaWriter.validateScaleAndPrecision(pair.getKey(), currField, precision, scale); jdbcTypeInfo = jdbcType.getSupport().generateJdbcTypeInfoFromRecordField(currField, schemaWriter, precision, scale); } else { jdbcTypeInfo = jdbcType.getSupport().generateJdbcTypeInfoFromRecordField(currField, schemaWriter); } columns.put(pair.getKey().toLowerCase(), jdbcTypeInfo); } return columns; }
From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java
public static LinkedHashMap<String, List<GenomicPosNode>> getPotentiallyMappedRegion( LinkedHashMap<String, DataNode> optrefmap, LinkedHashMap<String, List<OptMapResultNode>> resultListMap) { LinkedHashMap<String, List<GenomicPosNode>> targetRegionMap = new LinkedHashMap<>(); for (List<OptMapResultNode> resultList : resultListMap.values()) { List<GenomicPosNode> targetRegionList = getPotentiallyMappedRegion(optrefmap, resultList); targetRegionMap.put(resultList.get(0).parentFrag.name, targetRegionList); }/*from w w w. j a va 2s. c o m*/ return targetRegionMap; }
From source file:com.intel.iotkitlib.DeviceManagement.java
/** * Get full detail for specific device for the specified account. * @param deviceId the identifier for the device to get details for. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. * For synch model, return CloudResponse which wraps HTTP return code and response. *//* ww w. j ava 2 s . c o m*/ public CloudResponse getInfoOnDevice(String deviceId) { //initiating get for device info HttpGetTask getDeviceDetails = new HttpGetTask(); getDeviceDetails.setHeaders(basicHeaderList); LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>(); linkedHashMap.put("other_device_id", deviceId); String url = objIotKit.prepareUrl(objIotKit.getOneDeviceInfo, linkedHashMap); return super.invokeHttpExecuteOnURL(url, getDeviceDetails); }
From source file:com.intel.iotkitlib.DeviceManagement.java
/** * Delete a specific device for this account. All data from all time series associated with * the device will be deleted./*from w ww. j ava 2 s.c o m*/ * @param deviceId the identifier for the device that will be deleted. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. * For synch model, return CloudResponse which wraps HTTP return code and response. */ public CloudResponse deleteADevice(String deviceId) { //initiating delete of device HttpDeleteTask deleteADevice = new HttpDeleteTask(); deleteADevice.setHeaders(basicHeaderList); LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>(); linkedHashMap.put("other_device_id", deviceId); String url = objIotKit.prepareUrl(objIotKit.deleteDevice, linkedHashMap); return super.invokeHttpExecuteOnURL(url, deleteADevice); }
From source file:com.intel.iotkitlib.DeviceManagement.java
/** * Delete a specific component for a specific device. All data will be unavailable. The device id * that is used will be the current device that is cached usually after a create new device. * @param componentName the name that identifies the component. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. * For synch model, return CloudResponse which wraps HTTP return code and response. *///from w w w .j a v a2 s . c o m public CloudResponse deleteAComponent(final String componentName) { //initiating delete of component HttpDeleteTask deleteComponent = new HttpDeleteTask(); deleteComponent.setHeaders(basicHeaderList); LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>(); linkedHashMap.put("cname", componentName); String url = objIotKit.prepareUrl(objIotKit.deleteComponent, linkedHashMap); return super.invokeHttpExecuteOnURL(url, deleteComponent); }
From source file:com.logsniffer.fields.FieldsMap.java
/** * @return the types//from w ww .jav a2s.c om */ @Override public Map<String, FieldBaseTypes> getTypes() { final LinkedHashMap<String, FieldBaseTypes> types = new LinkedHashMap<String, FieldBaseTypes>(); for (final Map.Entry<String, Object> e : entrySet()) { types.put(e.getKey(), FieldBaseTypes.resolveType(e.getValue())); } return types; }
From source file:com.ibm.sbt.security.authentication.oauth.consumer.HMACOAuth1Handler.java
@Override public void getRequestTokenFromServer() throws OAuthException { int responseCode = HttpStatus.SC_OK; Context context = Context.get(); String responseBody = ""; try {/*from w ww. ja v a 2s. c o m*/ HttpClient client = new DefaultHttpClient(); if (getForceTrustSSLCertificate()) { client = SSLUtil.wrapHttpClient((DefaultHttpClient) client); } // In case of Twitter, this callback URL registered can be different from the URL specified below. String callbackUrl = getCallbackUrl(context); String consumerKey = getConsumerKey(); String nonce = getNonce(); String timeStamp = getTimestamp(); // HMAC requires parameter to be alphabetically sorted, using LinkedHashMap below to preserve // ordering LinkedHashMap<String, String> signatureParamsMap = new LinkedHashMap<String, String>(); signatureParamsMap.put(Configuration.CALLBACK, callbackUrl); signatureParamsMap.put(Configuration.CONSUMER_KEY, consumerKey); signatureParamsMap.put(Configuration.NONCE, nonce); signatureParamsMap.put(Configuration.SIGNATURE_METHOD, getSignatureMethod()); signatureParamsMap.put(Configuration.TIMESTAMP, timeStamp); signatureParamsMap.put(Configuration.VERSION, Configuration.OAUTH_VERSION1); String consumerSecret = getConsumerSecret(); String requestPostUrl = getRequestTokenURL(); HttpPost method = new HttpPost(requestPostUrl); String signature = HMACEncryptionUtility.generateHMACSignature(requestPostUrl, method.getMethod(), consumerSecret, "", signatureParamsMap); StringBuilder headerStr = new StringBuilder(); headerStr.append("OAuth ").append(Configuration.CALLBACK).append("=\"").append(callbackUrl) .append("\""); headerStr.append(",").append(Configuration.CONSUMER_KEY).append("=\"").append(consumerKey).append("\""); headerStr.append(",").append(Configuration.SIGNATURE_METHOD).append("=\"").append(getSignatureMethod()) .append("\""); headerStr.append(",").append(Configuration.TIMESTAMP).append("=\"").append(timeStamp).append("\""); headerStr.append(",").append(Configuration.NONCE).append("=\"").append(nonce).append("\""); headerStr.append(",").append(Configuration.VERSION).append("=\"").append(Configuration.OAUTH_VERSION1) .append("\""); headerStr.append(",").append(Configuration.SIGNATURE).append("=\"") .append(URLEncoder.encode(signature, "UTF-8")).append("\""); method.setHeader("Authorization", headerStr.toString()); HttpResponse httpResponse = client.execute(method); responseCode = httpResponse.getStatusLine().getStatusCode(); InputStream content = httpResponse.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); try { responseBody = StreamUtil.readString(reader); } finally { StreamUtil.close(reader); } } catch (Exception e) { throw new OAuthException(e, "Internal error - getRequestToken failed Exception: "); } if (responseCode != HttpStatus.SC_OK) { String exceptionDetail = buildErrorMessage(responseCode, responseBody); if (StringUtil.isNotEmpty(exceptionDetail)) { throw new OAuthException(null, "HMACOAuth1Handler.java : getRequestTokenFromServer failed." + exceptionDetail); } } else { /* * The Response from Twitter contains OAuth request token, OAuth request token secret, and a * boolean oauth_callback_confirmed with value set as true or false. */ setRequestToken(getTokenValue(responseBody, Configuration.OAUTH_TOKEN)); setRequestTokenSecret(getTokenValue(responseBody, Configuration.OAUTH_TOKEN_SECRET)); /* * OAUTH_CALLBACK_CONFIRMED : This property can be used for debugging applications which have not * provided the Callback URL while registering the Application. If OAUTH_CALLBACK_CONFIRMED is * returned as false, then the application needs to be modified to set a callback url. However, * when the Application has specified the Callback Url, and is different from the callback Url we * are passing, this property value is returned as true. */ setOAuthCallbackConfirmed(getTokenValue(responseBody, Configuration.OAUTH_CALLBACK_CONFIRMED)); } }
From source file:com.ibm.sbt.security.authentication.oauth.consumer.HMACOAuth1Handler.java
@Override public void getAccessTokenFromServer() throws OAuthException { int responseCode = HttpStatus.SC_OK; String responseBody = null;//from w ww .j av a2 s .c om try { HttpClient client = new DefaultHttpClient(); if (getForceTrustSSLCertificate()) { client = SSLUtil.wrapHttpClient((DefaultHttpClient) client); } StringBuilder requestPostUrl = new StringBuilder(getAccessTokenURL()); // adding the oauth_verifier to the request. requestPostUrl.append("?"); requestPostUrl.append(Configuration.OAUTH_VERIFIER).append('=') .append(URLEncoder.encode(verifierCode, "UTF-8")); HttpPost method = new HttpPost(requestPostUrl.toString()); // Collecting parameters for preparing the Signature String consumerKey = getConsumerKey(); String requestToken = getRequestToken(); String nonce = getNonce(); String timeStamp = getTimestamp(); /* * Generate a map of parameters which are required for creating signature. We are using a Linked * HashMap to preserver the order in which parameters are added to the Map, as the parameters need * to be sorted for Twitter Signature generation. */ LinkedHashMap<String, String> signatureParamsMap = new LinkedHashMap<String, String>(); signatureParamsMap.put(Configuration.CONSUMER_KEY, consumerKey); signatureParamsMap.put(Configuration.NONCE, nonce); signatureParamsMap.put(Configuration.OAUTH_TOKEN, requestToken); signatureParamsMap.put(Configuration.SIGNATURE_METHOD, getSignatureMethod()); signatureParamsMap.put(Configuration.TIMESTAMP, timeStamp); signatureParamsMap.put(Configuration.VERSION, Configuration.OAUTH_VERSION1); String requestTokenSecret = getRequestTokenSecret(); String consumerSecret = getConsumerSecret(); String signature = HMACEncryptionUtility.generateHMACSignature(requestPostUrl.toString(), method.getMethod(), consumerSecret, requestTokenSecret, signatureParamsMap); // Preparing the Header for getting access token StringBuilder headerStr = new StringBuilder(); headerStr.append("OAuth ").append(Configuration.CONSUMER_KEY).append("=\"").append(consumerKey) .append("\""); headerStr.append(",").append(Configuration.SIGNATURE_METHOD).append("=\"").append(getSignatureMethod()) .append("\""); headerStr.append(",").append(Configuration.TIMESTAMP).append("=\"").append(timeStamp).append("\""); headerStr.append(",").append(Configuration.NONCE).append("=\"").append(nonce).append("\""); headerStr.append(",").append(Configuration.VERSION).append("=\"").append(Configuration.OAUTH_VERSION1) .append("\""); // This is the request token which is obtained from getRequestTokenFromServer() method. headerStr.append(",").append(Configuration.OAUTH_TOKEN).append("=\"").append(requestToken).append("\""); headerStr.append(",").append(Configuration.SIGNATURE).append("=\"") .append(URLEncoder.encode(signature, "UTF-8")).append("\""); method.setHeader("Authorization", headerStr.toString()); method.setHeader("Authorization", headerStr.toString()); HttpResponse httpResponse = client.execute(method); responseCode = httpResponse.getStatusLine().getStatusCode(); InputStream content = httpResponse.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); try { responseBody = StreamUtil.readString(reader); } finally { StreamUtil.close(reader); } } catch (Exception e) { throw new OAuthException(e, "Internal error - getAccessToken failed Exception: "); } if (responseCode != HttpStatus.SC_OK) { String exceptionDetail = buildErrorMessage(responseCode, responseBody); if (exceptionDetail != null) { throw new OAuthException(null, "HMACOAuth1Handler.java : getAccessTokenFromServer failed. " + exceptionDetail); } } else { /* * Response from twitter contains Access Token, Access Token Secret, User Id and Screen Name of * the Application. */ setAccessToken(getTokenValue(responseBody, Configuration.OAUTH_TOKEN)); setAccessTokenSecret(getTokenValue(responseBody, Configuration.OAUTH_TOKEN_SECRET)); } }
From source file:com.epam.dlab.backendapi.dao.ExploratoryDAO.java
/** * Updates the info of exploratory in Mongo database. * * @param dto object of exploratory status info. * @return The result of an update operation. *//* w w w . ja v a 2 s . co m*/ @SuppressWarnings("serial") public UpdateResult updateExploratoryFields(ExploratoryStatusDTO dto) { Document values = new Document(STATUS, dto.getStatus()).append(UPTIME, dto.getUptime()); if (dto.getInstanceId() != null) { values.append(INSTANCE_ID, dto.getInstanceId()); } if (dto.getErrorMessage() != null) { values.append(ERROR_MESSAGE, DateRemoverUtil.removeDateFormErrorMessage(dto.getErrorMessage())); } if (dto.getExploratoryId() != null) { values.append(EXPLORATORY_ID, dto.getExploratoryId()); } if (dto.getResourceUrl() != null) { values.append(EXPLORATORY_URL, dto.getResourceUrl().stream().map(url -> { LinkedHashMap<String, String> map = new LinkedHashMap<>(); map.put(EXPLORATORY_URL_DESC, url.getDescription()); map.put(EXPLORATORY_URL_URL, url.getUrl()); return map; }).collect(Collectors.toList())); } else if (dto.getPrivateIp() != null) { UserInstanceDTO inst = fetchExploratoryFields(dto.getUser(), dto.getExploratoryName()); if (!inst.getPrivateIp().equals(dto.getPrivateIp()) && inst.getResourceUrl() != null) { // IP was // changed values.append(EXPLORATORY_URL, inst.getResourceUrl().stream() .map(url -> replaceIp(dto.getPrivateIp(), inst, url)).collect(Collectors.toList())); } } if (dto.getPrivateIp() != null) { values.append(EXPLORATORY_PRIVATE_IP, dto.getPrivateIp()); } if (dto.getExploratoryUser() != null) { values.append(EXPLORATORY_USER, dto.getExploratoryUser()); } if (dto.getExploratoryPassword() != null) { values.append(EXPLORATORY_PASS, dto.getExploratoryPassword()); } return updateOne(USER_INSTANCES, exploratoryCondition(dto.getUser(), dto.getExploratoryName()), new Document(SET, values)); }