List of usage examples for com.google.common.collect Maps newTreeMap
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap()
From source file:cuchaz.enigma.Deobfuscator.java
public Deobfuscator(ParsedJar jar) { this.parsedJar = jar; // build the jar index this.jarIndex = new JarIndex(entryPool); this.jarIndex.indexJar(this.parsedJar, true); // config the decompiler this.settings = DecompilerSettings.javaDefaults(); this.settings.setMergeVariables(Utils.getSystemPropertyAsBoolean("enigma.mergeVariables", true)); this.settings .setForceExplicitImports(Utils.getSystemPropertyAsBoolean("enigma.forceExplicitImports", true)); this.settings.setForceExplicitTypeArguments( Utils.getSystemPropertyAsBoolean("enigma.forceExplicitTypeArguments", true)); // DEBUG// ww w .j a va 2 s .c o m this.settings .setShowDebugLineNumbers(Utils.getSystemPropertyAsBoolean("enigma.showDebugLineNumbers", false)); this.settings .setShowSyntheticMembers(Utils.getSystemPropertyAsBoolean("enigma.showSyntheticMembers", false)); // init defaults this.translatorCache = Maps.newTreeMap(); this.renamer = new MappingsRenamer(this.jarIndex, null, this.entryPool); // init mappings setMappings(new Mappings()); }
From source file:org.eclipse.wb.internal.core.model.property.editor.DatePropertyEditor.java
@Override public String getText(Property property) throws Exception { Object value = property.getValue(); if (value instanceof Long) { value = new Date(((Long) value).longValue()); }//ww w. j a v a2s.co m if (value instanceof Date) { Map<String, Object> variables = Maps.newTreeMap(); if (property instanceof GenericProperty) { GenericProperty genericProperty = (GenericProperty) property; variables.put("control", genericProperty.getJavaInfo().getObject()); } variables.put("value", value); return (String) evaluate(m_toStringScript, variables); } return null; }
From source file:ru.runa.report.web.action.BaseDeployReportAction.java
private List<WfReportParameter> getReportParameters(DeployReportForm deployForm) { Map<Integer, List<WfReportParameter>> positionToParameter = Maps.newTreeMap(); Set<Integer> required = Sets.newHashSet(); for (String reqIdx : deployForm.getVarRequired()) { required.add(Integer.parseInt(reqIdx)); }//from ww w . jav a 2s. c o m int idx = 0; if (deployForm.getVarPosition() != null) { for (String positionString : deployForm.getVarPosition()) { int position = Integer.parseInt(positionString); if (!positionToParameter.containsKey(position)) { positionToParameter.put(position, Lists.<WfReportParameter>newArrayList()); } WfReportParameter parameter = new WfReportParameter(deployForm.getVarUserName()[idx], deployForm.getVarDescription()[idx], deployForm.getVarInternalName()[idx], position, ReportParameterType.valueOf(deployForm.getVarType()[idx]), required.contains(idx)); positionToParameter.get(position).add(parameter); ++idx; } } List<WfReportParameter> result = Lists.newArrayList(); idx = 0; for (Map.Entry<Integer, List<WfReportParameter>> entry : positionToParameter.entrySet()) { for (WfReportParameter parameter : entry.getValue()) { parameter.setPosition(idx); result.add(parameter); ++idx; } } return result; }
From source file:com.spotify.helios.cli.command.JobStatusCommand.java
@Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); final Map<JobId, Job> jobs; if (Strings.isNullOrEmpty(jobIdString)) { jobs = client.jobs().get();/*from w w w . ja v a 2s. c o m*/ } else { jobs = client.jobs(jobIdString).get(); } if (jobs == null) { out.printf("The specified Helios master either returned an error or job id matcher " + "\"%s\" matched no jobs%n", jobIdString); return 1; } final Set<JobId> jobIds = jobs.keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } // TODO (dano): it would sure be nice to be able to report container/task uptime final Map<JobId, ListenableFuture<JobStatus>> futures = JobStatusFetcher.getJobsStatuses(client, jobIds); final Map<JobId, JobStatus> statuses = Maps.newTreeMap(); statuses.putAll(allAsMap(futures)); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf( "There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; }
From source file:com.google.gerrit.server.access.ListAccess.java
@Override public Map<String, ProjectAccessInfo> apply(TopLevelResource resource) throws ResourceNotFoundException, ResourceConflictException, IOException { Map<String, ProjectAccessInfo> access = Maps.newTreeMap(); for (String p : projects) { Project.NameKey projectName = new Project.NameKey(p); ProjectControl pc = open(projectName); ProjectConfig config;/*ww w . j a v a2s . c om*/ try { // Load the current configuration from the repository, ensuring it's the most // recent version available. If it differs from what was in the project // state, force a cache flush now. // MetaDataUpdate md = metaDataUpdateFactory.create(projectName); try { config = ProjectConfig.read(md); if (config.updateGroupNames(groupBackend)) { md.setMessage("Update group names\n"); config.commit(md); projectCache.evict(config.getProject()); pc = open(projectName); } else if (config.getRevision() != null && !config.getRevision().equals(pc.getProjectState().getConfig().getRevision())) { projectCache.evict(config.getProject()); pc = open(projectName); } } catch (ConfigInvalidException e) { throw new ResourceConflictException(e.getMessage()); } finally { md.close(); } } catch (RepositoryNotFoundException e) { throw new ResourceNotFoundException(p); } access.put(p, new ProjectAccessInfo(pc, config)); } return access; }
From source file:org.apache.hadoop.hbase.master.procedure.MasterDDLOperationHelper.java
/** * Reopen all regions from a table after a schema change operation. **//*from w ww . j a v a 2 s . c o m*/ public static boolean reOpenAllRegions(final MasterProcedureEnv env, final TableName tableName, final List<HRegionInfo> regionInfoList) throws IOException { boolean done = false; LOG.info("Bucketing regions by region server..."); List<HRegionLocation> regionLocations = null; Connection connection = env.getMasterServices().getConnection(); try (RegionLocator locator = connection.getRegionLocator(tableName)) { regionLocations = locator.getAllRegionLocations(); } // Convert List<HRegionLocation> to Map<HRegionInfo, ServerName>. NavigableMap<HRegionInfo, ServerName> hri2Sn = new TreeMap<HRegionInfo, ServerName>(); for (HRegionLocation location : regionLocations) { hri2Sn.put(location.getRegionInfo(), location.getServerName()); } TreeMap<ServerName, List<HRegionInfo>> serverToRegions = Maps.newTreeMap(); List<HRegionInfo> reRegions = new ArrayList<HRegionInfo>(); for (HRegionInfo hri : regionInfoList) { ServerName sn = hri2Sn.get(hri); // Skip the offlined split parent region // See HBASE-4578 for more information. if (null == sn) { LOG.info("Skip " + hri); continue; } if (!serverToRegions.containsKey(sn)) { LinkedList<HRegionInfo> hriList = Lists.newLinkedList(); serverToRegions.put(sn, hriList); } reRegions.add(hri); serverToRegions.get(sn).add(hri); } LOG.info("Reopening " + reRegions.size() + " regions on " + serverToRegions.size() + " region servers."); AssignmentManager am = env.getMasterServices().getAssignmentManager(); am.setRegionsToReopen(reRegions); BulkReOpen bulkReopen = new BulkReOpen(env.getMasterServices(), serverToRegions, am); while (true) { try { if (bulkReopen.bulkReOpen()) { done = true; break; } else { LOG.warn("Timeout before reopening all regions"); } } catch (InterruptedException e) { LOG.warn("Reopen was interrupted"); // Preserve the interrupt. Thread.currentThread().interrupt(); break; } } return done; }
From source file:org.jclouds.aliyun.ecs.filters.FormSign.java
/** * Examines the specified query string parameters and returns a * canonicalized form./*ww w .ja v a 2 s . co m*/ * <p/> * The canonicalized query string is formed by first sorting all the query * string parameters, then URI encoding both the key and value and then * joining them, in order, separating key value pairs with an '&'. * * @return A canonicalized form for the specified query string parameters. */ protected String getCanonicalizedQueryString(Multimap<String, String> params) { SortedMap<String, String> sorted = Maps.newTreeMap(); if (params == null) { return ""; } Iterator<Map.Entry<String, String>> pairs = params.entries().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); String value = pair.getValue(); sorted.put(Strings2.urlEncode(key), Strings2.urlEncode(value)); } return Strings2.urlEncode(Joiner.on("&").withKeyValueSeparator("=").join(sorted)); }
From source file:org.apache.zookeeper.MockZooKeeper.java
private void init(ExecutorService executor) { tree = Maps.newTreeMap(); if (executor != null) { this.executor = executor; } else {/*from ww w . j a va2s . c o m*/ this.executor = Executors.newFixedThreadPool(1, new DefaultThreadFactory("mock-zookeeper")); } SetMultimap<String, Watcher> w = HashMultimap.create(); watchers = Multimaps.synchronizedSetMultimap(w); stopped = false; stepsToFail = new AtomicInteger(-1); failReturnCode = KeeperException.Code.OK; }
From source file:com.mmounirou.spotirss.spotify.tracks.SpotifyHrefQuery.java
private XTracks findBestMatchingTrack(List<XTracks> xtracks, final Track track) { if (xtracks.size() == 1) { return xtracks.get(0); }/* w w w. j av a 2s . c o m*/ TreeMap<Integer, XTracks> sortedTrack = Maps.newTreeMap(); for (XTracks xTrack : xtracks) { sortedTrack.put(getLevenshteinDistance(xTrack, track), xTrack); } Integer minDistance = Iterables.get(sortedTrack.keySet(), 0); XTracks choosedTrack = sortedTrack.get(minDistance); if (minDistance > 1) { SpotiRss.LOGGER.info(String.format("(%s:%s) choosed for (%s:%s) with distance %d", choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()), track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance)); } else { SpotiRss.LOGGER.debug(String.format("(%s:%s) choosed for (%s:%s) with distance %d", choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()), track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance)); } return choosedTrack; }
From source file:org.eclipse.wb.internal.core.model.description.helpers.FactoryDescriptionHelper.java
/** * Returns factory methods of given {@link Class} and its super classes. * //w ww .j a va 2 s . c om * @return the {@link Map} signature -> {@link FactoryMethodDescription}. */ @SuppressWarnings("unchecked") public static Map<String, FactoryMethodDescription> getDescriptionsMap(AstEditor editor, Class<?> factoryClass, boolean forStatic) throws Exception { // prepare Map[static,non-static] Map<String, FactoryMethodDescription>[] signaturesMaps = m_descriptionMaps.get(factoryClass); if (signaturesMaps == null) { signaturesMaps = new Map[2]; m_descriptionMaps.put(factoryClass, signaturesMaps); } // check cache int index = forStatic ? 0 : 1; Map<String, FactoryMethodDescription> signaturesMap = signaturesMaps[index]; if (signaturesMap == null) { signaturesMap = Maps.newTreeMap(); signaturesMaps[index] = signaturesMap; // this factory class methods { Map<String, FactoryMethodDescription> map = getDescriptionsMap0(editor, factoryClass, forStatic); signaturesMap.putAll(map); } // super factory class methods (cached) { Class<?> superFactoryClass = factoryClass.getSuperclass(); if (superFactoryClass != null) { Map<String, FactoryMethodDescription> map = getDescriptionsMap(editor, superFactoryClass, forStatic); signaturesMap.putAll(map); } } } // done return signaturesMap; }