當前位置: 首頁>>代碼示例>>Java>>正文


Java Collections.reverseOrder方法代碼示例

本文整理匯總了Java中java.util.Collections.reverseOrder方法的典型用法代碼示例。如果您正苦於以下問題:Java Collections.reverseOrder方法的具體用法?Java Collections.reverseOrder怎麽用?Java Collections.reverseOrder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.reverseOrder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findAll

import java.util.Collections; //導入方法依賴的package包/類
@Override
public Page<T> findAll(final Set<T> groups, final String criteria, final Pageable pageable, final Map<String, Comparator<T>> customComparators) {
	// Create the set with the right comparator
	final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator());
	orders.add(DEFAULT_ORDER);
	final Sort.Order order = orders.get(0);
	Comparator<T> comparator = customComparators.get(order.getProperty());
	if (order.getDirection() == Direction.DESC) {
		comparator = Collections.reverseOrder(comparator);
	}
	final Set<T> result = new TreeSet<>(comparator);

	// Filter the groups, filtering by the criteria
	addFilteredByPattern(groups, criteria, result);

	// Apply in-memory pagination
	return inMemoryPagination.newPage(result, pageable);
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:19,代碼來源:AbstractContainerLdaRepository.java

示例2: testWriteMapWithConsistentOrder

