Java ConcurrentMap is(Class clazz, Collection> clazzes, ConcurrentMap, Boolean> cache)

Here you can find the source of is(Class clazz, Collection> clazzes, ConcurrentMap, Boolean> cache)

Description

Checks is a class is assignable to a class in the give collection.

License

Educational Community License

Parameter

Parameter Description
clazz the class to check
clazzes the collection of classes to check against
cache the cache to check against

Exception

Parameter Description
IllegalArgumentException if any arg is null

Return

a if the class is assignable

Declaration

private static boolean is(Class<?> clazz, Collection<Class<?>> clazzes,
        ConcurrentMap<Class<?>, Boolean> cache) 

Method Source Code

//package com.java2s;
/**//  w  w  w  .  java2  s .c o  m
 * Copyright 2005-2015 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Collection;

import java.util.concurrent.ConcurrentMap;

public class Main {
    /**
     * Checks is a class is assignable to a class in the give collection.  Also handles caching.
     *
     * @param clazz the class to check
     * @param clazzes the collection of classes to check against
     * @param cache the cache to check against
     * @return a if the class is assignable
     * @throws IllegalArgumentException if any arg is null
     */
    private static boolean is(Class<?> clazz, Collection<Class<?>> clazzes,
            ConcurrentMap<Class<?>, Boolean> cache) {
        if (clazz == null) {
            throw new IllegalArgumentException("clazz is null");
        }

        if (clazzes == null) {
            throw new IllegalArgumentException("clazzes is null");
        }

        if (cache == null) {
            throw new IllegalArgumentException("cache is null");
        }

        Boolean result = cache.get(clazz);
        if (result == null) {
            result = Boolean.valueOf(isa(clazzes, clazz));
            cache.putIfAbsent(clazz, result);
        }
        return result.booleanValue();
    }

    /**
     * @param types class tokens to check against
     * @param type class token
     * @return true if the given Class is assignable from one of the classes in
     *         the given Class[]
     */
    private static boolean isa(Collection<Class<?>> types, Class<?> type) {
        for (Class<?> cur : types) {
            if (cur.isAssignableFrom(type)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. getFilesystem(String id)
  2. getNestedSet(K1 key, ConcurrentMap> set)
  3. getNewLogFactor(String factorName)
  4. getSingleInstance(Class classType)
  5. getTypeFromKind(String kind)
  6. isClassClass(Class clazz)
  7. putIfAbsent(ConcurrentMap map, K key, V value)
  8. putIfAbsent(ConcurrentMap map, K key, V value)
  9. putIfAbsent(ConcurrentMap map, K key, V value)