List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:de.monticore.cli.MontiCoreCLI.java
/** * Main method./*from ww w .ja v a 2 s . com*/ * * @param args the CLI arguments */ public static void main(String[] args) { if (args.length == 0) { // the only required input are the grammar file(s)/directories System.out.println("MontiCore CLI Usage: java -jar monticore-cli.jar <grammar files> <options>"); return; } // check if the input model(s) are specified without option and add it for // further processing if (!args[0].startsWith("-")) { ArrayList<String> fixedArgs = new ArrayList<String>(Arrays.asList(args)); fixedArgs.add(0, "-" + MontiCoreConfiguration.Options.GRAMMARS_SHORT.toString()); args = fixedArgs.toArray(new String[fixedArgs.size()]); } CLIArguments arguments = CLIArguments.forArguments(args); MontiCoreCLIConfiguration configuration = MontiCoreCLIConfiguration.fromArguments(arguments); // this will be CLI's default model path if none is specified Iterable<String> mp = Arrays.asList("monticore-cli.jar"); Iterable<String> mpArg = arguments.asMap().get(MontiCoreConfiguration.Options.MODELPATH.toString()); Iterable<String> mpShortArg = arguments.asMap() .get(MontiCoreConfiguration.Options.MODELPATH_SHORT.toString()); if ((mpArg == null || Iterables.isEmpty(mpArg)) && (mpShortArg == null || Iterables.isEmpty(mpShortArg))) { // prepare args which contain the fixed model path Map<String, Iterable<String>> wrappedArgs = new HashMap<>(); wrappedArgs.put(MontiCoreConfiguration.Options.MODELPATH.toString(), mp); wrappedArgs.putAll(arguments.asMap()); // use this fixed configuration configuration = MontiCoreCLIConfiguration.fromMap(wrappedArgs); } // we store the requested output directory as a system variable such that we // can inject it into the logback configuration System.setProperty(MC_OUT, configuration.getInternal().getOut().getAbsolutePath()); // this should always happen first in order to use any custom configurations if (System.getProperty(LOGBACK_CONFIGURATIONFILE) == null) { initLogging(configuration); } // this needs to be called after the statement above; otherwise logback will // ignore custom configurations supplied via system property Slf4jLog.init(); if (System.getProperty(LOGBACK_CONFIGURATIONFILE) != null) { Log.debug( "Using system property logback configuration " + System.getProperty(LOGBACK_CONFIGURATIONFILE), MontiCoreCLI.class.getName()); } // before we launch MontiCore we check if there are any ".mc4" files in the // input argument (source path) Iterator<Path> inputPaths = configuration.getInternal().getGrammars().getResolvedPaths(); if (!inputPaths.hasNext()) { System.clearProperty(MC_OUT); Log.error("0xA1000 There are no \".mc4\" files to parse. Please check the \"grammars\" option."); return; } try { // since this is the default we load the default script ClassLoader l = MontiCoreScript.class.getClassLoader(); String script = Resources .asCharSource(l.getResource("de/monticore/monticore_emf.groovy"), Charset.forName("UTF-8")) .read(); // BUT if the user specifies another script to use, we check if it is // there and load its content if (configuration.getScript().isPresent()) { if (!configuration.getScript().get().exists()) { System.clearProperty(MC_OUT); Log.error("0xA1001 Custom script \"" + configuration.getScript().get().getPath() + "\" not found!"); return; } script = Files.toString(configuration.getScript().get(), Charset.forName("UTF-8")); } // execute the scripts (either default or custom) new MontiCoreScript().run(script, configuration.getInternal()); } catch (IOException e) { System.clearProperty(MC_OUT); Log.error("0xA1002 Failed to load Groovy script.", e); } }
From source file:com.github.ferstl.maven.pomenforcers.model.CollectionToStringHelper.java
public static String toString(String prefix, Iterable<?> iterable) { StringBuilder sb = new StringBuilder(prefix).append(" [\n"); JOINER.appendTo(sb, iterable).append((iterable != null && !Iterables.isEmpty(iterable)) ? "\n]" : "]"); return sb.toString(); }
From source file:nz.co.testamation.common.util.ObjectUtil.java
public static boolean allNotEmpty(Object... objects) { for (Object object : objects) { if (object == null) { return false; }// w w w. j av a2 s . c om if (object instanceof CharSequence && StringUtils.isBlank((CharSequence) object)) { return false; } if (object instanceof Iterable && Iterables.isEmpty((Iterable<?>) object)) { return false; } } return true; }
From source file:net.roddrim.number5.tools.collect.N5Collections.java
public static <T> boolean isNullOrEmpty(@NonNull final Iterable<T> i) { return i == null || Iterables.isEmpty(i); }
From source file:org.apache.beam.sdk.io.gcp.spanner.MutationUtils.java
/** * Check if the mutation is a delete by a single primary key operation. * * @param m mutation/*from w w w. ja v a 2 s . c o m*/ * @return true if mutation is a point delete */ public static boolean isPointDelete(Mutation m) { return m.getOperation() == Mutation.Op.DELETE && Iterables.isEmpty(m.getKeySet().getRanges()) && Iterables.size(m.getKeySet().getKeys()) == 1; }
From source file:com.googlecode.blaisemath.util.Rectangles.java
/** * Return rectangle that is bounding box of all provided. * @param rects rectangles/*from ww w . ja v a 2s.com*/ * @return smallest box enclosing provided rectangles, null if argument is empty */ @Nullable public static Rectangle2D boundingBox(Iterable<? extends Rectangle2D> rects) { if (Iterables.isEmpty(rects)) { return null; } Rectangle2D res = null; for (Rectangle2D r : rects) { if (res == null) { res = r; } else { res = res.createUnion(r); } } return res; }
From source file:org.richfaces.cdk.util.MorePredicates.java
public static <S, D> Predicate<D> any(Iterable<S> options, Function<S, Predicate<D>> function) { if (options == null || Iterables.isEmpty(options)) { return Predicates.alwaysTrue(); }//from www. j a v a 2 s. com return Predicates.or(Iterables.transform(options, function)); }
From source file:com.google.api.server.spi.config.validation.InconsistentApiConfigurationException.java
private static String getErrorMessage(ApiConfig config, ApiConfig otherConfig, Iterable<ApiConfigInconsistency<Object>> inconsistencies) { Preconditions.checkArgument(!Iterables.isEmpty(inconsistencies)); ApiConfigInconsistency<?> firstInconsistency = Iterables.getFirst(inconsistencies, null); return String.format( "API-wide configuration does not match between the classes %s and %s. All " + "API classes with the same API name and version must have the exact same API-wide " + "configuration. Differing property: %s (%s vs %s).", config.getApiClassConfig().getApiClassJavaName(), otherConfig.getApiClassConfig().getApiClassJavaName(), firstInconsistency.getPropertyName(), firstInconsistency.getValue1(), firstInconsistency.getValue2()); }
From source file:com.vilt.minium.impl.WaitPredicates.java
/** * Predicate to use with {@link WaitWebElements#wait(Predicate)} methods which ensures that * evaluation will only be successful when this instance is empty (that is, evaluates * to zero {@link org.openqa.selenium.WebElement} instances). * * @param <T> the generic type/*w w w . j a v a2 s .c o m*/ * @return predicate that returns true if it is empty */ public static <T extends WebElements> Predicate<T> whileNotEmpty() { return new Predicate<T>() { @Override public boolean apply(T input) { return Iterables.isEmpty(input); } @Override public String toString() { return "whileNotEmpty()"; } }; }
From source file:org.trancecode.xproc.step.PipelineStepProcessor.java
private static Step addImplicitInputPort(final Step pipeline) { if (Iterables.isEmpty(pipeline.getInputPorts())) { return pipeline .declarePort(Port.newInputPort(pipeline.getName(), XProcPorts.SOURCE, pipeline.getLocation())); }//from w w w . j a v a2 s . c o m return pipeline; }