List of usage examples for com.google.common.collect Maps newTreeMap
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap()
From source file:org.waveprotocol.box.server.robots.RobotSerializerModule.java
@Provides @Singleton//from w w w . jav a 2s . c o m @Inject RobotSerializer provideRobotSerializer() { NavigableMap<ProtocolVersion, Gson> gsons = Maps.newTreeMap(); Gson gsonForPostV2 = new GsonFactory().create(); gsons.put(ProtocolVersion.V2_2, gsonForPostV2); // Remove lines below if we want to stop support for <0.22 gsons.put(ProtocolVersion.V2_1, gsonForPostV2); GsonFactory factoryForV2 = new GsonFactory(); ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2(); factoryForV2.registerTypeAdapter(Element.class, elementGsonAdaptorV2); factoryForV2.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2); gsons.put(ProtocolVersion.V2, factoryForV2.create()); return new RobotSerializer(gsons, ProtocolVersion.DEFAULT); }
From source file:org.sonatype.nexus.jmx.reflect.DescriptorHelper.java
/** * Build descriptor for given annotations. *//*from ww w .j a va 2 s . c o m*/ public static Descriptor build(final Annotation... annotations) { checkNotNull(annotations); log.trace("Building descriptor for annotations: {}", Arrays.asList(annotations)); Map<String, Object> fields = Maps.newTreeMap(); // TODO: consider caching which annotations actually have keys, perhaps even which methods // TODO: ... to avoid rescanning the list over and over? // find all DescriptorKey annotations for (Annotation annotation : findAllAnnotations(annotations)) { log.trace("Scanning annotation: {}", annotation); for (Method method : annotation.annotationType().getMethods()) { log.trace("Scanning method: {}", method); DescriptorKey key = method.getAnnotation(DescriptorKey.class); if (key == null) { continue; } log.trace("Found key: {}", key); // extract name and value for key String name = key.value(); Object value = null; try { value = method.invoke(annotation); } catch (Exception e) { Throwables.propagate(e); } // skip if there is no value if (value == null) { continue; } // convert types as described by DescriptorKey javadocs if (value instanceof Class) { // class constant value = ((Class) value).getCanonicalName(); } else if (value instanceof Enum) { // enum constant value = ((Enum) value).name(); } else if (value.getClass().isArray()) { Class<?> componentType = value.getClass().getComponentType(); if (Class.class.equals(componentType)) { // array of class constants, convert to string[] Class[] classes = (Class[]) value; String[] strings = new String[classes.length]; for (int i = 0; i < classes.length; i++) { strings[i] = classes[i].getName(); } value = strings; } else if (Enum.class.equals(componentType)) { // array of enum constants, convert to string[] Enum[] enums = (Enum[]) value; String[] strings = new String[enums.length]; for (int i = 0; i < enums.length; i++) { strings[i] = enums[i].name(); } value = strings; } else if (Annotation.class.equals(componentType)) { // annotations are forbidden throw new InvalidDescriptorKeyException(key, annotation, method); } // other component-types should be valid } else if (value instanceof Annotation) { // annotations are forbidden throw new InvalidDescriptorKeyException(key, annotation, method); } // other types should be valid fields.put(name, value); } } return new ImmutableDescriptor(fields); }
From source file:org.apache.tajo.engine.codegen.CaseWhenSwitchGenerator.java
public CaseWhenSwitchGenerator(EvalCodeGenerator generator, EvalCodeGenContext context, Stack<EvalNode> stack, TajoGeneratorAdapter.SwitchCase[] cases, EvalNode defaultEval) { this.generator = generator; this.context = context; this.stack = stack; this.casesMap = Maps.newTreeMap(); for (TajoGeneratorAdapter.SwitchCase switchCase : cases) { this.casesMap.put(switchCase.key(), switchCase); }/*from w ww. j av a 2 s . c om*/ this.defaultEval = defaultEval; }
From source file:nl.knaw.huygens.timbuctoo.model.base.BaseLocation.java
@Override public Map<String, String> createRelSearchRep(Map<String, String> mappedIndexInformation) { TreeMap<String, String> filteredMap = Maps.newTreeMap(); addValueToMap(mappedIndexInformation, filteredMap, URN); addValueToMap(mappedIndexInformation, filteredMap, LATITUDE); addValueToMap(mappedIndexInformation, filteredMap, LONGITUDE); return filteredMap; }
From source file:com.cloudera.science.ml.core.vectors.Weighted.java
/** * Sample items from a {@code List<Weighted<T>>} where items with higher weights * have a higher probability of being included in the sample. * //w w w .j a va2 s. c om * @param things The iterable to sample from * @param size The number of items to sample * @return A list containing the sampled items */ public static <T> List<Weighted<T>> sample(Iterable<Weighted<T>> things, int size, Random random) { if (random == null) { random = new Random(); } SortedMap<Double, Weighted<T>> sampled = Maps.newTreeMap(); for (Weighted<T> thing : things) { if (thing.weight() > 0) { double score = Math.log(random.nextDouble()) / thing.weight(); if (sampled.size() < size || score > sampled.firstKey()) { sampled.put(score, thing); } if (sampled.size() > size) { sampled.remove(sampled.firstKey()); } } } return Lists.newArrayList(sampled.values()); }
From source file:com.cloudera.oryx.computation.common.summary.SummaryStats.java
public SummaryStats(String name, Map<String, Entry> histogram, boolean trimmed) { this.name = name; this.numeric = null; this.histogram = Maps.newTreeMap(); if (histogram != null) { this.histogram.putAll(histogram); }//w w w.j a v a 2 s . c o m if (trimmed) { this.trimmed = Boolean.TRUE; } }
From source file:com.cloudera.oryx.kmeans.computation.local.SamplingRun.java
@Override public Collection<RealVector> call() throws Exception { SortedMap<Double, RealVector> reservoir = Maps.newTreeMap(); for (RealVector v : vecs) { Distance d = index.getDistance(v, foldId, true); if (d.getSquaredDistance() > 0.0) { double score = Math.log(random.nextDouble()) / d.getSquaredDistance(); if (reservoir.size() < sampleCount) { reservoir.put(score, v); } else if (score > reservoir.firstKey()) { reservoir.remove(reservoir.firstKey()); reservoir.put(score, v); }//from ww w.jav a2s .c o m } } return reservoir.values(); }
From source file:com.shaie.utils.IndexUtils.java
/** Prints the terms indexed under the given fields with full postings information. */ public static void printFieldTermsWithInfo(LeafReader reader, String... fields) throws IOException { for (final String field : fields) { System.out.println(format("Terms for field [%s], with positional info:", field)); final TermsEnum te = reader.terms(field).iterator(); BytesRef scratch;/* www . j a v a 2 s .c o m*/ PostingsEnum postings = null; while ((scratch = te.next()) != null) { System.out.println(format(" %s", scratch.utf8ToString())); postings = te.postings(postings, PostingsEnum.ALL); for (postings.nextDoc(); postings.docID() != DocIdSetIterator.NO_MORE_DOCS; postings.nextDoc()) { final Map<Integer, BytesRef> positions = Maps.newTreeMap(); boolean addedPayload = false; for (int i = 0; i < postings.freq(); i++) { final int pos = postings.nextPosition(); final BytesRef payload = postings.getPayload(); if (payload != null) { positions.put(pos, BytesRef.deepCopyOf(payload)); addedPayload = true; } else { positions.put(pos, null); } } if (addedPayload) { System.out.println( format(" doc=%d, freq=%d", postings.docID(), postings.freq(), positions)); for (final Entry<Integer, BytesRef> e : positions.entrySet()) { System.out.println(format(" pos=%d, payload=%s", e.getKey(), e.getValue())); } } else { System.out.println(format(" doc=%d, freq=%d, pos=%s", postings.docID(), postings.freq(), positions.keySet())); } } } } }
From source file:com.netflix.astyanax.shallows.EmptyCheckpointManager.java
@Override public SortedMap<String, String> getCheckpoints() throws ConnectionException { return Maps.newTreeMap(); }
From source file:reconcile.hbase.query.MeasureRowSizeDistribution.java
/** * Just a generic print function given an iterator. Not necessarily just for printing a single row * * @param scanner// w w w . j ava2s .c om * @throws IOException */ public static void printRow(ResultScanner scanner, int tick) throws IOException { // iterates through and prints int rows = 0; Map<Integer, Integer> mbMap = Maps.newTreeMap(); Map<Integer, Integer> kbMap = Maps.newTreeMap(); Timer t = new Timer(tick); for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { t.increment(); rows++; ImmutableBytesWritable bytes = rr.getBytes(); byte[] buf = bytes.get(); int offset = bytes.getOffset(); int kb = getKB(buf.length - offset); int mb = getMB(buf.length - offset); MapUtil.addCount(kbMap, kb); MapUtil.addCount(mbMap, mb); // print out the row we found and the columns we were looking for } System.out.println("mb size:"); for (int k : mbMap.keySet()) { System.out.println(k + ": " + mbMap.get(k)); } System.out.println("kb size:"); for (int k : kbMap.keySet()) { System.out.println(k + ": " + kbMap.get(k)); } System.out.println("total rows: " + rows); t.end(); }