List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:com.opengamma.analytics.financial.interestrate.market.description.MultipleCurrencyCurveSensitivityMarket.java
/** * Create a new multiple currency sensitivity by adding the sensitivity associated to a given currency. * If the currency is not yet present in the existing sensitivity a new map is created with the extra entry. * If the currency is already present, the associated sensitivities are added (in the sense of {@link InterestRateCurveSensitivity}) and a new map is created with all the other * existing entries and the entry with the currency and the sum sensitivity. * @param ccy The currency. Not null.//from ww w. ja v a 2s. co m * @param sensitivity The sensitivity associated to the currency. Not null. * @return The new multiple currency sensitivity. */ public MultipleCurrencyCurveSensitivityMarket plus(final Currency ccy, final CurveSensitivityMarket sensitivity) { ArgumentChecker.notNull(ccy, "Currency"); ArgumentChecker.notNull(sensitivity, "Sensitivity"); final TreeMap<Currency, CurveSensitivityMarket> map = new TreeMap<Currency, CurveSensitivityMarket>(); if (_sensitivity.containsKey(ccy)) { map.put(ccy, sensitivity.plus(_sensitivity.get(ccy))); for (final Currency loopccy : _sensitivity.keySet()) { if (loopccy != ccy) { map.put(loopccy, _sensitivity.get(loopccy)); } } } else { map.putAll(_sensitivity); map.put(ccy, sensitivity); } return new MultipleCurrencyCurveSensitivityMarket(map); }
From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperGradientAscent.java
private double computePartialDerivative(int i, TariffUtilityEstimate tariffUtilityEstimate, int NUM_RATES, TreeMap<Double, TariffSpecification> eval2touTariff) { double[] testPoint = new double[NUM_RATES]; testPoint[i] = STEP_SIZE;//from w w w .j av a2s .c o m double pprimePlus = evaluatePoint(tariffUtilityEstimate, testPoint); eval2touTariff.put(pprimePlus, tariffUtilityEstimate.getCorrespondingSpec(testPoint)); testPoint[i] = -STEP_SIZE; double pprimeMinus = evaluatePoint(tariffUtilityEstimate, testPoint); eval2touTariff.put(pprimeMinus, tariffUtilityEstimate.getCorrespondingSpec(testPoint)); return pprimePlus - pprimeMinus; }
From source file:gda.jython.commands.ScannableCommands.java
/** * The pos command. Reports the current position of a scannable or moves one or more scannables concurrently. * // w w w . j a va 2 s. c om * @param args * @return String reporting final positions * @throws Exception * - any exception within this method */ public static String pos(Object... args) throws Exception { if (args.length == 1) { if (args[0] == null) {// example: pos None, Jython command: pos([None]) throw new Exception( "Usage: pos [ScannableName] - returns the position of all Scannables [or the given scannable]"); } else if (args[0] instanceof IScannableGroup) { return ScannableUtils.prettyPrintScannableGroup((IScannableGroup) args[0]); } else if (args[0] instanceof ScannableBase) {// example: pos pseudoDeviceName, Jython command: // pos([pseudoDeviceName]) return ((ScannableBase) args[0]).__str__().toString(); } return args[0].toString(); } else if (args.length >= 2) {// example pos pseudoDeviceName newPosition, Jython command: // pos([pseudoDeviceName, newPosition] // identify scannables and the positions to move them to Scannable[] scannableList = new Scannable[args.length / 2]; HashMap<Scannable, Object> positionMap = new HashMap<Scannable, Object>(); int j = 0; for (int i = 0; i < args.length; i += 2) { if (args[i] instanceof Scannable) { scannableList[j] = (Scannable) args[i]; positionMap.put((Scannable) args[i], args[i + 1]); j++; } } // Check positions valid for (Scannable scannable : scannableList) { Object target = positionMap.get(scannable); if (!(scannable instanceof Detector)) { raiseDeviceExceptionIfPositionNotValid(scannable, target); } } try { // Group by level TreeMap<Integer, List<Scannable>> scannablesByLevel = new TreeMap<Integer, List<Scannable>>(); for (Scannable scn : scannableList) { Integer level = scn.getLevel(); if (!scannablesByLevel.containsKey(level)) { scannablesByLevel.put(level, new ArrayList<Scannable>()); } scannablesByLevel.get(level).add(scn); } // Move scannables of the same level concurrently String output = "Move completed: "; // KLUDGE for (Entry<Integer, List<Scannable>> currentLevelScannables : scannablesByLevel.entrySet()) { for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelStart(); } for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelMoveStart(); } // asynchronousMoveTo() for (Scannable scn1 : currentLevelScannables.getValue()) { if (scn1 instanceof DetectorSnapper) { Double collectionTime = PositionConvertorFunctions.toDouble(positionMap.get(scn1)); ((DetectorSnapper) scn1).prepareForAcquisition(collectionTime); ((DetectorSnapper) scn1).acquire(); } else if (scn1 instanceof Detector) { Double collectionTime = PositionConvertorFunctions.toDouble(positionMap.get(scn1)); ((Detector) scn1).setCollectionTime(collectionTime); ((Detector) scn1).prepareForCollection(); ((Detector) scn1).collectData(); } else { scn1.asynchronousMoveTo(positionMap.get(scn1)); } } // **isBusy()** // Wait for all moves to complete. If there is a problem with one, then stop the Scannables // which may still be moving (those that have not yet been waited for), and _then_ throw the // exception. Exception exceptionCaughtWhileWaitingOnIsBusy = null; for (Scannable scn1 : currentLevelScannables.getValue()) { if (exceptionCaughtWhileWaitingOnIsBusy == null) { // normal behaviour try { scn1.waitWhileBusy(); } catch (Exception e) { logger.error("Exception occured while waiting for " + scn1.getName() + " to complete move: ", e.getMessage()); // cause future passes through the loop to stop Scannables exceptionCaughtWhileWaitingOnIsBusy = e; } } else { // stop any motors that may be still moving try { logger.info("Stopping " + scn1.getName() + " due to problem moving previous scannable."); scn1.stop(); } catch (DeviceException e) { logger.error("Caught exception while stopping " + scn1.getName() + ": " + e.getMessage()); } } } if (exceptionCaughtWhileWaitingOnIsBusy != null) { throw exceptionCaughtWhileWaitingOnIsBusy; } for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelEnd(); } } if (scannableList.length > 1) { output += "\n"; } // return position for (Scannable scn3 : scannableList) { output += ScannableUtils.getFormattedCurrentPosition(scn3) + "\n"; } return output.trim(); } catch (Exception e) { // Call the atCommandFailure() hooks for (Scannable scn : scannableList) { scn.atCommandFailure(); } throw e; } } return ""; }
From source file:com.opengamma.analytics.financial.interestrate.market.description.MultipleCurrencyCurveSensitivityMarket.java
/** * Create a new multiple currency sensitivity by multiplying all the sensitivities in a multiple currency sensitivity by a common factor. * @param factor The multiplicative factor. * @return The new multiple currency sensitivity. *//*w w w . j a v a 2 s.c o m*/ public MultipleCurrencyCurveSensitivityMarket multipliedBy(final double factor) { final TreeMap<Currency, CurveSensitivityMarket> map = new TreeMap<Currency, CurveSensitivityMarket>(); for (final Currency loopccy : _sensitivity.keySet()) { map.put(loopccy, _sensitivity.get(loopccy).multipliedBy(factor)); } return new MultipleCurrencyCurveSensitivityMarket(map); }
From source file:com.opengamma.analytics.financial.interestrate.market.description.MultipleCurrencyCurveSensitivityMarket.java
/** * Returns a new multiple currency sensitivity by creating clean sensitivity for each currency (see {@link InterestRateCurveSensitivity} clean() method). * @return The cleaned sensitivity.//w w w. j av a 2 s . c o m */ public MultipleCurrencyCurveSensitivityMarket cleaned() { final TreeMap<Currency, CurveSensitivityMarket> map = new TreeMap<Currency, CurveSensitivityMarket>(); for (final Currency loopccy : _sensitivity.keySet()) { map.put(loopccy, _sensitivity.get(loopccy).cleaned()); } final MultipleCurrencyCurveSensitivityMarket result = new MultipleCurrencyCurveSensitivityMarket(map); return result; }
From source file:com.datatorrent.contrib.hdht.MockFileAccess.java
@Override public FileReader getReader(final long bucketKey, final String fileName) throws IOException { final HashMap<Slice, Pair<byte[], Integer>> data = Maps.newHashMap(); final ArrayList<Slice> keys = Lists.newArrayList(); final MutableInt index = new MutableInt(); DataInputStream is = getInputStream(bucketKey, fileName); Input input = new Input(is); while (!input.eof()) { byte[] keyBytes = kryo.readObject(input, byte[].class); byte[] value = kryo.readObject(input, byte[].class); Slice key = new Slice(keyBytes, 0, keyBytes.length); data.put(key, new Pair<byte[], Integer>(value, keys.size())); keys.add(key);// ww w. j av a2 s. com } input.close(); is.close(); return new FileReader() { @Override public void readFully(TreeMap<Slice, Slice> result) throws IOException { for (Map.Entry<Slice, Pair<byte[], Integer>> e : data.entrySet()) { result.put(e.getKey(), new Slice(e.getValue().first)); } } @Override public void reset() throws IOException { index.setValue(0); } @Override public boolean seek(Slice key) throws IOException { Pair<byte[], Integer> v = data.get(key); if (v == null) { index.setValue(0); return false; } index.setValue(v.second); return true; } @Override public boolean next(Slice key, Slice value) throws IOException { if (deletedFiles.contains("" + bucketKey + fileName)) { throw new IOException("Simulated error for deleted file: " + fileName); } int pos = index.intValue(); if (pos < keys.size()) { Slice k = keys.get(pos); key.buffer = k.buffer; key.offset = k.offset; key.length = k.length; Pair<byte[], Integer> v = data.get(k); value.buffer = v.first; value.offset = 0; value.length = v.first.length; index.increment(); return true; } return false; } @Override public void close() throws IOException { } }; }
From source file:org.andrico.andrico.facebook.FBBase.java
/** * Generate a URL to load in the browser for a user to see. * /*from w w w.j av a 2s. c om*/ * @param authToken Used as the auth_token parameter in the generated url. * @return String */ public String authorizationParameters(String authToken) { TreeMap<String, String> parameters = new TreeMap<String, String>(); parameters.put("api_key", mApiKey); parameters.put("auth_token", authToken); parameters.put("popup", "1"); parameters.put("v", "1.0"); return FBMethod.urlParameters(parameters); }
From source file:com.cyclopsgroup.waterview.ui.view.system.status.SetLocale.java
/** * Overwrite or implement method execute() * * @see com.cyclopsgroup.waterview.Module#execute(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.Context) *//* ww w .java 2 s .c om*/ public void execute(RuntimeData data, Context context) throws Exception { Locale[] locales = Locale.getAvailableLocales(); TreeMap availableLocales = new TreeMap(); for (int i = 0; i < locales.length; i++) { Locale locale = locales[i]; if (StringUtils.isEmpty(locale.getCountry())) { continue; } String key = locale.getCountry() + '|' + locale.getLanguage(); availableLocales.put(key, locale); } context.put("availableLocales", availableLocales.values()); context.put("currentLocale", data.getSessionContext().get(RuntimeData.LOCALE_NAME)); }
From source file:com.xpn.xwiki.objects.classes.UsersClass.java
@Override public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {/* www .j a v a 2s . com*/ select select = new select(prefix + name, 1); select.setMultiple(isMultiSelect()); select.setSize(getSize()); select.setName(prefix + name); select.setID(prefix + name); select.setDisabled(isDisabled()); List<String> list; if (isUsesList()) { list = getList(context); } else { list = new ArrayList<String>(); } List<String> selectlist; BaseProperty prop = (BaseProperty) object.safeget(name); if (prop == null) { selectlist = new ArrayList<String>(); } else { selectlist = getListFromString((String) prop.getValue()); } // Add options from Set for (String value : selectlist) { if (!list.contains(value)) { list.add(value); } } // Make sure we have guest list.remove(XWikiRightService.GUEST_USER_FULLNAME); list.add(0, XWikiRightService.GUEST_USER_FULLNAME); // Sort the user list TreeMap<String, String> map = new TreeMap<String, String>(); for (String value : list) { map.put(getText(value, context), value); } // Add options from Set for (Map.Entry<String, String> entry : map.entrySet()) { String display = entry.getKey(); String value = entry.getValue(); option option = new option(display, value); option.addElement(display); if (selectlist.contains(value)) { option.setSelected(true); } select.addElement(option); } buffer.append(select.toString()); if (!isUsesList()) { input in = new input(); in.setName(prefix + "newuser"); in.setSize(15); in.setDisabled(isDisabled()); buffer.append("<br />"); buffer.append(in.toString()); if (!isDisabled()) { button button = new button(); button.setTagText("Add"); button.setOnClick("addUser(this.form,'" + prefix + "'); return false;"); buffer.append(button.toString()); } } input in = new input(); in.setType("hidden"); in.setName(prefix + name); in.setDisabled(isDisabled()); buffer.append(in.toString()); }
From source file:cloudnet.weather.data.forecastio.FormatConverter.java
private void addWeatherdata(long datetime, String location, double temperature) { TreeMap<Long, Double> map; if (weatherData.containsKey(location)) { map = weatherData.get(location); } else {//from w w w. j a v a 2 s.c om map = new TreeMap<>(); weatherData.put(location, map); } map.put(datetime, temperature); }