当前位置: 首页>>代码示例>>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;未经允许,请勿转载。