List of usage examples for com.google.common.base Functions toStringFunction
public static Function<Object, String> toStringFunction()
From source file:com.mmounirou.spotirss.SpotiRss.java
/** * @param args/* w w w. ja va 2s . c om*/ * @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:com.clarkparsia.geneious.SOFAAnnotationGenerator.java
public static void main(String[] args) { final FilterTreeModel model = createTreeModel(); final FilterTree tree = new FilterTree(model, Functions.toStringFunction()); final JTextField field = new JTextField(10); tree.setFilterField(field);/*from w ww .ja v a 2 s . c o m*/ JFrame frame = new JFrame(); frame.getContentPane().add(field, BorderLayout.NORTH); frame.getContentPane().add(new JScrollPane(tree)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 480); frame.setVisible(true); frame.setLocationRelativeTo(null); }
From source file:org.apache.druid.indexer.path.HadoopGlobPathSplitter.java
/** * Splits given hadoop glob path by commas. * e.g. splitGlob("/a,/b") -> ["/a","/b"] * splitGlob("/a/{c,d}") -> ["/a/c", "/a/d"] *///w w w.j av a 2 s .c o m public static Iterable<String> splitGlob(String path) { return Iterables.transform(splitGlob(new CharStream(path)), Functions.toStringFunction()); }
From source file:org.kududb.util.NetUtil.java
/** * Convert a list of {@link HostAndPort} objects to a comma separate string. * The inverse of {@link #parseStrings(String, int)}. * * @param hostsAndPorts A list of {@link HostAndPort} objects. * @return Comma separate list of "host:port" pairs. *///from w w w. j av a 2 s .c o m public static String hostsAndPortsToString(List<HostAndPort> hostsAndPorts) { return Joiner.on(",").join(Lists.transform(hostsAndPorts, Functions.toStringFunction())); }
From source file:swingn.ui.ItemBox.java
public ItemBox() { this(Functions.toStringFunction()); }
From source file:swingn.ui.ItemBox.java
public ItemBox(Menu menu) { this(Functions.toStringFunction(), menu); }
From source file:com.google.devtools.build.lib.rules.python.PythonVersion.java
private static Iterable<String> convertToStrings(PythonVersion[] values) { return transform(ImmutableList.copyOf(values), Functions.toStringFunction()); }
From source file:org.polarsys.reqcycle.jdt.traceability.JDTPreferences.java
public static void savePreferences(Map<String, TType> map) { IConfigurationManager manager = ZigguratInject.make(IConfigurationManager.class); Map<String, Object> newMap = new HashMap<String, Object>( Maps.transformValues(map, Functions.toStringFunction())); try {//w w w . jav a 2 s . co m manager.saveSimpleConfiguration(newMap, null, null, JDT_TYPES_CONSTANT); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.jonross.seq4j.Fns.java
/** @see Functions#toStringFunction() */ public static Function<Object, String> asString() { return Functions.toStringFunction(); }
From source file:org.kududb.client.NoLeaderMasterFoundException.java
/** * Factory method that creates a NoLeaderException given a message and a list * (which may be empty, but must be initialized) of exceptions encountered: they indicate * why {@link GetMasterRegistrationRequest} calls to the masters in the config * have failed, to aid in debugging the issue. If the list is non-empty, each exception's * 'toString()' message is appended to 'msg' and the last exception is used as the * cause for the exception./*from w w w . j ava2s.c o m*/ * @param msg A message detailing why this exception occured. * @param causes List of exceptions encountered when retrieving registration from individual * masters. * @return An instantiated NoLeaderMasterFoundException which can be thrown. */ static NoLeaderMasterFoundException create(String msg, List<Exception> causes) { if (causes.isEmpty()) { return new NoLeaderMasterFoundException(msg); } String joinedMsg = msg + ". Exceptions received: " + Joiner.on(",").join(Lists.transform(causes, Functions.toStringFunction())); return new NoLeaderMasterFoundException(joinedMsg, causes.get(causes.size() - 1)); }