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

The following examples show how to use java.util.Collections#emptySortedSet() . 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: AddressBook.java    From batfish with Apache License 2.0 6 votes vote down vote up
SortedSet<IpWildcard> getIpWildcards(String entryName, Warnings w) {
  AddressBook addressBook = getAddressBook(entryName);
  AddressBookEntry entry = null;
  if (addressBook != null) {
    entry = addressBook.getEntries().get(entryName);
  }
  if (entry == null) {
    w.redFlag(
        "Could not find entry: \""
            + entryName
            + "\" in address book: \""
            + _name
            + "\" or any global address book");
    return Collections.emptySortedSet();
  } else {
    return entry.getIpWildcards(w);
  }
}
 
Example 2
Source File: Lease_Test.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Test
public void choices_first_new_occupancy_uses_all_units() {

    //expect
    context.checking(new Expectations() {
        {
            oneOf(mockUnitRepository).allUnits();
        }
    });

    // given
    Lease newLease = new Lease(){
        @Override
        public SortedSet<Occupancy> getOccupancies(){
            return Collections.emptySortedSet();
        }
    };
    newLease.unitRepository = mockUnitRepository;

    // when
    newLease.choices1NewOccupancy();

}
 
Example 3
Source File: HeaderSpace.java    From batfish with Apache License 2.0 6 votes vote down vote up
public HeaderSpace() {
  _dscps = Collections.emptySortedSet();
  _dstPorts = Collections.emptySortedSet();
  _ecns = Collections.emptySortedSet();
  _fragmentOffsets = Collections.emptySortedSet();
  _icmpCodes = Collections.emptySortedSet();
  _icmpTypes = Collections.emptySortedSet();
  _ipProtocols = Collections.emptySortedSet();
  _packetLengths = Collections.emptySortedSet();
  _srcOrDstPorts = Collections.emptySortedSet();
  _srcPorts = Collections.emptySortedSet();
  _tcpFlags = Collections.emptyList();
  _notDscps = Collections.emptySortedSet();
  _notDstPorts = Collections.emptySortedSet();
  _notEcns = Collections.emptySortedSet();
  _notFragmentOffsets = Collections.emptySortedSet();
  _notIcmpCodes = Collections.emptySortedSet();
  _notIcmpTypes = Collections.emptySortedSet();
  _notIpProtocols = Collections.emptySortedSet();
  _notPacketLengths = Collections.emptySortedSet();
  _notSrcPorts = Collections.emptySortedSet();
}
 
Example 4
Source File: HostgroupView.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public HostgroupView(String name, int volumeCount, InstanceGroupType instanceGroupType, Integer nodeCount) {
    this.name = name;
    this.volumeCount = volumeCount;
    instanceGroupConfigured = true;
    this.instanceGroupType = instanceGroupType;
    this.nodeCount = nodeCount;
    hosts = Collections.emptySortedSet();
    volumeTemplates = Collections.emptySet();
}
 
Example 5
Source File: Configuration.java    From batfish with Apache License 2.0 5 votes vote down vote up
private SortedSet<String> getRoutingPolicySources(@Nullable String routingPolicyName) {
  if (routingPolicyName == null) {
    return Collections.emptySortedSet();
  }
  RoutingPolicy rp = _routingPolicies.get(routingPolicyName);
  if (rp == null) {
    return Collections.emptySortedSet();
  }
  return rp.getSources().stream()
      .filter(not(RoutingPolicy::isGenerated))
      .collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder()));
}
 
Example 6
Source File: StandardServiceFacade.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
public SortedSet<ExtensionRepoBucket> getExtensionRepoBuckets(final URI baseUri) {
    final Set<String> authorizedBucketIds = getAuthorizedBucketIds(RequestAction.READ);
    if (authorizedBucketIds == null || authorizedBucketIds.isEmpty()) {
        // not authorized for any bucket, return empty list of items
        return Collections.emptySortedSet();
    }

    final SortedSet<ExtensionRepoBucket> repoBuckets = extensionService.getExtensionRepoBuckets(authorizedBucketIds);
    linkService.populateFullLinks(repoBuckets, baseUri);
    return repoBuckets;
}
 
