java.util.Collections.unmodifiableSet()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中java.util.Collections.unmodifiableSet()方法的一些代码示例,展示了Collections.unmodifiableSet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.unmodifiableSet()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:unmodifiableSet

Collections.unmodifiableSet介绍

[英]Returns a wrapper on the specified set which throws an UnsupportedOperationException whenever an attempt is made to modify the set.
[中]返回指定集合上的包装器,每当试图修改集合时,该包装器将抛出UnsupportedOperationException。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the set of all option arguments present on the command line.
 */
public Set<String> getOptionNames() {
  return Collections.unmodifiableSet(this.optionArgs.keySet());
}

代码示例来源:origin: square/retrofit

private static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) {
  Set<Annotation> result = null;
  for (Annotation annotation : annotations) {
   if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) {
    if (result == null) result = new LinkedHashSet<>();
    result.add(annotation);
   }
  }
  return result != null ? unmodifiableSet(result) : Collections.<Annotation>emptySet();
 }
}

代码示例来源:origin: spring-projects/spring-framework

public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod> supportedMethods) {
  super(HttpStatus.METHOD_NOT_ALLOWED, "Request method '" + method + "' not supported");
  Assert.notNull(method, "'method' is required");
  if (supportedMethods == null) {
    supportedMethods = Collections.emptySet();
  }
  this.method = method;
  this.supportedMethods = Collections.unmodifiableSet(new HashSet<>(supportedMethods));
}

代码示例来源:origin: apache/nifi

@Override
protected void init(final ProcessorInitializationContext context) {
  final List<PropertyDescriptor> properties = new ArrayList<>();
  properties.add(USE_FILENAME_IN_DETECTION);
  this.properties = Collections.unmodifiableList(properties);
  final Set<Relationship> rels = new HashSet<>();
  rels.add(REL_SUCCESS);
  this.relationships = Collections.unmodifiableSet(rels);
}

代码示例来源:origin: dropwizard/dropwizard