import java.util.Collections; //導入方法依賴的package包/類
public void testWriteMapWithConsistentOrder() throws IOException {
    Map<String, String> map =
        randomMap(new TreeMap<>(), randomIntBetween(2, 20),
            () -> randomAsciiOfLength(5),
            () -> randomAsciiOfLength(5));

    Map<String, Object> reverseMap = new TreeMap<>(Collections.reverseOrder());
    reverseMap.putAll(map);

    List<String> mapKeys = map.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList());
    List<String> reverseMapKeys = reverseMap.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList());

    assertNotEquals(mapKeys, reverseMapKeys);

    try (BytesStreamOutput output = new BytesStreamOutput(); BytesStreamOutput reverseMapOutput = new BytesStreamOutput()) {
        output.writeMapWithConsistentOrder(map);
        reverseMapOutput.writeMapWithConsistentOrder(reverseMap);

        assertEquals(output.bytes(), reverseMapOutput.bytes());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:BytesStreamsTests.java

示例3: locateExactMatchingTarget

import java.util.Collections; //導入方法依賴的package包/類
private CommandTarget locateExactMatchingTarget(final String userInput)// exact matching
    throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  CommandTarget commandTarget = null;

  Map<String, CommandTarget> commandTargetsMap = commandManager.getCommands();
  // Reverse sort the command names because we should start from longer names
  // E.g. Consider commands "A", "A B" & user input as "A B --opt1=val1"
  // In this case, "A B" is the most probable match & should be matched first
  // which can be achieved by reversing natural order of sorting.
  Set<String> commandNamesReverseSorted = new TreeSet<String>(Collections.reverseOrder());
  commandNamesReverseSorted.addAll(commandTargetsMap.keySet());

  // Now we need to locate the CommandTargets from the entries in the map
  for (final String commandName : commandNamesReverseSorted) {
    if (userInput.startsWith(commandName) && commandWordsMatch(userInput, commandName)) {
      // This means that the user has entered the command & name matches exactly
      commandTarget = commandTargetsMap.get(commandName);
      if (commandTarget != null) {
        String remainingBuffer = StringUtils.removeStart(userInput, commandName);
        commandTarget = commandTarget.duplicate(commandName, remainingBuffer);
        break;
      }
    }
  }
  return commandTarget;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:27,代碼來源:GfshParser.java

示例4: isDescending

import java.util.Collections; //導入方法依賴的package包/類
public static final boolean isDescending(SortedSet<?> set) {
    if (null == set.comparator()) {
        // natural order
        return false;
    }

    if (Collections.reverseOrder() == set.comparator()) {
        // reverse natural order.
        return true;
    }

    if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) {
        // it's a Collections.reverseOrder(Comparator).
        return true;
    }

    throw new IllegalStateException("can't determine ordering for " + set);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:EmptyNavigableSet.java

示例5: AudioEventCollector

import java.util.Collections; //導入方法依賴的package包/類
/**
 * @param nextListener
 *            A chained listener to which all audio events are passed.
 */
public AudioEventCollector(AudioEventListener nextListener) {
    this.nextListener = nextListener;
    final Comparator<AudioBufferInfo> lastRecordedBufferLastComparator =
        new Comparator<AudioBufferInfo>() {
        @Override
        public int compare(AudioBufferInfo a, AudioBufferInfo b) {
            if (a.getAudioBufferId() < b.getAudioBufferId()) {
                return -1;
            }
            if (a.getAudioBufferId() > b.getAudioBufferId()) {
                return 1;
            }
            return 0;
        }
    };
    recordedBuffersLastRecordedLast = new TreeSet<AudioBufferInfo>(
            lastRecordedBufferLastComparator);
    recordedBuffersLastRecordedFirst = new TreeSet<AudioBufferInfo>(
            Collections.reverseOrder(lastRecordedBufferLastComparator));
    resetHistory();
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:26,代碼來源:AudioEventCollector.java

示例6: getSlowdownProfile

import java.util.Collections; //導入方法依賴的package包/類
private TreeMap<Double,Double> getSlowdownProfile() {
	TreeMap<Double,Double> ret = new TreeMap<Double, Double>(Collections.reverseOrder());
	State tempStateBW = new State(0.0, 0.0);
	ret.put(tempStateBW.getVelocity(), tempStateBW.getPosition());

	double time = 0.0;
	double deltaTime = 0.5*(this.trackingPeriodInMillis/this.temporalResolution);
	//Compute where to slow down (can do forward here for both states...)
	while (tempStateBW.getVelocity() < MAX_VELOCITY*1.1) {
		double dampeningBW = getCurvatureDampening(getRobotReport(tempStateBW).getPathIndex(), true);
		//Use slightly conservative max deceleration (which is positive acceleration since we simulate FW dynamics)
		integrateRK4(tempStateBW, time, deltaTime, false, MAX_VELOCITY*1.1, dampeningBW, MAX_ACCELERATION);
		time += deltaTime;
		ret.put(tempStateBW.getVelocity(), tempStateBW.getPosition());
	}
	
	//for (Double speed : ret.keySet()) System.out.println("@speed " + speed + " --> " + ret.get(speed));
	return ret;
}
 
開發者ID:FedericoPecora,項目名稱:coordination_oru,代碼行數:20,代碼來源:TrajectoryEnvelopeTrackerRK4.java

示例7: GetAbundanceByMS1_TopN

import java.util.Collections; //導入方法依賴的package包/類
public float GetAbundanceByMS1_TopN(int topN, float pepweight) {
    if (PeptideID.isEmpty()) {
        return 0;
    }
    PriorityQueue<Float> TopQueue = new PriorityQueue<>(PeptideID.size(), Collections.reverseOrder());
    for (PepIonID peptide : PeptideID.values()) {
        if (peptide.PeakHeight != null && peptide.FilteringWeight > pepweight) {
            TopQueue.add(peptide.PeakHeight[0]);
        }
    }

    float totalabundance = 0f;
    int num = Math.min(topN, TopQueue.size());

    for (int i = 0; i < num; i++) {
        totalabundance += TopQueue.poll();
    }
    return totalabundance / num;
}
 
開發者ID:YcheCourseProject,項目名稱:DIA-Umpire-Maven,代碼行數:20,代碼來源:ProtID.java

示例8: onInflateLayout

import java.util.Collections; //導入方法依賴的package包/類
@Override
protected final void onInflateLayout(@NonNull final LayoutInflater inflater,
                                     final boolean tabsOnly) {
    if (!tabsOnly) {
        inflater.inflate(R.layout.tablet_layout, getTabSwitcher(), true);
    }

    primaryToolbar = getTabSwitcher().findViewById(R.id.primary_toolbar);
    secondaryToolbar = getTabSwitcher().findViewById(R.id.secondary_toolbar);
    tabContainer = getTabSwitcher().findViewById(R.id.tab_container);
    borderView = getTabSwitcher().findViewById(R.id.border_view);
    ViewGroup contentContainer = getTabSwitcher().findViewById(R.id.content_container);
    contentViewRecycler = new AttachedViewRecycler<>(contentContainer, inflater);
    tabRecyclerAdapter = new TabletTabRecyclerAdapter(getTabSwitcher(), getModel(), getStyle());
    getModel().addListener(tabRecyclerAdapter);
    tabViewRecycler = new AttachedViewRecycler<>(tabContainer, inflater,
            Collections.reverseOrder(new TabletItemComparator(getTabSwitcher())));
    tabViewRecycler.setAdapter(tabRecyclerAdapter);
    tabRecyclerAdapter.setViewRecycler(tabViewRecycler);
    dragHandler =
            new TabletDragTabsEventHandler(getTabSwitcher(), getArithmetics(), tabViewRecycler);
    adaptTabContainerAndToolbarMargins();
    adaptBorderColor();
}
 
開發者ID:michael-rapp,項目名稱:ChromeLikeTabSwitcher,代碼行數:25,代碼來源:TabletTabSwitcherLayout.java

示例9: main

import java.util.Collections; //導入方法依賴的package包/類
@SuppressWarnings("Duplicates")
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    PriorityQueue<Integer> minHeap = new PriorityQueue<>(10, Collections.reverseOrder());
    PriorityQueue<Integer> maxHeap = new PriorityQueue<>(10);

    int n = scanner.nextInt();

    for (int i = 0; i < n; i++) {
        int num = scanner.nextInt();

        if (minHeap.size() <= maxHeap.size()) {
            minHeap.add(num);
        } else {
            maxHeap.add(num);
        }

        while (!minHeap.isEmpty() && !maxHeap.isEmpty() && minHeap.peek() > maxHeap.peek()) {
            int min = minHeap.poll();
            int max = maxHeap.poll();

            minHeap.add(max);
            maxHeap.add(min);
        }

        double median = (minHeap.size() == maxHeap.size() ? ((minHeap.peek() + maxHeap.peek()) / 2.0) : minHeap.peek());

        System.out.println(median);
    }
}
 
開發者ID:viatsko,項目名稱:hack,代碼行數:32,代碼來源:HeapsFindTheRunningMedian.java

示例10: testPQOperation

import java.util.Collections; //導入方法依賴的package包/類
public void testPQOperation() {
    Integer[] data = {12, 5, 3, 6, 4, 2, 0, 23, -23, 982, 6028, 4039, 123, 9, 89, 2, 4, 9, 8, 54, 17, 90};
    PriorityQueue<Integer> pq = new PriorityQueue<Integer>(data);
    assertEquals(false, pq.isEmpty());
    assertEquals(data.length, pq.size());
    assertEquals(new Integer(-23), pq.peek());
    pq.add(-300);
    assertEquals(new Integer(-300), pq.poll());
    assertEquals(new Integer(-23), pq.poll());
    assertEquals(data.length-1, pq.size());
    
    pq.clear();
    assertEquals(true, pq.isEmpty());
    
    pq = new PriorityQueue<Integer>(data, Collections.reverseOrder());
    assertEquals(new Integer(6028), pq.peek());
    pq.add(30000);
    assertEquals(new Integer(30000), pq.poll());
    assertEquals(new Integer(6028), pq.poll());
    assertEquals(data.length-1, pq.size());
    
    pq = new PriorityQueue<Integer>(Collections.reverseOrder());
    
    for (int i=0; i<300; i++) {
        pq.add(234 + i);
    }
    assertEquals(300, pq.size());
    assertEquals(new Integer(234+299), pq.poll());
    
    for (int i=0; i<250; i++) {
        pq.poll();
    }
    assertEquals(49, pq.size());
    
}
 
開發者ID:MiguelSteph,項目名稱:data-structures-and-algorithm,代碼行數:36,代碼來源:TestPriorityQueue.java

示例11: displaySessionsListPage

import java.util.Collections; //導入方法依賴的package包/類
/**
 * 
 * @param cn Name of the application for which the sessions will be listed
 * @param req
 * @param resp
 * @param smClient  StringManager for the client's locale
 * @throws ServletException
 * @throws IOException
 */
protected void displaySessionsListPage(ContextName cn,
        HttpServletRequest req, HttpServletResponse resp,
        StringManager smClient)
        throws ServletException, IOException {
    List<Session> sessions = getSessionsForName(cn, smClient);
    String sortBy = req.getParameter("sort");
    String orderBy = null;
    if (null != sortBy && !"".equals(sortBy.trim())) {
        Comparator<Session> comparator = getComparator(sortBy);
        if (comparator != null) {
            orderBy = req.getParameter("order");
            if ("DESC".equalsIgnoreCase(orderBy)) {
                comparator = Collections.reverseOrder(comparator);
                orderBy = "ASC";
            } else {
                orderBy = "DESC";
            }
            try {
                Collections.sort(sessions, comparator);
            } catch (IllegalStateException ise) {
                // at least 1 of the sessions is invalidated
                req.setAttribute(APPLICATION_ERROR, "Can't sort session list: one session is invalidated");
            }
        } else {
            log("WARNING: unknown sort order: " + sortBy);
        }
    }
    // keep sort order
    req.setAttribute("sort", sortBy);
    req.setAttribute("order", orderBy);
    req.setAttribute("activeSessions", sessions);
    //strong>NOTE</strong> - This header will be overridden
    // automatically if a <code>RequestDispatcher.forward()</code> call is
    // ultimately invoked.
    resp.setHeader("Pragma", "No-cache"); // HTTP 1.0
    resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); // HTTP 1.1
    resp.setDateHeader("Expires", 0); // 0 means now
    getServletContext().getRequestDispatcher(sessionsListJspPath).include(req, resp);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:49,代碼來源:HTMLManagerServlet.java

示例12: rankDocument

import java.util.Collections; //導入方法依賴的package包/類
private Set<UUID> rankDocument(String[] terms, List<UUID> pageIds, Map<String, Posting> invertedIndex) {
    final double[] queryVector = new double[terms.length];
    final Map<UUID, double[]> docVectors = new HashMap<>();
    final Map<UUID, Double> docScores = new TreeMap<>(Collections.reverseOrder());
    for (int i = 0; i < terms.length; i++) {
        final String term = terms[i];
        if (!invertedIndex.containsKey(term)) {
            continue;
        }
        final Posting posting = invertedIndex.get(term);
        queryVector[i] = posting.invertedDocumentFrequency;

        for (TermInfo termInfo : posting.termInfos) {
            final UUID examplePageId = termInfo.examplePageId;
            if (pageIds.contains(examplePageId)) {
                if (!docVectors.containsKey(examplePageId)) {
                    docVectors.put(examplePageId, new double[terms.length]);
                }
                docVectors.get(examplePageId)[i] = termInfo.termFrequency;
            }
        }
    }

    for (Map.Entry<UUID, double[]> entry : docVectors.entrySet()) {
        final double dotProduct = dotProduct(entry.getValue(), queryVector);
        docScores.put(entry.getKey(), dotProduct);
    }

    return sortByComparator(docScores).keySet();
}
 
開發者ID:ABTSoftware,項目名稱:SciChart.Android.Examples,代碼行數:31,代碼來源:ExampleSearchProvider.java

示例13: TextRankSentence

import java.util.Collections; //導入方法依賴的package包/類
private TextRankSentence(String document) {
    sentenceList = Segment.splitSentence(document, "[,,。::“”??!!;;]");
    senWordList = Segment.splitWordInSentences(sentenceList, true);
    senNum = sentenceList.size();
    weight = new float[senNum][senNum];
    weight_sum = new float[senNum];
    SenRank = new float[senNum];
    top = new TreeMap<Float, Integer>(Collections.reverseOrder());
    initParam();
    calSenRanks();
    for (int i = 0; i < senNum; ++i) // 按rank值排序
        top.put(SenRank[i], i);
}
 
開發者ID:jsksxs360,項目名稱:AHANLP,代碼行數:14,代碼來源:TextRankSentence.java

示例14: main

import java.util.Collections; //導入方法依賴的package包/類
public static void main(String[] args) {

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("E");

    /*
      To get comparator that imposes reverse order on a Collection use
      static Comparator reverseOrder() method of Collections class
    */

    Comparator comparator = Collections.reverseOrder();

    System.out.println("Before sorting ArrayList in descending order : " + arrayList);

    /*
      To sort an ArrayList using comparator use,
      static void sort(List list, Comparator c) method of Collections class.
    */

    Collections.sort(arrayList, comparator);
    System.out.println("After sorting ArrayList in descending order : " + arrayList);
  }
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:30,代碼來源:SortArrayListInDescendingOrderExample.java

示例15: comparator

import java.util.Collections; //導入方法依賴的package包/類
public Comparator<? super K> comparator() {
    Comparator<? super K> cmp = m.comparator();
    if (isDescending)
        return Collections.reverseOrder(cmp);
    else
        return cmp;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:ConcurrentSkipListMap.java


注:本文中的java.util.Collections.reverseOrder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。