Example 7
Source File: Neo4JVertex.java    From neo4j-gremlin-bolt with Apache License 2.0 5 votes vote down vote up
Neo4JVertex(Neo4JGraph graph, Neo4JSession session, Neo4JElementIdProvider<?> vertexIdProvider, Neo4JElementIdProvider<?> edgeIdProvider, Collection<String> labels) {
    Objects.requireNonNull(graph, "graph cannot be null");
    Objects.requireNonNull(session, "session cannot be null");
    Objects.requireNonNull(vertexIdProvider, "vertexIdProvider cannot be null");
    Objects.requireNonNull(edgeIdProvider, "edgeIdProvider cannot be null");
    Objects.requireNonNull(labels, "labels cannot be null");
    // store fields
    this.graph = graph;
    this.partition = graph.getPartition();
    this.additionalLabels = graph.vertexLabels();
    this.session = session;
    this.vertexIdProvider = vertexIdProvider;
    this.edgeIdProvider = edgeIdProvider;
    this.labels = new TreeSet<>(labels);
    // this is the original set of labels
    this.originalLabels = Collections.emptySortedSet();
    // labels used to match vertex in database
    this.matchLabels = Collections.emptySortedSet();
    // graph labels
    this.graphLabels = additionalLabels;
    // initialize original properties and cardinalities
    this.originalProperties = new HashMap<>();
    this.originalCardinalities = new HashMap<>();
    // generate id
    this.id = vertexIdProvider.generate();
    // this is a new vertex, everything is in memory
    outEdgesLoaded = true;
    inEdgesLoaded = true;
}
 
Example 8
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 9
Source File: ChannelAspectInformation.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public ChannelAspectInformation ( final String factoryId, final String label, final String description, final String groupId, final SortedSet<String> requires, final Version version )
{
    this.factoryId = factoryId;
    this.groupId = groupId == null || groupId.isEmpty () ? "other" : groupId;
    this.label = label;
    this.description = description;
    this.requires = requires == null ? Collections.emptySortedSet () : Collections.unmodifiableSortedSet ( requires );
    this.version = version;
    this.resolved = true;
}
 
Example 10
Source File: HostgroupView.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public HostgroupView(String name) {
    this.name = name;
    volumeCount = null;
    instanceGroupConfigured = false;
    instanceGroupType = InstanceGroupType.CORE;
    nodeCount = 0;
    hosts = Collections.emptySortedSet();
    volumeTemplates = Collections.emptySet();
}
 
Example 11
Source File: NotificationStoreTest.java    From notification with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplitNotificationsNotificationsEmpty() throws Exception {
  final Set<Notification> expected = Collections.emptySortedSet();
  final UserNotifications actual =
      store.splitNotifications(TEST_USER, Sets.<Notification>newTreeSet());
  assertThat(actual.getNotifications()).isEqualTo(expected);
}
 
Example 12
Source File: GoalUtils.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Get eligible replicas among the given candidate replicas for the proposed swap operation of the source replica.
 * Invariant-1: No replica is eligible if the candidate broker is excluded for leadership and the source replica is the leader.
 * Invariant-2: No replica is eligible if the candidate broker is excluded for replica move.
 *
 * @param clusterModel The state of the cluster.
 * @param sourceReplica Source replica for intended swap operation.
 * @param candidateReplicas Candidate replicas (from the same candidate broker) to swap with the source replica in the order
 *                          of attempts to swap.
 * @param optimizationOptions Options to take into account while applying the given action.
 * @return Eligible replicas for swap.
 */
public static SortedSet<Replica> eligibleReplicasForSwap(ClusterModel clusterModel,
                                                         Replica sourceReplica,
                                                         SortedSet<Replica> candidateReplicas,
                                                         OptimizationOptions optimizationOptions) {
  if (candidateReplicas.isEmpty()) {
    return candidateReplicas;
  }
  Broker destinationBroker = candidateReplicas.first().broker();
  if (optimizationOptions.excludedBrokersForLeadership().contains(destinationBroker.id())
      && !sourceReplica.isOriginalOffline()
      && sourceReplica.isLeader()) {
    return Collections.emptySortedSet();
  }
  if (optimizationOptions.excludedBrokersForReplicaMove().contains(destinationBroker.id())
      && !sourceReplica.isOriginalOffline()) {
    return Collections.emptySortedSet();
  }

  // CASE#1: All candidate replicas are eligible if any of the following is true:
  // (1) there are no new brokers in the cluster,
  // (2) the given candidate set contains no replicas,
  // (3) the intended swap is between replicas of new brokers,
  // (4) the intended swap is between a replica on a new broker, which originally was in the destination broker, and
  // any replica in the destination broker.
  Broker sourceBroker = sourceReplica.broker();

  if (clusterModel.newBrokers().isEmpty()
      || (sourceBroker.isNew() && (destinationBroker.isNew() || sourceReplica.originalBroker() == destinationBroker))) {
    return candidateReplicas;
  }

  // CASE#2: A subset of candidate replicas might be eligible if only the destination broker is a new broker and it
  // contains replicas that were originally in the source broker.
  if (destinationBroker.isNew()) {
    candidateReplicas.removeIf(replica -> replica.originalBroker() != sourceBroker);
    return candidateReplicas;
  }

  // CASE#3: No swap is possible between old brokers when there are new brokers in the cluster.
  return Collections.emptySortedSet();
}
 
