Java Code Examples for java.util.Collections#emptySortedMap()

The following examples show how to use java.util.Collections#emptySortedMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartRepository.java    From microbean-helm with Apache License 2.0 6 votes vote down vote up
/**
 * Performs a deep copy of the supplied {@link Map} such that the
 * {@link SortedMap} returned has copies of the supplied {@link
 * Map}'s {@linkplain Map#values() values}.
 *
 * <p>This method may return {@code null} if {@code source} is
 * {@code null}.</p>
 *
 * <p>The {@link SortedMap} returned by this method is
 * mutable.</p>
 *
 * @param source the {@link Map} to copy; may be {@code null} in
 * which case {@code null} will be returned
 *
 * @return a mutable {@link SortedMap}, or {@code null}
 */
private static final SortedMap<String, SortedSet<Entry>> deepCopy(final Map<? extends String, ? extends SortedSet<Entry>> source) {
  final SortedMap<String, SortedSet<Entry>> returnValue;
  if (source == null) {
    returnValue = null;
  } else if (source.isEmpty()) {
    returnValue = Collections.emptySortedMap();
  } else {
    returnValue = new TreeMap<>();
    final Collection<? extends Map.Entry<? extends String, ? extends SortedSet<Entry>>> entrySet = source.entrySet();
    if (entrySet != null && !entrySet.isEmpty()) {
      for (final Map.Entry<? extends String, ? extends SortedSet<Entry>> entry : entrySet) {
        final String key = entry.getKey();
        final SortedSet<Entry> value = entry.getValue();
        if (value == null) {
          returnValue.put(key, null);
        } else {
          final SortedSet<Entry> newValue = new TreeSet<>(value.comparator());
          newValue.addAll(value);
          returnValue.put(key, newValue);
        }
      }
    }
  }
  return returnValue;
}
 
Example 2
Source File: RepositoryAggregatorTest.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private SortedMap<MetaKey, String> makeMavenCoords ( final String groupId, final String artifactId, final String version, final String extension, final String classifier )
{
    if ( groupId == null || artifactId == null || version == null )
    {
        return Collections.emptySortedMap ();
    }

    final MavenInformation mi = new MavenInformation ();

    mi.setGroupId ( groupId );
    mi.setArtifactId ( artifactId );
    mi.setVersion ( version );
    mi.setExtension ( extension );
    mi.setClassifier ( classifier );

    return fromMavenInformation ( mi );
}
 
Example 3
Source File: RepositoryAggregatorTest.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private SortedMap<MetaKey, String> fromMavenInformation ( final MavenInformation info )
{
    if ( info == null )
    {
        return Collections.emptySortedMap ();
    }

    try
    {
        return new TreeMap<> ( MetaKeys.unbind ( info ) );
    }
    catch ( final Exception e )
    {
        throw new RuntimeException ( e );
    }
}
 
Example 4
Source File: Broker.java    From cruise-control with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructor for Broker class.
 *
 * @param host           The host this broker is on
 * @param id             The id of the broker.
 * @param brokerCapacityInfo Capacity information of the created broker.
 * @param populateReplicaPlacementInfo Whether populate replica placement over disk information or not.
 */
Broker(Host host, int id, BrokerCapacityInfo brokerCapacityInfo, boolean populateReplicaPlacementInfo) {
  Map<Resource, Double> brokerCapacity = brokerCapacityInfo.capacity();
  if (brokerCapacity == null) {
    throw new IllegalArgumentException("Attempt to create broker " + id + " on host " + host.name() + " with null capacity.");
  }
  _host = host;
  _id = id;
  _brokerCapacity = new double[Resource.cachedValues().size()];
  for (Map.Entry<Resource, Double> entry : brokerCapacity.entrySet()) {
    Resource resource = entry.getKey();
    _brokerCapacity[resource.id()] = (resource == Resource.CPU) ? (entry.getValue() * brokerCapacityInfo.numCpuCores())
                                                                : entry.getValue();
  }

  if (populateReplicaPlacementInfo) {
    _diskByLogdir = new TreeMap<>();
    brokerCapacityInfo.diskCapacityByLogDir().forEach((key, value) -> _diskByLogdir.put(key, new Disk(key, this, value)));
  } else {
    _diskByLogdir = Collections.emptySortedMap();
  }

  _replicas = new HashSet<>();
  _leaderReplicas = new HashSet<>();
  _topicReplicas = new HashMap<>();
  _sortedReplicas = new HashMap<>();
  _immigrantReplicas = new HashSet<>();
  _currentOfflineReplicas = new HashSet<>();
  // Initially broker does not contain any load.
  _load = new Load();
  _leadershipLoadForNwResources = new Load();
  _state = State.ALIVE;
}
 
Example 5
Source File: ChartRepository.java    From microbean-helm with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link Index}.
 *
 * @param entries a {@link Map} of {@link SortedSet}s of {@link
 * Entry} objects indexed by the name of the Helm chart they
 * describe; may be {@code null}; copied by value
 */
Index(final Map<? extends String, ? extends SortedSet<Entry>> entries) {
  super();
  if (entries == null || entries.isEmpty()) {
    this.entries = Collections.emptySortedMap();
  } else {
    this.entries = Collections.unmodifiableSortedMap(deepCopy(entries));
  }
}
 
Example 6
Source File: BlazeRenderErrorContributor.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static SortedMap<ArtifactLocation, TargetIdeInfo> getGeneratedResources(
    TargetIdeInfo target) {
  if (target == null || target.getAndroidIdeInfo() == null) {
    return Collections.emptySortedMap();
  }
  SortedMap<ArtifactLocation, TargetIdeInfo> generatedResources = Maps.newTreeMap();
  generatedResources.putAll(
      target.getAndroidIdeInfo().getResources().stream()
          .filter(ArtifactLocation::isGenerated)
          .collect(Collectors.toMap(Function.identity(), resource -> target)));
  return generatedResources;
}
 
Example 7
Source File: CollectionFieldsBuilder.java    From auto-matter with Apache License 2.0 5 votes vote down vote up
public CollectionFields build() {
  List<String> _strings = (strings != null) ? Collections.unmodifiableList(new ArrayList<String>(strings)) : Collections.<String>emptyList();
  Map<String, Integer> _integers = (integers != null) ? Collections.unmodifiableMap(new HashMap<String, Integer>(integers)) : Collections.<String, Integer>emptyMap();
  SortedMap<String, Integer> _sortedIntegers = (sortedIntegers != null) ? Collections.unmodifiableSortedMap(new TreeMap<String, Integer>(sortedIntegers)) : Collections.<String, Integer>emptySortedMap();
  NavigableMap<String, Integer> _navigableIntegers = (navigableIntegers != null) ? Collections.unmodifiableNavigableMap(new TreeMap<String, Integer>(navigableIntegers)) : Collections.<String, Integer>emptyNavigableMap();
  Set<Long> _numbers = (numbers != null) ? Collections.unmodifiableSet(new HashSet<Long>(numbers)) : Collections.<Long>emptySet();
  SortedSet<Long> _sortedNumbers = (sortedNumbers != null) ? Collections.unmodifiableSortedSet(new TreeSet<Long>(sortedNumbers)) : Collections.<Long>emptySortedSet();
  NavigableSet<Long> _navigableNumbers = (navigableNumbers != null) ? Collections.unmodifiableNavigableSet(new TreeSet<Long>(navigableNumbers)) : Collections.<Long>emptyNavigableSet();
  return new Value(_strings, _integers, _sortedIntegers, _navigableIntegers, _numbers, _sortedNumbers, _navigableNumbers);
}
 
Example 8
Source File: CollectionFieldsBuilder.java    From auto-matter with Apache License 2.0 5 votes vote down vote up
private Value(@AutoMatter.Field("strings") List<String> strings, @AutoMatter.Field("integers") Map<String, Integer> integers, @AutoMatter.Field("sortedIntegers") SortedMap<String, Integer> sortedIntegers, @AutoMatter.Field("navigableIntegers") NavigableMap<String, Integer> navigableIntegers, @AutoMatter.Field("numbers") Set<Long> numbers, @AutoMatter.Field("sortedNumbers") SortedSet<Long> sortedNumbers, @AutoMatter.Field("navigableNumbers") NavigableSet<Long> navigableNumbers) {
  this.strings = (strings != null) ? strings : Collections.<String>emptyList();
  this.integers = (integers != null) ? integers : Collections.<String, Integer>emptyMap();
  this.sortedIntegers = (sortedIntegers != null) ? sortedIntegers : Collections.<String, Integer>emptySortedMap();
  this.navigableIntegers = (navigableIntegers != null) ? navigableIntegers : Collections.<String, Integer>emptyNavigableMap();
  this.numbers = (numbers != null) ? numbers : Collections.<Long>emptySet();
  this.sortedNumbers = (sortedNumbers != null) ? sortedNumbers : Collections.<Long>emptySortedSet();
  this.navigableNumbers = (navigableNumbers != null) ? navigableNumbers : Collections.<Long>emptyNavigableSet();
}
 
Example 9
Source File: CollectionsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_emptySortedMap() {
    SortedMap<String, Integer> map = Collections.emptySortedMap();

    check_unmodifiableOrderedMap_defaultMethods(
            map,
            new ArrayList<>() /* keysInOrder */,
            new ArrayList<>() /* valuesInOrder */,
            "absent key" /* absentKey */,
            -1 /* absentValue */);
    check_unmodifiableSet(map.keySet(), "absent element");
    check_orderedSet(map.keySet(), new ArrayList<>() /* expectedElementsInOrder */);
    check_unmodifiableSet(map.entrySet(), new AbstractMap.SimpleEntry<>("absent element", 42));
    check_orderedCollection(map.values(), new ArrayList<>() /* expectedValuesInOrder */);
}
 
Example 10
Source File: AccessContext.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public default SortedMap<String, String> getAspectStates ()
{
    return Collections.emptySortedMap ();
}
 
Example 11
Source File: NamedStructureEquivalenceSets.java    From batfish with Apache License 2.0 4 votes vote down vote up
@JsonCreator
public NamedStructureEquivalenceSets(
    @JsonProperty(PROP_STRUCTURE_CLASS_NAME) String structureClassName) {
  _structureClassName = structureClassName;
  _sameNamedStructures = Collections.emptySortedMap();
}
 
Example 12
Source File: ReturnEmptySortedMap.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void return_empty_sorted_map_java () {

	Map<String, String> sortedEmptyMap = Collections.emptySortedMap();
	
	assertTrue(sortedEmptyMap.isEmpty());
}