From b83e667af51edb5d50937abeeb7e1ab414b6ca05 Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 6 Aug 2024 23:56:13 +0800 Subject: [PATCH] Update MutableCollection --- .../collection/mutable/MutableCollection.java | 207 ++++++++++-------- 1 file changed, 110 insertions(+), 97 deletions(-) diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableCollection.java b/kala-collection/src/main/java/kala/collection/mutable/MutableCollection.java index 23b55933..9b47b5e4 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableCollection.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableCollection.java @@ -1,97 +1,110 @@ -package kala.collection.mutable; - -import kala.collection.Collection; -import kala.collection.internal.convert.AsJavaConvert; -import kala.collection.factory.CollectionFactory; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Iterator; -import java.util.Objects; -import java.util.stream.Collector; -import java.util.stream.Stream; - -public interface MutableCollection extends Collection, MutableAnyCollection { - - //region Static Factories - - static @NotNull CollectionFactory> factory() { - return CollectionFactory.narrow(MutableSeq.factory()); - } - - static @NotNull MutableCollection of() { - return MutableSeq.of(); - } - - @Contract("_ -> new") - static @NotNull MutableCollection of(E value1) { - return MutableSeq.of(value1); - } - - @Contract("_, _ -> new") - static @NotNull MutableCollection of(E value1, E value2) { - return MutableSeq.of(value1, value2); - } - - @Contract("_, _, _ -> new") - static @NotNull MutableCollection of(E value1, E value2, E value3) { - return MutableSeq.of(value1, value2, value3); - } - - @Contract("_, _, _, _ -> new") - static @NotNull MutableCollection of(E value1, E value2, E value3, E value4) { - return MutableSeq.of(value1, value2, value3, value4); - } - - @Contract("_, _, _, _, _ -> new") - static @NotNull MutableCollection of(E value1, E value2, E value3, E value4, E value5) { - return MutableSeq.of(value1, value2, value3, value4, value5); - } - - @SafeVarargs - static @NotNull MutableCollection of(E... values) { - return from(values); - } - - static @NotNull MutableCollection from(E @NotNull [] values) { - return MutableSeq.from(values); - } - - static @NotNull MutableCollection from(@NotNull Iterable values) { - return MutableSeq.from(values); - } - - static @NotNull MutableCollection from(@NotNull Iterator it) { - return MutableSeq.from(it); - } - - static @NotNull MutableCollection from(@NotNull Stream stream) { - return MutableSeq.from(stream); - } - - static > @NotNull MutableCollectionEditor edit(@NotNull C collection) { - return new MutableCollectionEditor<>(collection); - } - - //endregion - - @Override - default @NotNull String className() { - return "MutableCollection"; - } - - @Override - default @NotNull CollectionFactory> iterableFactory() { - return factory(); - } - - @Override - default @NotNull java.util.Collection asJava() { - return new AsJavaConvert.MutableCollectionAsJava<>(this); - } - - @SuppressWarnings({"MethodDoesntCallSuperMethod"}) - default @NotNull MutableCollection clone() { - return this.iterableFactory().from(this); - } -} +/* + * Copyright 2024 Glavo + * + * 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 kala.collection.mutable; + +import kala.collection.Collection; +import kala.collection.internal.convert.AsJavaConvert; +import kala.collection.factory.CollectionFactory; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Iterator; +import java.util.stream.Stream; + +public interface MutableCollection extends Collection, MutableAnyCollection { + + //region Static Factories + + static @NotNull CollectionFactory> factory() { + return CollectionFactory.narrow(MutableSeq.factory()); + } + + static @NotNull MutableCollection of() { + return MutableSeq.of(); + } + + @Contract("_ -> new") + static @NotNull MutableCollection of(E value1) { + return MutableSeq.of(value1); + } + + @Contract("_, _ -> new") + static @NotNull MutableCollection of(E value1, E value2) { + return MutableSeq.of(value1, value2); + } + + @Contract("_, _, _ -> new") + static @NotNull MutableCollection of(E value1, E value2, E value3) { + return MutableSeq.of(value1, value2, value3); + } + + @Contract("_, _, _, _ -> new") + static @NotNull MutableCollection of(E value1, E value2, E value3, E value4) { + return MutableSeq.of(value1, value2, value3, value4); + } + + @Contract("_, _, _, _, _ -> new") + static @NotNull MutableCollection of(E value1, E value2, E value3, E value4, E value5) { + return MutableSeq.of(value1, value2, value3, value4, value5); + } + + @SafeVarargs + static @NotNull MutableCollection of(E... values) { + return from(values); + } + + static @NotNull MutableCollection from(E @NotNull [] values) { + return MutableSeq.from(values); + } + + static @NotNull MutableCollection from(@NotNull Iterable values) { + return MutableSeq.from(values); + } + + static @NotNull MutableCollection from(@NotNull Iterator it) { + return MutableSeq.from(it); + } + + static @NotNull MutableCollection from(@NotNull Stream stream) { + return MutableSeq.from(stream); + } + + static > @NotNull MutableCollectionEditor edit(@NotNull C collection) { + return new MutableCollectionEditor<>(collection); + } + + //endregion + + @Override + default @NotNull String className() { + return "MutableCollection"; + } + + @Override + default @NotNull CollectionFactory> iterableFactory() { + return factory(); + } + + @Override + default @NotNull java.util.Collection asJava() { + return new AsJavaConvert.MutableCollectionAsJava<>(this); + } + + @SuppressWarnings({"MethodDoesntCallSuperMethod"}) + default @NotNull MutableCollection clone() { + return this.iterableFactory().from(this); + } +}