本文整理了Java中java.util.Collections.reverse()
方法的一些代码示例,展示了Collections.reverse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.reverse()
方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:reverse
[英]Modifies the specified List by reversing the order of the elements.
[中]通过颠倒元素的顺序来修改指定的列表。
代码示例来源:origin: jenkinsci/jenkins
/**
* Reverses a collection so that it can be easily walked in reverse order.
* @since 1.525
*/
public static <T> Iterable<T> reverse(Collection<T> collection) {
List<T> list = new ArrayList<T>(collection);
Collections.reverse(list);
return list;
}
代码示例来源:origin: JakeWharton/butterknife
Type(ResourceMethod... methods) {
List<ResourceMethod> methodList = new ArrayList<>(methods.length);
Collections.addAll(methodList, methods);
Collections.sort(methodList);
Collections.reverse(methodList);
this.methods = ImmutableList.copyOf(methodList);
}
代码示例来源:origin: stackoverflow.com
Collections.sort(testList);
Collections.reverse(testList);
代码示例来源:origin: ysc/QuestionAnsweringSystem
public List<CandidateAnswer> getTopNCandidateAnswer(int topN) {
//按CandidateAnswer的分值排序,返回topN
List<CandidateAnswer> result = new ArrayList<>();
Collections.sort(candidateAnswers);
Collections.reverse(candidateAnswers);
int len = candidateAnswers.size();
if (topN > len) {
topN = len;
}
for (int i = 0; i < candidateAnswers.size(); i++) {
result.add(candidateAnswers.get(i));
}
return result;
}
代码示例来源:origin: google/guava
@Override
public Iterable<E> order(List<E> insertionOrder) {
List<E> list = new ArrayList<E>();
for (E e : delegate.order(insertionOrder)) {
list.add(e);
}
Collections.reverse(list);
return list;
}
代码示例来源:origin: konsoletyper/teavm
private static String commonSuperClass(ClassReaderSource classSource, String a, String b) {
if (a.equals(b)) {
return a;
}
List<String> firstPath = pathToRoot(classSource, a);
List<String> secondPath = pathToRoot(classSource, b);
Collections.reverse(firstPath);
Collections.reverse(secondPath);
int min = Math.min(firstPath.size(), secondPath.size());
for (int i = 1; i < min; ++i) {
if (!firstPath.get(i).equals(secondPath.get(i))) {
return firstPath.get(i - 1);
}
}
return firstPath.get(0);
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static List<Mention> getOrderedAntecedents(
Mention m,
int antecedentSentence,
int mPosition,
List<List<Mention>> orderedMentionsBySentence,
Dictionaries dict) {
List<Mention> orderedAntecedents = new ArrayList<>();
// ordering antecedents
if (antecedentSentence == m.sentNum) { // same sentence
orderedAntecedents.addAll(orderedMentionsBySentence.get(m.sentNum).subList(0, mPosition));
if(dict.relativePronouns.contains(m.spanToString())) Collections.reverse(orderedAntecedents);
else {
orderedAntecedents = sortMentionsByClause(orderedAntecedents, m);
}
} else { // previous sentence
orderedAntecedents.addAll(orderedMentionsBySentence.get(antecedentSentence));
}
return orderedAntecedents;
}
代码示例来源:origin: spring-projects/spring-framework
AnnotationAttributes result = new AnnotationAttributes(attributesList.get(0));
List<String> annotationTypes = new ArrayList<>(attributesMap.keySet());
Collections.reverse(annotationTypes);
Set<String> metaAnns = metaAnnotationMap.get(currentAnnotationType);
if (metaAnns != null && metaAnns.contains(annotationName)) {
AnnotationAttributes currentAttributes = currentAttributesList.get(0);
for (String overridableAttributeName : overridableAttributeNames) {
Object value = currentAttributes.get(overridableAttributeName);
代码示例来源:origin: CalebFenton/simplify
private void replaceFieldGet() {
List<Integer> getAddresses = new LinkedList<>();
for (int address : addresses) {
if (canReplaceFieldGet(address)) {
getAddresses.add(address);
}
}
if (0 == getAddresses.size()) {
return;
}
madeChanges = true;
unreflectedFieldCount += getAddresses.size();
Collections.reverse(getAddresses);
for (int address : getAddresses) {
BuilderInstruction replacement = buildFieldGetReplacement(address);
removeMoveResultIfNecessary(address);
manipulator.replaceInstruction(address, replacement);
}
}
代码示例来源:origin: google/guava
void calculateNextPermutation() {
int j = findNextJ();
if (j == -1) {
nextPermutation = null;
return;
}
int l = findNextL(j);
Collections.swap(nextPermutation, j, l);
int n = nextPermutation.size();
Collections.reverse(nextPermutation.subList(j + 1, n));
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
rides.add(ride);
Collections.reverse(rides);
rides.get(0).accessStats = new Stats();
rides.get(0).accessDist = 0;
transit.add(segment);
stats.add(segment.walkTime);
if(segment.waitStats != null) stats.add(segment.waitStats);
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Returns the current stack as a list
*/
public List<T> asList() {
List<T> result = Generics.newArrayList(size);
TreeShapedStack<T> current = this;
for (int index = 0; index < size; ++index) {
result.add(current.data);
current = current.pop();
}
Collections.reverse(result);
return result;
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Removes all entries from c except for the top {@code num}.
*/
public static <E extends Comparable<E>> void retainTopKeyComparable(Counter<E> c, int num) {
int numToPurge = c.size() - num;
if (numToPurge <= 0) {
return;
}
List<E> l = Counters.toSortedListKeyComparable(c);
Collections.reverse(l);
for (int i = 0; i < numToPurge; i++) {
c.remove(l.get(i));
}
}
代码示例来源:origin: apache/incubator-dubbo
_writeReplace.setAccessible(true);
List primitiveFields = new ArrayList();
List compoundFields = new ArrayList();
|| (field.getType().getName().startsWith("java.lang.")
&& !field.getType().equals(Object.class)))
primitiveFields.add(field);
else
compoundFields.add(field);
List fields = new ArrayList();
fields.addAll(primitiveFields);
fields.addAll(compoundFields);
Collections.reverse(fields);
_fields = new Field[fields.size()];
fields.toArray(_fields);
代码示例来源:origin: square/javapoet
/** Returns all enclosing classes in this, outermost first. */
private List<ClassName> enclosingClasses() {
List<ClassName> result = new ArrayList<>();
for (ClassName c = this; c != null; c = c.enclosingClassName) {
result.add(c);
}
Collections.reverse(result);
return result;
}
}
代码示例来源:origin: spring-cloud/spring-cloud-gateway
/**
* The X-Forwarded-For header contains a comma separated list of IP addresses. This
* method parses those IP addresses into a list. If no X-Forwarded-For header is
* found, an empty list is returned. If multiple X-Forwarded-For headers are found, an
* empty list is returned out of caution.
* @return The parsed values of the X-Forwarded-Header.
*/
@Override
public InetSocketAddress resolve(ServerWebExchange exchange) {
List<String> xForwardedValues = extractXForwardedValues(exchange);
Collections.reverse(xForwardedValues);
if (!xForwardedValues.isEmpty()) {
int index = Math.min(xForwardedValues.size(), maxTrustedIndex) - 1;
return new InetSocketAddress(xForwardedValues.get(index), 0);
}
return defaultRemoteIpResolver.resolve(exchange);
}
代码示例来源:origin: stackoverflow.com
ArrayList aList = new ArrayList();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
Collections.reverse(aList);
System.out.println("After Reverse Order, ArrayList Contains : " + aList);
代码示例来源:origin: stanfordnlp/CoreNLP
Map<Integer, CorefCluster> corefClusters,
Dictionaries dict) {
List<Mention> orderedAntecedents = new ArrayList<>();
orderedAntecedents = sortMentionsForPronoun(orderedAntecedents, m1, true);
if(dict.relativePronouns.contains(m1.spanToString())) Collections.reverse(orderedAntecedents);
} else { // previous sentence
orderedAntecedents.addAll(orderedMentionsBySentence.get(antecedentSentence));
代码示例来源:origin: spring-projects/spring-framework
List<ContextConfigurationAttributes> reversedList = new ArrayList<>(list);
Collections.reverse(reversedList);
Class<?> declaringClass = reversedList.get(0).getDeclaringClass();
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* A List of the keys in c, sorted from highest count to lowest.
*
* @return A List of the keys in c, sorted from highest count to lowest.
*/
public static <E extends Comparable<E>> List<E> toSortedListKeyComparable(Counter<E> c) {
List<E> l = new ArrayList<>(c.keySet());
Comparator<E> comp = toComparatorWithKeys(c);
Collections.sort(l, comp);
Collections.reverse(l);
return l;
}
内容来源于网络,如有侵权,请联系作者删除!