Tabnine Logo
Set.size
Code IndexAdd Tabnine to your IDE (free)

How to use
size
method
in
java.util.Set

Best Java code snippets using java.util.Set.size (Showing top 20 results out of 115,038)

Refine searchRefine arrow

  • Set.add
  • Set.iterator
  • Iterator.next
  • Set.toArray
  • Set.contains
  • Iterator.hasNext
  • Map.get
origin: google/guava

@Override
public int size() {
 int size = set1.size();
 for (E e : set2) {
  if (!set1.contains(e)) {
   size++;
  }
 }
 return size;
}
origin: libgdx/libgdx

public Class[] getInterfaces() {
  return interfaces.toArray(new Class[this.interfaces.size()]);
}
origin: spring-projects/spring-framework

public static Method[] getPropertyMethods(PropertyDescriptor[] properties, boolean read, boolean write) {
  Set methods = new HashSet();
  for (int i = 0; i < properties.length; i++) {
    PropertyDescriptor pd = properties[i];
    if (read) {
      methods.add(pd.getReadMethod());
    }
    if (write) {
      methods.add(pd.getWriteMethod());
    }
  }
  methods.remove(null);
  return (Method[]) methods.toArray(new Method[methods.size()]);
}
origin: prestodb/presto

private static boolean fieldsEquals(RecordCursor cursor, Set<Field> fields)
{
  if (fields.size() < 2) {
    return true; // Nothing to compare
  }
  Iterator<Field> fieldIterator = fields.iterator();
  Field firstField = fieldIterator.next();
  while (fieldIterator.hasNext()) {
    if (!fieldEquals(cursor, firstField, fieldIterator.next())) {
      return false;
    }
  }
  return true;
}
origin: spring-projects/spring-framework

private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
  Set<String> fileNames = new HashSet<>();
  Iterator<String> fileIter = request.getFileNames();
  while (fileIter.hasNext()) {
    fileNames.add(fileIter.next());
  }
  assertEquals(2, fileNames.size());
  assertTrue(fileNames.contains("file1"));
  assertTrue(fileNames.contains("file2"));
  MultipartFile file1 = request.getFile("file1");
  MultipartFile file2 = request.getFile("file2");
  Map<String, MultipartFile> fileMap = request.getFileMap();
  List<String> fileMapKeys = new LinkedList<>(fileMap.keySet());
  assertEquals(2, fileMapKeys.size());
  assertEquals(file1, fileMap.get("file1"));
  assertEquals(file2, fileMap.get("file2"));
  assertEquals("file1", file1.getName());
  assertEquals("", file1.getOriginalFilename());
  assertNull(file1.getContentType());
  assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
  assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
    FileCopyUtils.copyToByteArray(file1.getInputStream())));
  assertEquals("file2", file2.getName());
  assertEquals("myOrigFilename", file2.getOriginalFilename());
  assertEquals("text/plain", file2.getContentType());
  assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
  assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
    FileCopyUtils.copyToByteArray(file2.getInputStream())));
}
origin: spring-projects/spring-framework

  @Override
  public String toString() {
    if (this.httpMethods.size() == 1) {
      return this.httpMethods.iterator().next().toString();
    }
    else {
      return this.httpMethods.toString();
    }
  }
}
origin: google/guava

static char[] randomChars(Random rand, int size) {
 Set<Character> chars = new HashSet<>(size);
 for (int i = 0; i < size; i++) {
  char c;
  while (true) {
   c = (char) rand.nextInt(Character.MAX_VALUE - Character.MIN_VALUE + 1);
   if (!chars.contains(c)) {
    break;
   }
  }
  chars.add(c);
 }
 char[] retValue = new char[chars.size()];
 int i = 0;
 for (char c : chars) {
  retValue[i++] = c;
 }
 Arrays.sort(retValue);
 return retValue;
}
origin: neo4j/neo4j

@Override
public File[] listFiles( File directory )
{
  directory = canonicalFile( directory );
  if ( files.containsKey( directory ) || !directories.contains( directory ) )
  {
    // This means that you're trying to list files on a file, not a directory.
    return null;
  }
  List<String> directoryPathItems = splitPath( directory );
  Set<File> found = new HashSet<>();
  Iterator<File> files = new CombiningIterator<>( asList( this.files.keySet().iterator(), directories.iterator() ) );
  while ( files.hasNext() )
  {
    File file = files.next();
    List<String> fileNamePathItems = splitPath( file );
    if ( directoryMatches( directoryPathItems, fileNamePathItems ) )
    {
      found.add( constructPath( fileNamePathItems, directoryPathItems ) );
    }
  }
  return found.toArray( new File[found.size()] );
}
origin: apache/incubator-dubbo

private Set<String> resolvePackagesToScan(Set<String> packagesToScan) {
  Set<String> resolvedPackagesToScan = new LinkedHashSet<String>(packagesToScan.size());
  for (String packageToScan : packagesToScan) {
    if (StringUtils.hasText(packageToScan)) {
      String resolvedPackageToScan = environment.resolvePlaceholders(packageToScan.trim());
      resolvedPackagesToScan.add(resolvedPackageToScan);
    }
  }
  return resolvedPackagesToScan;
}
origin: google/guava

/**
 * Returns a new proxy for {@code interfaceType}. Proxies of the same interface are equal to each
 * other if the {@link DummyProxy} instance that created the proxies are equal.
 */
final <T> T newProxy(TypeToken<T> interfaceType) {
 Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
 interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
 // Make the proxy serializable to work with SerializableTester
 interfaceClasses.add(Serializable.class);
 Object dummy =
   Proxy.newProxyInstance(
     interfaceClasses.iterator().next().getClassLoader(),
     interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
     new DummyHandler(interfaceType));
 @SuppressWarnings("unchecked") // interfaceType is T
 T result = (T) dummy;
 return result;
}
origin: apache/kafka

@Test
public void testLinger() throws Exception {
  long lingerMs = 10L;
  RecordAccumulator accum = createTestRecordAccumulator(
      1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, lingerMs);
  accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs);
  assertEquals("No partitions should be ready", 0, accum.ready(cluster, time.milliseconds()).readyNodes.size());
  time.sleep(10);
  assertEquals("Our partition's leader should be ready", Collections.singleton(node1), accum.ready(cluster, time.milliseconds()).readyNodes);
  List<ProducerBatch> batches = accum.drain(cluster, Collections.singleton(node1), Integer.MAX_VALUE, 0).get(node1.id());
  assertEquals(1, batches.size());
  ProducerBatch batch = batches.get(0);
  Iterator<Record> iter = batch.records().records().iterator();
  Record record = iter.next();
  assertEquals("Keys should match", ByteBuffer.wrap(key), record.key());
  assertEquals("Values should match", ByteBuffer.wrap(value), record.value());
  assertFalse("No more records", iter.hasNext());
}
origin: robolectric/robolectric

@Implementation
protected @Nullable String[] getPackagesForUid(int uid) {
 String[] packageNames = packagesForUid.get(uid);
 if (packageNames != null) {
  return packageNames;
 }
 Set<String> results = new HashSet<>();
 for (PackageInfo packageInfo : packageInfos.values()) {
  if (packageInfo.applicationInfo != null && packageInfo.applicationInfo.uid == uid) {
   results.add(packageInfo.packageName);
  }
 }
 return results.isEmpty() ? null : results.toArray(new String[results.size()]);
}
origin: spring-projects/spring-framework

Enumeration<String> parameterEnum = request.getParameterNames();
while (parameterEnum.hasMoreElements()) {
  parameterNames.add(parameterEnum.nextElement());
assertEquals(3, parameterNames.size());
assertTrue(parameterNames.contains("field3"));
assertTrue(parameterNames.contains("field4"));
assertTrue(parameterNames.contains("getField"));
assertEquals("value3", request.getParameter("field3"));
List<String> parameterValues = Arrays.asList(request.getParameterValues("field3"));
  String key = (String) o;
  parameterMapKeys.add(key);
  parameterMapValues.add(request.getParameterMap().get(key));
origin: neo4j/neo4j

@Test
@Graph( { "a TO b", "b TO c", "c TO a" } )
public void canCreateGraphFromMultipleStrings()
{
  Map<String,Node> graph = data.get();
  Set<Node> unique = new HashSet<>();
  Node n = graph.get( "a" );
  while ( unique.add( n ) )
  {
    try ( Transaction ignored = graphdb.beginTx() )
    {
      n = n.getSingleRelationship( RelationshipType.withName( "TO" ), Direction.OUTGOING ).getEndNode();
    }
  }
  assertEquals( graph.size(), unique.size() );
}
origin: prestodb/presto

public void noMoreSplits(PlanNodeId planNodeId)
{
  if (noMoreSplits.contains(planNodeId)) {
    return;
  }
  noMoreSplits.add(planNodeId);
  if (noMoreSplits.size() < sourceStartOrder.size()) {
    return;
  }
  checkState(noMoreSplits.size() == sourceStartOrder.size());
  checkState(noMoreSplits.containsAll(sourceStartOrder));
  status.setNoMoreLifespans();
}
origin: spring-projects/spring-framework

@Test
public void testPopulatedSet() throws Exception {
  HasMap hasMap = (HasMap) this.beanFactory.getBean("set");
  assertTrue(hasMap.getSet().size() == 3);
  assertTrue(hasMap.getSet().contains("bar"));
  TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
  assertTrue(hasMap.getSet().contains(jenny));
  assertTrue(hasMap.getSet().contains(null));
  Iterator it = hasMap.getSet().iterator();
  assertEquals("bar", it.next());
  assertEquals(jenny, it.next());
  assertEquals(null, it.next());
}
origin: google/guava

public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
 assertTrue(multiset.isEmpty());
 assertEquals(0, multiset.size());
 assertEquals(0, multiset.toArray().length);
 assertTrue(multiset.entrySet().isEmpty());
 assertFalse(multiset.iterator().hasNext());
 assertEquals(0, multiset.entrySet().size());
 assertEquals(0, multiset.entrySet().toArray().length);
 assertFalse(multiset.entrySet().iterator().hasNext());
}
origin: google/guava

