All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javolution.util.internal.map.UnmodifiableMapImpl Maven / Gradle / Ivy

The newest version!
/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.util.internal.map;

import java.util.Iterator;

import javolution.util.function.Equality;
import javolution.util.service.MapService;

/**
 *  * An unmodifiable view over a map.
 */
public class UnmodifiableMapImpl extends MapView {

    /** Read-Only Iterator. */
    private class IteratorImpl implements Iterator> {
        private final Iterator> targetIterator = target()
                .iterator();

        @Override
        public boolean hasNext() {
            return targetIterator.hasNext();
        }

        @Override
        public Entry next() {
            return targetIterator.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Read-Only Map.");
        }
    }

    private static final long serialVersionUID = 0x600L; // Version.

    public UnmodifiableMapImpl(MapService target) {
        super(target);
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("Unmodifiable");
    }

    @Override
    public boolean containsKey(Object key) {
        return target().containsKey(key);
    }

    @Override
    public V get(Object key) {
        return target().get(key);
    }

    @Override
    public Iterator> iterator() {
        return new IteratorImpl();
    }

    @Override
    public Equality keyComparator() {
        return target().keyComparator();
    }

    @Override
    public V put(K key, V value) {
        throw new UnsupportedOperationException("Unmodifiable");
    }

    @Override
    public V remove(Object key) {
        throw new UnsupportedOperationException("Unmodifiable");
    }

    @Override
    public MapService threadSafe() {
        return this;
    }

    @Override
    public Equality valueComparator() {
        return target().valueComparator();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy