List of usage examples for java.lang String CASE_INSENSITIVE_ORDER
Comparator CASE_INSENSITIVE_ORDER
To view the source code for java.lang String CASE_INSENSITIVE_ORDER.
Click Source Link
From source file:com.jci.utils.CommonUtils.java
/** * Gets the git json mapping./* w w w .j a v a 2 s .co m*/ * * @param destName the dest name * @param jasonValue the jason value * @return the git json mapping * @throws JsonParseException the json parse exception * @throws JsonMappingException the json mapping exception * @throws IOException Signals that an I/O exception has occurred. */ public TreeMap<String, HashMap<Integer, String>> getGitJsonMapping(String destName, String jasonValue) throws JsonParseException, JsonMappingException, IOException { HashMap<Integer, String> map = null; ObjectMapper mapper = new ObjectMapper(); TreeMap<String, HashMap<Integer, String>> mappingList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); TypeReference<HashMap<Integer, String>> typeRef = new TypeReference<HashMap<Integer, String>>() { }; map = mapper.readValue(jasonValue, typeRef); mappingList.put(destName, map); return mappingList; }
From source file:eu.planets_project.pp.plato.massmigration.MassMigrationRunner.java
public void run() { sourceDir = new File(setup.getSourcePath()); resultDir = new File(setup.getResultPath()); if (!sourceDir.exists() || !sourceDir.isDirectory() || !sourceDir.canRead()) { setup.getStatus().setStatus(MassMigrationStatus.FAILED); throw new IllegalArgumentException("Cannot read from source directory: " + setup.getSourcePath()); }/*ww w .j av a 2s. c o m*/ File currentResultdir = new File(resultDir, setup.getName() + "-" + System.nanoTime()); setup.setLastResultPath(currentResultdir.getAbsolutePath()); if (!currentResultdir.mkdirs()) { setup.getStatus().setStatus(MassMigrationStatus.FAILED); throw new IllegalArgumentException("Cannot write to result directory: " + setup.getSourcePath()); } try { File[] list = sourceDir.listFiles(new FileDirectoryFilter()); List<String> array = new ArrayList<String>(); for (int i = 0; i < list.length; i++) { array.add(list[i].getName()); } inputFiles = array.toArray(new String[] {}); java.util.Arrays.sort(inputFiles, String.CASE_INSENSITIVE_ORDER); Map<String, String> alternativesPaths = new HashMap<String, String>(); // create directories for each alternative for (MassMigrationExperiment exp : setup.getExperiments()) { String altPath = FileUtils.makeFilename(makeUniqueActionName(exp.getAction())); File dir = new File(currentResultdir, altPath); if (dir.mkdir()) { // add this path only if it can be created alternativesPaths.put(exp.getAction().getShortname(), dir.getAbsolutePath()); } } setup.getStatus().setNumOfSamples(inputFiles.length); setup.getStatus().setNumOfTools(setup.getExperiments().size()); int current = 0; for (String filename : inputFiles) { File file = new File(sourceDir + File.separator + filename); current++; int currentTool = 0; setup.getStatus().setCurrentSample(current); try { byte[] data = FileUtils.getBytesFromFile(file); /* * migrate this file with every migration service, so we have to load it only once */ for (MassMigrationExperiment exp : setup.getExperiments()) { currentTool++; setup.getStatus().setCurrentTool(currentTool); MigrationResult result = runExperiment(exp, file.getName(), data); if ((result != null) && (result.isSuccessful())) { // store migration result String altPath = alternativesPaths.get(exp.getAction().getShortname()); if (altPath != null) { File mResult = new File(altPath, file.getName() + "." + result.getTargetFormat().getDefaultExtension()); OutputStream out = new BufferedOutputStream(new FileOutputStream(mResult)); out.write(result.getMigratedObject().getData().getData()); out.close(); } } } } catch (IOException ioe) { log.error("Could not load file: " + file.getAbsolutePath(), ioe); } catch (Exception e) { log.error( "Exception while running experiment on file " + file.getAbsolutePath() + e.getMessage(), e); } } /* * Calculation finished - collect result values and export them for further calculations */ Locale locale = Locale.getDefault(); NumberFormat format = NumberFormat.getNumberInstance(locale); //new DecimalFormat("##########.##"); ToolExperience toolExp = null; List<String> allProperties = new ArrayList<String>(); Map<String, DetailedExperimentInfo> accumulatedAvg = new HashMap<String, DetailedExperimentInfo>(); for (MassMigrationExperiment e : setup.getExperiments()) { /* calculate average per experiment */ /* put measurements of sample files to toolExp */ toolExp = MeasurementStatistics.generateToolExperience(e.getResult()); /* get calculated average per property */ DetailedExperimentInfo average = MeasurementStatistics.getAverage(toolExp); accumulatedAvg.put(e.getAction().getShortname(), average); e.getAverages().clear(); e.getAverages().put(average); /* a list of all properties to iterate over the values */ allProperties.clear(); allProperties.addAll(toolExp.getMeasurements().keySet()); Collections.sort(allProperties); /* * write all measurements of this experiment to a file */ String statistics = FileUtils.makeFilename(makeUniqueActionName(e.getAction())); File statisticsFile = new File(currentResultdir, statistics + ".csv"); try { BufferedWriter out = new BufferedWriter(new FileWriter(statisticsFile)); StringBuffer header = new StringBuffer(); header.append("sample"); for (String key : allProperties) { header.append(CSV_SEPARATOR).append(key); } /* write header */ out.append(header); out.newLine(); List<String> keySet = new ArrayList<String>(e.getResult().keySet()); String[] toSort = keySet.toArray(new String[] {}); java.util.Arrays.sort(toSort, String.CASE_INSENSITIVE_ORDER); /* write measured values for all samples */ for (int i = 0; i < toSort.length; i++) { String sample = toSort[i]; /* 1. column: sample name */ out.append(sample); /* followed by all properties */ DetailedExperimentInfo info = e.getResult().get(sample); for (String prop : allProperties) { out.append(CSV_SEPARATOR); Measurement m = info.getMeasurements().get(prop); if (m != null) { if (m.getValue() instanceof INumericValue) { /* */ double value = ((INumericValue) m.getValue()).value(); out.append(format.format(value)); } else out.append(m.getValue().toString()); } } out.newLine(); } /* write header again */ out.append(header); out.newLine(); /* and write calculated average */ out.append("average"); for (String key : allProperties) { out.append(CSV_SEPARATOR); Measurement m = e.getAverages().getMeasurements().get(key); if (m != null) { if (m.getValue() instanceof INumericValue) { double value = ((INumericValue) m.getValue()).value(); out.append(format.format(value)); } else out.append(m.getValue().toString()); } } out.newLine(); out.append("startupTime"); out.append(CSV_SEPARATOR); try { out.append(Double.toString(toolExp.getStartupTime())); } catch (Exception ex) { log.error("Error in calculating the startup time (linear regression): " + ex.getMessage()); out.append("Err"); } out.newLine(); out.close(); } catch (IOException e1) { log.error("Could not write statistics for: " + statistics, e1); } } /* * and write accumulated values */ File statisticsFile = new File(currentResultdir, "accumulated.csv"); allProperties.clear(); allProperties.add(MigrationResult.MIGRES_ELAPSED_TIME_PER_MB); allProperties.add(MigrationResult.MIGRES_USED_TIME_PER_MB); allProperties.add(MigrationResult.MIGRES_ELAPSED_TIME); allProperties.add(MigrationResult.MIGRES_USED_TIME); //... try { BufferedWriter out = new BufferedWriter(new FileWriter(statisticsFile)); /* write machine info */ if (toolExp != null) { // use machine info of last experiment! for (String prop : toolExp.getMeasurements().keySet()) { if (prop.startsWith("machine:")) { out.append(prop).append(CSV_SEPARATOR).append(toolExp.getMeasurements().get(prop) .getList().get(0).getValue().getFormattedValue()); out.newLine(); } } out.newLine(); } /* write header */ out.append("tool"); for (String key : allProperties) { out.append(CSV_SEPARATOR).append(key); } out.newLine(); /* write averaged values for all actions */ for (String action : accumulatedAvg.keySet()) { /* 1. column: action name */ out.append(action); /* followed by all properties */ DetailedExperimentInfo average = accumulatedAvg.get(action); for (String prop : allProperties) { out.append(CSV_SEPARATOR); Measurement m = average.getMeasurements().get(prop); if (m != null) { if (m.getValue() instanceof INumericValue) { /* */ double value = ((INumericValue) m.getValue()).value(); out.append(format.format(value)); } else out.append(m.getValue().toString()); } } out.newLine(); } out.newLine(); out.close(); } catch (IOException e1) { log.error("Could not write accumulated statistics.", e1); } setup.getStatus().setStatus(MassMigrationStatus.FINISHED); } catch (RuntimeException e) { setup.getStatus().setStatus(MassMigrationStatus.FAILED); log.error("Massmigration failed.", e); } }
From source file:com.galeoconsulting.leonardinius.api.impl.ServletVelocityHelperImpl.java
@Override public List<LanguageBean> getRegisteredLanguages() { List<LanguageBean> list = Lists.newArrayList(); for (ScriptEngineFactory factory : scriptService.getRegisteredScriptEngines()) { list.add(LanguageBean.valueOf(factory)); }/* ww w . j a v a 2 s . c o m*/ Collections.sort(list, new Comparator<LanguageBean>() { @Override public int compare(LanguageBean o1, LanguageBean o2) { return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()); } }); return list; }
From source file:uk.org.rbc1b.roms.db.common.MergeUtilTest.java
@Test public void testMergeOverlappingStrings() { final List<Pair<String, String>> outputs = new ArrayList<Pair<String, String>>(); MergeUtil.merge(Arrays.asList("bar", "foo"), Arrays.asList("foo", "quux"), String.CASE_INSENSITIVE_ORDER, new MergeUtil.Callback<String, String>() { @Override/* www. j av a 2 s .c o m*/ public void output(String leftValue, String rightValue) { outputs.add(new ImmutablePair<String, String>(leftValue, rightValue)); } }); assertEquals(Arrays.asList(new ImmutablePair<String, String>("bar", null), new ImmutablePair<String, String>("foo", "foo"), new ImmutablePair<String, String>(null, "quux")), outputs); }
From source file:com.pearson.pdn.learningstudio.helloworld.OAuth1SignatureServlet.java
private String normalizeParams(String httpMethod, URL url, Map<String, String> oauthParams, byte[] requestBody) throws UnsupportedEncodingException { // Sort the parameters in lexicographical order, 1st by Key then by Value Map<String, String> kvpParams = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); kvpParams.putAll(oauthParams);/* w ww . j a va 2s .c o m*/ // Place any query string parameters into a key value pair using equals // ("=") to mark // the key/value relationship and join each parameter with an ampersand // ("&") if (url.getQuery() != null) { for (String keyValue : url.getQuery().split("&")) { String[] p = keyValue.split("="); kvpParams.put(p[0], p[1]); } } // Include the body parameter if dealing with a POST or PUT request if ("POST".equals(httpMethod) || "PUT".equals(httpMethod)) { String body = Base64.encodeBase64String(requestBody).replaceAll("\r\n", ""); // url encode the body 2 times now before combining other params body = URLEncoder.encode(body, "UTF-8"); body = URLEncoder.encode(body, "UTF-8"); kvpParams.put("body", body); } // separate the key and values with a "=" // separate the kvp with a "&" StringBuilder combinedParams = new StringBuilder(); String delimiter = ""; for (String key : kvpParams.keySet()) { combinedParams.append(delimiter); combinedParams.append(key); combinedParams.append("="); combinedParams.append(kvpParams.get(key)); delimiter = "&"; } // url encode the entire string again before returning return URLEncoder.encode(combinedParams.toString(), "UTF-8"); }
From source file:io.cloudslang.content.amazon.services.helpers.AwsSignatureHelper.java
/** * Creates a comma separated list of headers. * * @param headers Headers to be signed./* www .j ava 2 s.c om*/ * @return Comma separated list of headers to be signed. */ public String getSignedHeadersString(Map<String, String> headers) { List<String> sortedList = new ArrayList<>(headers.keySet()); Collections.sort(sortedList, String.CASE_INSENSITIVE_ORDER); StringBuilder signedHeaderString = new StringBuilder(); for (String header : sortedList) { if (signedHeaderString.length() > START_INDEX) { signedHeaderString.append(SEMICOLON); } signedHeaderString.append(nullToEmpty(header).toLowerCase()); } return signedHeaderString.toString(); }
From source file:edu.pitt.dbmi.ipm.service.storage.Storage.java
/** * Return query result as array of Strings * /*ww w .ja v a 2 s . c om*/ * @param res * @param jObj * @param jArr * @param val * @return Strings[] */ public String[] jsonResAsArray(JSONObject res, String jObj, String jArr, String val) { try { JSONArray bindings = (res.getJSONObject(jObj)).getJSONArray(jArr); String userID = null; List<String> rr = new ArrayList<String>(); for (int i = 0; i < bindings.length(); i++) { JSONObject c = bindings.getJSONObject(i); rr.add(new JSONObject(c.getString(val)).getString("value")); } Collections.sort(rr, String.CASE_INSENSITIVE_ORDER); String[] toret = rr.toArray(new String[rr.size()]); rr.clear(); rr = null; return toret; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:org.docrj.smartcard.reader.AppViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww. j ava2s . co m*/ toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); // persistent data in shared prefs SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE); mEditor = ss.edit(); mSelectedAppPos = ss.getInt("selected_app_pos", 0); Gson gson = new Gson(); String json = ss.getString("groups", null); if (json == null) { mUserGroups = new LinkedHashSet<>(); } else { Type collectionType = new TypeToken<LinkedHashSet<String>>() { }.getType(); mUserGroups = gson.fromJson(json, collectionType); } // alphabetize, case insensitive mSortedAllGroups = new ArrayList<>(mUserGroups); mSortedAllGroups.addAll(Arrays.asList(DEFAULT_GROUPS)); Collections.sort(mSortedAllGroups, String.CASE_INSENSITIVE_ORDER); // when deleting an app results in an empty group, we remove the group; // we may need to adjust group position indices for batch select and app // browse activities, which apply to the sorted list of groups mSelectedGrpPos = ss.getInt("selected_grp_pos", 0); mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos); mExpandedGrpPos = ss.getInt("expanded_grp_pos", -1); mExpandedGrpName = (mExpandedGrpPos == -1) ? "" : mSortedAllGroups.get(mExpandedGrpPos); Intent intent = getIntent(); mAppPos = intent.getIntExtra(EXTRA_APP_POS, 0); mName = (EditText) findViewById(R.id.app_name); mAid = (EditText) findViewById(R.id.app_aid); mType = (RadioGroup) findViewById(R.id.radio_grp_type); mNote = (TextView) findViewById(R.id.note); mGroups = (TextView) findViewById(R.id.group_list); // view only mName.setFocusable(false); mAid.setFocusable(false); for (int i = 0; i < mType.getChildCount(); i++) { mType.getChildAt(i).setClickable(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); w.setStatusBarColor(getResources().getColor(R.color.primary_dark)); } }
From source file:com.evolveum.midpoint.web.component.search.TextPopupPanel.java
private List<String> prepareAutoCompleteList(String input) { List<String> values = new ArrayList<>(); if (lookup == null || lookup.asObjectable().getRow() == null) { return values; }/*from w ww . jav a 2s . c o m*/ List<LookupTableRowType> rows = new ArrayList<>(); rows.addAll(lookup.asObjectable().getRow()); Collections.sort(rows, new Comparator<LookupTableRowType>() { @Override public int compare(LookupTableRowType o1, LookupTableRowType o2) { String s1 = WebComponentUtil.getOrigStringFromPoly(o1.getLabel()); String s2 = WebComponentUtil.getOrigStringFromPoly(o2.getLabel()); return String.CASE_INSENSITIVE_ORDER.compare(s1, s2); } }); for (LookupTableRowType row : rows) { String rowLabel = WebComponentUtil.getOrigStringFromPoly(row.getLabel()); if (StringUtils.isEmpty(input) || rowLabel.toLowerCase().startsWith(input.toLowerCase())) { values.add(rowLabel); } if (values.size() > MAX_ITEMS) { break; } } return values; }
From source file:org.carewebframework.ui.xml.ZK2XML.java
/** * Adds the root component to the XML document at the current level along with all bean * properties that return String or primitive types. Then, recurses over all of the root * component's children.// ww w .ja v a 2s.c o m * * @param root The root component. * @param parent The parent XML node. */ private void toXML(Component root, Node parent) { TreeMap<String, String> properties = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); Class<?> clazz = root.getClass(); ComponentDefinition def = root.getDefinition(); String cmpname = def.getName(); if (def.getImplementationClass() != clazz) { properties.put("use", clazz.getName()); } if (def.getApply() != null) { properties.put("apply", def.getApply()); } Node child = doc.createElement(cmpname); parent.appendChild(child); for (PropertyDescriptor propDx : PropertyUtils.getPropertyDescriptors(root)) { Method getter = propDx.getReadMethod(); Method setter = propDx.getWriteMethod(); String name = propDx.getName(); if (getter != null && setter != null && !isExcluded(name, cmpname, null) && !setter.isAnnotationPresent(Deprecated.class) && (getter.getReturnType() == String.class || getter.getReturnType().isPrimitive())) { try { Object raw = getter.invoke(root); String value = raw == null ? null : raw.toString(); if (StringUtils.isEmpty(value) || ("id".equals(name) && value.startsWith("z_")) || isExcluded(name, cmpname, value)) { continue; } properties.put(name, value.toString()); } catch (Exception e) { } } } for (Entry<String, String> entry : properties.entrySet()) { Attr attr = doc.createAttribute(entry.getKey()); child.getAttributes().setNamedItem(attr); attr.setValue(entry.getValue()); } properties = null; for (Component cmp : root.getChildren()) { toXML(cmp, child); } }