org.mayanjun.mybatisx.dal.generator.ReadOnlyMap Maven / Gradle / Ivy
/*
* Copyright 2016-2018 mayanjun.org
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.mayanjun.mybatisx.dal.generator;
import java.util.*;
/**
* Read-only to not-same package
*
* @author mayanjun(7/3/16)
*/
public class ReadOnlyMap implements Map {
private Map container;
public ReadOnlyMap() {
this.container = new HashMap();
}
@Override
public int hashCode() {
return container.hashCode();
}
@Override
public boolean equals(Object o) {
return container.equals(o);
}
@Override
public int size() {
return container.size();
}
@Override
public boolean isEmpty() {
return container.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return container.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return container.containsValue(value);
}
@Override
public V get(Object key) {
return container.get(key);
}
@Override
public V put(K key, V value) {
throw new UnsupportedOperationException("Read only map, can not be modified");
}
@Override
public V remove(Object key) {
throw new UnsupportedOperationException("Read only map, can not be modified");
}
@Override
public void putAll(Map extends K, ? extends V> m) {
throw new UnsupportedOperationException("Read only map, can not be modified");
}
@Override
public void clear() {
throw new UnsupportedOperationException("Read only map, can not be modified");
}
@Override
public Set keySet() {
return container.keySet();
}
@Override
public Collection values() {
return new ReadOnlyList(container.values());
}
@Override
public Set> entrySet() {
return container.entrySet();
}
V putInternal(K key, V value) {
return container.put(key, value);
}
void putAllInternal(Map extends K, ? extends V> m) {
container.putAll(m);
}
V removeInternal(Object key) {
return container.remove(key);
}
public static class ReadOnlyList extends ArrayList {
public ReadOnlyList() {
}
public ReadOnlyList(Collection extends E> c) {
super(c);
}
public ReadOnlyList(int initialCapacity) {
super(initialCapacity);
}
@Override
public E set(int index, E element) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public boolean add(E e) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public void add(int index, E element) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public E remove(int index) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public boolean addAll(Collection extends E> c) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public boolean addAll(int index, Collection extends E> c) {
throw new UnsupportedOperationException("Read only list");
}
@Override
protected void removeRange(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("Read only list");
}
@Override
public boolean removeAll(Collection> c) {
throw new UnsupportedOperationException("Read only list");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy