List of usage examples for com.google.common.collect Lists newLinkedList
@GwtCompatible(serializable = true) public static <E> LinkedList<E> newLinkedList(Iterable<? extends E> elements)
From source file:com.google.jstestdriver.JsTestDriver.java
public static void main(String[] args) { try {//from w w w.ja v a 2 s.co m // pre-parse parsing... These are the flags // that must be dealt with before we parse the flags. CmdFlags cmdLineFlags = new CmdLineFlagsFactory().create(args); List<Plugin> cmdLinePlugins = cmdLineFlags.getPlugins(); // configure logging before we start seriously processing. LogManager.getLogManager().readConfiguration(cmdLineFlags.getRunnerMode().getLogConfig()); final PluginLoader pluginLoader = new PluginLoader(); // load all the command line plugins. final List<Module> pluginModules = pluginLoader.load(cmdLinePlugins); logger.debug("loaded plugins %s", pluginModules); List<Module> initializeModules = Lists.newLinkedList(pluginModules); Configuration configuration = cmdLineFlags.getConfigurationSource().parse(cmdLineFlags.getBasePath(), new YamlParser()); File basePath = configuration.getBasePath().getCanonicalFile(); initializeModules.add(new InitializeModule(pluginLoader, basePath, new Args4jFlagsParser(cmdLineFlags), cmdLineFlags.getRunnerMode())); initializeModules.add(new Module() { public void configure(Binder binder) { Multibinder.newSetBinder(binder, PluginInitializer.class).addBinding() .to(TestResultPrintingInitializer.class); } }); Injector initializeInjector = Guice.createInjector(initializeModules); final List<Module> actionRunnerModules = initializeInjector.getInstance(Initializer.class).initialize( pluginModules, configuration, cmdLineFlags.getRunnerMode(), cmdLineFlags.getUnusedFlagsAsArgs()); Injector injector = Guice.createInjector(actionRunnerModules); injector.getInstance(ActionRunner.class).runActions(); logger.info("Finished action run."); } catch (CmdLineException e) { System.out.println(e.getMessage()); System.exit(1); } catch (FailureException e) { System.out.println("Tests failed: " + e.getMessage()); System.exit(1); } catch (Exception e) { logger.debug("Error {}", e); e.printStackTrace(); System.out.println("Unexpected Runner Condition: " + e.getMessage() + "\n Use --runnerMode DEBUG for more information."); System.exit(1); } }
From source file:com.mmounirou.spotirss.SpotiRss.java
/** * @param args//w w w . ja v a 2s .co m * @throws IOException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws SpotifyClientException * @throws ChartRssException * @throws SpotifyException */ public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SpotifyClientException { if (args.length == 0) { System.err.println("usage : java -jar spotiboard.jar <charts-folder>"); return; } Properties connProperties = new Properties(); InputStream inStream = SpotiRss.class.getResourceAsStream("/spotify-server.properties"); try { connProperties.load(inStream); } finally { IOUtils.closeQuietly(inStream); } String host = connProperties.getProperty("host"); int port = Integer.parseInt(connProperties.getProperty("port")); String user = connProperties.getProperty("user"); final SpotifyClient spotifyClient = new SpotifyClient(host, port, user); final Map<String, Playlist> playlistsByTitle = getPlaylistsByTitle(spotifyClient); final File outputDir = new File(args[0]); outputDir.mkdirs(); TrackCache cache = new TrackCache(); try { for (String strProvider : PROVIDERS) { String providerClassName = EntryToTrackConverter.class.getPackage().getName() + "." + StringUtils.capitalize(strProvider); final EntryToTrackConverter converter = (EntryToTrackConverter) SpotiRss.class.getClassLoader() .loadClass(providerClassName).newInstance(); Iterable<String> chartsRss = getCharts(strProvider); final File resultDir = new File(outputDir, strProvider); resultDir.mkdir(); final SpotifyHrefQuery hrefQuery = new SpotifyHrefQuery(cache); Iterable<String> results = FluentIterable.from(chartsRss).transform(new Function<String, String>() { @Override @Nullable public String apply(@Nullable String chartRss) { try { long begin = System.currentTimeMillis(); ChartRss bilboardChartRss = ChartRss.getInstance(chartRss, converter); Map<Track, String> trackHrefs = hrefQuery.getTrackHrefs(bilboardChartRss.getSongs()); String strTitle = bilboardChartRss.getTitle(); File resultFile = new File(resultDir, strTitle); List<String> lines = Lists.newLinkedList(FluentIterable.from(trackHrefs.keySet()) .transform(Functions.toStringFunction())); lines.addAll(trackHrefs.values()); FileUtils.writeLines(resultFile, Charsets.UTF_8.displayName(), lines); Playlist playlist = playlistsByTitle.get(strTitle); if (playlist != null) { playlist.getTracks().clear(); playlist.getTracks().addAll(trackHrefs.values()); spotifyClient.patch(playlist); LOGGER.info(String.format("%s chart exported patched", strTitle)); } LOGGER.info(String.format("%s chart exported in %s in %d s", strTitle, resultFile.getAbsolutePath(), (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - begin))); } catch (Exception e) { LOGGER.error(String.format("fail to export %s charts", chartRss), e); } return ""; } }); // consume iterables Iterables.size(results); } } finally { cache.close(); } }
From source file:org.caleydo.vis.lineup.model.RankColumnModels.java
/** * flatten the hierarchy of the given columns * //w ww .ja v a 2 s. c o m * @param cols * @return */ public static Set<ARankColumnModel> flatten(Iterable<ARankColumnModel> cols) { Set<ARankColumnModel> result = new HashSet<>(); Deque<ARankColumnModel> queue = Lists.newLinkedList(cols); while (!queue.isEmpty()) { ARankColumnModel s = queue.pollFirst(); if (!result.add(s)) continue; if (s instanceof ACompositeRankColumnModel) queue.addAll(((ACompositeRankColumnModel) s).getChildren()); } return result; }
From source file:com.nitayjoffe.util.iterators.IteratorUtils.java
public static <E> Iterator<E> interleave(final Iterable<Iterator<E>> iterators) { return new AbstractIterator<E>() { private Queue<Iterator<E>> queue = Lists.newLinkedList(iterators); @Override/*w w w .j av a2 s . c o m*/ protected E computeNext() { while (!queue.isEmpty()) { Iterator<E> topIter = queue.poll(); if (topIter.hasNext()) { E result = topIter.next(); queue.offer(topIter); return result; } } return endOfData(); } }; }
From source file:org.jbb.lib.logging.health.LogbackStateStorage.java
public static List<Status> getLastStatuses() { return Lists.newLinkedList(Iterables.limit(STATUSES.descendingMap().values(), TAIL_SIZE)); }
From source file:net.diogobohm.timed.api.ui.domain.TaskList.java
public TaskList(List<Task> taskList) { this.taskList = Lists.newLinkedList(taskList); sortTasks(); }
From source file:org.thiesen.collections.list.impl.MutableLinkedList.java
public static <T> MutableLinkedList<T> copyOf(final Iterable<T> elements) { return new MutableLinkedList<T>(Lists.newLinkedList(elements)); }
From source file:ratpack.handling.internal.DescribingHandlers.java
public static void describeTo(Handler handler, StringBuilder stringBuilder) { Class<? extends Handler> clazz = handler.getClass(); if (clazz.isAnonymousClass()) { ClassPool pool = ClassPool.getDefault(); CtClass ctClass;//from w w w .j a v a 2 s . c o m try { ctClass = pool.get(clazz.getName()); CtBehavior[] behaviors = ctClass.getDeclaredBehaviors(); Iterable<CtBehavior> withLineNumberIterable = Iterables.filter(Arrays.asList(behaviors), input -> input.getMethodInfo().getLineNumber(0) > 0); LinkedList<CtBehavior> withLineNumber = Lists.newLinkedList(withLineNumberIterable); Collections.sort(withLineNumber, (o1, o2) -> Integer.valueOf(o1.getMethodInfo().getLineNumber(0)) .compareTo(o2.getMethodInfo().getLineNumber(0))); if (!withLineNumber.isEmpty()) { CtBehavior method = withLineNumber.get(0); int lineNumber = method.getMethodInfo().getLineNumber(0); ClassFile classFile = ctClass.getClassFile(); String sourceFile = classFile.getSourceFile(); if (lineNumber != -1 && sourceFile != null) { stringBuilder.append("anonymous class ").append(clazz.getName()) .append(" at approximately line ").append(lineNumber).append(" of ") .append(sourceFile); return; } } } catch (NotFoundException ignore) { // fall through } } stringBuilder.append(clazz.getName()); }
From source file:org.trnltk.util.DiffUtil.java
public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) { final diff_match_patch dmp = new diff_match_patch(); final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2); if (CollectionUtils.isEmpty(diffs)) { return null; } else {/*w ww. j a v a 2 s . co m*/ if (ignoreWhiteSpace) { final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists .newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() { @Override public boolean apply(diff_match_patch.Diff input) { if (input.operation.equals(diff_match_patch.Operation.EQUAL)) return false; else if (StringUtils.isBlank(input.text)) return false; return true; } })); if (filteredDiffs.isEmpty()) return null; } dmp.diff_cleanupSemantic(diffs); final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace); if (ignoreWhiteSpace) { if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2])) return null; } return diffLines; } }
From source file:org.thiesen.collections.list.impl.MutableLinkedList.java
public static <T> MutableLinkedList<T> copyOf(final T... elements) { return new MutableLinkedList<T>(Lists.newLinkedList(Arrays.asList(elements))); }