Java 8 Collection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Collection class.

This code example shows how to use the following methods:contains
    } 
    return out;
  } 
 
  public static URI unredirect(URI uri) throws IOException {
    if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
      return uri;
    } 
    URL url = uri.toURL();
 
    URLConnection conn = url.openConnection();
    if (!(conn instanceof HttpURLConnection)) {
      throw new IOException();
    } 
    HttpURLConnection connection = (HttpURLConnection) conn;
    connection.setInstanceFollowRedirects(false);
    connection.setDoInput(false);
    connection.setRequestMethod("HEAD");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try { 
8
CodeRank
This code example shows how to use the following methods:addAll
        // empty 
    } 
 
    public StringsCompleter(final Collection<String> strings) {
        assert strings != null;
        getStrings().addAll(strings);
    } 
 
    public StringsCompleter(final String... strings) {
        this(Arrays.asList(strings));
    } 
 
    public Collection<String> getStrings() {
        return strings;
    } 
 
    public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
        // buffer could be null 
        assert candidates != null;
 
8
CodeRank
This code example shows how to use the following methods:iterator, size
	 * @throws IncorrectResultSizeDataAccessException if more than one 
	 * result object has been found in the given Collection 
	 * @see org.springframework.util.CollectionUtils#hasUniqueObject 
	 */ 
	public static <T> T uniqueResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
		int size = (results != null ? results.size() : 0);
		if (size == 0) {
			return null; 
		} 
		if (!CollectionUtils.hasUniqueObject(results)) {
			throw new IncorrectResultSizeDataAccessException(1, size);
		} 
		return results.iterator().next();
	} 
 
	/** 
	 * Return a unique result object from the given Collection. 
	 * <p>Throws an exception if 0 or more than 1 instance found. 
	 * @param results the result Collection (can be {@code null}) 
	 * @return the unique result object 
8
CodeRank
This code example shows how to use the following methods:size
        } 
        if (value instanceof String) {
            return value.toString().trim().length() > 0;
        } 
        if (value instanceof Collection<?>) {
            return ((Collection<?>)value).size() > 0;
        } 
        if (value instanceof BinaryField) {
            return ((BinaryField)value).exists();
        } 
        if (value.getClass().isArray()) {
            try { 
                return java.lang.reflect.Array.getLength(value) > 0;
            } catch(Exception e) {
                throw new UnexpectedException(e);
            } 
        } 
        return true; 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:size
    this(new DataList(initialCapacity));
  } 
 
  public StringArray(Collection<String> c)
  { 
    this(new DataList(c.size()));
    addAll(c);
  } 
 
  public StringArray(DataList list)
  { 
    super(list, SCHEMA, String.class, String.class);
  } 
 
  @Override 
  public StringArray clone() throws CloneNotSupportedException 
  { 
    return (StringArray) super.clone(); 
  } 
 
8
CodeRank
This code example shows how to use the following methods:add
import java.util.concurrent.Callable;
 
public class PathNotationParser implements NotationParser<Object, String> {
 
    public void describe(Collection<String> candidateFormats) {
        candidateFormats.add("String or CharSequence instances e.g. 'some/path'");
        candidateFormats.add("Boolean values e.g. true, Boolean.TRUE");
        candidateFormats.add("Number values e.g. 42, 3.14");
        candidateFormats.add("A File instance");
        candidateFormats.add("A Closure that returns any supported value.");
        candidateFormats.add("A Callable that returns any supported value.");
    } 
 
    public static NotationParser<Object, String> create() {
        return NotationParserBuilder 
                .toType(String.class)
                .noImplicitConverters() 
                .allowNullInput() 
                .parser(new PathNotationParser()) 
                .toComposite(); 
8
CodeRank
This code example shows how to use the following methods:add, isEmpty
  } 
 
  @Override 
  public void onError(final Throwable e)
  { 
    _exceptions.add(e);
    checkDone(); 
  } 
 
  private void checkDone() 
  { 
    if (_count.decrementAndGet() == 0)
    { 
      if (_exceptions.isEmpty())
      { 
        _callback.onSuccess(None.none()); 
      } 
      else 
      { 
        _callback.onError(new MultiException(_exceptions));

8
CodeRank
This code example shows how to use the following methods:iterator, size
    Assert.assertEquals(jackFollowings.size(), 1);
 
    ODocument loadedKim = jackFollowings.iterator().next();
    Assert.assertEquals(loadedKim.field("name"), "Kim");
    Collection<ODocument> kimFollowings = loadedKim.field("following");
    Assert.assertNotNull(kimFollowings);
    Assert.assertEquals(kimFollowings.size(), 1);
 
    ODocument loadedTeri = kimFollowings.iterator().next();
    Assert.assertEquals(loadedTeri.field("name"), "Teri");
    Collection<ODocument> teriFollowings = loadedTeri.field("following");
    Assert.assertNotNull(teriFollowings);
    Assert.assertEquals(teriFollowings.size(), 1);
 
    Assert.assertEquals(teriFollowings.iterator().next().field("name"), "Jack");
 
    db.close();
  } 
} 
8
CodeRank
This code example shows how to use the following methods:isEmpty
        this.nodes.clear();
    } 
 
    @Override 
    public void invalidate(Collection<Address> addresses) {
        if (!addresses.isEmpty()) {
            this.nodes.keySet().removeAll(addresses);
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:size, empty, peek, get
		screen.setParent( this );
		m_children.add( m_children.size( ), screen );
	} 
 
	private void sendPopEvent() { 
		if( m_screenStack.empty( ) )
		{ 
			return; 
		} 
 
		// Only pop and send events if the stack is not empty 
		int poppedToScreenHandle = getHandle( );
		if( m_screenStack.size( ) >= 2 )
		{ 
			// Get the previous screen before the last one. 
			poppedToScreenHandle = m_screenStack.get(m_screenStack.size()-2).getHandle();
		} 
 
		EventQueue.getDefault( ).postWidgetStackScreenPoppedEvent( 
				getHandle(), 

7
CodeRank

Related Java 8 Collection Questions & Answers:

See Code Examples for Java 8 Collection Methods: