Skip to content
Permalink
Browse files

Add `servicetalk-utils-internal` module (#862)

__Motivation__

We need a internal module to share `MathUtil` class between
other internal modules.

__Modifications__

- Add `servicetalk-utils-internal` module with `MathUtil` class;

__Result__

Resolves #189: Consolidate duplicate MathUtil.
  • Loading branch information
heowc authored and idelpivnitskiy committed Nov 13, 2019
1 parent 1e687e6 commit 183c5efd1c671dabb8a8f2644e9edbec451afa42
@@ -28,6 +28,7 @@ dependencies {
implementation project(":servicetalk-client-api-internal")
implementation project(":servicetalk-concurrent-internal")
implementation project(":servicetalk-concurrent-api-internal")
implementation project(":servicetalk-utils-internal")
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
implementation "org.slf4j:slf4j-api:$slf4jVersion"

This file was deleted.

@@ -27,7 +27,7 @@
import javax.annotation.Nullable;

import static io.servicetalk.http.api.HeaderUtils.HASH_CODE_SEED;
import static io.servicetalk.http.api.MathUtil.findNextPositivePowerOfTwo;
import static io.servicetalk.utils.internal.MathUtil.findNextPositivePowerOfTwo;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Collections.emptyIterator;
@@ -21,6 +21,7 @@ dependencies {

implementation project(":servicetalk-annotations")
implementation project(":servicetalk-opentracing-internal")
implementation project(":servicetalk-utils-internal")
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
implementation "org.slf4j:slf4j-api:$slf4jVersion"
}
@@ -18,7 +18,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;

import static io.servicetalk.opentracing.internal.MathUtil.safeFindNextPositivePowerOfTwo;
import static io.servicetalk.utils.internal.MathUtil.safeFindNextPositivePowerOfTwo;

/**
* Utility methods for sampling strategies.
@@ -0,0 +1,22 @@
/*
* Copyright © 2018-2019 Apple Inc. and the ServiceTalk project authors
*
* 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.
*/

apply plugin: "io.servicetalk.servicetalk-gradle-plugin-internal-library"

dependencies {
implementation project(":servicetalk-annotations")
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
}
@@ -1,5 +1,5 @@
/*
* Copyright © 2018 Apple Inc. and the ServiceTalk project authors
* Copyright © 2018-2019 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.servicetalk.opentracing.internal;
package io.servicetalk.utils.internal;

/**
* Internal math utilities.
@@ -31,7 +31,7 @@ private MathUtil() {
* @param value from which to search for next power of 2
* @return The next power of 2 or the value itself if it is a power of 2
*/
private static int findNextPositivePowerOfTwo(final int value) {
public static int findNextPositivePowerOfTwo(final int value) {
assert value > Integer.MIN_VALUE && value < 0x40000000;
return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
@@ -0,0 +1,19 @@
/*
* Copyright © 2019 Apple Inc. and the ServiceTalk project authors
*
* 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.
*/
@ElementsAreNonnullByDefault
package io.servicetalk.utils.internal;

import io.servicetalk.annotations.ElementsAreNonnullByDefault;
@@ -71,7 +71,8 @@ include "servicetalk-annotations",
"servicetalk-test-resources",
"servicetalk-transport-api",
"servicetalk-transport-netty",
"servicetalk-transport-netty-internal"
"servicetalk-transport-netty-internal",
"servicetalk-utils-internal"

project(":servicetalk-examples:grpc:helloworld").name = "servicetalk-examples-grpc-helloworld"
project(":servicetalk-examples:grpc:routeguide").name = "servicetalk-examples-grpc-routeguide"

0 comments on commit 183c5ef

Please sign in to comment.
You can’t perform that action at this time.