Example usage for java.util.concurrent ConcurrentNavigableMap values

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

Introduction

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

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.google.cloud.dns.testing.LocalDnsHelper.java

/**
 * Lists zones. Next page token is the last listed zone name and is returned only of there is more
 * to list and if the user does not exclude nextPageToken from field options.
 *///w w  w .ja  v  a2s.c om
@VisibleForTesting
Response listZones(String projectId, String query) {
    Map<String, Object> options = OptionParsers.parseListZonesOptions(query);
    Response response = checkListOptions(options);
    if (response != null) {
        return response;
    }
    ConcurrentSkipListMap<String, ZoneContainer> containers = findProject(projectId).zones();
    String[] fields = (String[]) options.get("fields");
    String dnsName = (String) options.get("dnsName");
    String pageToken = (String) options.get("pageToken");
    Integer maxResults = options.get("maxResults") == null ? null
            : Integer.valueOf((String) options.get("maxResults"));
    boolean sizeReached = false;
    boolean hasMorePages = false;
    LinkedList<String> serializedZones = new LinkedList<>();
    String lastZoneName = null;
    ConcurrentNavigableMap<String, ZoneContainer> fragment = pageToken != null
            ? containers.tailMap(pageToken, false)
            : containers;
    for (ZoneContainer zoneContainer : fragment.values()) {
        ManagedZone zone = zoneContainer.zone();
        if (dnsName == null || zone.getDnsName().equals(dnsName)) {
            if (sizeReached) {
                // we do not add this, just note that there would be more and there should be a token
                hasMorePages = true;
                break;
            } else {
                try {
                    lastZoneName = zone.getName();
                    serializedZones.addLast(jsonFactory.toString(OptionParsers.extractFields(zone, fields)));
                } catch (IOException e) {
                    return Error.INTERNAL_ERROR.response(String.format(
                            "Error when serializing managed zone %s in project %s", lastZoneName, projectId));
                }
            }
        }
        sizeReached = maxResults != null && maxResults.equals(serializedZones.size());
    }
    boolean includePageToken = hasMorePages
            && (fields == null || Arrays.asList(fields).contains("nextPageToken"));
    return toListResponse(serializedZones, "managedZones", lastZoneName, includePageToken);
}

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

/**
 * Updates all {@link ModelClass} instances with updates list of static inject annotation processor factories.
 *//*from w w  w .j ava 2s . com*/
private void updateProcessorFactoriesInModelClasses() {
    Iterator<ModelClass<?>> items = modelClasses.values().iterator();
    updateProcessorFactoriesInModelClasses(items);
    Iterator<ConcurrentNavigableMap<String, ModelClass<?>>> mapItems = adapterImplementations.values()
            .iterator();
    while (mapItems.hasNext()) {
        ConcurrentNavigableMap<String, ModelClass<?>> mapItem = mapItems.next();
        updateProcessorFactoriesInModelClasses(mapItem.values().iterator());
    }
}

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 w w  w  . j a  v a 2 s.  c o 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;
}