Java Code Examples for java.util.Collections.reverse()

The following are Jave code examples for showing how to use reverse() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: uavstack   File: RuntimeNotifySliceMgr.java   View Source Code Vote up 6 votes
public List<Slice> getSlices(Slice cur, long range) {

        List<Integer> rangePoints = getPreRangePoint(cur, range);
        List<Slice> slices = new ArrayList<>();
        for (int point : rangePoints) {
            String key = CACHE_PREFIX + cur.getKey() + "_" + point;
            @SuppressWarnings("unchecked")
            List<String> rangeSlicesStr = cm.lrange(UAV_CACHE_REGION, key, 0, -1);
            if (rangeSlicesStr.isEmpty()) {
                continue;
            }
            for (String ss : rangeSlicesStr) {
                Slice s = new Slice(ss);
                slices.add(s);
            }
        }
        Collections.reverse(slices);
        return slices;
    }
 
Example 2
Project: firebase-admin-java   File: RBTreeSortedMapTest.java   View Source Code Vote up 6 votes
@Test
public void reverseIterationIsInOrder() {
  for (Map<Integer, Integer> any : someMaps(integers(), integers())) {
    List<Integer> expectedKeys = new ArrayList<>(any.keySet());
    Collections.sort(expectedKeys);
    Collections.reverse(expectedKeys);

    ImmutableSortedMap<Integer, Integer> map = RBTreeSortedMap.fromMap(any, IntComparator);
    List<Integer> actualKeys = new ArrayList<>();
    Iterator<Map.Entry<Integer, Integer>> iterator = map.reverseIterator();
    while (iterator.hasNext()) {
      actualKeys.add(iterator.next().getKey());
    }

    assertEquals(expectedKeys, actualKeys);
  }
}
 
Example 3
Project: javaide   File: ReverseOrderVectorExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("A");
    v.add("B");
    v.add("C");
    v.add("D");
    v.add("E");

    System.out.println("Before Reverse Order, Vector Contains : " + v);

    /*
      To reverse the order of all elements of Java Vector use,
      static void reverse(List list) method of Collections class.

      This method reverse the order of elements of specified list.
    */

    Collections.reverse(v);

    System.out.println("After Reverse Order, Vector Contains : " + v);
  }
 
Example 4
Project: syndesis   File: ReflectiveSorterTest.java   View Source Code Vote up 6 votes
@Test
public void stringSort() {

    List<TestPersonInterface> toSort = getTestData();

    toSort.sort(new ReflectiveSorter<>(TestPersonInterface.class, getOptions("lastName", "asc")));
    String[] expectedNames = {
        "Feynman",
        "Heisenberg",
        "Maxwell",
        "Schrödinger"
    };

    for (int i = 0; i < expectedNames.length; i++) {
        assertEquals(toSort.get(i).getLastName(), expectedNames[i]);
    }

    toSort.sort(new ReflectiveSorter<>(TestPersonInterface.class, getOptions("lastName", "DESC")));
    List<String> reversed = Arrays.asList(expectedNames);
    Collections.reverse(reversed);

    for (int i = 0; i < expectedNames.length; i++) {
        assertEquals(toSort.get(i).getLastName(), expectedNames[i]);
    }
}
 
Example 5
Project: Neukoelln_SER316   File: NotesList.java   View Source Code Vote up 5 votes
public void update(Vector ns) {
      notes = ns;
      // NotesVectorSorter.sort(notes);
Collections.sort(notes);
if (sortOrderDesc) {
	Collections.reverse(notes);		    
}		
      updateUI();
  }
 
Example 6
Project: SER316-Munich   File: NotesList.java   View Source Code Vote up 5 votes
public void update(Vector ns) {
      notes = ns;
      // NotesVectorSorter.sort(notes);
Collections.sort(notes);
if (sortOrderDesc) {
	Collections.reverse(notes);		    
}		
      updateUI();
  }
 
Example 7
Project: Tesseract-OCR-Scanner   File: RSSExpandedReader.java   View Source Code Vote up 5 votes
private List<ExpandedPair> checkRows(boolean reverse) {
  // Limit number of rows we are checking
  // We use recursive algorithm with pure complexity and don't want it to take forever
  // Stacked barcode can have up to 11 rows, so 25 seems reasonable enough
  if (this.rows.size() > 25) {
    this.rows.clear();  // We will never have a chance to get result, so clear it
    return null;
  }

  this.pairs.clear();
  if (reverse) {
    Collections.reverse(this.rows);
  }

  List<ExpandedPair> ps = null;
  try {
    ps = checkRows(new ArrayList<ExpandedRow>(), 0);
  } catch (NotFoundException e) {
    // OK
  }

  if (reverse) {
    Collections.reverse(this.rows);
  }

  return ps;
}
 
Example 8
Project: QrCode   File: RSSExpandedReader.java   View Source Code Vote up 5 votes
private List<ExpandedPair> checkRows(boolean reverse) {
  // Limit number of rows we are checking
  // We use recursive algorithm with pure complexity and don't want it to take forever
  // Stacked barcode can have up to 11 rows, so 25 seems reasonable enough
  if (this.rows.size() > 25) {
    this.rows.clear();  // We will never have a chance to get result, so clear it
    return null;
  }

  this.pairs.clear();
  if (reverse) {
    Collections.reverse(this.rows);
  }

  List<ExpandedPair> ps = null;
  try {
    ps = checkRows(new ArrayList<ExpandedRow>(), 0);
  } catch (NotFoundException e) {
    // OK
  }

  if (reverse) {
    Collections.reverse(this.rows);
  }

  return ps;
}
 
Example 9
Project: guava-mock   File: Collections2.java   View Source Code Vote up 5 votes
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));
}
 
Example 10
Project: CF-rating-prediction   File: RatingCalculatorTeam.java   View Source Code Vote up 5 votes
public RatingCalculatorTeam(List<Team> allContestants) {
    this.allContestants = (ArrayList<Team>) allContestants;
    this.numberOfContestants = allContestants.size();
    recalculateRanks();
    Collections.sort(this.allContestants);
    Collections.reverse(allContestants);
}
 
Example 11
Project: jieba4j-tag   File: FinalSeg.java   View Source Code Vote up 5 votes
public void viterbi(String sentence, List<String> tokens) {
    Vector<Map<Character, Double>> v = new Vector<Map<Character, Double>>();
    Map<Character, Node> path = new HashMap<Character, Node>();

    v.add(new HashMap<Character, Double>());
    for (char state : states) {
        Double emP = emit.get(state).get(sentence.charAt(0));
        if (null == emP)
            emP = MIN_FLOAT;
        v.get(0).put(state, start.get(state) + emP);
        path.put(state, new Node(state, null));
    }

    for (int i = 1; i < sentence.length(); ++i) {
        Map<Character, Double> vv = new HashMap<Character, Double>();
        v.add(vv);
        Map<Character, Node> newPath = new HashMap<Character, Node>();
        for (char y : states) {
            Double emp = emit.get(y).get(sentence.charAt(i));
            if (emp == null)
                emp = MIN_FLOAT;
            Pair<Character> candidate = null;
            for (char y0 : prevStatus.get(y)) {
                Double tranp = trans.get(y0).get(y);
                if (null == tranp)
                    tranp = MIN_FLOAT;
                tranp += (emp + v.get(i - 1).get(y0));
                if (null == candidate)
                    candidate = new Pair<Character>(y0, tranp);
                else if (candidate.freq <= tranp) {
                    candidate.freq = tranp;
                    candidate.key = y0;
                }
            }
            vv.put(y, candidate.freq);
            newPath.put(y, new Node(y, path.get(candidate.key)));
        }
        path = newPath;
    }
    double probE = v.get(sentence.length() - 1).get('E');
    double probS = v.get(sentence.length() - 1).get('S');
    Vector<Character> posList = new Vector<Character>(sentence.length());
    Node win;
    if (probE < probS)
        win = path.get('S');
    else
        win = path.get('E');

    while (win != null) {
        posList.add(win.value);
        win = win.parent;
    }
    Collections.reverse(posList);

    int begin = 0, next = 0;
    for (int i = 0; i < sentence.length(); ++i) {
        char pos = posList.get(i);
        if (pos == 'B')
            begin = i;
        else if (pos == 'E') {
            tokens.add(sentence.substring(begin, i + 1));
            next = i + 1;
        }
        else if (pos == 'S') {
            tokens.add(sentence.substring(i, i + 1));
            next = i + 1;
        }
    }
    if (next < sentence.length())
        tokens.add(sentence.substring(next));
}
 
Example 12
Project: empiria.player   File: SynchronousScriptsLoader.java   View Source Code Vote up 5 votes
public void injectScripts(ScriptUrl[] scripts, SynchronousScriptsCallback callback) {
    Stack<ScriptUrl> scriptsStack = new Stack<>();
    Collections.addAll(scriptsStack, scripts);
    Collections.reverse(scriptsStack);

    RequestCallback nextScriptLoaderCallback = createNextScriptLoaderCallback(scriptsStack, callback);

    injectScript(scriptsStack, nextScriptLoaderCallback);
}
 
Example 13
Project: alvisnlp   File: PathLibrary.java   View Source Code Vote up 5 votes
private List<Element> getList() {
	List<Element> result = new ArrayList<Element>();
	for (PathNode n = this; n != null; n = n.prev)
		result.add(n.element);
	Collections.reverse(result);
	return result;
}
 
Example 14
Project: SparkSeq   File: Utils.java   View Source Code Vote up 5 votes
public static <T extends Comparable<T>, V> List<V> sorted(Map<T,V> c, boolean reverse) {
    List<T> t = new ArrayList<T>(c.keySet());
    Collections.sort(t);
    if ( reverse ) Collections.reverse(t);

    List<V> l = new ArrayList<V>();
    for ( T k : t ) {
        l.add(c.get(k));
    }
    return l;
}
 
Example 15
Project: PrivacyStreams   File: StreamReverser.java   View Source Code Vote up 4 votes
@Override
protected void reorder(List<Item> items) {
    Collections.reverse(items);
}
 
Example 16
Project: floatingMenu   File: FloatingMenuAnimationHandler.java   View Source Code Vote up 4 votes
private AnimatorSet closeRadialMenuAnimation(Point center) {
    setAnimating(true);
    Animator lastAnimation = null;
    int startAngle = floatingMenuButton.getStartAngle();
    int endAngle = floatingMenuButton.getEndAngle();
    int radius = floatingMenuButton.getRadius();
    List<SubButton> subActionItems = menu.getSubMenuButtons();
    ArrayList<Animator> animatorArrayList = new ArrayList<>();
    for (int i = 0; i < subActionItems.size(); i++) {
        final SubButton currentSubButton = subActionItems.get(i);
        final View currentSubButtonView = currentSubButton.getView();
        // Button Properties along the animation
        ArrayList<PropertyValuesHolder> properties = new ArrayList<>();
        properties.add(PropertyValuesHolder.ofFloat(View.SCALE_X, (float) 0.75));
        properties.add(PropertyValuesHolder.ofFloat(View.SCALE_Y, (float) 0.75));
        PropertyValuesHolder[] parameters = new PropertyValuesHolder[properties.size() - 1];
        parameters = properties.toArray(parameters);
        ObjectAnimator propertiesAnimation = ObjectAnimator.ofPropertyValuesHolder(currentSubButtonView, parameters);
        // Button Position along the animation
        final ArrayList<Point> radialPointsPorCurrentPosition = getArcPointsForButton(center, startAngle, endAngle, subActionItems.size(), i, radius);
        Collections.reverse(radialPointsPorCurrentPosition);
        ValueAnimator positionAnimation = ValueAnimator.ofFloat(0, radialPointsPorCurrentPosition.size());
        positionAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Float value = ((Float) animation.getAnimatedValue());
                if (value.intValue() < radialPointsPorCurrentPosition.size()) {
                    Point p = radialPointsPorCurrentPosition.get(value.intValue());
                    currentSubButtonView.setX(p.x);
                    currentSubButtonView.setY(p.y);
                    currentSubButton.setX(p.x);
                    currentSubButton.setY(p.y);
                }
            }
        });
        positionAnimation.setDuration(closingDuration);
        positionAnimation.setInterpolator(closingInterpolator);
        menuButtonAnimationListener = new FloatingMenuButtonAnimationListener(FloatingMenuAnimationHandler.this, currentSubButton, MenuState.CLOSING_RADIAL);
        positionAnimation.addListener(menuButtonAnimationListener);
        if (i == 0) {
            lastAnimation = positionAnimation;
        }
        animatorArrayList.add(propertiesAnimation);
        animatorArrayList.add(positionAnimation);
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(this);
    }
    AnimatorSet closeRadialAnimatorSet = new AnimatorSet();
    closeRadialAnimatorSet.playTogether(animatorArrayList);
    return closeRadialAnimatorSet;
}
 
Example 17
Project: OpenJSharp   File: ObjectStreamClass.java   View Source Code Vote up 4 votes
private ClassDataSlot[] getClassDataLayout0()
    throws InvalidClassException
{
    ArrayList<ClassDataSlot> slots = new ArrayList<>();
    Class<?> start = cl, end = cl;

    // locate closest non-serializable superclass
    while (end != null && Serializable.class.isAssignableFrom(end)) {
        end = end.getSuperclass();
    }

    HashSet<String> oscNames = new HashSet<>(3);

    for (ObjectStreamClass d = this; d != null; d = d.superDesc) {
        if (oscNames.contains(d.name)) {
            throw new InvalidClassException("Circular reference.");
        } else {
            oscNames.add(d.name);
        }

        // search up inheritance hierarchy for class with matching name
        String searchName = (d.cl != null) ? d.cl.getName() : d.name;
        Class<?> match = null;
        for (Class<?> c = start; c != end; c = c.getSuperclass()) {
            if (searchName.equals(c.getName())) {
                match = c;
                break;
            }
        }

        // add "no data" slot for each unmatched class below match
        if (match != null) {
            for (Class<?> c = start; c != match; c = c.getSuperclass()) {
                slots.add(new ClassDataSlot(
                    ObjectStreamClass.lookup(c, true), false));
            }
            start = match.getSuperclass();
        }

        // record descriptor/class pairing
        slots.add(new ClassDataSlot(d.getVariantFor(match), true));
    }

    // add "no data" slot for any leftover unmatched classes
    for (Class<?> c = start; c != end; c = c.getSuperclass()) {
        slots.add(new ClassDataSlot(
            ObjectStreamClass.lookup(c, true), false));
    }

    // order slots from superclass -> subclass
    Collections.reverse(slots);
    return slots.toArray(new ClassDataSlot[slots.size()]);
}
 
