Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2015-04-13 PlanBase Inc. & Glen Peterson
//
// 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.organicdesign.fp.collections;
import org.organicdesign.fp.tuple.Tuple2;
import java.util.Iterator;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
An unmodifiable map.
This cannot extend Collection because the remove() method would then be inherited
from both Collection and Map and Collection.remove() returns a boolean while Map.remove() returns
a V (the type of the value in the key/value pair). Maybe an UnmodSizedIterable is called for?
*/
public interface UnmodMap extends Map, UnmodIterable> {
// ========================================== Static ==========================================
/**
* A map entry (key-value pair). The UnmodMap.entrySet method returns
* a collection-view of the map, whose elements are of this class. The
* only way to obtain a reference to a map entry is from the
* iterator of this collection-view.
*
* @see UnmodMap#entrySet()
*/
interface UnEntry extends Map.Entry {
/** Not allowed - this is supposed to be unmodifiable */
@SuppressWarnings("deprecation")
@Override @Deprecated default V setValue(V value) {
throw new UnsupportedOperationException("Modification attempted");
}
static UnEntry entryToUnEntry(Map.Entry entry) {
return Tuple2.of(entry.getKey(), entry.getValue());
}
static
UnmodIterator> entryIterToUnEntryUnIter(Iterator> innerIter) {
return new UnmodIterator>() {
@Override public boolean hasNext() { return innerIter.hasNext(); }
@Override public UnEntry next() {
return UnmodMap.UnEntry.entryToUnEntry(innerIter.next());
}
};
}
static UnmodSortedIterator> unSortIterEntToUnSortIterUnEnt(
UnmodSortedIterator> innerIter) {
return new UnmodSortedIterator>() {
@Override public boolean hasNext() { return innerIter.hasNext(); }
@Override public UnEntry next() {
return UnmodMap.UnEntry.entryToUnEntry(innerIter.next());
}
};
}
//
// class Impl implements UnEntry {
// private final K key;
// private final V val;
// private Impl(K k, V v) { key = k; val = v; }
// @Override public K getKey() { return key; }
// @Override public V getValue() { return val; }
// @Override
// public boolean equals(Object other) {
// if (this == other) { return true; }
// if ((other == null) || !(other instanceof UnEntry)) { return false; }
//
// UnEntry that = (UnEntry) other;
// return Objects.equals(this.key, that.getKey()) &&
// Objects.equals(this.getValue(), that.getValue());
// }
//
// @Override
// public int hashCode() {
// int ret = 0;
// if (key != null) { ret = key.hashCode(); }
// if (val != null) { return ret ^ val.hashCode(); }
// // If it's uninitialized, it's equal to every other uninitialized instance.
// return ret;
// }
//
// @Override public String toString() {
// return "UnEntry(" + key + "," + val + ")";
// }
// };
}
UnmodMap