public boolean containsValue()

in src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java [1560:1608]


    public boolean containsValue(final Object value) {
        Objects.requireNonNull(value, "value");
        // See explanation of modCount use above
        final Segment<K, V>[] segments = this.segments;
        final int[] mc = new int[segments.length];
        // Try a few times without locking
        for (int k = 0; k < RETRIES_BEFORE_LOCK; ++k) {
            // final int sum = 0;
            int mcsum = 0;
            for (int i = 0; i < segments.length; ++i) {
                // final int c = segments[i].count;
                mcsum += mc[i] = segments[i].modCount;
                if (segments[i].containsValue(value)) {
                    return true;
                }
            }
            boolean cleanSweep = true;
            if (mcsum != 0) {
                for (int i = 0; i < segments.length; ++i) {
                    // final int c = segments[i].count;
                    if (mc[i] != segments[i].modCount) {
                        cleanSweep = false;
                        break;
                    }
                }
            }
            if (cleanSweep) {
                return false;
            }
        }
        // Resort to locking all segments
        for (final Segment<K, V> segment : segments) {
            segment.lock();
        }
        boolean found = false;
        try {
            for (final Segment<K, V> segment : segments) {
                if (segment.containsValue(value)) {
                    found = true;
                    break;
                }
            }
        } finally {
            for (final Segment<K, V> segment : segments) {
                segment.unlock();
            }
        }
        return found;
    }