Add ImmutableHashSet
This commit is contained in:
parent
be74555064
commit
85e6cd69de
1 changed files with 123 additions and 0 deletions
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||||
|
* Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||||
|
* Licensed under the GNU Affero General Public License v3
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.staropensource.sosengine.base.types.immutable;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An unmodifiable {@link HashSet}.
|
||||||
|
*
|
||||||
|
* @param <E> contained type
|
||||||
|
* @since v1-alpha2
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "unused" })
|
||||||
|
public class ImmutableHashSet<E> extends HashSet<E> {
|
||||||
|
/**
|
||||||
|
* Creates a new immutable hash set.
|
||||||
|
*
|
||||||
|
* @since v1-alpha2
|
||||||
|
*/
|
||||||
|
public ImmutableHashSet() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a {@link Set} into an {@link ImmutableHashSet}.
|
||||||
|
*
|
||||||
|
* @param set {@link Set} to convert
|
||||||
|
* @since v1-alpha2
|
||||||
|
*/
|
||||||
|
public ImmutableHashSet(@NotNull Set<E> set) {
|
||||||
|
super.addAll(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean add(Object o) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object o) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean addAll(@NotNull Collection collection) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(@NotNull Collection collection) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean removeIf(Predicate filter) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws UnsupportedOperationException always, array list is immutable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(@NotNull Collection collection) {
|
||||||
|
throw new UnsupportedOperationException("This method cannot be executed on an ImmutableHashSet");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue