List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:com.smartitengineering.cms.api.impl.type.FieldDefImpl.java
@Override public VariationDef getVariationDefForMimeType(String mimeType) { TreeMap<String, VariationDef> map = new TreeMap<String, VariationDef>(); for (VariationDef def : variationDefs) { if (def.getMIMEType().equals(mimeType)) { map.put(def.getName(), def); }/*w ww . j a va 2 s.c o m*/ } if (map.isEmpty()) { return null; } else { return map.firstEntry().getValue(); } }
From source file:net.anthonypoon.ngram.rollingregression.RollingRegressionReducer.java
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { TreeMap<String, Double> currElement = new TreeMap(); boolean pastThreshold = false; for (Text val : values) { String[] strArray = val.toString().split("\t"); if (Double.valueOf(strArray[1]) > threshold) { pastThreshold = true;/*from www. j a v a 2s .c o m*/ } currElement.put(strArray[0], Math.log(Double.valueOf(strArray[1]))); } if (pastThreshold) { for (Integer i = 0; i <= upbound - lowbound; i++) { if (!currElement.containsKey(String.valueOf(lowbound + i))) { if (i != 0) { currElement.put(String.valueOf(lowbound + i), currElement.get(String.valueOf(lowbound + i - 1))); } else { currElement.put(String.valueOf(lowbound + i), 0.0); } } } TreeMap<String, Double> result = new TreeMap(); for (Integer i = 0 + range; i <= upbound - lowbound - range; i++) { SimpleRegression regression = new SimpleRegression(); for (Integer l = -range; l <= range; l++) { regression.addData(l.doubleValue(), currElement.get(String.valueOf(i + lowbound + l))); } if (!Double.isNaN(regression.getSlope())) { if (!positiveOnly || regression.getSlope() > 0) { result.put(String.valueOf(lowbound + i), regression.getSlope()); } } } for (Map.Entry<String, Double> pair : result.entrySet()) { context.write(key, new Text(pair.getKey() + "\t" + String.format("%.5f", pair.getValue()))); } } }
From source file:com.tassadar.multirommgr.installfragment.UbuntuManifest.java
private void addChannel(String full_name, JSONObject channelObject) throws JSONException { String flavour_name, channel_name; int idx = full_name.indexOf('/'); if (idx == -1) { flavour_name = NO_FLAVOUR;/*from w ww. j av a 2s . c o m*/ channel_name = full_name; full_name = NO_FLAVOUR + "/" + full_name; } else { flavour_name = full_name.substring(0, idx); channel_name = full_name.substring(idx + 1); } UbuntuChannel channel = new UbuntuChannel(channel_name, full_name, channelObject); TreeMap<String, UbuntuChannel> channelMap = m_flavours.get(flavour_name); if (channelMap == null) { channelMap = new TreeMap<String, UbuntuChannel>(); m_flavours.put(flavour_name, channelMap); } channelMap.put(channel_name, channel); }
From source file:org.apache.james.container.spring.lifecycle.LogProviderImpl.java
/** * @see LogProviderManagementMBean#getLogLevels() *///w ww .j a v a 2 s . c o m public Map<String, String> getLogLevels() { TreeMap<String, String> levels = new TreeMap<String, String>(); Iterator<String> names = logMap.keySet().iterator(); while (names.hasNext()) { String name = names.next(); String level = getLogLevel(name); if (level != null) levels.put(name, level); } return levels; }
From source file:org.wso2.carbon.metrics.impl.ReporterTest.java
private SortedMap<String, Object> values(AttributeList attributes) { final TreeMap<String, Object> values = new TreeMap<String, Object>(); if (attributes != null) { for (Object o : attributes) { final Attribute attribute = (Attribute) o; values.put(attribute.getName(), attribute.getValue()); }// w w w. j a va 2 s . c om } return values; }
From source file:me.neatmonster.spacertk.actions.FileActions.java
/** * Gets information about a File/*from ww w .j a va 2s . c o m*/ * @param file File to get information about * @return Information about a file */ @Action(aliases = { "getFileInformations", "fileInformations", "informations" }) public TreeMap<String, Object> getFileInformations(final String file) { final TreeMap<String, Object> fileInformations = new TreeMap<String, Object>(); final File file_ = new File(file); if (file_.exists()) { fileInformations.put("Name", file_.getName()); fileInformations.put("Path", file_.getPath()); fileInformations.put("Size", file_.length()); fileInformations.put("Execute", file_.canExecute()); fileInformations.put("Read", file_.canRead()); fileInformations.put("Write", file_.canWrite()); fileInformations.put("IsDirectory", file_.isDirectory()); fileInformations.put("IsFile", file_.isFile()); fileInformations.put("IsHidden", file_.isHidden()); final FileNameMap fileNameMap = URLConnection.getFileNameMap(); fileInformations.put("Mime", fileNameMap.getContentTypeFor("file://" + file_.getPath())); return fileInformations; } return new TreeMap<String, Object>(); }
From source file:io.mapzone.arena.refine.RefinePanel.java
@Override public void createContents(final Composite parent) { parent.setLayout(FormLayoutFactory.defaults().create()); final TreeMap<String, RefineFunction> functions = Maps.newTreeMap(); for (Class<RefineFunction> cl : availableFunctions) { try {// w w w. j a v a 2s . c o m RefineFunction function = cl.newInstance(); function.init(map); functions.put(function.title(), function); } catch (Exception e) { throw new RuntimeException(e); } } Combo combo = new Combo(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN); @SuppressWarnings("hiding") final Composite functionContainer = tk().createComposite(parent, SWT.NONE); final List<String> content = Lists.newArrayList(functions.keySet()); combo.setItems(content.stream().toArray(String[]::new)); combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String functionTitle = content.get(combo.getSelectionIndex()); RefineFunction function = functions.get(functionTitle); UIUtils.disposeChildren(functionContainer); // create panel IPanelSection section = tk().createPanelSection(functionContainer, function.description(), SWT.BORDER); section.setExpanded(true); section.getBody().setLayout(FormLayoutFactory.defaults().create()); function.createContents(tk(), section.getBody()); FormDataFactory.on(section.getBody()).fill(); functionContainer.layout(); } }); // layout final Label selectLabel = tk().createLabel(parent, i18n.get("selectFunction"), SWT.NONE); FormDataFactory.on(selectLabel).top(1).left(1); FormDataFactory.on(combo).top(selectLabel, 3).left(1).noBottom(); FormDataFactory.on(functionContainer).fill().top(combo, 5); }
From source file:com.haulmont.cuba.web.app.ui.core.settings.SettingsWindow.java
@Override public void init(Map<String, Object> params) { Boolean changeThemeEnabledParam = (Boolean) params.get("changeThemeEnabled"); if (changeThemeEnabledParam != null) { changeThemeEnabled = changeThemeEnabledParam; }/*from w w w . j a v a2 s . c o m*/ AppWorkArea.Mode mode = userSettingsTools.loadAppWindowMode(); msgTabbed = getMessage("modeTabbed"); msgSingle = getMessage("modeSingle"); modeOptions.setOptionsList(Arrays.asList(msgTabbed, msgSingle)); if (mode == AppWorkArea.Mode.TABBED) modeOptions.setValue(msgTabbed); else modeOptions.setValue(msgSingle); ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME); Set<String> supportedThemes = themeRepository.getAvailableThemes(); appThemeField.setOptionsList(new ArrayList<>(supportedThemes)); String userAppTheme = userSettingsTools.loadAppWindowTheme(); appThemeField.setValue(userAppTheme); ComboBox vAppThemeField = (ComboBox) WebComponentsHelper.unwrap(appThemeField); vAppThemeField.setTextInputAllowed(false); appThemeField.setEditable(changeThemeEnabled); initTimeZoneFields(); User user = userSession.getUser(); changePasswordBtn.setAction( new BaseAction("changePassw").withCaption(getMessage("changePassw")).withHandler(event -> { Window passwordDialog = openWindow("sec$User.changePassword", OpenType.DIALOG, ParamsMap.of("currentPasswordRequired", true)); passwordDialog.addCloseListener(actionId -> { // move focus back to window changePasswordBtn.requestFocus(); }); })); if (!user.equals(userSession.getCurrentOrSubstitutedUser()) || ExternalUserCredentials.isLoggedInWithExternalAuth(userSession)) { changePasswordBtn.setEnabled(false); } Map<String, Locale> locales = globalConfig.getAvailableLocales(); TreeMap<String, Object> options = new TreeMap<>(); for (Map.Entry<String, Locale> entry : locales.entrySet()) { options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue())); } appLangField.setOptionsMap(options); appLangField.setValue(userManagementService.loadOwnLocale()); Action commitAction = new BaseAction("commit").withCaption(messages.getMainMessage("actions.Ok")) .withShortcut(clientConfig.getCommitShortcut()).withHandler(event -> commit()); addAction(commitAction); okBtn.setAction(commitAction); cancelBtn.setAction(new BaseAction("cancel").withCaption(messages.getMainMessage("actions.Cancel")) .withHandler(event -> cancel())); initDefaultScreenField(); }
From source file:com.ibm.sbt.security.authentication.oauth.consumer.HMACOAuth1Handler.java
/** * createAuthorizationHeader/*w w w.j a v a 2 s .c om*/ * * @param url * @param params * @return */ public String createAuthorizationHeader(String url, Map<String, String> params) throws OAuthException { String nonce = getNonce(); String timeStamp = getTimestamp(); String consumerKey = getConsumerKey(); String consumerSecret = getConsumerSecret(); String method = Context.get().getHttpRequest().getMethod(); /* * This is the Access Token which is obtained from the Application, while registering the App. User * will have to create these tokens, in the application, if not generated already. This Access Token * if required for executing APIs on Twitter. */ /* This is the Access Token Secret which is obtained from the getAccessTokenFromServer() method. */ String tokenSecret = getAccessTokenSecret(); /* * Generate a map of parameters which are required for creating signature. We are using a TreeMap here * instead of Linked HashMap, since the authorization header creates a signature using the parameters * passed by the User for API Execution. And all these parameters need to be sorted for Twitter * Signature generation. */ TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put(Configuration.CONSUMER_KEY, consumerKey); treeMap.put(Configuration.NONCE, nonce); treeMap.put(Configuration.SIGNATURE_METHOD, getSignatureMethod()); treeMap.put(Configuration.VERSION, Configuration.OAUTH_VERSION1); treeMap.put(Configuration.TIMESTAMP, timeStamp); treeMap.put(Configuration.OAUTH_TOKEN, applicationAccessToken); for (Map.Entry<String, String> entry : params.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); treeMap.put(key, value); } String signature = ""; try { // generate the complete URL first signature = HMACEncryptionUtility.generateHMACSignature(url, method, consumerSecret, tokenSecret, treeMap); } catch (Exception e) { throw new OAuthException(e, "createAuthorizationHeader failed with Exception"); } StringBuilder headerStr = new StringBuilder(); headerStr.append("OAuth ").append(Configuration.CONSUMER_KEY).append("=\"").append(consumerKey) .append("\""); headerStr.append(",").append(Configuration.NONCE).append("=\"").append(nonce).append("\""); try { headerStr.append(",").append(Configuration.SIGNATURE).append("=\"") .append(URLEncoder.encode(signature, "UTF-8")).append("\""); } catch (UnsupportedEncodingException e1) { throw new OAuthException(e1, "createAuthorizationHeader failed with UnsupportedEncodingException"); } headerStr.append(",").append(Configuration.SIGNATURE_METHOD).append("=\"").append(getSignatureMethod()) .append("\""); headerStr.append(",").append(Configuration.TIMESTAMP).append("=\"").append(timeStamp).append("\""); headerStr.append(",").append(Configuration.OAUTH_TOKEN).append("=\"").append(applicationAccessToken) .append("\""); headerStr.append(",").append(Configuration.VERSION).append("=\"").append(Configuration.OAUTH_VERSION1) .append("\""); return headerStr.toString(); }
From source file:com.amazonaws.services.sns.util.SignatureChecker.java
private TreeMap<String, String> publishMessageValues(Map<String, String> parsedMessage) { TreeMap<String, String> signables = new TreeMap<String, String>(); String[] keys = { MESSAGE, MESSAGE_ID, SUBJECT, TYPE, TIMESTAMP, TOPIC }; for (String key : keys) { if (parsedMessage.containsKey(key)) { signables.put(key, parsedMessage.get(key)); }/*from www .j a va 2 s. c om*/ } return signables; }