List of usage examples for com.google.common.collect Sets newTreeSet
public static <E extends Comparable> TreeSet<E> newTreeSet()
From source file:org.cinchapi.concourse.server.upgrade.Upgrader.java
/** * Run the program...// w ww.j a v a 2 s.c o m * * @param args * @throws ReflectiveOperationException */ public static void main(String... args) throws ReflectiveOperationException { // Temporarily turn on console logging so the user can see the log // messages while the upgrades happen. Although we revert the setting // after the tasks have finished, console logging will be enabled for // the duration of this JVM's lifecycle. That should be okay as long as // the Upgrader runs in a different JVM that the normal ConcourseServer // process. boolean enableConsoleLogging = GlobalState.ENABLE_CONSOLE_LOGGING; GlobalState.ENABLE_CONSOLE_LOGGING = true; try { int currentSystemVersion = getCurrentSystemVersion(); // Find the new upgrade tasks Set<UpgradeTask> tasks = Sets.newTreeSet(); for (String pkg : pkgs) { Reflections reflections = new Reflections(pkg); Set<Class<? extends UpgradeTask>> classes = reflections.getSubTypesOf(UpgradeTask.class); classes.addAll(reflections.getSubTypesOf(SmartUpgradeTask.class)); for (Class<? extends UpgradeTask> clazz : classes) { UpgradeTask task = clazz.newInstance(); if (task.version() > currentSystemVersion) { tasks.add(task); } } } // Run the new upgrade tasks for (UpgradeTask task : tasks) { System.out.println(task); try { task.run(); } catch (Exception e) { if (task instanceof Upgrade2) { // CON-137: Even if Upgrade2 fails and we can't migrate // data, still set the system version so we aren't // blocked on this task in the future. UpgradeTask.setCurrentSystemVersion(task.version()); Logger.info("Due to a bug in a previous " + "release, the system version has " + "been force upgraded " + "to {}", task.version()); } else { System.exit(1); // fail fast because we assume // subsequent tasks depend on the one // that failed } } } System.exit(0); } finally { GlobalState.ENABLE_CONSOLE_LOGGING = enableConsoleLogging; } }
From source file:com.metamx.druid.utils.ExposeS3DataSource.java
public static void main(String[] args) throws ServiceException, IOException, NoSuchAlgorithmException { CLI cli = new CLI(); cli.addOption(new RequiredOption(null, "s3Bucket", true, "s3 bucket to pull data from")); cli.addOption(new RequiredOption(null, "s3Path", true, "base input path in s3 bucket. Everything until the date strings.")); cli.addOption(new RequiredOption(null, "timeInterval", true, "ISO8601 interval of dates to index")); cli.addOption(new RequiredOption(null, "granularity", true, String.format( "granularity of index, supported granularities: [%s]", Arrays.asList(Granularity.values())))); cli.addOption(new RequiredOption(null, "zkCluster", true, "Cluster string to connect to ZK with.")); cli.addOption(new RequiredOption(null, "zkBasePath", true, "The base path to register index changes to.")); CommandLine commandLine = cli.parse(args); if (commandLine == null) { return;/* w w w. ja v a 2 s.c o m*/ } String s3Bucket = commandLine.getOptionValue("s3Bucket"); String s3Path = commandLine.getOptionValue("s3Path"); String timeIntervalString = commandLine.getOptionValue("timeInterval"); String granularity = commandLine.getOptionValue("granularity"); String zkCluster = commandLine.getOptionValue("zkCluster"); String zkBasePath = commandLine.getOptionValue("zkBasePath"); Interval timeInterval = new Interval(timeIntervalString); Granularity gran = Granularity.valueOf(granularity.toUpperCase()); final RestS3Service s3Client = new RestS3Service(new AWSCredentials( System.getProperty("com.metamx.aws.accessKey"), System.getProperty("com.metamx.aws.secretKey"))); ZkClient zkClient = new ZkClient(new ZkConnection(zkCluster), Integer.MAX_VALUE, new StringZkSerializer()); zkClient.waitUntilConnected(); for (Interval interval : gran.getIterable(timeInterval)) { log.info("Processing interval[%s]", interval); String s3DatePath = JOINER.join(s3Path, gran.toPath(interval.getStart())); if (!s3DatePath.endsWith("/")) { s3DatePath += "/"; } StorageObjectsChunk chunk = s3Client.listObjectsChunked(s3Bucket, s3DatePath, "/", 2000, null, true); TreeSet<String> commonPrefixes = Sets.newTreeSet(); commonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes())); if (commonPrefixes.isEmpty()) { log.info("Nothing at s3://%s/%s", s3Bucket, s3DatePath); continue; } String latestPrefix = commonPrefixes.last(); log.info("Latest segments at [s3://%s/%s]", s3Bucket, latestPrefix); chunk = s3Client.listObjectsChunked(s3Bucket, latestPrefix, "/", 2000, null, true); Integer partitionNumber; if (chunk.getCommonPrefixes().length == 0) { partitionNumber = null; } else { partitionNumber = -1; for (String partitionPrefix : chunk.getCommonPrefixes()) { String[] splits = partitionPrefix.split("/"); partitionNumber = Math.max(partitionNumber, Integer.parseInt(splits[splits.length - 1])); } } log.info("Highest segment partition[%,d]", partitionNumber); if (partitionNumber == null) { final S3Object s3Obj = new S3Object(new S3Bucket(s3Bucket), String.format("%sdescriptor.json", latestPrefix)); updateWithS3Object(zkBasePath, s3Client, zkClient, s3Obj); } else { for (int i = partitionNumber; i >= 0; --i) { final S3Object partitionObject = new S3Object(new S3Bucket(s3Bucket), String.format("%s%s/descriptor.json", latestPrefix, i)); updateWithS3Object(zkBasePath, s3Client, zkClient, partitionObject); } } } }
From source file:cc.recommenders.names.VmPackageName.java
/** * @return the packages of the given types as returned by {@link ITypeName#getPackage()} */// w w w .j a v a 2 s.c o m public static Set<IPackageName> packages(Set<ITypeName> types) { Set<IPackageName> res = Sets.newTreeSet(); for (ITypeName type : types) { res.add(type.getPackage()); } return res; }
From source file:cc.recommenders.names.CoRePackageName.java
/** * @return the packages of the given types as returned by {@link ICoReTypeName#getPackage()} *//*from w w w. j a va 2 s. c o m*/ public static Set<ICoRePackageName> packages(Set<ICoReTypeName> types) { Set<ICoRePackageName> res = Sets.newTreeSet(); for (ICoReTypeName type : types) { res.add(type.getPackage()); } return res; }
From source file:com.android.sdklib.repository.local.Update.java
public static UpdateResult computeUpdates(@NonNull LocalPkgInfo[] localPkgs, @NonNull Multimap<PkgType, RemotePkgInfo> remotePkgs) { UpdateResult result = new UpdateResult(); Set<RemotePkgInfo> updates = Sets.newTreeSet(); // Find updates to locally installed packages for (LocalPkgInfo local : localPkgs) { RemotePkgInfo update = findUpdate(local, remotePkgs, result); if (update != null) { updates.add(update);//www .j a v a 2s . c o m } } // Find new packages not yet installed nextRemote: for (RemotePkgInfo remote : remotePkgs.values()) { if (updates.contains(remote)) { // if package is already a known update, it's not new. continue nextRemote; } IPkgDesc remoteDesc = remote.getDesc(); for (LocalPkgInfo local : localPkgs) { IPkgDesc localDesc = local.getDesc(); if (remoteDesc.compareTo(localDesc) == 0 || remoteDesc.isUpdateFor(localDesc)) { // if package is same as an installed or is an update for an installed // one, then it's not new. continue nextRemote; } } result.addNewPkgs(remote); } return result; }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.font.FontSupport.java
/** * @return names of all fonts into system. *//*from ww w .j av a 2 s . co m*/ public static String[] getFontFamilies() throws Exception { Set<String> families = Sets.newTreeSet(); // add all font families families.addAll(getFontFamilies(true)); families.addAll(getFontFamilies(false)); // sort names String[] sortFamilies = families.toArray(new String[families.size()]); Arrays.sort(sortFamilies); return sortFamilies; }
From source file:org.eclipse.recommenders.tests.jdt.AstUtils.java
public static Tuple<CompilationUnit, Set<Integer>> createAstWithMarkers(final String content) { final Set<Integer> markers = Sets.newTreeSet(); int pos = 0;/* w w w . j ava2s . com*/ final StringBuilder sb = new StringBuilder(content); while ((pos = sb.indexOf(MARKER, pos)) != -1) { sb.delete(pos, pos + 1); markers.add(pos); } final CompilationUnit cu = createAst(sb.toString()); // final IJavaElement javaElement = cu.getJavaElement(); // final ITypeRoot typeRoot = cu.getTypeRoot(); // final IType findPrimaryType = typeRoot.findPrimaryType(); return Tuple.newTuple(cu, markers); }
From source file:edu.harvard.med.screensaver.model.libraries.PlateRange.java
private static PlateRange findNextPlateRange(PeekingIterator<Plate> iter) { SortedSet<Plate> platesScreened = Sets.newTreeSet(); platesScreened.add(iter.next());//from w w w . j a va 2s . c om while (iter.hasNext()) { Plate next = iter.peek(); Plate last = platesScreened.last(); if (next.getPlateNumber() > last.getPlateNumber() + 1) { break; } else if (!next.getCopy().equals(last.getCopy())) { break; } platesScreened.add(iter.next()); } return new PlateRange(platesScreened); }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.font.FontSupport.java
private static Set<String> getFontFamilies(boolean scalable) throws Exception { Set<String> families = Sets.newTreeSet(); ///* ww w .ja va 2s . co m*/ FontData[] fontList = Display.getDefault().getFontList(null, scalable); for (FontData fontData : fontList) { families.add(fontData.getName()); } // return families; }
From source file:com.enonic.cms.core.search.builder.ContentIndexDataAccessRightsFactory.java
public void create(final ContentIndexData contentIndexData, final Collection<ContentAccessEntity> contentAccessRights, Map<GroupKey, CategoryAccessEntity> categoryAccessRights) { if (contentAccessRights == null) { return;//from w w w.j a v a 2 s.c o m } final Set<String> readAccess = Sets.newTreeSet(); final Set<String> deleteAccess = Sets.newTreeSet(); final Set<String> updateAccess = Sets.newTreeSet(); final Set<String> browseAccess = Sets.newTreeSet(); final Set<String> approveAccess = Sets.newTreeSet(); final Set<String> administrateAccess = Sets.newTreeSet(); for (final ContentAccessEntity contentAccess : contentAccessRights) { final GroupKey group = contentAccess.getGroup().getGroupKey(); final String groupKey = group.toString(); if (contentAccess.isReadAccess()) { readAccess.add(groupKey); } if (contentAccess.isUpdateAccess()) { updateAccess.add(groupKey); } if (contentAccess.isDeleteAccess()) { deleteAccess.add(groupKey); } } for (GroupKey categoryAccessGroup : categoryAccessRights.keySet()) { CategoryAccessEntity categoryAccess = categoryAccessRights.get(categoryAccessGroup); final String groupKey = categoryAccessGroup.toString(); if (categoryAccess.givesAdminBrowse()) { browseAccess.add(groupKey); } if (categoryAccess.givesApprove()) { approveAccess.add(groupKey); } if (categoryAccess.givesAdministrate()) { administrateAccess.add(groupKey); } } contentIndexData.addContentIndexDataElement(CONTENT_ACCESS_READ_FIELDNAME, readAccess, false); contentIndexData.addContentIndexDataElement(CONTENT_ACCESS_UPDATE_FIELDNAME, updateAccess, false); contentIndexData.addContentIndexDataElement(CONTENT_ACCESS_DELETE_FIELDNAME, deleteAccess, false); contentIndexData.addContentIndexDataElement(CONTENT_CATEGORY_ACCESS_BROWSE_FIELDNAME, browseAccess, false); contentIndexData.addContentIndexDataElement(CONTENT_CATEGORY_ACCESS_APPROVE_FIELDNAME, approveAccess, false); contentIndexData.addContentIndexDataElement(CONTENT_CATEGORY_ACCESS_ADMINISTRATE_FIELDNAME, administrateAccess, false); }