下面列出了java.util.Collection#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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();
}
}
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;
}
/**
* 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;
}
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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
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);
}
@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;
}
/**
* 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();
}
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);
}
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);
}
}
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);
}
}
/**
* 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());
}
@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);
}
};
}
};
}
public static String removeEndBrackets(final Collection collection) {
final String string = collection.toString();
return string.substring(1, string.length() - 1);
}
private String formatThreadName() {
Collection<StorageLocation> dataDirs =
DataNode.getStorageLocations(dn.getConf());
return "DataNode: [" + dataDirs.toString() + "] " +
" heartbeating to " + nnAddr;
}
/**
* 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();
}