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.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
/** An unmodifiable map */
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 wrap(Map.Entry entry) {
return Tuple2.of(entry.getKey(), entry.getValue());
}
static UnmodIterator> wrap(Iterator> innerIter) {
return new UnmodIterator>() {
@Override public boolean hasNext() { return innerIter.hasNext(); }
@Override public UnEntry next() { return UnmodMap.UnEntry.wrap(innerIter.next()); }
};
}
static UnmodSortedIterator> wrap(UnmodSortedIterator> innerIter) {
return new UnmodSortedIterator>() {
@Override public boolean hasNext() { return innerIter.hasNext(); }
@Override public UnEntry next() { return UnmodMap.UnEntry.wrap(innerIter.next()); }
};
}
static UnEntry of(K k, V v) { return Tuple2.of(k, v); }
//
// 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