Example usage for java.util.concurrent ConcurrentNavigableMap isEmpty

List of usage examples for java.util.concurrent ConcurrentNavigableMap isEmpty

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentNavigableMap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:org.apache.sling.models.impl.AdapterImplementations.java

/**
 * Remove implementation mapping for the given adapter type.
 * @param adapterTypeName Adapter type name
 * @param implTypeName Implementation type name
 *//*from   w  w  w .ja  v  a 2 s  . c o m*/
public void remove(String adapterTypeName, String implTypeName) {
    String key = adapterTypeName;
    if (StringUtils.equals(adapterTypeName, implTypeName)) {
        modelClasses.remove(key);
    } else {
        // although we already use a ConcurrentMap synchronize explicitly because we apply non-atomic operations on it
        synchronized (adapterImplementations) {
            ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
            if (implementations != null) {
                implementations.remove(implTypeName);
                if (implementations.isEmpty()) {
                    adapterImplementations.remove(key);
                }
            }
        }
    }
}

From source file:org.apache.sling.models.impl.AdapterImplementations.java

/**
 * Lookup the best-matching implementation for the given adapter type by enquiring the {@link ImplementationPicker} services.
 * @param adapterType Adapter type//from  ww  w  .  j ava 2  s.co m
 * @param adaptable Adaptable for reference
 * @return Implementation type or null if none detected
 */
@SuppressWarnings("unchecked")
public <ModelType> ModelClass<ModelType> lookup(Class<ModelType> adapterType, Object adaptable) {
    String key = adapterType.getName();

    // lookup in cache for models without adapter classes
    ModelClass<ModelType> modelClass = (ModelClass<ModelType>) modelClasses.get(key);
    if (modelClass != null) {
        return modelClass;
    }

    // not found? look in cache with adapter classes
    ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
    if (implementations == null || implementations.isEmpty()) {
        return null;
    }
    Collection<ModelClass<?>> implementationsCollection = implementations.values();
    ModelClass<?>[] implementationWrappersArray = implementationsCollection
            .toArray(new ModelClass<?>[implementationsCollection.size()]);

    // prepare array for implementation picker
    Class<?>[] implementationsArray = new Class<?>[implementationsCollection.size()];
    for (int i = 0; i < implementationWrappersArray.length; i++) {
        implementationsArray[i] = implementationWrappersArray[i].getType();
    }

    for (ImplementationPicker picker : this.sortedImplementationPickers) {
        Class<?> implementation = picker.pick(adapterType, implementationsArray, adaptable);
        if (implementation != null) {
            for (int i = 0; i < implementationWrappersArray.length; i++) {
                if (implementation == implementationWrappersArray[i].getType()) {
                    return (ModelClass<ModelType>) implementationWrappersArray[i];
                }
            }
        }
    }

    return null;
}

From source file:org.apache.sling.models.impl.AdapterImplementations.java

/**
 * @param adapterType the type to check/*from   w  w  w. j a v  a  2  s  .  c  o  m*/
 * @return {@code true} in case the given type is a model (may be with a different adapter class)
 */
@SuppressWarnings("unchecked")
public <ModelType> boolean isModelClass(Class<ModelType> adapterType) {
    String key = adapterType.getName();

    // lookup in cache for models without adapter classes
    ModelClass<ModelType> modelClass = (ModelClass<ModelType>) modelClasses.get(key);
    if (modelClass != null) {
        return true;
    }

    // not found? look in cache with adapter classes
    ConcurrentNavigableMap<String, ModelClass<?>> implementations = adapterImplementations.get(key);
    if (implementations == null || implementations.isEmpty()) {
        return false;
    }
    return true;
}