List of usage examples for org.apache.commons.lang3 StringUtils join
public static String join(final Iterable<?> iterable, final String separator)
Joins the elements of the provided Iterable into a single String containing the provided elements.
No delimiter is added before or after the list.
From source file:net.ae97.pokebot.extensions.scrolls.OnlineCommand.java
@Override public void runEvent(CommandEvent event) { try {//from w ww.ja va 2 s . co m List<String> lines = new LinkedList<>(); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", "PokeBot - " + PokeBot.VERSION); conn.connect(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { lines.add(line); } } JsonParser parser = new JsonParser(); JsonElement element = parser.parse(StringUtils.join(lines, "\n")); JsonObject obj = element.getAsJsonObject(); int online = obj.get("data").getAsJsonObject().get("online").getAsInt(); event.respond("there are " + online + " online users in Scrolls"); } catch (IOException | JsonSyntaxException ex) { PokeBot.getLogger().log(Level.SEVERE, "Error on getting online players for Scrolls", ex); event.respond("error on finding online players: " + ex.getLocalizedMessage()); } }
From source file:net.ae97.pokebot.extensions.scrolls.StatCommand.java
@Override public void runEvent(CommandEvent event) { try {//from ww w . j a v a2 s . c o m List<String> lines = new LinkedList<>(); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", "PokeBot - " + PokeBot.VERSION); conn.connect(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { lines.add(line); } } JsonParser parser = new JsonParser(); JsonElement element = parser.parse(StringUtils.join(lines, "\n")); JsonObject obj = element.getAsJsonObject(); JsonObject dataObject = obj.get("data").getAsJsonObject(); StringBuilder builder = new StringBuilder(); builder.append("Stats - "); builder.append("Online today: ").append(dataObject.get("onlinetoday").getAsInt()); builder.append(" - "); builder.append("Gold earned: ").append(dataObject.get("goldearned").getAsInt()); builder.append(" - "); builder.append("Games played: ").append(dataObject.get("gamesplayed").getAsInt()); builder.append(" - "); builder.append("Total users: ").append(dataObject.get("totalusers").getAsInt()); String message = builder.toString(); event.respond(message); } catch (IOException | JsonSyntaxException ex) { PokeBot.getLogger().log(Level.SEVERE, "Error on getting stats for Scrolls", ex); event.respond("Error on getting stats: " + ex.getLocalizedMessage()); } }
From source file:cn.com.axiom.utils.Collections3.java
/** * ?Collection(toString())String, separator *///from w w w . j av a 2 s .com @SuppressWarnings("rawtypes") public static String convertToString(final Collection collection, final String separator) { return StringUtils.join(collection, separator); }
From source file:com.google.code.yourpresenter.view.PreferencesView.java
/** * @return the mediaDirs/*from w w w.j av a2 s .co m*/ * @throws YpException */ public String getMediaDirs() throws YpException { String[] dirs = this.preferenceService.findStringArrayById(IConstants.MEDIA_DIRS); setMediaDirs(StringUtils.join(dirs, ",")); return mediaDirs; }
From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.ThinkingSeedGenerator.java
public static String ThinkingSeedGenerator(String seed, int difficulty, String language) throws ClassNotFoundException, SQLException, IOException, InstantiationException, IllegalAccessException {/* ww w . j a v a 2s . c o m*/ ArrayList<String> mined = new ArrayList<String>(); Connect c = new Connect(language); RandomWordGenerator r = new RandomWordGenerator(c); String randomPhrase = r.selectRandomWord(seed, difficulty); int size = randomPhrase.split(",").length; Random rand = new Random(); if (language.equalsIgnoreCase("en")) { while (mined.size() < size) { int Point = rand.nextInt(1172);//number of words in english thesaurus String word = FileUtils.readLines(new File(c.getEnglish_thes())).get(Point).trim(); if (mined.contains(word)) {//|| inf.getStop().contains(word)) { continue; } mined.add(word); } } else if (language.equalsIgnoreCase("de")) { while (mined.size() < size) { int Point = rand.nextInt(1704);//number of words in german thesaurus String word = FileUtils.readLines(new File(c.getGerman_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } else { while (mined.size() < size) { int Point = rand.nextInt(933);//number of words in greek thesaurus String word = FileUtils.readLines(new File(c.getGreek_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } c.CloseConnection(); return StringUtils.join(mined, ","); }
From source file:com.github.rvesse.airline.io.printers.TestTroffPrinter.java
@Test public void title_01() { StringWriter strWriter = new StringWriter(); TroffPrinter printer = new TroffPrinter(new PrintWriter(strWriter)); printer.start("Test", 1); printer.finish();/*w ww. j av a 2 s .c om*/ //@formatter:off String expected = StringUtils.join(new String[] { ".TH \"Test\" \"1\" \"\" \"\" \"\"", "" }, '\n'); //@formatter:on Assert.assertEquals(strWriter.toString(), expected); }
From source file:com.vrem.wifianalyzer.wifi.ChannelAvailableAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView;//from www .jav a 2s. c o m if (view == null) { view = MainContext.INSTANCE.getLayoutInflater().inflate(R.layout.channel_available_details, parent, false); } WiFiChannelCountry wiFiChannelCountry = getItem(position); ((TextView) view.findViewById(R.id.channel_available_country)) .setText(wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName()); ((TextView) view.findViewById(R.id.channel_available_title_ghz_2)).setText(WiFiBand.GHZ2.getBand() + " : "); ((TextView) view.findViewById(R.id.channel_available_ghz_2)) .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ",")); ((TextView) view.findViewById(R.id.channel_available_title_ghz_5)).setText(WiFiBand.GHZ5.getBand() + " : "); ((TextView) view.findViewById(R.id.channel_available_ghz_5)) .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ",")); return view; }
From source file:com.aqnote.app.wifianalyzer.wifi.ChannelAvailableAdapterTest.java
@Test public void testGetView() throws Exception { // setup// ww w . j a v a 2 s .com String expected = wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName(); String expected_GHZ_2 = StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ","); String expected_GHZ_5 = StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ","); // execute View actual = fixture.getView(0, null, null); // validate assertNotNull(actual); assertEquals(expected, ((TextView) actual.findViewById(R.id.channel_available_country)).getText()); assertEquals(WiFiBand.GHZ2.getBand() + " : ", ((TextView) actual.findViewById(R.id.channel_available_title_ghz_2)).getText()); assertEquals(expected_GHZ_2, ((TextView) actual.findViewById(R.id.channel_available_ghz_2)).getText()); assertEquals(WiFiBand.GHZ5.getBand() + " : ", ((TextView) actual.findViewById(R.id.channel_available_title_ghz_5)).getText()); assertEquals(expected_GHZ_5, ((TextView) actual.findViewById(R.id.channel_available_ghz_5)).getText()); }
From source file:com.orm.androrm.migration.RenameRelationMigration.java
@Override public boolean execute(Context context, Class<T> model) { MigrationHelper helper = new MigrationHelper(context); List<String> tables = helper.getRelationTableNames(mOldName); String newName = DatabaseBuilder.getTableName(model); mValue = StringUtils.join(tables, ","); if (isApplied(model, context)) { return false; }// w w w .ja v a2 s. c o m DatabaseAdapter adapter = DatabaseAdapter.getInstance(context); for (String table : tables) { List<String> parts = Arrays.asList(table.replace(mOldName, newName).split("_")); Collections.sort(parts); String name = StringUtils.join(parts, "_"); try { adapter.renameTable(table, name); } catch (SQLException e) { return false; } } return true; }
From source file:com.ibm.util.merge.directive.Require.java
public String getTags() { return StringUtils.join(tags, ","); }