private static void assertEmpty(Set<? extends List<?>> set) {
 assertTrue(set.isEmpty());
 assertEquals(0, set.size());
 assertFalse(set.iterator().hasNext());
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
@Test
public void setCollectionPropertyWithArrayValue() {
  IndexedTestBean target = new IndexedTestBean();
  AbstractPropertyAccessor accessor = createAccessor(target);
  Collection<String> coll = new HashSet<>();
  coll.add("coll1");
  accessor.setPropertyValue("collection", coll.toArray());
  List<String> set = new LinkedList<>();
  set.add("set1");
  accessor.setPropertyValue("set", set.toArray());
  List<String> sortedSet = new ArrayList<>();
  sortedSet.add("sortedSet1");
  accessor.setPropertyValue("sortedSet", sortedSet.toArray());
  Set<String> list = new HashSet<>();
  list.add("list1");
  accessor.setPropertyValue("list", list.toArray());
  assertEquals(1, target.getCollection().size());
  assertTrue(target.getCollection().containsAll(coll));
  assertEquals(1, target.getSet().size());
  assertTrue(target.getSet().containsAll(set));
  assertEquals(1, target.getSortedSet().size());
  assertTrue(target.getSortedSet().containsAll(sortedSet));
  assertEquals(1, target.getList().size());
  assertTrue(target.getList().containsAll(list));
}
origin: google/guava

 @Override
 TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) {
  Set<Type> combined = new LinkedHashSet<>(asList(upperBounds));
  // Since this is an artifically generated type variable, we don't bother checking
  // subtyping between declared type bound and actual type bound. So it's possible that we
  // may generate something like <capture#1-of ? extends Foo&SubFoo>.
  // Checking subtype between declared and actual type bounds
  // adds recursive isSubtypeOf() call and feels complicated.
  // There is no contract one way or another as long as isSubtypeOf() works as expected.
  combined.addAll(asList(typeParam.getBounds()));
  if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound.
   combined.remove(Object.class);
  }
  return super.captureAsTypeVariable(combined.toArray(new Type[0]));
 }
};
java.utilSetsize

Javadoc

Returns the number of elements in this set.

Popular methods of Set

  • add
    Adds the specified element to this set if it is not already present (optional operation). More forma
  • contains
    Returns true if this set contains the specified element. More formally, returns true if and only if
  • iterator
  • isEmpty
    Returns true if this set contains no elements.
  • addAll
    Adds all of the elements in the specified collection to this set if they're not already present (opt
  • remove
    Removes the specified element from this set if it is present (optional operation). More formally, re
  • toArray
    Returns an array containing all of the elements in this set; the runtime type of the returned array
  • stream
  • clear
    Removes all of the elements from this set (optional operation). The set will be empty after this cal
  • removeAll
    Removes from this set all of its elements that are contained in the specified collection (optional o
  • forEach
  • equals
    Compares the specified object with this set for equality. Returnstrue if the specified object is als
  • forEach,
  • equals,
  • containsAll,
  • retainAll,
  • hashCode,
  • removeIf,
  • parallelStream,
  • spliterator,
  • of

Popular in Java

  • Reading from database using SQL prepared statement
  • getApplicationContext (Context)
  • startActivity (Activity)
  • getSystemService (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • String (java.lang)
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • ImageIO (javax.imageio)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now