List of usage examples for com.google.common.collect ImmutableSet isEmpty
boolean isEmpty();
From source file:com.facebook.buck.step.fs.UnzipStep.java
@VisibleForTesting static void extractZipFile(String zipFile, String destination, ImmutableSet<String> filesToExtract, boolean overwriteExistingFiles) throws IOException { // Create output directory is not exists File folder = new File(destination); // TODO UnzipStep could be a CompositeStep with a MakeCleanDirectoryStep for the output dir. if (!folder.exists() && !folder.mkdirs()) { throw new IOException(String.format("Folder %s could not be created.", folder.toString())); }/*from www . ja va 2 s . c om*/ try (ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFile))) { for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { String fileName = entry.getName(); // If filesToExtract is not empty, check if current entry is contained. if (!filesToExtract.isEmpty() && !filesToExtract.contains(fileName)) { continue; } File target = new File(folder, fileName); if (target.exists() && !overwriteExistingFiles) { continue; } if (entry.isDirectory()) { // Create the directory and all its parent directories if (!target.mkdirs()) { throw new IOException(String.format("Folder %s could not be created.", target.toString())); } } else { // Create parent folder File parentFolder = target.getParentFile(); if (!parentFolder.exists() && !parentFolder.mkdirs()) { throw new IOException( String.format("Folder %s could not be created.", parentFolder.toString())); } // Write file try (FileOutputStream out = new FileOutputStream(target)) { ByteStreams.copy(zip, out); } } } } }
From source file:com.google.javascript.jscomp.newtypes.ObjectType.java
static ImmutableSet<ObjectType> joinSets(ImmutableSet<ObjectType> objs1, ImmutableSet<ObjectType> objs2) { if (objs1.isEmpty()) { return objs2; } else if (objs2.isEmpty()) { return objs1; }//from w w w. j a v a 2 s .co m ObjectType[] objs1Arr = objs1.toArray(new ObjectType[0]); ObjectType[] keptFrom1 = Arrays.copyOf(objs1Arr, objs1Arr.length); ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder(); for (ObjectType obj2 : objs2) { boolean addedObj2 = false; for (int i = 0; i < objs1Arr.length; i++) { ObjectType obj1 = objs1Arr[i]; NominalType nominalType1 = obj1.nominalType; NominalType nominalType2 = obj2.nominalType; if (areRelatedClasses(nominalType1, nominalType2)) { if (nominalType2 == null && nominalType1 != null && !obj1.isSubtypeOf(obj2) || nominalType1 == null && nominalType2 != null && !obj2.isSubtypeOf(obj1)) { // Don't merge other classes with record types break; } keptFrom1[i] = null; addedObj2 = true; // obj1 and obj2 may be in a subtype relation. // Even then, we want to join them because we don't want to forget // any extra properties in the subtype object. newObjs.add(join(obj1, obj2)); break; } } if (!addedObj2) { newObjs.add(obj2); } } for (ObjectType o : keptFrom1) { if (o != null) { newObjs.add(o); } } return newObjs.build(); }
From source file:io.mindmaps.graql.internal.query.match.MatchQuerySelect.java
MatchQuerySelect(MatchQueryInternal inner, ImmutableSet<String> names) { super(inner); if (names.isEmpty()) { throw new IllegalArgumentException(ErrorMessage.SELECT_NONE_SELECTED.getMessage()); }/*from w w w.ja va 2s . c om*/ this.names = names; }
From source file:google.registry.tools.DeleteReservedListCommand.java
@Override protected void init() throws Exception { checkArgument(ReservedList.get(name).isPresent(), "Cannot delete the reserved list %s because it doesn't exist.", name); ReservedList existing = ReservedList.get(name).get(); ImmutableSet<String> tldsUsedOn = existing.getReferencingTlds(); checkArgument(tldsUsedOn.isEmpty(), "Cannot delete reserved list because it is used on these tld(s): %s", Joiner.on(", ").join(tldsUsedOn)); stageEntityChange(existing, null);//from w w w. j a va 2s . c o m }
From source file:org.androidtransfuse.TransfuseAnalysisException.java
public TransfuseAnalysisException(String message, ImmutableSet<Exception> errors) { //todo: print out all errors super(message, errors.isEmpty() ? null : errors.iterator().next()); }
From source file:org.geogit.api.plumbing.ResolveBranchId.java
@Override public Optional<Ref> call() { Preconditions.checkState(id != null, "id has not been set."); Predicate<Ref> filter = new Predicate<Ref>() { @Override//from ww w . ja va 2 s . c o m public boolean apply(@Nullable Ref ref) { return ref.getObjectId().equals(id); } }; ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call(); if (refs.isEmpty()) { return Optional.absent(); } else { return Optional.of(refs.iterator().next()); } }
From source file:org.locationtech.geogig.api.plumbing.ResolveBranchId.java
@Override protected Optional<Ref> _call() { Preconditions.checkState(id != null, "id has not been set."); Predicate<Ref> filter = new Predicate<Ref>() { @Override//from ww w. ja v a 2 s . c o m public boolean apply(@Nullable Ref ref) { return ref.getObjectId().equals(id); } }; ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call(); if (refs.isEmpty()) { return Optional.absent(); } else { return Optional.of(refs.iterator().next()); } }
From source file:google.registry.tools.DeletePremiumListCommand.java
@Override protected void init() throws Exception { checkArgument(PremiumList.exists(name), "Cannot delete the premium list %s because it doesn't exist.", name);//from www . ja va2s . c om premiumList = PremiumList.get(name).get(); ImmutableSet<String> tldsUsedOn = premiumList.getReferencingTlds(); checkArgument(tldsUsedOn.isEmpty(), "Cannot delete premium list because it is used on these tld(s): %s", Joiner.on(", ").join(tldsUsedOn)); }
From source file:org.locationtech.geogig.plumbing.ResolveBranchId.java
@Override protected Optional<Ref> _call() { Preconditions.checkState(id != null, "id has not been set."); Predicate<Ref> filter = new Predicate<Ref>() { private ObjectId id = ResolveBranchId.this.id; @Override//from w ww . jav a 2 s . c o m public boolean apply(@Nullable Ref ref) { String refName = ref.getName(); ObjectId refId = ref.getObjectId(); return refName.startsWith(Ref.HEADS_PREFIX) && refId.equals(this.id); } }; ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call(); if (refs.isEmpty()) { return Optional.absent(); } else { return Optional.of(refs.iterator().next()); } }
From source file:google.registry.tools.GetLrpTokenCommand.java
@Override public void run() throws Exception { checkArgument((tokenString == null) == (assignee != null), "Exactly one of either token or assignee must be specified."); ImmutableSet.Builder<LrpTokenEntity> tokensBuilder = new ImmutableSet.Builder<>(); if (tokenString != null) { LrpTokenEntity token = ofy().load().key(Key.create(LrpTokenEntity.class, tokenString)).now(); if (token != null) { tokensBuilder.add(token);/* w ww . j a v a 2 s . co m*/ } } else { tokensBuilder.addAll(ofy().load().type(LrpTokenEntity.class).filter("assignee", assignee)); } ImmutableSet<LrpTokenEntity> tokens = tokensBuilder.build(); if (!tokens.isEmpty()) { for (LrpTokenEntity token : tokens) { System.out.println(token); if (includeHistory && token.getRedemptionHistoryEntry() != null) { System.out .println(ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString()); } } } else { System.out.println("Token not found."); } }