Java Collection Contain contains(final Collection mimeTypes, final MimeType mimeType)

Here you can find the source of contains(final Collection mimeTypes, final MimeType mimeType)

Description

Checks if a specific MimeType is in a collection of mime types

License

Open Source License

Parameter

Parameter Description
mimeTypes A collection of MimeType s
mimeType The mime type to test

Return

True if the mime type is in the collection

Declaration

public static boolean contains(final Collection<MimeType> mimeTypes, final MimeType mimeType) 

Method Source Code


//package com.java2s;
/*  Copyright (C) 2014 Reinventing Geospatial, Inc
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.// ww  w .j av  a2 s .  c  o  m
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>,
 *  or write to the Free Software Foundation, Inc., 59 Temple Place -
 *  Suite 330, Boston, MA 02111-1307, USA.
 */

import java.util.Collection;

import javax.activation.MimeType;

public class Main {
    /**
     * Checks if a specific {@link MimeType} is in a collection of mime types
     *
     * @param mimeTypes
     *             A collection of {@link MimeType}s
     * @param mimeType
     *             The mime type to test
     * @return True if the mime type is in the collection
     */
    public static boolean contains(final Collection<MimeType> mimeTypes, final MimeType mimeType) {
        if (mimeTypes == null) {
            throw new IllegalArgumentException("The collection of mimeTypes cannot be null.");
        }

        if (mimeType == null) {
            throw new IllegalArgumentException("mimeType cannot be null.");
        }

        return mimeTypes.stream().filter(format -> format != null)
                .anyMatch(allowedImageOutputFormat -> allowedImageOutputFormat.match(mimeType));
    }
}

Related

  1. contains(Collection objectArray, Object element)
  2. contains(Collection container, String strSearch)
  3. contains(Collection mainCollection, String str)
  4. contains(Collection c1, Collection c2)
  5. contains(Collection collection, T item)
  6. contains(final Collection c, final T o)
  7. contains(Object o, Collection c)
  8. containsAll(Collection c, Iterable subset)
  9. containsAll(Collection coll, Collection other)

  10. HOME | Copyright © www.java2s.com 2016