Example 13
Source File: Numbers.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a {@code NaN}, zero, empty or {@code null} value of the given type. This method
 * tries to return the closest value that can be interpreted as <cite>"none"</cite>, which
 * is usually not the same than <cite>"zero"</cite>. More specifically:
 *
 * <ul>
 *   <li>If the given type is a floating point <strong>primitive</strong> type ({@code float}
 *       or {@code double}), then this method returns {@link Float#NaN} or {@link Double#NaN}
 *       depending on the given type.</li>
 *
 *   <li>If the given type is an integer <strong>primitive</strong> type or the character type
 *       ({@code long}, {@code int}, {@code short}, {@code byte} or {@code char}), then this
 *       method returns the zero value of the given type.</li>
 *
 *   <li>If the given type is the {@code boolean} <strong>primitive</strong> type, then this
 *       method returns {@link Boolean#FALSE}.</li>
 *
 *   <li>If the given type is an array or a collection, then this method returns an empty
 *       array or collection. The given type is honored on a <cite>best effort</cite> basis.</li>
 *
 *   <li>For all other cases, including the wrapper classes of primitive types, this method
 *       returns {@code null}.</li>
 * </ul>
 *
 * Despite being defined in the {@code Numbers} class, the scope of this method has been
 * extended to array and collection types because those objects can also be seen as
 * mathematical concepts.
 *
 * @param  <T>   the compile-time type of the requested object.
 * @param  type  the type of the object for which to get a nil value.
 * @return an object of the given type which represents a nil value, or {@code null}.
 *
 * @see org.apache.sis.xml.NilObject
 */
@SuppressWarnings("unchecked")
public static <T> T valueOfNil(final Class<T> type) {
    final Numbers mapping = MAPPING.get(type);
    if (mapping != null) {
        if (type.isPrimitive()) {
            return (T) mapping.nullValue;
        }
    } else if (type != null && type != Object.class) {
        if (type == Map         .class) return (T) Collections.EMPTY_MAP;
        if (type == List        .class) return (T) Collections.EMPTY_LIST;
        if (type == Queue       .class) return (T) CollectionsExt.emptyQueue();
        if (type == SortedSet   .class) return (T) Collections.emptySortedSet();
        if (type == NavigableSet.class) return (T) Collections.emptyNavigableSet();
        if (type.isAssignableFrom(Set.class)) {
            return (T) Collections.EMPTY_SET;
        }
        final Class<?> element = type.getComponentType();
        if (element != null) {
            return (T) Array.newInstance(element, 0);
        }
    }
    return null;
}
 
Example 14
Source File: NotificationStoreTest.java    From notification with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitNotificationsNotificationsNull() throws Exception {
  final Set<Notification> expected = Collections.emptySortedSet();
  final UserNotifications actual = store.splitNotifications(TEST_USER, null);
  assertThat(actual.getNotifications()).isEqualTo(expected);
}
 
Example 15
Source File: UserNotifications.java    From notification with Apache License 2.0 4 votes vote down vote up
/** Constructor */
public UserNotifications() {
  this.unseen = Collections.<Notification>emptySortedSet();
  this.seen = Collections.<Notification>emptySortedSet();
}
 
Example 16
Source File: UserNotifications.java    From notification with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param unseen Unseen notifications
 */
public UserNotifications(final Stream<Notification> unseen) {
  Objects.requireNonNull(unseen, "unseen == null");
  this.unseen = unseen.collect(Collectors.toCollection(TreeSet::new));
  this.seen = Collections.<Notification>emptySortedSet();
}
 
Example 17
Source File: BgpAdvertisement.java    From batfish with Apache License 2.0 4 votes vote down vote up
@JsonCreator
public BgpAdvertisement(
    @JsonProperty(PROP_TYPE) BgpAdvertisementType type,
    @JsonProperty(PROP_NETWORK) @Nonnull Prefix network,
    @JsonProperty(PROP_NEXT_HOP_IP) @Nonnull Ip nextHopIp,
    @JsonProperty(PROP_SRC_NODE) @Nonnull String srcNode,
    @JsonProperty(PROP_SRC_VRF) @Nonnull String srcVrf,
    @JsonProperty(PROP_SRC_IP) @Nonnull Ip srcIp,
    @JsonProperty(PROP_DST_NODE) @Nonnull String dstNode,
    @JsonProperty(PROP_DST_VRF) @Nonnull String dstVrf,
    @JsonProperty(PROP_DST_IP) @Nonnull Ip dstIp,
    @JsonProperty(PROP_SRC_PROTOCOL) @Nonnull RoutingProtocol srcProtocol,
    @JsonProperty(PROP_ORIGIN_TYPE) @Nonnull OriginType originType,
    @JsonProperty(PROP_LOCAL_PREFERENCE) long localPreference,
    @JsonProperty(PROP_MED) long med,
    @JsonProperty(PROP_ORIGINATOR_IP) Ip originatorIp,
    @JsonProperty(PROP_AS_PATH) @Nonnull AsPath asPath,
    @JsonProperty(PROP_COMMUNITIES) SortedSet<Community> communities,
    @JsonProperty(PROP_CLUSTER_LIST) SortedSet<Long> clusterList,
    @JsonProperty(PROP_WEIGHT) int weight) {
  _type = type;
  _network = network;
  _nextHopIp = nextHopIp;
  _srcNode = srcNode;
  _srcVrf = srcVrf;
  _srcIp = srcIp;
  _dstNode = dstNode;
  _dstVrf = dstVrf;
  _dstIp = dstIp;
  _srcProtocol = srcProtocol;
  _originType = originType;
  _localPreference = localPreference;
  _med = med;
  _originatorIp = originatorIp;
  _asPath = asPath;
  _communities =
      communities == null ? Collections.emptySortedSet() : ImmutableSortedSet.copyOf(communities);
  _clusterList =
      clusterList == null ? Collections.emptySortedSet() : ImmutableSortedSet.copyOf(clusterList);
  _weight = weight;
}
 
Example 18
Source File: IncrementalDataPlanePluginTest.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Test
public void testStaticInterfaceRoutesWithoutEdge() {
  NetworkFactory nf = new NetworkFactory();
  Configuration c =
      nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
  Vrf vrf = nf.vrfBuilder().setOwner(c).setName(DEFAULT_VRF_NAME).build();
  Interface i =
      nf.interfaceBuilder()
          .setOwner(c)
          .setVrf(vrf)
          .setAddress(ConcreteInterfaceAddress.parse("10.0.0.0/24"))
          .build();
  StaticRoute srBoth =
      StaticRoute.builder()
          .setNetwork(Prefix.parse("10.0.1.0/24"))
          .setNextHopInterface(i.getName())
          .setNextHopIp(Ip.parse("10.0.0.1"))
          .setAdministrativeCost(1)
          .build();
  vrf.getStaticRoutes().add(srBoth);
  StaticRoute srJustInterface =
      StaticRoute.builder()
          .setNetwork(Prefix.parse("10.0.2.0/24"))
          .setNextHopInterface(i.getName())
          .setAdministrativeCost(1)
          .build();
  vrf.getStaticRoutes().add(srJustInterface);
  Map<String, Configuration> configs = ImmutableMap.of(c.getHostname(), c);
  IncrementalBdpEngine engine =
      new IncrementalBdpEngine(
          // TODO: parametrize settings with different schedules
          new IncrementalDataPlaneSettings(),
          new BatfishLogger(BatfishLogger.LEVELSTR_DEBUG, false));
  Topology topology = new Topology(Collections.emptySortedSet());
  ComputeDataPlaneResult dp =
      engine.computeDataPlane(
          configs,
          TopologyContext.builder().setLayer3Topology(topology).build(),
          Collections.emptySet());

  // generating fibs should not crash
  dp._dataPlane.getFibs();
}
 
Example 19
Source File: ReturnEmptySortedSet.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void return_empty_sorted_set_java8 () {
	
	Set<String> emptySortedSet = Collections.emptySortedSet();
	
	assertTrue(emptySortedSet.isEmpty());
}
 
Example 20
Source File: UserNotifications.java    From notification with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor
 *
 * @param unseen Unseen notifications
 */
public UserNotifications(final Iterable<Notification> unseen) {
  this.unseen = Objects.requireNonNull(unseen, "unseen == null");
  this.seen = Collections.<Notification>emptySortedSet();
}