From: Robert Varga Date: Thu, 2 Mar 2023 00:54:33 +0000 (+0100) Subject: Remove most of atomix.utils.* X-Git-Tag: v7.0.5~95 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=aad091c6b6f05b167214f0f0091aaad5446a6715 Remove most of atomix.utils.* Most of the defined interfaces are not used anywhere, remove them. JIRA: CONTROLLER-2071 Change-Id: Iffa3fc760be89752868249f7e8eb189e231f8006 Signed-off-by: Robert Varga --- diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/ConfiguredType.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/ConfiguredType.java deleted file mode 100644 index b90eb95ff2..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/ConfiguredType.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -import io.atomix.utils.config.TypedConfig; - -/** - * Configured type. - */ -public interface ConfiguredType extends NamedType { - - /** - * Returns a new configuration. - * - * @return a new configuration - */ - C newConfig(); - -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/Identifier.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/Identifier.java deleted file mode 100644 index 46321a6169..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/Identifier.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2016-present Open Networking Foundation - * - * 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 io.atomix.utils; - -/** - * Abstract identifier backed by another value, e.g. string, int. - */ -public interface Identifier> { - - /** - * Returns the backing identifier value. - * - * @return identifier - */ - T id(); -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/Managed.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/Managed.java deleted file mode 100644 index d79a038395..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/Managed.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2017-present Open Networking Foundation - * - * 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 io.atomix.utils; - -import java.util.concurrent.CompletableFuture; - -/** - * Interface for types that can be asynchronously started and stopped. - * - * @param managed type - */ -public interface Managed { - - /** - * Starts the managed object. - * - * @return A completable future to be completed once the object has been started. - */ - CompletableFuture start(); - - /** - * Returns a boolean value indicating whether the managed object is running. - * - * @return Indicates whether the managed object is running. - */ - boolean isRunning(); - - /** - * Stops the managed object. - * - * @return A completable future to be completed once the object has been stopped. - */ - CompletableFuture stop(); - -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/NamedType.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/NamedType.java deleted file mode 100644 index 17b9cab749..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/NamedType.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -/** - * Named type. - */ -public interface NamedType extends Named, Type { -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/ServiceException.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/ServiceException.java deleted file mode 100644 index 6d37087054..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/ServiceException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -/** - * Service exception. - */ -public class ServiceException extends AtomixRuntimeException { - public ServiceException() { - } - - public ServiceException(String message) { - super(message); - } - - public ServiceException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/Type.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/Type.java deleted file mode 100644 index e6462201d6..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/Type.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -/** - * Identifier interface for types. - */ -public interface Type { - - /** - * Returns the type name. - * - * @return the type name - */ - String name(); - -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/Version.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/Version.java deleted file mode 100644 index 914ed0b597..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/Version.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -import com.google.common.collect.ComparisonChain; - -import java.util.Objects; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.lang.Integer.parseInt; - -/** - * Atomix software version. - */ -public final class Version implements Comparable { - - /** - * Returns a new version from the given version string. - * - * @param version the version string - * @return the version object - * @throws IllegalArgumentException if the version string is invalid - */ - public static Version from(String version) { - String[] fields = version.split("[.-]", 4); - checkArgument(fields.length >= 3, "version number is invalid"); - return new Version( - parseInt(fields[0]), - parseInt(fields[1]), - parseInt(fields[2]), - fields.length == 4 ? fields[3] : null); - } - - /** - * Returns a new version from the given parts. - * - * @param major the major version number - * @param minor the minor version number - * @param patch the patch version number - * @param build the build version number - * @return the version object - */ - public static Version from(int major, int minor, int patch, String build) { - return new Version(major, minor, patch, build); - } - - private final int major; - private final int minor; - private final int patch; - private final String build; - - private Version(int major, int minor, int patch, String build) { - checkArgument(major >= 0, "major version must be >= 0"); - checkArgument(minor >= 0, "minor version must be >= 0"); - checkArgument(patch >= 0, "patch version must be >= 0"); - this.major = major; - this.minor = minor; - this.patch = patch; - this.build = Build.from(build).toString(); - } - - /** - * Returns the major version number. - * - * @return the major version number - */ - public int major() { - return major; - } - - /** - * Returns the minor version number. - * - * @return the minor version number - */ - public int minor() { - return minor; - } - - /** - * Returns the patch version number. - * - * @return the patch version number - */ - public int patch() { - return patch; - } - - /** - * Returns the build version number. - * - * @return the build version number - */ - public String build() { - return build; - } - - @Override - public int compareTo(Version that) { - return ComparisonChain.start() - .compare(this.major, that.major) - .compare(this.minor, that.minor) - .compare(this.patch, that.patch) - .compare(Build.from(this.build), Build.from(that.build)) - .result(); - } - - @Override - public int hashCode() { - return Objects.hash(major, minor, patch, build); - } - - @Override - public boolean equals(Object object) { - if (object == this) { - return true; - } - if (!(object instanceof Version)) { - return false; - } - Version that = (Version) object; - return this.major == that.major - && this.minor == that.minor - && this.patch == that.patch - && Objects.equals(this.build, that.build); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder() - .append(major) - .append('.') - .append(minor) - .append('.') - .append(patch); - String build = Build.from(this.build).toString(); - if (build != null) { - builder.append('-').append(build); - } - return builder.toString(); - } - - /** - * Build version. - */ - private static class Build implements Comparable { - - /** - * Creates a new build version from the given string. - * - * @param build the build version string - * @return the build version - * @throws IllegalArgumentException if the build version string is invalid - */ - public static Build from(String build) { - if (build == null) { - return new Build(Type.FINAL, 0); - } else if (build.equalsIgnoreCase(Type.SNAPSHOT.name())) { - return new Build(Type.SNAPSHOT, 0); - } - - for (Type type : Type.values()) { - if (type.name != null && build.length() >= type.name.length() && build.substring(0, type.name.length()).equalsIgnoreCase(type.name)) { - try { - int version = parseInt(build.substring(type.name.length())); - return new Build(type, version); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(build + " is not a valid build version string"); - } - } - } - throw new IllegalArgumentException(build + " is not a valid build version string"); - } - - private final Type type; - private final int version; - - private Build(Type type, int version) { - this.type = type; - this.version = version; - } - - @Override - public int compareTo(Build that) { - return ComparisonChain.start() - .compare(this.type.ordinal(), that.type.ordinal()) - .compare(this.version, that.version) - .result(); - } - - @Override - public int hashCode() { - return Objects.hash(type, version); - } - - @Override - public boolean equals(Object object) { - if (object == this) { - return true; - } - if (!(object instanceof Build)) { - return false; - } - Build that = (Build) object; - return Objects.equals(this.type, that.type) && this.version == that.version; - } - - @Override - public String toString() { - return type.format(version); - } - - /** - * Build type. - */ - private enum Type { - SNAPSHOT("snapshot"), - ALPHA("alpha"), - BETA("beta"), - RC("rc"), - FINAL(null); - - private final String name; - - Type(String name) { - this.name = name; - } - - String format(int version) { - if (name == null) { - return null; - } else if ("snapshot".equals(name)) { - return "SNAPSHOT"; - } else { - return String.format("%s%d", name, version); - } - } - - @Override - public String toString() { - return name; - } - } - } -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/serializer/Namespaces.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/serializer/Namespaces.java index a86af2b8b8..f2daecd235 100644 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/serializer/Namespaces.java +++ b/third-party/atomix/utils/src/main/java/io/atomix/utils/serializer/Namespaces.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Multisets; import com.google.common.collect.Sets; -import io.atomix.utils.Version; import io.atomix.utils.serializer.serializers.ArraysAsListSerializer; import io.atomix.utils.serializer.serializers.ImmutableListSerializer; import io.atomix.utils.serializer.serializers.ImmutableMapSerializer; @@ -100,7 +99,6 @@ public final class Namespaces { .register(String[].class) .register(boolean[].class) .register(Object[].class) - .register(Version.class) .build("BASIC"); /** diff --git a/third-party/atomix/utils/src/test/java/io/atomix/utils/VersionTest.java b/third-party/atomix/utils/src/test/java/io/atomix/utils/VersionTest.java deleted file mode 100644 index 5416749b97..0000000000 --- a/third-party/atomix/utils/src/test/java/io/atomix/utils/VersionTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * 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 io.atomix.utils; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Version test. - */ -public class VersionTest { - @Test - public void testVersionComparison() { - assertTrue(Version.from("1.0.0").compareTo(Version.from("2.0.0")) < 0); - assertTrue(Version.from("2.0.0").compareTo(Version.from("1.0.0")) > 0); - assertTrue(Version.from("1.0.0").compareTo(Version.from("0.1.0")) > 0); - assertTrue(Version.from("0.1.0").compareTo(Version.from("1.0.0")) < 0); - assertTrue(Version.from("0.1.0").compareTo(Version.from("0.1.1")) < 0); - assertTrue(Version.from("1.0.0").compareTo(Version.from("0.0.1")) > 0); - assertTrue(Version.from("1.1.1").compareTo(Version.from("1.0.3")) > 0); - assertTrue(Version.from("1.0.0").compareTo(Version.from("1.0.0-beta1")) > 0); - assertTrue(Version.from("1.0.0-rc2").compareTo(Version.from("1.0.0-rc1")) > 0); - assertTrue(Version.from("1.0.0-rc1").compareTo(Version.from("1.0.0-beta1")) > 0); - assertTrue(Version.from("2.0.0-beta1").compareTo(Version.from("1.0.0")) > 0); - assertTrue(Version.from("1.0.0-alpha1").compareTo(Version.from("1.0.0-SNAPSHOT")) > 0); - } - - @Test - public void testVersionToString() { - assertEquals("1.0.0", Version.from("1.0.0").toString()); - assertEquals("1.0.0-alpha1", Version.from("1.0.0-alpha1").toString()); - assertEquals("1.0.0-beta1", Version.from("1.0.0-beta1").toString()); - assertEquals("1.0.0-rc1", Version.from("1.0.0-rc1").toString()); - assertEquals("1.0.0-SNAPSHOT", Version.from("1.0.0-SNAPSHOT").toString()); - } - - @Test - public void testInvalidVersions() { - assertIllegalArgument(() -> Version.from("1")); - assertIllegalArgument(() -> Version.from("1.0")); - assertIllegalArgument(() -> Version.from("1.0-beta1")); - assertIllegalArgument(() -> Version.from("1.0.0.0")); - assertIllegalArgument(() -> Version.from("1.0.0.0-beta1")); - assertIllegalArgument(() -> Version.from("1.0.0-not1")); - assertIllegalArgument(() -> Version.from("1.0.0-alpha")); - assertIllegalArgument(() -> Version.from("1.0.0-beta")); - assertIllegalArgument(() -> Version.from("1.0.0-rc")); - } - - private void assertIllegalArgument(Runnable callback) { - try { - callback.run(); - fail(); - } catch (IllegalArgumentException e) { - } - } -}