List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:com.palantir.atlasdb.keyvalue.impl.ValidatingQueryRewritingKeyValueService.java
@Override public Map<Cell, Value> getRows(String tableName, Iterable<byte[]> rows, ColumnSelection columnSelection, long timestamp) { if (Iterables.isEmpty(rows) || columnSelection.noColumnsSelected()) { return ImmutableMap.of(); }/*from w w w. j a v a 2 s. c o m*/ return delegate.getRows(tableName, rows, columnSelection, timestamp); }
From source file:org.eclipse.papyrus.infra.table.controlmode.helpers.TableMoveHelper.java
/** * Creates an iterable containing all the Papyrus Tables that are descending from the context. * // w w w . j av a2s. c o m * @author olivier melois (Atos) */ public static Iterable<EObject> createDescendantTablesIterable(EObject context) { Set<EObject> result = Sets.newHashSet(); TreeIterator<EObject> eAllContents = EcoreUtil.getAllProperContents(context, true); // was context.eAllContents(). Iterator<EObject> contextAndDescendants = Iterators.concat(eAllContents, Iterators.singletonIterator(context)); final Predicate<Setting> keepPapyrusTableInstances = new Predicate<Setting>() { public boolean apply(Setting setting) { boolean result = true; if (setting != null) { EObject settingEObject = setting.getEObject(); result &= settingEObject instanceof PapyrusTableInstance; result &= PapyrustableinstancePackage.Literals.PAPYRUS_TABLE_INSTANCE__TABLE == setting .getEStructuralFeature(); } else { result = false; } return result; } }; /* * Predicate used to keep the usages which are PapyrusTableInstances */ Predicate<Setting> keepTableInstances = new Predicate<Setting>() { public boolean apply(Setting setting) { boolean result = true; if (setting != null) { EObject settingEObject = setting.getEObject(); result &= settingEObject instanceof TableInstance; result &= setting .getEStructuralFeature() == TableinstancePackage.Literals.TABLE_INSTANCE__CONTEXT; Collection<Setting> references = PapyrusEcoreUtils.getUsages(settingEObject); Iterable<Setting> papyrusTableInstances = Iterables.filter(references, keepPapyrusTableInstances); //Veryfing that there is at least one papyrusTableInstance result = result && !Iterables.isEmpty(papyrusTableInstances); } else { result = false; } return result; } }; /* * Function to get the eObject from a setting */ Function<Setting, EObject> getEObject = new Function<Setting, EObject>() { public EObject apply(Setting input) { EObject settingEObject = input.getEObject(); Collection<Setting> references = PapyrusEcoreUtils.getUsages(settingEObject); Iterable<Setting> papyrusTableInstances = Iterables.filter(references, keepPapyrusTableInstances); //Getting the eobject of thie first element of this iterable. return Iterables.get(papyrusTableInstances, 0).getEObject(); } }; /* * For the context and his descendants : */ while (contextAndDescendants.hasNext()) { EObject current = contextAndDescendants.next(); //Usages Iterable<Setting> usages = PapyrusEcoreUtils.getUsages(current); //Filtering to keep only papyrus table instances. Iterable<Setting> tableInstanceSettings = Iterables.filter(usages, keepTableInstances); //Getting the eObjects Iterable<EObject> papyrusTableInstances = Iterables.transform(tableInstanceSettings, getEObject); //Adding all the kept usages. Iterables.addAll(result, papyrusTableInstances); } return result; }
From source file:com.google.devtools.build.lib.rules.objc.J2ObjcSource.java
/** * Returns whether this {@link J2ObjcSource} contains any ObjC source (.m, .mm) files. *///from ww w .ja v a 2s . co m public boolean hasSourceFiles() { return !Iterables.isEmpty(objcSrcs); }
From source file:org.eclipse.sirius.diagram.ui.business.internal.query.RequestQuery.java
/** * Checks if the current {@link Request} request is about a GMF Text drop. * //w w w. j av a2 s.co m * @return true if the current {@link Request} request is about a GMF Text * drop */ public boolean isTextDropRequest() { boolean isTextDropRequest = false; if (RequestConstants.REQ_ADD.equals(request.getType()) && request instanceof GroupRequest) { GroupRequest groupRequest = (GroupRequest) request; isTextDropRequest = !Iterables .isEmpty(Iterables.filter(groupRequest.getEditParts(), TextEditPart.class)); } return isTextDropRequest; }
From source file:org.opendaylight.yangtools.yang.model.api.SchemaPath.java
/** * Create a child path based on concatenation of this path and a relative path. * * @param relative Relative path/*from w w w .ja va2 s.co m*/ * @return A new child path */ public SchemaPath createChild(final Iterable<QName> relative) { if (Iterables.isEmpty(relative)) { return this; } SchemaPath parentPath = this; for (QName qname : relative) { parentPath = parentPath.createInstance(parentPath, qname); } return parentPath; }
From source file:com.shopzilla.hadoop.repl.HadoopREPL.java
@Override protected void evaluate(final String input) throws ExitSignal { popHistory();// w ww . j a v a2 s . c o m final Iterable<String> inputParts = ARG_SPLITTER.limit(2).split(input); if (Iterables.isEmpty(inputParts)) { // Do nothing } else { final String command = Iterables.get(inputParts, 0).toLowerCase(); if (commandMappings.containsKey(call(command))) { commandMappings.get(call(command)).execute( new CommandInvocation(command, Iterables .toArray(ARG_SPLITTER.split(Iterables.get(inputParts, 1, "")), String.class)), sessionState); } else { sessionState.output("Unknown command \"%s\"", command); } pushHistory(input); } }
From source file:com.google.googlejavaformat.java.Formatter.java
/** * Construct a {@code Formatter} given a Java compilation unit. Parses the code; builds a {@link * JavaInput} and the corresponding {@link JavaOutput}. * * @param javaInput the input, a Java compilation unit * @param javaOutput the {@link JavaOutput} * @param options the {@link JavaFormatterOptions} *//*from w ww .j a v a2 s . c o m*/ static void format(final JavaInput javaInput, JavaOutput javaOutput, JavaFormatterOptions options) throws FormatterException { Context context = new Context(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); context.put(DiagnosticListener.class, diagnostics); Options.instance(context).put("allowStringFolding", "false"); // TODO(cushon): this should default to the latest supported source level, remove this after // backing out // https://github.com/google/error-prone-javac/commit/c97f34ddd2308302587ce2de6d0c984836ea5b9f Options.instance(context).put(Option.SOURCE, "9"); JCCompilationUnit unit; JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8); try { fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of()); } catch (IOException e) { // impossible throw new IOError(e); } SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return javaInput.getText(); } }; Log.instance(context).useSource(source); ParserFactory parserFactory = ParserFactory.instance(context); JavacParser parser = parserFactory.newParser(javaInput.getText(), /*keepDocComments=*/ true, /*keepEndPos=*/ true, /*keepLineMap=*/ true); unit = parser.parseCompilationUnit(); unit.sourcefile = source; javaInput.setCompilationUnit(unit); Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables .filter(diagnostics.getDiagnostics(), Formatter::errorDiagnostic); if (!Iterables.isEmpty(errorDiagnostics)) { throw FormatterException.fromJavacDiagnostics(errorDiagnostics); } OpsBuilder builder = new OpsBuilder(javaInput, javaOutput); // Output the compilation unit. new JavaInputAstVisitor(builder, options.indentationMultiplier()).scan(unit, null); builder.sync(javaInput.getText().length()); builder.drain(); Doc doc = new DocBuilder().withOps(builder.build()).build(); doc.computeBreaks(javaOutput.getCommentsHelper(), MAX_LINE_LENGTH, new Doc.State(+0, 0)); doc.write(javaOutput); javaOutput.flush(); }
From source file:com.facebook.buck.cli.BuckConfig.java
/** * Takes a sequence of {@code .buckconfig} files and loads them, in order, to create a * {@code BuckConfig} object. Each successive file that is loaded has the ability to override * definitions from a previous file./* w ww.java 2s .co m*/ * @param projectFilesystem project for which the {@link BuckConfig} is being created. * @param files The sequence of {@code .buckconfig} files to load. */ public static BuckConfig createFromFiles(ProjectFilesystem projectFilesystem, Iterable<File> files, Platform platform) throws IOException { Preconditions.checkNotNull(projectFilesystem); Preconditions.checkNotNull(files); BuildTargetParser buildTargetParser = new BuildTargetParser(projectFilesystem); if (Iterables.isEmpty(files)) { return new BuckConfig(ImmutableMap.<String, Map<String, String>>of(), projectFilesystem, buildTargetParser, platform); } // Convert the Files to Readers. ImmutableList.Builder<Reader> readers = ImmutableList.builder(); for (File file : files) { readers.add(Files.newReader(file, Charsets.UTF_8)); } return createFromReaders(readers.build(), projectFilesystem, buildTargetParser, platform); }
From source file:org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.java
/** * Create a child path based on concatenation of this path and a relative path. * * @param relative Relative path/*from w w w . j ava 2 s . c om*/ * @return A new child path */ public SchemaNodeIdentifier createChild(final Iterable<QName> relative) { if (Iterables.isEmpty(relative)) { return this; } SchemaNodeIdentifier parentNode = this; for (QName qname : relative) { parentNode = parentNode.createInstance(parentNode, qname); } return parentNode; }
From source file:eu.trentorise.opendata.commons.validation.Preconditions.java
/** * * Checks if provided iterable is non null and non empty . * * @param prependedErrorMessage the exception message to use if the check * fails; will be converted to a string using String.valueOf(Object) and * prepended to more specific error messages. * * @throws IllegalArgumentException if provided collection fails validation * * @return a non-null non-empty iterable *///from w w w . j a v a 2 s . c o m public static <T> Iterable<T> checkNotEmpty(@Nullable Iterable<T> iterable, @Nullable Object prependedErrorMessage) { checkArgument(iterable != null, "%s -- Reason: Found null iterable.", prependedErrorMessage); if (Iterables.isEmpty(iterable)) { throw new IllegalArgumentException( String.valueOf(prependedErrorMessage) + " -- Reason: Found empty collection."); } return iterable; }