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

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

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

Collections.checkedSet介绍

[英]Returns a dynamically typesafe view of the specified set. Trying to insert an element of the wrong type into this set throws a ClassCastException. At creation time the types in s are not checked for correct type.
[中]

代码示例

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

@Override
 public Set<String> create(String[] elements) {
  Set<String> innerSet = new HashSet<>();
  Collections.addAll(innerSet, elements);
  return Collections.checkedSet(innerSet, String.class);
 }
})

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

classes.add(Collections.checkedNavigableSet(Collections.emptyNavigableSet(), Void.class).getClass());
classes.add(Collections.checkedQueue(new LinkedList<>(), Void.class).getClass());
classes.add(Collections.checkedSet(Collections.emptySet(), Void.class).getClass());
classes.add(Collections.checkedSortedMap(Collections.emptySortedMap(), Void.class, Void.class).getClass());
classes.add(Collections.checkedSortedSet(Collections.emptySortedSet(), Void.class).getClass());

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

checkedSet = Collections.checkedSet(es, Size.class);
checkedSortedSet = Collections.checkedSortedSet(ts, String.class);
checkedList = Collections.checkedList(ll, String.class);

代码示例来源:origin: org.geotools/gt2-geometry

@SuppressWarnings("unchecked")
public Set<Point> getElements() {
  //return (Set<Point>) super.elements;
  return Collections.checkedSet( (Set<Point>) super.elements, Point.class );
}

代码示例来源:origin: org.geotools/gt2-geometry

@SuppressWarnings("unchecked")
  public Set<? extends Primitive> getElements() {
    return Collections.checkedSet( (Set<Primitive>) super.elements, Primitive.class );
  }
}

代码示例来源:origin: org.bitbucket.dollar/dollar

@Override
public Dollar.SetWrapper<T> checked(Class<T> requiredClass) {
  set = Collections.checkedSet(set, requiredClass);
  return this;
}

代码示例来源:origin: org.geotools/gt2-geometry

@SuppressWarnings("unchecked")
public Set<OrientableSurface> getElements() {
  //return (Set<OrientableSurface>) super.elements;
  return Collections.checkedSet( (Set<OrientableSurface>) super.elements, OrientableSurface.class );
      
}

代码示例来源:origin: org.geotools/gt2-geometry

@SuppressWarnings("unchecked")
public Set<OrientableCurve> getElements() {
  return (Set<OrientableCurve>)
    Collections.checkedSet( (Set<OrientableCurve>) elements, OrientableCurve.class ); 
}

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

public Set<PropertyChangeListener> getPropertyChangeListeners() {
  return Collections.checkedSet(listeners, PropertyChangeListener.class);
}

代码示例来源:origin: biz.aQute.bnd/biz.aQute.bnd

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new LinkedHashSet<>(), c);
}

代码示例来源:origin: biz.aQute.bnd/bnd

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new LinkedHashSet<T>(), c);
}

代码示例来源:origin: biz.aQute.bnd/org.osgi.impl.bundle.repoindex.cli

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new HashSet<T>(), c);
}

代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new LinkedHashSet<>(), c);
}

代码示例来源:origin: biz.aQute/bndlib

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new HashSet<T>(), c);
}

代码示例来源:origin: biz.aQute.bnd/biz.aQute.resolve

public static <T> Set<T> set(Class<T> c) {
  return Collections.checkedSet(new LinkedHashSet<>(), c);
}

代码示例来源:origin: com.google.guava/guava-testlib

@Override
 public Set<String> create(String[] elements) {
  Set<String> innerSet = new HashSet<>();
  Collections.addAll(innerSet, elements);
  return Collections.checkedSet(innerSet, String.class);
 }
})

代码示例来源:origin: com.google.guava/guava-testlib-jdk5

@Override public Set<String> create(String[] elements) {
  Set<String> innerSet = new HashSet<String>();
  Collections.addAll(innerSet, elements);
  return Collections.checkedSet(innerSet, String.class);
 }
})

代码示例来源:origin: org.glassfish.common/amx-core

/**
Create a checked Set<String>, first verifying that all elements
are in fact String.
@param s the Set
@throws ClassCastException
 */
public static <T> Set<T> checkedSet(final Set<?> s, final Class<T> theClass)
{
  final Set<T> cs = checkSet(s, theClass);
  return Collections.checkedSet(cs, theClass);
}

代码示例来源:origin: org.glassfish.main.common/amx-core

/**
Create a checked Set<String>, first verifying that all elements
are in fact String.
@param s the Set
@throws ClassCastException
 */
public static <T> Set<T> checkedSet(final Set<?> s, final Class<T> theClass)
{
  final Set<T> cs = checkSet(s, theClass);
  return Collections.checkedSet(cs, theClass);
}

代码示例来源:origin: com.github.rinde/rinsim-problem

static ImmutableMap<ParcelDTO, DefaultParcel> contentsToMap(PDPModel pm,
  DefaultVehicle vehicle) {
 // this is ok since we actually check the type
 @SuppressWarnings({ "unchecked", "rawtypes" })
 final Set<DefaultParcel> ps = Collections.checkedSet(
   (Set) newLinkedHashSet(pm.getContents(vehicle)), DefaultParcel.class);
 return toMap(ps);
}

相关文章

Collections类方法