Java Code Examples for java.util.Collection#toString()
The following examples show how to use
java.util.Collection#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaultResponses.java From spring-vault with Apache License 2.0 | 6 votes |
/** * Obtain the error message from a JSON response. * @param json must not be {@literal null}. * @return extracted error string. */ @SuppressWarnings("unchecked") public static String getError(String json) { Assert.notNull(json, "Error JSON must not be null"); if (json.contains("\"errors\":")) { try { Map<String, Object> map = OBJECT_MAPPER.readValue(json.getBytes(), Map.class); if (map.containsKey("errors")) { Collection<String> errors = (Collection<String>) map.get("errors"); if (errors.size() == 1) { return errors.iterator().next(); } return errors.toString(); } } catch (IOException o_O) { // ignore } } return json; }
Example 2
Source File: RoleSelection.java From triplea with GNU General Public License v3.0 | 6 votes |
private Button newFactionButton( final GamePlayer gamePlayer, final ComboBox<String> controllingPlayer) { final Collection<String> playerAlliances = gameData.getAllianceTracker().getAlliancesPlayerIsIn(gamePlayer); final var faction = new Button(playerAlliances.toString()); faction.setOnAction( e -> { controllingPlayer.getSelectionModel().select(PlayerType.HUMAN_PLAYER.getLabel()); playerAlliances.stream() .map(gameData.getAllianceTracker()::getPlayersInAlliance) .flatMap(Collection::stream) .map(roleForPlayers::get) .map(ComboBox::getSelectionModel) .forEach(selectionModel -> selectionModel.select(PlayerType.HUMAN_PLAYER.getLabel())); }); return faction; }
Example 3
Source File: ObjectWriter.java From butterfly-persistence with Apache License 2.0 | 6 votes |
public UpdateResult deleteByPrimaryKeysBatch(IObjectMapping mapping, Collection primaryKeys, String sql, Connection connection) throws PersistenceException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(sql); Iterator iterator = primaryKeys.iterator(); while(iterator.hasNext()){ Object primaryKey = iterator.next(); insertPrimaryKeyValue(mapping, primaryKey, preparedStatement, 1); preparedStatement.addBatch(); } UpdateResult result = new UpdateResult(); result.setAffectedRecords(preparedStatement.executeBatch()); // addGeneratedKeys(preparedStatement, result); return result; } catch (SQLException e) { throw new PersistenceException("Error batch deleting objects in database. Primary keys were: (" + primaryKeys.toString() + ")\nSql: " + sql, e); } finally { JdbcUtil.close(preparedStatement); } }
Example 4
Source File: ObjectWriter.java From butterfly-persistence with Apache License 2.0 | 6 votes |
public UpdateResult updateBatch(IObjectMapping mapping, Collection objects, String sql, Connection connection) throws PersistenceException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(sql); Iterator iterator = objects.iterator(); while(iterator.hasNext()){ Object object = iterator.next(); int parameterCount = insertObjectFieldsInStatement(mapping, object, preparedStatement); insertPrimaryKeyFromObject(mapping, object, preparedStatement, parameterCount); preparedStatement.addBatch(); } UpdateResult result = new UpdateResult(); result.setAffectedRecords(preparedStatement.executeBatch()); //addGeneratedKeys(preparedStatement, result); return result; } catch (SQLException e) { throw new PersistenceException("Error batch updating objects in database. Objects were: (" + objects.toString() + ")\nSql: " + sql, e); } finally { JdbcUtil.close(preparedStatement); } }
Example 5
Source File: ObjectWriter.java From butterfly-persistence with Apache License 2.0 | 6 votes |
public UpdateResult insertBatch(IObjectMapping mapping, Collection objects, String sql, Connection connection) throws PersistenceException { PreparedStatement preparedStatement = null; try { preparedStatement = prepareStatementForInsert(mapping, connection, sql, preparedStatement); Iterator iterator = objects.iterator(); while(iterator.hasNext()){ Object object = iterator.next(); insertObjectFieldsInStatement(mapping, object, preparedStatement); preparedStatement.addBatch(); } UpdateResult result = new UpdateResult(); result.setAffectedRecords(preparedStatement.executeBatch()); addGeneratedKeys(mapping, preparedStatement, result); return result; } catch (SQLException e) { throw new PersistenceException("Error batch inserting objects in database. Objects were: (" + objects.toString() + ")\nSql: " + sql, e); } finally { JdbcUtil.close(preparedStatement); } }
Example 6
Source File: AnnotationHelper.java From rice with Educational Community License v2.0 | 6 votes |
private String getTypeOrFieldNameForMsg(final BodyDeclaration n) { if (n instanceof TypeDeclaration) { return ((TypeDeclaration) n).getName(); } else if (n instanceof FieldDeclaration) { final FieldDeclaration fd = (FieldDeclaration) n; //this wont work for nested classes but we should be in nexted classes at this point final CompilationUnit unit = getCompilationUnit(n); final TypeDeclaration parent = unit.getTypes().get(0); Collection<String> variableNames = new ArrayList<String>(); if (fd.getVariables() != null) { for (VariableDeclarator vd : fd.getVariables()) { variableNames.add(vd.getId().getName()); } } return variableNames.size() == 1 ? parent.getName() + "." + variableNames.iterator().next() : parent.getName() + "." + variableNames.toString(); } return null; }
Example 7
Source File: EVCacheMetricsFactory.java From EVCache with Apache License 2.0 | 6 votes |
public Timer getPercentileTimer(String metric, Collection<Tag> tags, Duration max) { final String name = tags != null ? metric + tags.toString() : metric; final Timer duration = timerMap.get(name); if (duration != null) return duration; writeLock.lock(); try { if (timerMap.containsKey(name)) return timerMap.get(name); else { Id id = getId(metric, tags); final Timer _duration = PercentileTimer.builder(getRegistry()).withId(id).withRange(Duration.ofNanos(100000), max).build(); timerMap.put(name, _duration); return _duration; } } finally { writeLock.unlock(); } }
Example 8
Source File: EVCacheMetricsFactory.java From EVCache with Apache License 2.0 | 6 votes |
public Counter getCounter(String cName, Collection<Tag> tags) { final String name = tags != null ? cName + tags.toString() : cName; Counter counter = counterMap.get(name); if (counter == null) { writeLock.lock(); try { if (counterMap.containsKey(name)) { counter = counterMap.get(name); } else { List<Tag> tagList = new ArrayList<Tag>(tags.size() + 1); tagList.addAll(tags); final Id id = getId(cName, tagList); counter = getRegistry().counter(id); counterMap.put(name, counter); } } finally { writeLock.unlock(); } } return counter; }
Example 9
Source File: ClientSetupPanel.java From triplea with GNU General Public License v3.0 | 5 votes |
PlayerRow( final String playerName, final Collection<String> playerAlliances, final boolean enabled) { playerNameLabel.setText(playerName); enabledCheckBox.addActionListener(disablePlayerActionListener); enabledCheckBox.setSelected(enabled); final boolean hasAlliance = !playerAlliances.contains(playerName); alliance = new JButton(hasAlliance ? playerAlliances.toString() : ""); alliance.setVisible(hasAlliance); }
Example 10
Source File: BlobLibraryCacheManager.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public void register( ExecutionAttemptID task, Collection<PermanentBlobKey> requiredLibraries, Collection<URL> requiredClasspaths) { // Make sure the previous registration referred to the same libraries and class paths. // NOTE: the original collections may contain duplicates and may not already be Set // collections with fast checks whether an item is contained in it. // lazy construction of a new set for faster comparisons if (libraries.size() != requiredLibraries.size() || !new HashSet<>(requiredLibraries).containsAll(libraries)) { throw new IllegalStateException( "The library registration references a different set of library BLOBs than" + " previous registrations for this job:\nold:" + libraries.toString() + "\nnew:" + requiredLibraries.toString()); } // lazy construction of a new set with String representations of the URLs if (classPaths.size() != requiredClasspaths.size() || !requiredClasspaths.stream().map(URL::toString).collect(Collectors.toSet()) .containsAll(classPaths)) { throw new IllegalStateException( "The library registration references a different set of library BLOBs than" + " previous registrations for this job:\nold:" + classPaths.toString() + "\nnew:" + requiredClasspaths.toString()); } this.referenceHolders.add(task); }
Example 11
Source File: JenkinsTest.java From osmo with GNU Lesser General Public License v2.1 | 5 votes |
/** * Provides a list of class names for model objects from which the different test steps have been executed. * * @return The string list. */ public String getClassName() { Collection<JenkinsStep> mySteps = new LinkedHashSet<>(); mySteps.addAll(steps); Collection<String> name = new LinkedHashSet<>(); for (JenkinsStep step : mySteps) { name.add(step.getClassName()); } return name.toString(); }
Example 12
Source File: DefaultCollectionRenderer.java From Raccoon with Apache License 2.0 | 5 votes |
@Override public String render(Collection collection, Locale locale) { final String renderedResult; if (collection.size() == 0) { renderedResult = ""; } else if (collection.size() == 1) { renderedResult = collection.iterator().next().toString(); } else { renderedResult = collection.toString(); } return renderedResult; }
Example 13
Source File: ObjectWriter.java From butterfly-persistence with Apache License 2.0 | 5 votes |
public UpdateResult updateBatch(IObjectMapping mapping, Collection objects, Collection oldPrimaryKeys, String sql, Connection connection) throws PersistenceException { PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(sql); Iterator objectIterator = objects.iterator(); Iterator oldPrimaryKeyIterator = oldPrimaryKeys.iterator(); while(objectIterator.hasNext()){ Object object = objectIterator.next(); Object oldPrimaryKey = oldPrimaryKeyIterator.next(); int parameterCount = insertObjectFieldsInStatement(mapping, object, preparedStatement); insertPrimaryKeyValue(mapping, oldPrimaryKey, preparedStatement, parameterCount); preparedStatement.addBatch(); } UpdateResult result = new UpdateResult(); result.setAffectedRecords(preparedStatement.executeBatch()); //addGeneratedKeys(preparedStatement, result); return result; } catch (SQLException e) { throw new PersistenceException("Error batch updating objects in database. Objects were: (" + objects.toString() + ")\nOld Primary Keys were: (" + oldPrimaryKeys + ")" + "\nSql: " + sql, e); } finally { JdbcUtil.close(preparedStatement); } }
Example 14
Source File: CompileRule.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
public void assertMessage(File basedir, String path, ErrorMessage expected) throws Exception { Collection<String> messages = getBuildContextLog().getMessages(new File(basedir, path)); if (messages.size() != 1) { throw new ComparisonFailure("Number of messages", expected.toString(), messages.toString()); } String message = messages.iterator().next(); if (!expected.isMatch(message)) { throw new ComparisonFailure("", expected.toString(), message); } }
Example 15
Source File: BlobLibraryCacheManager.java From flink with Apache License 2.0 | 5 votes |
public void register( ExecutionAttemptID task, Collection<PermanentBlobKey> requiredLibraries, Collection<URL> requiredClasspaths) { // Make sure the previous registration referred to the same libraries and class paths. // NOTE: the original collections may contain duplicates and may not already be Set // collections with fast checks whether an item is contained in it. // lazy construction of a new set for faster comparisons if (libraries.size() != requiredLibraries.size() || !new HashSet<>(requiredLibraries).containsAll(libraries)) { throw new IllegalStateException( "The library registration references a different set of library BLOBs than" + " previous registrations for this job:\nold:" + libraries.toString() + "\nnew:" + requiredLibraries.toString()); } // lazy construction of a new set with String representations of the URLs if (classPaths.size() != requiredClasspaths.size() || !requiredClasspaths.stream().map(URL::toString).collect(Collectors.toSet()) .containsAll(classPaths)) { throw new IllegalStateException( "The library registration references a different set of library BLOBs than" + " previous registrations for this job:\nold:" + classPaths.toString() + "\nnew:" + requiredClasspaths.toString()); } this.referenceHolders.add(task); }
Example 16
Source File: CopyOnWriteArraySetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * toString holds toString of elements */ public void testToString() { assertEquals("[]", new CopyOnWriteArraySet().toString()); Collection full = populatedSet(3); String s = full.toString(); for (int i = 0; i < 3; ++i) assertTrue(s.contains(String.valueOf(i))); assertEquals(new ArrayList(full).toString(), full.toString()); }
Example 17
Source File: InputConnectionCommandEditor.java From speechutils with Apache License 2.0 | 5 votes |
@Override public Op combineOps(final Collection<Op> ops) { return new Op(ops.toString(), ops.size()) { @Override public Op run() { final Deque<Op> combination = new ArrayDeque<>(); mInputConnection.beginBatchEdit(); for (Op op : ops) { if (op != null && !op.isNoOp()) { Op undo = op.run(); if (undo == null) { break; } combination.push(undo); } } mInputConnection.endBatchEdit(); return new Op(combination.toString(), combination.size()) { @Override public Op run() { mInputConnection.beginBatchEdit(); while (!combination.isEmpty()) { Op undo1 = combination.pop().run(); if (undo1 == null) { break; } } mInputConnection.endBatchEdit(); return combineOps(ops); } }; } }; }
Example 18
Source File: StringFactory.java From tinkerpop with Apache License 2.0 | 4 votes |
public static String removeEndBrackets(final Collection collection) { final String string = collection.toString(); return string.substring(1, string.length() - 1); }
Example 19
Source File: BPServiceActor.java From big-c with Apache License 2.0 | 4 votes |
private String formatThreadName() { Collection<StorageLocation> dataDirs = DataNode.getStorageLocations(dn.getConf()); return "DataNode: [" + dataDirs.toString() + "] " + " heartbeating to " + nnAddr; }
Example 20
Source File: CollectionUtils.java From AndroidUtilCode with Apache License 2.0 | 2 votes |
/** * Return the string of collection. * * @param collection The collection. * @return the string of collection */ public static String toString(Collection collection) { if (collection == null) return "null"; return collection.toString(); }