List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.apache.hadoop.hbase.regionserver.tableindexed.IndexMaintenanceUtils.java
public static Put createIndexUpdate(final IndexSpecification indexSpec, final byte[] row, final SortedMap<byte[], byte[]> columnValues) { byte[] indexRow = indexSpec.getKeyGenerator().createIndexKey(row, columnValues); Put update = new Put(indexRow); update.add(IndexedTable.INDEX_COL_FAMILY, IndexedTable.INDEX_BASE_ROW, row); for (byte[] col : indexSpec.getIndexedColumns()) { byte[] val = columnValues.get(col); if (val == null) { throw new RuntimeException("Unexpected missing column value. [" + Bytes.toString(col) + "]"); }// w w w . j av a 2s. c om byte[][] colSeperated = KeyValue.parseColumn(col); update.add(colSeperated[0], colSeperated[1], val); } for (byte[] col : indexSpec.getAdditionalColumns()) { byte[] val = columnValues.get(col); if (val != null) { byte[][] colSeperated = KeyValue.parseColumn(col); update.add(colSeperated[0], colSeperated[1], val); } } return update; }
From source file:annis.CSVHelper.java
public static SortedMap<Integer, SortedSet<String>> exportCSVHeader(Iterator<AnnotatedMatch> matches, PrintWriter w) {/* w ww . j a v a 2 s.c o m*/ // figure out what annotations are used at each match position SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<>(); while (matches.hasNext()) { AnnotatedMatch match = matches.next(); for (int j = 0; j < match.size(); ++j) { AnnotatedSpan span = match.get(j); if (columnsByNodePos.get(j) == null) { columnsByNodePos.put(j, new TreeSet<String>()); } for (Annotation annotation : span.getAnnotations()) { columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName()); } for (Annotation meta : span.getMetadata()) { columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName()); } } } CSVWriter csvWriter = new CSVWriter(w, '\t', CSVWriter.NO_QUOTE_CHARACTER, '\\'); // print column names and data types int count = columnsByNodePos.keySet().size(); ArrayList<String> headerLine = new ArrayList<>(); for (int j = 0; j < count; ++j) { headerLine.add(fullColumnName(j + 1, "id")); headerLine.add(fullColumnName(j + 1, "span")); SortedSet<String> annotationNames = columnsByNodePos.get(j); for (String name : annotationNames) { headerLine.add(fullColumnName(j + 1, name)); } } csvWriter.writeNext(headerLine.toArray(new String[headerLine.size()])); return columnsByNodePos; }
From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexMaintenanceUtils.java
public static Put createOrgUpdate(final byte[] row, final SortedMap<byte[], byte[]> columnValues) { byte[] indexRow = row; Put update = null;/*from w w w . ja va 2s.co m*/ update = new Put(indexRow); for (byte[] col : columnValues.keySet()) { try { byte[] val = columnValues.get(col); byte[][] colSeperated = HStoreKey.parseColumn(col); update.add(colSeperated[0], colSeperated[1], val); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); continue; } } return update; }
From source file:arun.com.chromer.util.ColorUtil.java
@ColorInt public static int getClosestAccentColor(@ColorInt int color) { final SortedMap<Double, Integer> set = new TreeMap<>(); color = (0xFFFFFF - color) | 0xFF000000; for (int i = 0; i < ACCENT_COLORS_700.length; i++) { set.put(colorDifference(color, ACCENT_COLORS_700[i]), i); }/*from w ww. j av a2 s. c o m*/ return ACCENT_COLORS_700[set.get(set.firstKey())]; }
From source file:Main.java
/** * Converter Map<Object, Object> instance to xml string. Note: currently, we * aren't consider more about some collection types, such as array,list, * * @param dataMap//from w w w . j a v a 2 s . c o m * the data map * * @return the string */ public static String converter(SortedMap<String, String> dataMap) { StringBuilder strBuilder = new StringBuilder(); strBuilder.append("<xml>\n"); Set<String> objSet = dataMap.keySet(); for (Object key : objSet) { if (key == null) { continue; } strBuilder.append("<").append(key.toString()).append(">"); Object value = dataMap.get(key); strBuilder.append(coverter(value)); strBuilder.append("</").append(key.toString()).append(">\n"); } strBuilder.append("</xml>"); return strBuilder.toString(); }
From source file:annis.WekaHelper.java
public static String exportAsArff(List<AnnotatedMatch> annotatedMatches) { StringBuilder sb = new StringBuilder(); // header: relation name (unused) sb.append("@relation name\n"); sb.append("\n"); // figure out what annotations are used at each match position SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<Integer, SortedSet<String>>(); for (int i = 0; i < annotatedMatches.size(); ++i) { AnnotatedMatch match = annotatedMatches.get(i); for (int j = 0; j < match.size(); ++j) { AnnotatedSpan span = match.get(j); if (columnsByNodePos.get(j) == null) { columnsByNodePos.put(j, new TreeSet<String>()); }/* w w w . j a v a 2 s . c o m*/ for (Annotation annotation : span.getAnnotations()) { columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName()); } for (Annotation meta : span.getMetadata()) { columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName()); } } } // print column names and data types int count = columnsByNodePos.keySet().size(); for (int j = 0; j < count; ++j) { sb.append("@attribute ").append(fullColumnName(j + 1, "id")).append(" string\n"); sb.append("@attribute ").append(fullColumnName(j + 1, "span")).append(" string\n"); SortedSet<String> annotationNames = columnsByNodePos.get(j); for (String name : annotationNames) { sb.append("@attribute ").append(fullColumnName(j + 1, name)).append(" string\n"); } } sb.append("\n@data\n\n"); // print values for (AnnotatedMatch match : annotatedMatches) { List<String> line = new ArrayList<String>(); int k = 0; for (; k < match.size(); ++k) { AnnotatedSpan span = match.get(k); Map<String, String> valueByName = new HashMap<String, String>(); if (span != null) { if (span.getAnnotations() != null) { for (Annotation annotation : span.getAnnotations()) { valueByName.put("anno_" + annotation.getQualifiedName(), annotation.getValue()); } } if (span.getMetadata() != null) { for (Annotation meta : span.getMetadata()) { valueByName.put("meta_" + meta.getQualifiedName(), meta.getValue()); } } line.add("'" + span.getId() + "'"); line.add("'" + span.getCoveredText().replace("'", "\\'") + "'"); } for (String name : columnsByNodePos.get(k)) { if (valueByName.containsKey(name)) { line.add("'" + valueByName.get(name).replace("'", "\\'") + "'"); } else { line.add("'NULL'"); } } } for (int l = k; l < count; ++l) { line.add("'NULL'"); for (int m = 0; m <= columnsByNodePos.get(l).size(); ++m) { line.add("'NULL'"); } } sb.append(StringUtils.join(line, ",")); sb.append("\n"); } return sb.toString(); }
From source file:nu.yona.app.api.service.ActivityMonitorService.java
private static String printForegroundTask(Context context) { currentApp = "NULL"; try {/*from w ww . j av a2 s. c o m*/ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); long time = System.currentTimeMillis(); List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - AppConstant.ONE_SECOND * AppConstant.ONE_SECOND, time); if (appList != null && appList.size() > 0) { SortedMap<Long, UsageStats> mySortedMap = new TreeMap<>(); for (UsageStats usageStats : appList) { mySortedMap.put(usageStats.getLastTimeUsed(), usageStats); } if (!mySortedMap.isEmpty()) { currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName(); } } } else { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); currentApp = am.getRunningAppProcesses().get(0).processName; } } catch (Exception e) { AppUtils.reportException(ActivityMonitorService.class.getSimpleName(), e, Thread.currentThread()); } return currentApp; }
From source file:com.taobao.android.builder.tasks.manager.transform.TransformManager.java
public static List<TransformTask> findTransformTaskByTransformType(AppVariantContext appVariantContext, Class<?> transformClass) { List<TransformTask> transformTasksList = Lists.newArrayList(); VariantConfiguration config = appVariantContext.getVariantConfiguration(); TaskCollection<TransformTask> transformTasks = appVariantContext.getProject().getTasks() .withType(TransformTask.class); SortedMap<String, TransformTask> transformTaskSortedMap = transformTasks.getAsMap(); String variantName = config.getFullName(); for (String taskName : transformTaskSortedMap.keySet()) { TransformTask transformTask = transformTaskSortedMap.get(taskName); if (variantName == transformTask.getVariantName()) { if (transformTask.getTransform().getClass() == transformClass) { transformTasksList.add(transformTask); }/* w w w. j ava 2 s. c o m*/ } } return transformTasksList; }
From source file:Main.java
public static String getStreamEncoding(InputStream stream) throws IOException { String encoding = null;/* w w w . j a v a 2 s.c om*/ boolean DEBUG = false; if (DEBUG) { SortedMap map = Charset.availableCharsets(); Object[] keys = map.keySet().toArray(); for (int i = 0; i < keys.length; i++) { System.out.println("Key = " + keys[i] + " Value = " + map.get(keys[i])); } } int ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); // UCS-4 Big Endian (1234) if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xFE) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xFF) { encoding = UCS_4BE; } } else if (ch == 0xFF) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xFE) { encoding = UNKNOWN; } } else if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x3C) { encoding = UCS_4BE; } } else if (ch == 0x3C) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UNKNOWN; } } } else if (ch == 0x3C) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UNKNOWN; } else if (ch == 0x3F) { encoding = UTF_16BE; } } } } else if (ch == 0x3C) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UCS_4LE; } } else if (ch == 0x3F) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UTF_16LE; } } } else if (ch == 0x3F) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x78) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x6D) { encoding = UTF_8; } } } } else if (ch == 0xFF) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xFE) { ch = stream.read(); encoding = UTF_16LE; if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UCS_4LE; } } } } else if (ch == 0xFE) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xFF) { ch = stream.read(); encoding = UTF_16BE; if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x00) { encoding = UNKNOWN; } } } } else if (ch == 0xEF) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xBB) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xBF) { // System.out.println( "Found UTF-8 byte order mark."); // strip utf-8 byte order mark stream.mark(1024); encoding = UTF_8; } } } else if (ch == 0x4C) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x6F) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0xA7) { ch = stream.read(); if (DEBUG) System.out.print("[" + ch + "]"); if (ch == 0x94) { encoding = EBCDIC; } } } } if (DEBUG) System.out.println("getStreamEncoding() [" + encoding + "]"); return encoding; }
From source file:org.apache.http.contrib.auth.AWSScheme.java
/** * Returns the canonicalized AMZ headers. * * @param headers// ww w.j a v a 2s.c o m * The list of request headers. * @return The canonicalized AMZ headers. */ private static String getCanonicalizedAmzHeaders(final Header[] headers) { StringBuilder sb = new StringBuilder(); Pattern spacePattern = Pattern.compile("\\s+"); // Create a lexographically sorted list of headers that begin with x-amz SortedMap<String, String> amzHeaders = new TreeMap<String, String>(); for (Header header : headers) { String name = header.getName().toLowerCase(); if (name.startsWith("x-amz-")) { String value = ""; if (amzHeaders.containsKey(name)) value = amzHeaders.get(name) + "," + header.getValue(); else value = header.getValue(); // All newlines and multiple spaces must be replaced with a // single space character. Matcher m = spacePattern.matcher(value); value = m.replaceAll(" "); amzHeaders.put(name, value); } } // Concatenate all AMZ headers for (Entry<String, String> entry : amzHeaders.entrySet()) { sb.append(entry.getKey()).append(':').append(entry.getValue()).append("\n"); } return sb.toString(); }