/** * Returns the value which matches the given destination or null if there is * no matching value. If there are multiple values, the results are sorted * and the last item (the biggest) is returned. * * @param destination the destination to find the value for * @return the largest matching value or null if no value matches */ @SuppressWarnings({"rawtypes", "unchecked"}) public DestinationMapEntry chooseValue(final ActiveMQDestination destination) { Set<DestinationMapEntry> set = get(destination); if (set == null || set.isEmpty()) { return null; } //Comparator to sort in order - we want to pick the exact match by destination or the //closest parent that applies final Comparator<DestinationMapEntry> comparator = new Comparator<DestinationMapEntry>() { @Override public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) { return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2)); } }; //Sort and filter out any children and non matching entries final SortedSet<DestinationMapEntry> sortedSet = set.stream() .filter(entry -> isMatchOrParent(destination, (DestinationMapEntry)entry)) .collect(Collectors.toCollection(() -> new TreeSet<DestinationMapEntry>(comparator))); return sortedSet.size() > 0 ? sortedSet.first() : null; }
/** * Returns the value which matches the given destination or null if there is * no matching value. If there are multiple values, the results are sorted * and the last item (the biggest) is returned. * * @param destination the destination to find the value for * @return the largest matching value or null if no value matches */ @SuppressWarnings({"rawtypes", "unchecked"}) public DestinationMapEntry chooseValue(final ActiveMQDestination destination) { Set<DestinationMapEntry> set = get(destination); if (set == null || set.isEmpty()) { return null; } //Comparator to sort in order - we want to pick the exact match by destination or the //closest parent that applies final Comparator<DestinationMapEntry> comparator = new Comparator<DestinationMapEntry>() { @Override public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) { return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2)); } }; //Sort and filter out any children and non matching entries final SortedSet<DestinationMapEntry> sortedSet = set.stream() .filter(entry -> isMatchOrParent(destination, (DestinationMapEntry)entry)) .collect(Collectors.toCollection(() -> new TreeSet<DestinationMapEntry>(comparator))); return sortedSet.size() > 0 ? sortedSet.first() : null; }
/** * Returns the value which matches the given destination or null if there is * no matching value. If there are multiple values, the results are sorted * and the last item (the biggest) is returned. * * @param destination the destination to find the value for * @return the largest matching value or null if no value matches */ @SuppressWarnings({"rawtypes", "unchecked"}) public DestinationMapEntry chooseValue(final ActiveMQDestination destination) { Set<DestinationMapEntry> set = get(destination); if (set == null || set.isEmpty()) { return null; } //Comparator to sort in order - we want to pick the exact match by destination or the //closest parent that applies final Comparator<DestinationMapEntry> comparator = new Comparator<DestinationMapEntry>() { @Override public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) { return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2)); } }; //Sort and filter out any children and non matching entries final SortedSet<DestinationMapEntry> sortedSet = set.stream() .filter(entry -> isMatchOrParent(destination, (DestinationMapEntry)entry)) .collect(Collectors.toCollection(() -> new TreeSet<DestinationMapEntry>(comparator))); return sortedSet.size() > 0 ? sortedSet.first() : null; }
/** * Returns the value which matches the given destination or null if there is * no matching value. If there are multiple values, the results are sorted * and the last item (the biggest) is returned. * * @param destination the destination to find the value for * @return the largest matching value or null if no value matches */ @SuppressWarnings({"rawtypes", "unchecked"}) public DestinationMapEntry chooseValue(final ActiveMQDestination destination) { Set<DestinationMapEntry> set = get(destination); if (set == null || set.isEmpty()) { return null; } //Comparator to sort in order - we want to pick the exact match by destination or the //closest parent that applies final Comparator<DestinationMapEntry> comparator = new Comparator<DestinationMapEntry>() { @Override public int compare(DestinationMapEntry entry1, DestinationMapEntry entry2) { return destination.equals(entry1.destination) ? -1 : (destination.equals(entry2.destination) ? 1 : entry1.compareTo(entry2)); } }; //Sort and filter out any children and non matching entries final SortedSet<DestinationMapEntry> sortedSet = set.stream() .filter(entry -> isMatchOrParent(destination, (DestinationMapEntry)entry)) .collect(Collectors.toCollection(() -> new TreeSet<DestinationMapEntry>(comparator))); return sortedSet.size() > 0 ? sortedSet.first() : null; }