diff --git a/CHANGELOG.md b/CHANGELOG.md index db90ee602c3..2e1e7076e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## 2.0.0 ### Backward incompatible changes #### Common -- Flow API is now used from `java.util.concurrent.Flow`, Helidon specific `Flow` class is now removed +- Removed `io.helidon.reactive.Flow`, please use `java.util.concurrent.Flow` +- Removed `io.helidon.common.CollectionsHelper`, please use factory methods of `Set`, `Map` and `List` +- Removed `io.helidon.common.OptionalHelper`, please use methods of `java.util.Optional` +- Removed `io.helidon.common.StackWalker`, please use `java.lang.StackWalker` +- Removed `io.helidon.common.InputStreamHelper`, please use `java.io.InputStream` methods + #### Tracing - We have upgraded to OpenTracing version 0.33.0 that is not backward compatible, the following breaking changes exist (these are OpenTracing changes, not Helidon changes): diff --git a/archetypes/mp/src/main/resources/archetype-resources/src/main/java/__applicationName__.java.vm b/archetypes/mp/src/main/resources/archetype-resources/src/main/java/__applicationName__.java.vm index 6af161f1a0b..f07465fa2d2 100644 --- a/archetypes/mp/src/main/resources/archetype-resources/src/main/java/__applicationName__.java.vm +++ b/archetypes/mp/src/main/resources/archetype-resources/src/main/java/__applicationName__.java.vm @@ -6,8 +6,6 @@ import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; -import io.helidon.common.CollectionsHelper; - /** * Simple JAXRS Application that registers one resource class. */ @@ -17,6 +15,6 @@ public class ${applicationName} extends Application { @Override public Set> getClasses() { - return CollectionsHelper.setOf(${restResourceName}.class); + return Set.of(${restResourceName}.class); } } diff --git a/common/common/src/main/java/io/helidon/common/CollectionsHelper.java b/common/common/src/main/java/io/helidon/common/CollectionsHelper.java deleted file mode 100644 index 1b70fb2f4ec..00000000000 --- a/common/common/src/main/java/io/helidon/common/CollectionsHelper.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. - * - * 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.helidon.common; - -import java.util.AbstractMap; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * A set of static methods similar to Java9's List.of(), Set.of() and Map.of(). - */ -public abstract class CollectionsHelper { - - private CollectionsHelper(){}; - - /** - * Returns an immutable list containing zero elements. - * - * @param the {@code List}'s element type - * @return an empty {@code List} - */ - public static List listOf(){ - return Collections.emptyList(); - } - - /** - * Returns an unmodifiable list containing the given elements. - * - * @param the {@code List}'s element type - * @param elts the elements - * @return a {@code List} containing the specified elements - * - */ - @SafeVarargs - public static List listOf(T... elts){ - List list = Arrays.asList(elts); - return Collections.unmodifiableList(list); - } - - /** - * Returns an immutable set containing zero elements. - * - * @param the {@code Set}'s element type - * @return an empty {@code Set} - */ - public static Set setOf(){ - return Collections.emptySet(); - } - - /** - * Create an unmodifiable set containing the given elements. - * - * @param the {@code Set}'s element type - * @param elts elements to add - * @return a {@code Set} containing the specified elements - */ - @SafeVarargs - public static Set setOf(T... elts){ - Set set = new HashSet<>(); - set.addAll(Arrays.asList(elts)); - return Collections.unmodifiableSet(set); - } - - /** - * Returns an {@link java.util.Map.Entry} containing the given key and value. - * - * @param the key's type - * @param the value's type - * @param k key - * @param v value - * @return an {@code Entry} containing the specified key and value - */ - public static Map.Entry mapEntry(K k, V v){ - return new AbstractMap.SimpleEntry<>(k, v); - } - - /** - * Returns an immutable map containing zero mappings. - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @return an empty {@code Map} - */ - public static Map mapOf(){ - return Collections.emptyMap(); - } - - /** - * Create an unmodifiable map containing a single mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 key - * @param v1 value - * @return a {@code Map} containing the specified mappings - */ - public static Map mapOf(K k1, V v1){ - Map map = new HashMap<>(); - map.put(k1, v1); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 2 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @return a {@code Map} containing the specified mappings - */ - public static Map mapOf(K k1, V v1, K k2, V v2){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 3 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @param k3 third key - * @param v3 third value - * @return a {@code Map} containing the specified mappings - */ - public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - map.put(k3, v3); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 4 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @param k3 third key - * @param v3 third value - * @param k4 fourth key - * @param v4 fourth value - * @return a {@code Map} containing the specified mappings - */ - @SuppressWarnings("checkstyle:ParameterNumber") - public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - map.put(k3, v3); - map.put(k4, v4); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 5 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @param k3 third key - * @param v3 third value - * @param k4 fourth key - * @param v4 fourth value - * @param k5 fifth key - * @param v5 fifth value - * @return a {@code Map} containing the specified mappings - */ - @SuppressWarnings("checkstyle:ParameterNumber") - public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - map.put(k3, v3); - map.put(k4, v4); - map.put(k5, v5); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 5 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @param k3 third key - * @param v3 third value - * @param k4 fourth key - * @param v4 fourth value - * @param k5 fifth key - * @param v5 fifth value - * @param k6 sixth key - * @param v6 sixth value - * @return a {@code Map} containing the specified mappings - */ - @SuppressWarnings("checkstyle:ParameterNumber") - public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - map.put(k3, v3); - map.put(k4, v4); - map.put(k5, v5); - map.put(k6, v6); - return Collections.unmodifiableMap(map); - } - - /** - * Create an unmodifiable map containing 5 mappings. - * - * @param the {@code Map}'s key type - * @param the {@code Map}'s value type - * @param k1 first key - * @param v1 first value - * @param k2 second key - * @param v2 second value - * @param k3 third key - * @param v3 third value - * @param k4 fourth key - * @param v4 fourth value - * @param k5 fifth key - * @param v5 fifth value - * @param k6 sixth key - * @param v6 sixth value - * @param k7 seventh key - * @param v7 seventh value - * @return a {@code Map} containing the specified mappings - */ - @SuppressWarnings("checkstyle:ParameterNumber") - public static Map mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7){ - Map map = new HashMap<>(); - map.put(k1, v1); - map.put(k2, v2); - map.put(k3, v3); - map.put(k4, v4); - map.put(k5, v5); - map.put(k6, v6); - map.put(k7, v7); - return Collections.unmodifiableMap(map); - } -} diff --git a/common/common/src/main/java/io/helidon/common/Errors.java b/common/common/src/main/java/io/helidon/common/Errors.java index ec6218d56df..88c911e9efa 100644 --- a/common/common/src/main/java/io/helidon/common/Errors.java +++ b/common/common/src/main/java/io/helidon/common/Errors.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ @SuppressWarnings("WeakerAccess") public final class Errors extends LinkedList { private static final Set WALKER_OPTIONS = - CollectionsHelper.setOf(StackWalker.Option.RETAIN_CLASS_REFERENCE); + Set.of(StackWalker.Option.RETAIN_CLASS_REFERENCE); private final boolean hasFatal; private final boolean hasWarning; diff --git a/common/common/src/main/java/io/helidon/common/InputStreamHelper.java b/common/common/src/main/java/io/helidon/common/InputStreamHelper.java deleted file mode 100644 index 1cfc776e4c5..00000000000 --- a/common/common/src/main/java/io/helidon/common/InputStreamHelper.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. - * - * 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.helidon.common; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -/** - * A set of static utility methods for {@code InputStream}. - */ -public abstract class InputStreamHelper { - - private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; - private static final int DEFAULT_BUFFER_SIZE = 8192; - - private InputStreamHelper(){} - - /** - * Reads all remaining bytes from the input stream.This method blocks until - * all remaining bytes have been read and end of stream is detected, or an - * exception is thrown. - * @param is the {@code InputStream} to use - * @return a byte array containing the bytes read from this input stream - * @throws IOException if an I/O error occurs - * @throws OutOfMemoryError if an array of the required size cannot be - * allocated. For example, if an array larger than {@code 2GB} would - * be required to store the bytes. - */ - public static byte[] readAllBytes(InputStream is) throws IOException { - byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; - int capacity = buf.length; - int nread = 0; - int n; - for (;;) { - // read to EOF which may read more or less than initial buffer size - while ((n = is.read(buf, nread, capacity - nread)) > 0){ - nread += n; - } - - // if the last call to read returned -1, then we're done - if (n < 0){ - break; - } - - // need to allocate a larger buffer - if (capacity <= MAX_BUFFER_SIZE - capacity) { - capacity = capacity << 1; - } else { - if (capacity == MAX_BUFFER_SIZE){ - throw new OutOfMemoryError("Required array size too large"); - } - capacity = MAX_BUFFER_SIZE; - } - buf = Arrays.copyOf(buf, capacity); - } - return (capacity == nread) ? buf : Arrays.copyOf(buf, nread); - } -} diff --git a/common/common/src/main/java/io/helidon/common/OptionalHelper.java b/common/common/src/main/java/io/helidon/common/OptionalHelper.java deleted file mode 100644 index 4da36d9c73a..00000000000 --- a/common/common/src/main/java/io/helidon/common/OptionalHelper.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. - * - * 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.helidon.common; - -import java.util.Objects; -import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.stream.Stream; - -/** - * A wrapper on top of {@code Optional} to replicate some of the new Java9 - * methods. - * @param the type of the underlying optional value - */ -public class OptionalHelper { - - private Optional optional; - - private OptionalHelper(Optional optional){ - Objects.requireNonNull(optional); - this.optional = optional; - } - - /** - * Static factory method to create a new {@code OptionalHelper} instance. - * @param the type of the underly optional value - * @param optional the optional to wrap - * @return the created {@code OptionalHelper} instance - */ - public static OptionalHelper from(Optional optional){ - return new OptionalHelper<>(optional); - } - - /** - * Get the underlying {@code Optional} instance. - * @return the wrapped {@code Optional} - */ - public Optional asOptional(){ - return optional; - } - - /** - * If the underlying {@code Optional} does not have a value, set it to the - * {@code Optional} produced by the supplying function. - * - * @param supplier the supplying function that produces an {@code Optional} - * @return returns this instance of {@code OptionalHelper} with the same - * the underlying {@code Optional} if a value is present, otherwise - * with the {@code Optional} produced by the supplying function. - * @throws NullPointerException if the supplying function is {@code null} or - * produces a {@code null} result - */ - public OptionalHelper or(Supplier> supplier){ - Objects.requireNonNull(supplier); - if (!optional.isPresent()) { - Optional supplied = supplier.get(); - Objects.requireNonNull(supplied); - optional = supplied; - } - return this; - } - - /** - * If a value is present, performs the given action with the value, - * otherwise performs the given empty-based action. - * - * @param action the action to be performed, if a value is present - * @param emptyAction the empty-based action to be performed, if no value is - * present - * @throws NullPointerException if a value is present and the given action - * is {@code null}, or no value is present and the given empty-based - * action is {@code null}. - */ - public void ifPresentOrElse(Consumer action, Runnable emptyAction) { - if (optional.isPresent()) { - action.accept(optional.get()); - } else { - emptyAction.run(); - } - } - - /** - * If a value is present, returns a sequential {@link Stream} containing - * only that value, otherwise returns an empty {@code Stream}. - * - * @return the optional value as a {@code Stream} - */ - public Stream stream(){ - if (!optional.isPresent()) { - return Stream.empty(); - } else { - return Stream.of(optional.get()); - } - } -} diff --git a/common/common/src/main/java/io/helidon/common/StackWalker.java b/common/common/src/main/java/io/helidon/common/StackWalker.java deleted file mode 100644 index 36cfc31cd02..00000000000 --- a/common/common/src/main/java/io/helidon/common/StackWalker.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. - * - * 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.helidon.common; - -import java.util.Arrays; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Stream; - -/** - * A dummy replicate of Java9's StackWalker. - */ -public final class StackWalker { - private static final StackWalker INSTANCE = new StackWalker(); - - static { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("getStackWalker")); - } - } - - /** - * Returns a {@code StackWalker} instance with default options. - * - * @return a {@code StackWalker} configured with the default options - */ - public static StackWalker getInstance() { - return INSTANCE; - } - - /** - * Returns a {@code StackWalker} instance with the given {@code option} specifying - * the stack frame information it can access. - * - * @param option ignored (used by java9 forward) - * @return a {@code StackWalker} configured with the given options - */ - public static StackWalker getInstance(Option option) { - // ignore options - return INSTANCE; - } - - /** - * Returns a {@code StackWalker} instance with the given {@code options} specifying - * the stack frame information it can access. - * - * @param options ignored (used by java9 forward) - * @return a {@code StackWalker} configured with the given options - */ - public static StackWalker getInstance(Set