本文整理汇总了Java中java.util.Collections.rotate方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.rotate方法的具体用法?Java Collections.rotate怎么用?Java Collections.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reorderBySourcePosition
import java.util.Collections; //导入方法依赖的package包/类
/**
* Rotate the list of dimension specifiers until all dimensions with type annotations appear in
* source order.
* <p>
* <p>javac reorders dimension specifiers in method declarations with mixed-array notation, which
* means that any type annotations don't appear in source order.
* <p>
* <p>For example, the type of {@code int @A [] f() @B [] {}} is parsed as {@code @B [] @A []}.
* <p>
* <p>This doesn't handle cases with un-annotated dimension specifiers, so the formatting logic
* checks the token stream to figure out which side of the method name they appear on.
*/
private static Iterable<List<AnnotationTree>> reorderBySourcePosition(
Deque<List<AnnotationTree>> dims) {
int lastAnnotation = -1;
int lastPos = -1;
int idx = 0;
for (List<AnnotationTree> dim : dims) {
if (!dim.isEmpty()) {
int pos = ((JCTree) dim.get(0)).getStartPosition();
if (pos < lastPos) {
List<List<AnnotationTree>> list = new ArrayList<>(dims);
Collections.rotate(list, -(lastAnnotation + 1));
return list;
}
lastPos = pos;
lastAnnotation = idx;
}
idx++;
}
return dims;
}
示例2: moveAlgorithmAtIndex
import java.util.Collections; //导入方法依赖的package包/类
public void moveAlgorithmAtIndex(int sourcePosition, int targetPosition)
{
logger.debug("Shifting algorithm in list. Source=" + sourcePosition + ", Target=" + targetPosition);
if (sourcePosition <= targetPosition)
{
Collections.rotate(this.algorithmList.subList(sourcePosition, targetPosition + 1), -1);
}
else
{
Collections.rotate(this.algorithmList.subList(targetPosition, sourcePosition + 1), 1);
}
}
示例3: nextHost
import java.util.Collections; //导入方法依赖的package包/类
/**
* Returns an {@link Iterable} of hosts to be used for a request call.
* Ideally, the first host is retrieved from the iterable and used successfully for the request.
* Otherwise, after each failure the next host has to be retrieved from the iterator so that the request can be retried until
* there are no more hosts available to retry against. The maximum total of attempts is equal to the number of hosts in the iterable.
* The iterator returned will never be empty. In case there are no healthy hosts available, or dead ones to be be retried,
* one dead host gets returned so that it can be retried.
*/
private HostTuple<Iterator<HttpHost>> nextHost() {
final HostTuple<Set<HttpHost>> hostTuple = this.hostTuple;
Collection<HttpHost> nextHosts = Collections.emptySet();
do {
Set<HttpHost> filteredHosts = new HashSet<>(hostTuple.hosts);
for (Map.Entry<HttpHost, DeadHostState> entry : blacklist.entrySet()) {
if (System.nanoTime() - entry.getValue().getDeadUntilNanos() < 0) {
filteredHosts.remove(entry.getKey());
}
}
if (filteredHosts.isEmpty()) {
//last resort: if there are no good host to use, return a single dead one, the one that's closest to being retried
List<Map.Entry<HttpHost, DeadHostState>> sortedHosts = new ArrayList<>(blacklist.entrySet());
if (sortedHosts.size() > 0) {
Collections.sort(sortedHosts, new Comparator<Map.Entry<HttpHost, DeadHostState>>() {
@Override
public int compare(Map.Entry<HttpHost, DeadHostState> o1, Map.Entry<HttpHost, DeadHostState> o2) {
return Long.compare(o1.getValue().getDeadUntilNanos(), o2.getValue().getDeadUntilNanos());
}
});
HttpHost deadHost = sortedHosts.get(0).getKey();
logger.trace("resurrecting host [" + deadHost + "]");
nextHosts = Collections.singleton(deadHost);
}
} else {
List<HttpHost> rotatedHosts = new ArrayList<>(filteredHosts);
Collections.rotate(rotatedHosts, rotatedHosts.size() - lastHostIndex.getAndIncrement());
nextHosts = rotatedHosts;
}
} while(nextHosts.isEmpty());
return new HostTuple<>(nextHosts.iterator(), hostTuple.authCache);
}
示例4: SortAndAnimate
import java.util.Collections; //导入方法依赖的package包/类
/**
* @param sortByDate true to sort bookmarks by date false to sort them by position in the book
*/
public void SortAndAnimate(boolean sortByDate) {
Bookmark.sortByDate = sortByDate;
for (int i = 1; i < bookmarkList.size(); i++) {
int j = Math.abs(Collections.binarySearch(bookmarkList.subList(0, i), bookmarkList.get(i)) + 1);
Collections.rotate(bookmarkList.subList(j, i + 1), j - i);
notifyItemMoved(i, j);
}
}
示例5: SortAndAnimate
import java.util.Collections; //导入方法依赖的package包/类
/**
* @param sortByDate true to sort highlights by date false to sort them by position in the book
*/
public void SortAndAnimate(boolean sortByDate) {
Highlight.sortByDate = sortByDate;
for (int i = 1; i < highlightList.size(); i++) {
int j = Math.abs(Collections.binarySearch(highlightList.subList(0, i), highlightList.get(i)) + 1);
Collections.rotate(highlightList.subList(j, i + 1), j - i);
notifyItemMoved(i, j);
}
}
示例6: createUnequalTestCasesFor
import java.util.Collections; //导入方法依赖的package包/类
private static List<List<?>> createUnequalTestCasesFor(Md5sum... md5sums) {
List<List<?>> result = new ArrayList<>();
List<Md5sum> input = ImmutableList.copyOf(md5sums);
ArrayList<Md5sum> shifting = Lists.newArrayList(md5sums);
for (int i = 1; i < md5sums.length; i++) {
Collections.rotate(shifting, 1);
result.addAll(zip(input, shifting));
}
return result;
}
示例7: moveRowsUp
import java.util.Collections; //导入方法依赖的package包/类
public Boolean moveRowsUp(int from, int to) {
if (from - 1 < 0) {
return false;
}
to = to + 1;
Collections.rotate(records.subList(from - 1, to), -1);
setSaved(false);
return true;
}
示例8: moveRowsDown
import java.util.Collections; //导入方法依赖的package包/类
public Boolean moveRowsDown(int from, int to) {
if (to + 1 > records.size() - 1) {
return false;
}
to += 1;
Collections.rotate(records.subList(from, to + 1), 1);
setSaved(false);
return true;
}
示例9: moveRowsUp
import java.util.Collections; //导入方法依赖的package包/类
@JsonIgnore
public Boolean moveRowsUp(int from, int to) {
if (from - 1 < 0) {
return false;
}
to = to + 1;
Collections.rotate(attributes.subList(from - 1, to), -1);
changeSave();
return true;
}
示例10: annotateSubtitleFile
import java.util.Collections; //导入方法依赖的package包/类
/**
* Parse a subtitle file and add annotation if dictionary definitions were found.
*
* @return true if at least one annotation was added, false otherwise.
*/
public String[] annotateSubtitleFile(String fileName, String fileContents) throws IOException, FatalParsingException {
SubtitleFile subtitle = new SubtitleFile(fileName, fileContents, config.getSubtitleStyles());
// Loop through the subtitle file captions one by one
while (subtitle.hasNext()) {
String currentCaptionText = subtitle.nextCaption();
List<String> colors = new ArrayList<>(config.getHighlightColors());
// Parse subtitle and lookup definitions
List<String> alreadyDefinedWords = new ArrayList<>();
List<String> annotations = new ArrayList<>();
for (DictionaryMatch match : getFilteredMatches(currentCaptionText)) {
String color = colors.iterator().next();
List<String> tokenDefs = annotateDictionaryMatch(match, color);
if (!tokenDefs.isEmpty() && !alreadyDefinedWords.contains(match.getTextForm())) {
annotations.addAll(tokenDefs);
// Set a different color for words that are defined
subtitle.colorizeCaptionWord(match.getTextForm(), color);
Collections.rotate(colors, -1);
alreadyDefinedWords.add(match.getTextForm());
}
}
subtitle.annotate(annotations);
}
return subtitle.getNbCaptionAnnotated() == 0 ? null : subtitle.toAssFormat();
}
示例11: moveRowsDown
import java.util.Collections; //导入方法依赖的package包/类
@JsonIgnore
public Boolean moveRowsDown(int from, int to) {
if (to + 1 > attributes.size() - 1) {
return false;
}
to += 1;
Collections.rotate(attributes.subList(from, to + 1), 1);
changeSave();
return true;
}
示例12: getNeighbors
import java.util.Collections; //导入方法依赖的package包/类
private List<NodeId> getNeighbors() {
List<NodeId> nodes = clusterService.getNodes().stream()
.map(ControllerNode::id)
.collect(Collectors.toCollection(ArrayList::new));
// sort neighbors by id
Collections.sort(nodes, (node1, node2) ->
node1.toString().compareTo(node2.toString()));
// rotate the local node to index 0
Collections.rotate(nodes, -1 * nodes.indexOf(clusterService.getLocalNode().id()));
log.debug("neighbors (raw): {}", nodes); //TODO remove
// generate the sub-list that will contain local node and selected neighbors
nodes = nodes.subList(0, numNeighbors + 1);
log.debug("neighbors: {}", nodes); //TODO remove
return nodes;
}
示例13: moveRowsDown
import java.util.Collections; //导入方法依赖的package包/类
public Boolean moveRowsDown(int from, int to) {
if (to + 1 > testSteps.size() - 1) {
return false;
}
to += 1;
Collections.rotate(testSteps.subList(from, to + 1), 1);
setSaved(false);
return true;
}
示例14: quietRotate
import java.util.Collections; //导入方法依赖的package包/类
private void quietRotate() { //Doesn't return, and doesn't update the rotation counter. Use this for the pre-caching, as initial rotation is arbitrary.
Collections.rotate(contents,1);
}
示例15: stressPopCoding
import java.util.Collections; //导入方法依赖的package包/类
private CodingMethod stressPopCoding(CodingMethod coding) {
assert(stress != null); // this method is only for testing
// Don't turn it into a pop coding if it's already something special.
if (!(coding instanceof Coding)) return coding;
Coding valueCoding = ((Coding)coding).getValueCoding();
Histogram hist = getValueHistogram();
int fVlen = stressLen(hist.getTotalLength());
if (fVlen == 0) return coding;
List<Integer> popvals = new ArrayList<>();
if (stress.nextBoolean()) {
// Build the population from the value list.
Set<Integer> popset = new HashSet<>();
for (int i = start; i < end; i++) {
if (popset.add(values[i])) popvals.add(values[i]);
}
} else {
int[][] matrix = hist.getMatrix();
for (int mrow = 0; mrow < matrix.length; mrow++) {
int[] row = matrix[mrow];
for (int mcol = 1; mcol < row.length; mcol++) {
popvals.add(row[mcol]);
}
}
}
int reorder = stress.nextInt();
if ((reorder & 7) <= 2) {
// Lose the order.
Collections.shuffle(popvals, stress);
} else {
// Keep the order, mostly.
if (((reorder >>>= 3) & 7) <= 2) Collections.sort(popvals);
if (((reorder >>>= 3) & 7) <= 2) Collections.reverse(popvals);
if (((reorder >>>= 3) & 7) <= 2) Collections.rotate(popvals, stressLen(popvals.size()));
}
if (popvals.size() > fVlen) {
// Cut the list down.
if (((reorder >>>= 3) & 7) <= 2) {
// Cut at end.
popvals.subList(fVlen, popvals.size()).clear();
} else {
// Cut at start.
popvals.subList(0, popvals.size()-fVlen).clear();
}
}
fVlen = popvals.size();
int[] fvals = new int[1+fVlen];
for (int i = 0; i < fVlen; i++) {
fvals[1+i] = (popvals.get(i)).intValue();
}
PopulationCoding pop = new PopulationCoding();
pop.setFavoredValues(fvals, fVlen);
int[] lvals = PopulationCoding.LValuesCoded;
for (int i = 0; i < lvals.length / 2; i++) {
int popl = lvals[stress.nextInt(lvals.length)];
if (popl < 0) continue;
if (PopulationCoding.fitTokenCoding(fVlen, popl) != null) {
pop.setL(popl);
break;
}
}
if (pop.tokenCoding == null) {
int lmin = fvals[1], lmax = lmin;
for (int i = 2; i <= fVlen; i++) {
int val = fvals[i];
if (lmin > val) lmin = val;
if (lmax < val) lmax = val;
}
pop.tokenCoding = stressCoding(lmin, lmax);
}
computePopSizePrivate(pop, valueCoding, valueCoding);
return pop;
}