Example 18
Project: xdman   File: DownloadList.java   View Source Code Vote up 4 votes
public void sort() {
	Collections.sort(this.list);
	if (!XDMConfig.sortAsc) {
		Collections.reverse(list);
	}
}
 
Example 19
Project: decoy   File: MessageListPanelEx.java   View Source Code Vote up 4 votes
private void onMessageLoaded(final List<IMMessage> messages) {
    if (messages == null) {
        return;
    }

    boolean noMoreMessage = messages.size() < LOAD_MESSAGE_COUNT;

    if (remote) {
        Collections.reverse(messages);
    }

    // 在第一次加载的过程中又收到了新消息,做一下去重
    if (firstLoad && items.size() > 0) {
        for (IMMessage message : messages) {
            int removeIndex = 0;
            for (IMMessage item : items) {
                if (item.isTheSame(message)) {
                    adapter.remove(removeIndex);
                    break;
                }
                removeIndex++;
            }
        }
    }

    // 加入anchor
    if (firstLoad && anchor != null) {
        messages.add(anchor);
    }

    // 在更新前,先确定一些标记
    List<IMMessage> total = new ArrayList<>();
    total.addAll(items);
    boolean isBottomLoad = direction == QueryDirectionEnum.QUERY_NEW;
    if (isBottomLoad) {
        total.addAll(messages);
    } else {
        total.addAll(0, messages);
    }
    adapter.updateShowTimeItem(total, true, firstLoad); // 更新要显示时间的消息
    updateReceipt(total); // 更新已读回执标签

    // 加载状态修改,刷新界面
    if (isBottomLoad) {
        // 底部加载
        if (noMoreMessage) {
            adapter.loadMoreEnd(messages, true);
        } else {
            adapter.loadMoreComplete(messages);
        }
    } else {
        // 顶部加载
        if (noMoreMessage) {
            adapter.fetchMoreEnd(messages, true);
        } else {
            adapter.fetchMoreComplete(messages);
        }
    }

    // 如果是第一次加载,updateShowTimeItem返回的就是lastShowTimeItem
    if (firstLoad) {
        doScrollToBottom();
        sendReceipt(); // 发送已读回执
    }

    firstLoad = false;
}
 
Example 20
Project: BaseClient   File: PlayerSelector.java   View Source Code Vote up 4 votes
private static <T extends Entity> List<T> func_179658_a(List<T> p_179658_0_, Map<String, String> p_179658_1_, ICommandSender p_179658_2_, Class <? extends T > p_179658_3_, String p_179658_4_, final BlockPos p_179658_5_)
{
    int i = parseIntWithDefault(p_179658_1_, "c", !p_179658_4_.equals("a") && !p_179658_4_.equals("e") ? 1 : 0);

    if (!p_179658_4_.equals("p") && !p_179658_4_.equals("a") && !p_179658_4_.equals("e"))
    {
        if (p_179658_4_.equals("r"))
        {
            Collections.shuffle((List<?>)p_179658_0_);
        }
    }
    else if (p_179658_5_ != null)
    {
        Collections.sort((List<T>)p_179658_0_, new Comparator<Entity>()
        {
            public int compare(Entity p_compare_1_, Entity p_compare_2_)
            {
                return ComparisonChain.start().compare(p_compare_1_.getDistanceSq(p_179658_5_), p_compare_2_.getDistanceSq(p_179658_5_)).result();
            }
        });
    }

    Entity entity = p_179658_2_.getCommandSenderEntity();

    if (entity != null && p_179658_3_.isAssignableFrom(entity.getClass()) && i == 1 && ((List)p_179658_0_).contains(entity) && !"r".equals(p_179658_4_))
    {
        p_179658_0_ = Lists.newArrayList((T)entity);
    }

    if (i != 0)
    {
        if (i < 0)
        {
            Collections.reverse((List<?>)p_179658_0_);
        }

        p_179658_0_ = ((List)p_179658_0_).subList(0, Math.min(Math.abs(i), ((List)p_179658_0_).size()));
    }

    return (List)p_179658_0_;
}