public static <T> Set<T> of(Iterable<T> elements) {
    final Set<T> set = new HashSet<>();
    for (T element : elements) {
      set.add(element);
    }
    return unmodifiableSet(set);
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Update the exposed {@link #cacheNames} set with the given name.
 * <p>This will always be called within a full {@link #cacheMap} lock
 * and effectively behaves like a {@code CopyOnWriteArraySet} with
 * preserved order but exposed as an unmodifiable reference.
 * @param name the name of the cache to be added
 */
private void updateCacheNames(String name) {
  Set<String> cacheNames = new LinkedHashSet<>(this.cacheNames.size() + 1);
  cacheNames.addAll(this.cacheNames);
  cacheNames.add(name);
  this.cacheNames = Collections.unmodifiableSet(cacheNames);
}

代码示例来源:origin: org.osgi/org.osgi.core

public Set<Map.Entry<String, Object>> entrySet() {
  if (entries != null) {
    return entries;
  }
  Set<Map.Entry<String, Object>> all = new HashSet<Map.Entry<String, Object>>(properties.entrySet());
  add: for (String key : service.getPropertyKeys()) {
    for (String k : properties.keySet()) {
      if (key.equalsIgnoreCase(k)) {
        continue add;
      }
    }
    all.add(new Entry(key, service.getProperty(key)));
  }
  return entries = Collections.unmodifiableSet(all);
}

代码示例来源:origin: apache/nifi

@Override
protected void init(final ProcessorInitializationContext context) {
  final Set<Relationship> relationships = new HashSet<>();
  relationships.add(REL_ATTACHMENTS);
  relationships.add(REL_ORIGINAL);
  relationships.add(REL_FAILURE);
  this.relationships = Collections.unmodifiableSet(relationships);
  final List<PropertyDescriptor> descriptors = new ArrayList<>();
  this.descriptors = Collections.unmodifiableList(descriptors);
}

代码示例来源:origin: MovingBlocks/Terasology

/**
 * @param uri the uri to look uo
 * @return a set that contains all keys for that uri, never <code>null</code>
 */
public Set<String> getModuleConfigKeys(SimpleUri uri) {
  Map<String, JsonElement> map = config.getModuleConfigs().get(uri);
  if (map == null) {
    return Collections.emptySet();
  }
  return Collections.unmodifiableSet(map.keySet());
}

代码示例来源:origin: spring-projects/spring-security

@Override
  public void setupModule(SetupContext context) {
    SecurityJackson2Modules.enableDefaultTyping((ObjectMapper) context.getOwner());
    context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
    context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
    context.setMixInAnnotations(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.class);
    context.setMixInAnnotations(Collections.<Object>unmodifiableSet(Collections.emptySet()).getClass(), UnmodifiableSetMixin.class);
    context.setMixInAnnotations(Collections.<Object>unmodifiableList(Collections.emptyList()).getClass(), UnmodifiableListMixin.class);
    context.setMixInAnnotations(User.class, UserMixin.class);
    context.setMixInAnnotations(UsernamePasswordAuthenticationToken.class, UsernamePasswordAuthenticationTokenMixin.class);
    context.setMixInAnnotations(BadCredentialsException.class, BadCredentialsExceptionMixin.class);
  }
}

代码示例来源:origin: apache/nifi

@Override
protected void init(final ProcessorInitializationContext context) {
  final List<PropertyDescriptor> properties = new ArrayList<>();
  properties.add(MODE);
  this.properties = Collections.unmodifiableList(properties);
  final Set<Relationship> relationships = new HashSet<>();
  relationships.add(REL_SUCCESS);
  relationships.add(REL_FAILURE);
  this.relationships = Collections.unmodifiableSet(relationships);
}

代码示例来源:origin: dropwizard/dropwizard

public static <T> Set<T> of(T e1, T e2) {
  final Set<T> set = new HashSet<>(2);
  set.add(e1);
  set.add(e2);
  return unmodifiableSet(set);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the ids of the managed {@link MessageListenerContainer} instance(s).
 * @since 4.2.3
 * @see #getListenerContainer(String)
 */
public Set<String> getListenerContainerIds() {
  return Collections.unmodifiableSet(this.listenerContainers.keySet());
}

代码示例来源:origin: square/okhttp

/**
 * Returns the distinct query parameter names in this URL, like {@code ["a", "b"]} for {@code
 * http://host/?a=apple&b=banana}. If this URL has no query this returns the empty set.
 *
 * <p><table summary="">
 *   <tr><th>URL</th><th>{@code queryParameterNames()}</th></tr>
 *   <tr><td>{@code http://host/}</td><td>{@code []}</td></tr>
 *   <tr><td>{@code http://host/?}</td><td>{@code [""]}</td></tr>
 *   <tr><td>{@code http://host/?a=apple&k=key+lime}</td><td>{@code ["a", "k"]}</td></tr>
 *   <tr><td>{@code http://host/?a=apple&a=apricot}</td><td>{@code ["a"]}</td></tr>
 *   <tr><td>{@code http://host/?a=apple&b}</td><td>{@code ["a", "b"]}</td></tr>
 * </table>
 */
public Set<String> queryParameterNames() {
 if (queryNamesAndValues == null) return Collections.emptySet();
 Set<String> result = new LinkedHashSet<>();
 for (int i = 0, size = queryNamesAndValues.size(); i < size; i += 2) {
  result.add(queryNamesAndValues.get(i));
 }
 return Collections.unmodifiableSet(result);
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Update the exposed {@link #cacheNames} set with the given name.
 * <p>This will always be called within a full {@link #cacheMap} lock
 * and effectively behaves like a {@code CopyOnWriteArraySet} with
 * preserved order but exposed as an unmodifiable reference.
 * @param name the name of the cache to be added
 */
private void updateCacheNames(String name) {
  Set<String> cacheNames = new LinkedHashSet<>(this.cacheNames.size() + 1);
  cacheNames.addAll(this.cacheNames);
  cacheNames.add(name);
  this.cacheNames = Collections.unmodifiableSet(cacheNames);
}

代码示例来源:origin: apache/shiro

public Set<String> keySet() {
  return CollectionUtils.isEmpty(this.combinedPrincipals) ?
      Collections.<String>emptySet() :
      Collections.unmodifiableSet(this.combinedPrincipals.keySet());
}

代码示例来源:origin: apache/kafka

/**
 * Creates an instance with the specified parameters.
 *
 * @param topicPartitions List of topic partitions
 */
public MemberAssignment(Set<TopicPartition> topicPartitions) {
  this.topicPartitions = topicPartitions == null ? Collections.<TopicPartition>emptySet() :
    Collections.unmodifiableSet(new HashSet<>(topicPartitions));
}

代码示例来源:origin: apache/nifi

@Override
protected void init(final ProcessorInitializationContext context) {
  final Set<Relationship> relationships = new HashSet<>();
  relationships.add(REL_FAILURE);
  relationships.add(REL_SUCCESS);
  this.relationships = Collections.unmodifiableSet(relationships);
  final List<PropertyDescriptor> properties = new ArrayList<>();
  properties.add(HASH_VALUE_ATTRIBUTE);
  this.properties = Collections.unmodifiableList(properties);
}

代码示例来源:origin: dropwizard/dropwizard

public static <T> Set<T> of(T e1, T e2, T e3) {
  final Set<T> set = new HashSet<>(3);
  set.add(e1);
  set.add(e2);
  set.add(e3);
  return unmodifiableSet(set);
}

代码示例来源:origin: google/guava

@Override
public Set<E> incidentEdges() {
 return Collections.unmodifiableSet(incidentEdgeMap.keySet());
}

相关文章

微信公众号

最新文章

更多

Collections类方法