List of usage examples for com.google.common.collect Maps newTreeMap
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap()
From source file:com.lastcalc.servlets.StatelessServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { final WorksheetRequest request = Misc.gson.fromJson(req.getReader(), WorksheetRequest.class); final WorksheetResponse response = new WorksheetResponse(); if (request.getRecognizedWords) { response.recognizedWords = SequentialParser.recognizedWords; }/* w w w. j av a 2s .c o m*/ final ArrayList<Line> qaPairs = new ArrayList<Line>(); if (request.questions != null) { int earliestModified = Integer.MAX_VALUE; final TreeMap<Integer, String> orderedQuestions = Maps.newTreeMap(); orderedQuestions.putAll(request.questions); for (final Entry<Integer, String> e : orderedQuestions.entrySet()) { final int pos = e.getKey() - 1; if (pos < qaPairs.size()) { final Line qaPair = qaPairs.get(pos); qaPair.question = e.getValue(); earliestModified = Math.min(earliestModified, pos); } else { qaPairs.add(new Line(e.getValue(), null)); } } for (int x = earliestModified; x < qaPairs.size(); x++) { final Line qaPair = qaPairs.get(x); qaPair.answer = null; } // Remove any qaPairs that have been removed from the browser DOM if (!orderedQuestions.isEmpty()) { while (qaPairs.size() > orderedQuestions.lastKey()) { qaPairs.remove(qaPairs.size() - 1); } } } // Recompute worksheet final SequentialParser seqParser = SequentialParser.create(); for (final Line qap : qaPairs) { if (qap.question.trim().length() == 0) { qap.answer = TokenList.createD(); } else { if (qap.answer == null) { qap.answer = seqParser.parseNext(Tokenizer.tokenize(qap.question)); } else { seqParser.processNextAnswer(qap.answer); } } } response.answers = Maps.newHashMap(); response.answerTypes = Maps.newHashMap(); response.variables = seqParser.getUserDefinedKeywordMap(); for (int x = 0; x < qaPairs.size(); x++) { final TokenList answer = qaPairs.get(x).answer; final TokenList strippedAnswer = seqParser.stripUDF(answer); response.answers.put(x + 1, strippedAnswer.toString()); response.answerTypes.put(x + 1, strippedAnswer.size() == 1 && strippedAnswer.get(0) instanceof UserDefinedParser ? AnswerType.FUNCTION : AnswerType.NORMAL); } resp.setContentType("application/json; charset=UTF-8"); Misc.gson.toJson(response, resp.getWriter()); if (Currencies.shouldUpdate()) { Currencies.updateExchangeRates(); } }
From source file:com.outerspacecat.memcache.StaticContinuum.java
/** * Create a new continuum./*from w w w . j av a2 s . c om*/ * * @param nodes the Memcache nodes to use. Must be non {@code null}, must * contain one or more elements, and each element must be non * {@code null}. */ public StaticContinuum(final Iterable<? extends NamedDataSource<MemcacheConnection>> nodes) { Preconditions.checkNotNull(nodes, "nodes required"); Preconditions.checkArgument(nodes.iterator().hasNext(), "nodes must contain at least one element"); for (NamedDataSource<MemcacheConnection> node : nodes) Preconditions.checkNotNull(node, "each nodes element must be non null"); continuum = Maps.newTreeMap(); for (NamedDataSource<MemcacheConnection> node : nodes) { continuum.put(hash(node.getName()), node); for (int i = 0; i < NUM_REPLICAS; ++i) continuum.put(hash(node.getName() + "_" + i), node); } }
From source file:org.apache.druid.indexer.HadoopDruidDetermineConfigurationJob.java
@Override public boolean run() { JobHelper.ensurePaths(config);/*from w w w .j ava 2s . c om*/ if (config.isDeterminingPartitions()) { job = config.getPartitionsSpec().getPartitionJob(config); return JobHelper.runSingleJob(job, config); } else { int shardsPerInterval = config.getPartitionsSpec().getNumShards(); Map<Long, List<HadoopyShardSpec>> shardSpecs = Maps.newTreeMap(); int shardCount = 0; for (Interval segmentGranularity : config.getSegmentGranularIntervals().get()) { DateTime bucket = segmentGranularity.getStart(); if (shardsPerInterval > 0) { List<HadoopyShardSpec> specs = Lists.newArrayListWithCapacity(shardsPerInterval); for (int i = 0; i < shardsPerInterval; i++) { specs.add(new HadoopyShardSpec(new HashBasedNumberedShardSpec(i, shardsPerInterval, config.getPartitionsSpec().getPartitionDimensions(), HadoopDruidIndexerConfig.JSON_MAPPER), shardCount++)); } shardSpecs.put(bucket.getMillis(), specs); log.info("DateTime[%s], spec[%s]", bucket, specs); } else { final HadoopyShardSpec spec = new HadoopyShardSpec(NoneShardSpec.instance(), shardCount++); shardSpecs.put(bucket.getMillis(), Collections.singletonList(spec)); log.info("DateTime[%s], spec[%s]", bucket, spec); } } config.setShardSpecs(shardSpecs); return true; } }
From source file:z.tool.util.CollectionUtil.java
public static <E> List<E> convertTreeList(List<? extends IParent<E>> sourceList) { if (ZUtils.isEmpty(sourceList)) { return Collections.emptyList(); }//from w w w . j a va 2 s. com List<E> treeList = Lists.newArrayList(); // tree map Map<Long, IParent<E>> tMap = Maps.newTreeMap(); for (IParent<E> a : sourceList) { a.clearChildren(); tMap.put(a.getId(), a); } for (IParent<E> r : tMap.values()) { @SuppressWarnings("unchecked") E e = (E) r; if (r.getParentId() > 0 && null != tMap.get(r.getParentId())) { tMap.get(r.getParentId()).addChild(e); } else { treeList.add(e); } } return treeList; }
From source file:com.ibm.vicos.server.VICOSServer.java
protected void startUp() { invokedSequenceNumber = new AtomicLong(-1); executedSequenceNumber = new AtomicLong(-1); operations = Maps.newTreeMap(); authenticators = Maps.newTreeMap();//from w w w . j a v a 2s .com state = new KVSState(Maps.newTreeMap()); final Config config = ConfigFactory.load(); int pendingListMaxLength = config.getInt("vicos.system.flowcontrol.pending-list-max-length"); final Module overrides = Modules.override(new DefaultServerModule()).with(new Module() { @Override public void configure(Binder binder) { binder.bind(AtomicLong.class).annotatedWith(Names.named("lastInvokedSeqNo")) .toInstance(invokedSequenceNumber); binder.bind(AtomicLong.class).annotatedWith(Names.named("lastAppliedSeqNo")) .toInstance(executedSequenceNumber); binder.bind(com.ibm.vicos.common.State.class).annotatedWith(Names.named("")).toInstance(state); binder.bind(new TypeLiteral<NavigableMap<Long, Authenticator>>() { }).toInstance(authenticators); binder.bind(new TypeLiteral<NavigableMap<Long, Operation>>() { }).toInstance(operations); binder.bind(Integer.class).annotatedWith(Names.named("pendingListMaxLength")) .toInstance(pendingListMaxLength); } }); system = ActorSystemInstance.getInstance(config); serverActorRef = system.actorOf( Props.create(GuiceInjector.class, Guice.createInjector(overrides), ServerActor.class), config.getString("vicos.server.name")); }
From source file:cuchaz.enigma.mapping.MethodMapping.java
public MethodMapping(String obfName, MethodDescriptor obfDescriptor, String deobfName, Mappings.EntryModifier modifier) { Preconditions.checkNotNull(obfName, "Method obf name cannot be null"); Preconditions.checkNotNull(obfDescriptor, "Method obf desc cannot be null"); this.obfName = obfName; this.deobfName = NameValidator.validateMethodName(deobfName); this.obfDescriptor = obfDescriptor; this.localVariables = Maps.newTreeMap(); this.modifier = modifier; }
From source file:com.google.transconsole.common.messages.Bundle.java
/** * Constructs an empty Bundle.//w w w . ja va 2 s . c om * * @param projectId Translation Console ID of project (e.g. "gws"). * @param languageId Translation Console ID of language (e.g. "en-US"). */ public Bundle(String projectId, String languageId) { this.projectId = Preconditions.checkNotNull(projectId); this.languageId = Preconditions.checkNotNull(languageId); messages = Maps.newTreeMap(); }
From source file:org.eclipse.wb.internal.swt.model.layout.LayoutDataNameSupport.java
@Override protected Map<String, String> getValueMap() { // prepare variables Map<String, String> valueMap = Maps.newTreeMap(); {//from ww w .j a v a 2 s . c om valueMap.put("dataAcronym", getAcronym()); valueMap.put("dataClassName", getClassName()); valueMap.put("controlName", getParentName()); valueMap.put("controlName-cap", getParentNameCap()); } return valueMap; }
From source file:de.tuberlin.uebb.jdae.transformation.Reduction.java
public Reduction(final Collection<Equation> equations) { final ImmutableList.Builder<GlobalEquation> be = ImmutableList.builder(); this.names = Maps.newTreeMap(); final Map<Unknown, Integer> layout = Maps.newTreeMap(); final TransitiveRelation<Unknown> equivalent = Relations.newTransitiveRelation(); for (Equation eq : equations) { for (Unknown unknown : eq.unknowns()) { final Unknown base = unknown.base(); final Integer order = layout.get(base); if (order == null || (unknown.der > order)) layout.put(base, unknown.der); }//from w w w. j ava 2 s . co m if (eq instanceof Equality) { final Unknown l = ((Equality) eq).lhs; final Unknown r = ((Equality) eq).rhs; Unknown min = Ordering.natural().min(l, r); Unknown max = Ordering.natural().max(l, r); if (min.der == 0) { equivalent.relate(min, max); } } } final Navigator<Unknown> direct = equivalent.direct(); final Map<Unknown, Unknown> repres = Maps.newTreeMap(); for (Map.Entry<Unknown, Integer> entry : layout.entrySet()) { final Unknown base = entry.getKey(); final int max = entry.getValue(); final Unknown repr = Collections.max(Navigators.closure(direct, base), Ordering.natural()); for (int i = 0; i <= max; i++) { repres.put(base.der(i), repr.der(i)); } } final Function<Unknown, GlobalVariable> pack_dense = new Function<Unknown, GlobalVariable>() { final Map<Integer, Integer> mem = Maps.newTreeMap(); public GlobalVariable apply(Unknown u) { if (!mem.containsKey(u.nr)) { mem.put(u.nr, (mem.size() + 1)); names.put(mem.get(u.nr), u.name); } return new GlobalVariable(u.name, mem.get(u.nr), u.der); } }; ctxt = Maps.transformValues(repres, pack_dense); for (Equation eq : equations) { if (eq instanceof Equality) { final Unknown l = ((Equality) eq).lhs; final Unknown r = ((Equality) eq).rhs; final Unknown min = Ordering.natural().min(l, r); if (min.der != 0) be.add(eq.bind(ctxt)); } else { be.add(eq.bind(ctxt)); } } reduced = be.build(); this.unknowns = ImmutableSortedSet.copyOf(ctxt.values()); }
From source file:org.eclipse.wb.internal.core.utils.reflect.IntrospectionHelper.java
/** * @return the consolidated {@link BeanDescriptor}. *///from w w w . j a v a2 s.c o m public BeanDescriptor getBeanDescriptor() throws IntrospectionException { if (m_beanDescriptor == null) { // temporary data structure for bean descriptor class BeanDescData { String name; String displayName; String shortDescription; Class<?> customizerClass; Map<String, Object> values = Maps.newTreeMap(); } BeanDescData beanDescData = new BeanDescData(); // collect the bean descriptor data from all classes in supertype hierarchy for (BeanInfo info : getBeanInfos()) { BeanDescriptor desc = info.getBeanDescriptor(); if (desc != null) { // set the name if (beanDescData.name == null) { beanDescData.name = desc.getName(); } // set the display name if (beanDescData.displayName == null) { beanDescData.displayName = desc.getDisplayName(); } // set the short description if (beanDescData.shortDescription == null) { beanDescData.shortDescription = desc.getShortDescription(); } // set the customizer class if (beanDescData.customizerClass == null) { beanDescData.customizerClass = desc.getCustomizerClass(); } // set the attribute values Enumeration<String> attrNames = desc.attributeNames(); while (attrNames.hasMoreElements()) { String name = attrNames.nextElement(); Object value = desc.getValue(name); if (!beanDescData.values.containsKey(name)) { beanDescData.values.put(name, value); } } } } // create a new bean descriptor with the collected data m_beanDescriptor = new BeanDescriptor(m_clazz, beanDescData.customizerClass); m_beanDescriptor.setName(beanDescData.name); m_beanDescriptor.setDisplayName(beanDescData.displayName); m_beanDescriptor.setShortDescription(beanDescData.shortDescription); for (Map.Entry<String, Object> entry : beanDescData.values.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); m_beanDescriptor.setValue(name, value); } } return m_beanDescriptor; }