From 85e6cd69de25f8ea8bd648a44095187c3906260e Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 20 Jul 2024 18:22:14 +0200 Subject: [PATCH] Add ImmutableHashSet --- .../types/immutable/ImmutableHashSet.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 base/src/main/java/de/staropensource/sosengine/base/types/immutable/ImmutableHashSet.java diff --git a/base/src/main/java/de/staropensource/sosengine/base/types/immutable/ImmutableHashSet.java b/base/src/main/java/de/staropensource/sosengine/base/types/immutable/ImmutableHashSet.java new file mode 100644 index 00000000..db18eea0 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/types/immutable/ImmutableHashSet.java @@ -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 . + */ + +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 contained type + * @since v1-alpha2 + */ +@SuppressWarnings({ "unused" }) +public class ImmutableHashSet extends HashSet { + /** + * 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 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"); + } +}