You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by zm...@apache.org on 2015/08/26 23:00:36 UTC
[46/51] [partial] aurora git commit: Move packages from
com.twitter.common to org.apache.aurora.common
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/LongParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/LongParser.java b/commons/src/main/java/com/twitter/common/args/parsers/LongParser.java
deleted file mode 100644
index 2355911..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/LongParser.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * Long parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class LongParser extends NumberParser<Long> {
- @Override
- Long parseNumber(String raw) {
- return Long.parseLong(raw);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/MapParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/MapParser.java b/commons/src/main/java/com/twitter/common/args/parsers/MapParser.java
deleted file mode 100644
index efd4846..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/MapParser.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.reflect.TypeToken;
-
-import com.twitter.common.args.ArgParser;
-import com.twitter.common.args.Parser;
-import com.twitter.common.args.ParserOracle;
-import com.twitter.common.args.Parsers;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Map parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class MapParser extends TypeParameterizedParser<Map<?, ?>> {
-
- private static final Splitter KEY_VALUE_SPLITTER =
- Splitter.on("=").trimResults().omitEmptyStrings();
-
- public MapParser() {
- super(2);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- Map<?, ?> doParse(ParserOracle parserOracle, String raw, List<Type> typeParams) {
- Type keyType = typeParams.get(0);
- Parser<?> keyParser = parserOracle.get(TypeToken.of(keyType));
-
- Type valueType = typeParams.get(1);
- Parser<?> valueParser = parserOracle.get(TypeToken.of(valueType));
-
- ImmutableMap.Builder<Object, Object> map = ImmutableMap.builder();
- for (String keyAndValue : Parsers.MULTI_VALUE_SPLITTER.split(raw)) {
- List<String> fields = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyAndValue));
- checkArgument(fields.size() == 2,
- "Failed to parse key/value pair " + keyAndValue);
-
- map.put(keyParser.parse(parserOracle, keyType, fields.get(0)),
- valueParser.parse(parserOracle, valueType, fields.get(1)));
- }
-
- return map.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/NonParameterizedTypeParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/NonParameterizedTypeParser.java b/commons/src/main/java/com/twitter/common/args/parsers/NonParameterizedTypeParser.java
deleted file mode 100644
index eee04ad..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/NonParameterizedTypeParser.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.lang.reflect.Type;
-
-import com.twitter.common.args.Parser;
-import com.twitter.common.args.ParserOracle;
-
-/**
- * Base class for parsers of types that are not parameterized.
- *
- * @author William Farner
- */
-public abstract class NonParameterizedTypeParser<T> implements Parser<T> {
-
- /**
- * Performs the parsing of the raw string.
- *
- * @param raw Value to parse.
- * @return The parsed value.
- * @throws IllegalArgumentException If the value could not be parsed into the target type.
- */
- public abstract T doParse(String raw) throws IllegalArgumentException;
-
- @Override
- public T parse(ParserOracle parserOracle, Type type, String raw) throws IllegalArgumentException {
- return doParse(raw);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/NumberParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/NumberParser.java b/commons/src/main/java/com/twitter/common/args/parsers/NumberParser.java
deleted file mode 100644
index 181eb9c..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/NumberParser.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-/**
- * Parser that handles common functionality for parsing numbers.
- *
- * @author William Farner
- */
-public abstract class NumberParser<T extends Number> extends NonParameterizedTypeParser<T> {
-
- /**
- * Performs the actual parsing of the value into the target type.
- *
- * @param raw Raw value to parse.
- * @return The parsed value.
- * @throws NumberFormatException If the raw value does not represent a valid number of the target
- * type.
- */
- abstract T parseNumber(String raw) throws NumberFormatException;
-
- @Override
- public T doParse(String raw) throws IllegalArgumentException {
- try {
- return parseNumber(raw);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException(String.format("Invalid value: " + e.getMessage()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/PairParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/PairParser.java b/commons/src/main/java/com/twitter/common/args/parsers/PairParser.java
deleted file mode 100644
index 2c43c5c..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/PairParser.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.lang.reflect.Type;
-import java.util.List;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.TypeToken;
-
-import com.twitter.common.args.ArgParser;
-import com.twitter.common.args.Parser;
-import com.twitter.common.args.ParserOracle;
-import com.twitter.common.args.Parsers;
-import com.twitter.common.collections.Pair;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Pair parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class PairParser extends TypeParameterizedParser<Pair<?, ?>> {
-
- public PairParser() {
- super(2);
- }
-
- @Override
- Pair<?, ?> doParse(ParserOracle parserOracle, String raw, List<Type> typeParams) {
- Type leftType = typeParams.get(0);
- Parser<?> leftParser = parserOracle.get(TypeToken.of(leftType));
-
- Type rightType = typeParams.get(1);
- Parser<?> rightParser = parserOracle.get(TypeToken.of(rightType));
-
- List<String> parts = ImmutableList.copyOf(Parsers.MULTI_VALUE_SPLITTER.split(raw));
- checkArgument(parts.size() == 2,
- "Only two values may be specified for a pair, you gave " + parts.size());
-
- return Pair.of(leftParser.parse(parserOracle, leftType, parts.get(0)),
- rightParser.parse(parserOracle, rightType, parts.get(1)));
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/PatternParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/PatternParser.java b/commons/src/main/java/com/twitter/common/args/parsers/PatternParser.java
deleted file mode 100644
index afa2f17..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/PatternParser.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * A regular expression parser.
- */
-@ArgParser
-public class PatternParser extends NonParameterizedTypeParser<Pattern> {
-
- @Override
- public Pattern doParse(String raw) throws IllegalArgumentException {
- try {
- return Pattern.compile(raw);
- } catch (PatternSyntaxException e) {
- throw new IllegalArgumentException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/RangeParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/RangeParser.java b/commons/src/main/java/com/twitter/common/args/parsers/RangeParser.java
deleted file mode 100644
index b2a5947..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/RangeParser.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Range;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * A parser that handles closed ranges. For the input "4-6", it will capture [4, 5, 6].
- */
-@ArgParser
-public class RangeParser extends NonParameterizedTypeParser<Range<Integer>> {
- @Override
- public Range<Integer> doParse(String raw) throws IllegalArgumentException {
- ImmutableList<String> numbers =
- ImmutableList.copyOf(Splitter.on('-').omitEmptyStrings().split(raw));
- try {
- int from = Integer.parseInt(numbers.get(0));
- int to = Integer.parseInt(numbers.get(1));
- if (numbers.size() != 2) {
- throw new IllegalArgumentException("Failed to parse the range:" + raw);
- }
- if (to < from) {
- return Range.closed(to, from);
- } else {
- return Range.closed(from, to);
- }
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Failed to parse the range:" + raw, e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/SetParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/SetParser.java b/commons/src/main/java/com/twitter/common/args/parsers/SetParser.java
deleted file mode 100644
index f05e0fe..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/SetParser.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Set;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.reflect.TypeToken;
-
-import com.twitter.common.args.ArgParser;
-import com.twitter.common.args.Parser;
-import com.twitter.common.args.ParserOracle;
-import com.twitter.common.args.Parsers;
-
-/**
- * Set parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class SetParser extends TypeParameterizedParser<Set<?>> {
-
- public SetParser() {
- super(1);
- }
-
- @Override
- Set<?> doParse(final ParserOracle parserOracle, String raw, List<Type> typeParams) {
- final Type setType = typeParams.get(0);
- final Parser<?> parser = parserOracle.get(TypeToken.of(setType));
-
- return ImmutableSet.copyOf(Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw),
- new Function<String, Object>() {
- @Override public Object apply(String raw) {
- return parser.parse(parserOracle, setType, raw);
- }
- }));
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/ShortParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/ShortParser.java b/commons/src/main/java/com/twitter/common/args/parsers/ShortParser.java
deleted file mode 100644
index 776ead4..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/ShortParser.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * Short parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class ShortParser extends NumberParser<Short> {
- @Override
- Short parseNumber(String raw) {
- return Short.parseShort(raw);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/StringParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/StringParser.java b/commons/src/main/java/com/twitter/common/args/parsers/StringParser.java
deleted file mode 100644
index 7fa4308..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/StringParser.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * String parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class StringParser extends NonParameterizedTypeParser<String> {
- @Override
- public String doParse(String raw) {
- return raw;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/TypeParameterizedParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/TypeParameterizedParser.java b/commons/src/main/java/com/twitter/common/args/parsers/TypeParameterizedParser.java
deleted file mode 100644
index 2124e38..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/TypeParameterizedParser.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.lang.reflect.Type;
-import java.util.List;
-
-import com.twitter.common.args.Parser;
-import com.twitter.common.args.ParserOracle;
-import com.twitter.common.args.TypeUtil;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Parser that makes implementation of parsers for parameterized types simpler.
- *
- * @param <T> The raw type this parser can parse.
- *
- * @author William Farner
- */
-public abstract class TypeParameterizedParser<T> implements Parser<T> {
-
- private final int typeParamCount;
-
- /**
- * Creates a new type parameterized parser.
- *
- * @param typeParamCount Strict number of type parameters to allow on the assigned type.
- */
- TypeParameterizedParser(int typeParamCount) {
- this.typeParamCount = typeParamCount;
- }
-
- /**
- * Performs the actual parsing.
- *
- * @param parserOracle The registered parserOracle for delegation.
- * @param raw The raw value to parse.
- * @param typeParams The captured actual type parameters for {@code T}.
- * @return The parsed value.
- * @throws IllegalArgumentException If the value could not be parsed.
- */
- abstract T doParse(ParserOracle parserOracle, String raw, List<Type> typeParams)
- throws IllegalArgumentException;
-
- @Override public T parse(ParserOracle parserOracle, Type type, String raw) {
- List<Type> typeParams = TypeUtil.getTypeParams(type);
- checkArgument(typeParams.size() == typeParamCount, String.format(
- "Expected %d type parameters for %s but got %d",
- typeParamCount, type, typeParams.size()));
-
- return doParse(parserOracle, raw, typeParams);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/URIParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/URIParser.java b/commons/src/main/java/com/twitter/common/args/parsers/URIParser.java
deleted file mode 100644
index 8828520..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/URIParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * URI parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class URIParser extends NonParameterizedTypeParser<URI> {
- @Override
- public URI doParse(String raw) {
- try {
- return new URI(raw);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Malformed URI " + raw + ", " + e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/URLParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/URLParser.java b/commons/src/main/java/com/twitter/common/args/parsers/URLParser.java
deleted file mode 100644
index 5df8413..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/URLParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import com.twitter.common.args.ArgParser;
-
-/**
- * URL parser.
- *
- * @author William Farner
- */
-@ArgParser
-public class URLParser extends NonParameterizedTypeParser<URL> {
- @Override
- public URL doParse(String raw) {
- try {
- return new URL(raw);
- } catch (MalformedURLException e) {
- throw new IllegalArgumentException("Malformed URL " + raw + ", " + e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/args/parsers/UnitParser.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/args/parsers/UnitParser.java b/commons/src/main/java/com/twitter/common/args/parsers/UnitParser.java
deleted file mode 100644
index aedfc05..0000000
--- a/commons/src/main/java/com/twitter/common/args/parsers/UnitParser.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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 com.twitter.common.args.parsers;
-
-import java.util.EnumSet;
-import java.util.Map;
-
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-
-import com.twitter.common.args.ArgParser;
-import com.twitter.common.quantity.Data;
-import com.twitter.common.quantity.Time;
-import com.twitter.common.quantity.Unit;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Unit parser.
- * Units are matched (case sensitively) against the result of {@link Unit#toString()}.
- */
-@ArgParser
-public class UnitParser extends NonParameterizedTypeParser<Unit<?>> {
-
- private final Map<String, Unit<?>> unitValues;
-
- public UnitParser() {
- unitValues = Maps.uniqueIndex(
- ImmutableList.<Unit<?>>builder().add(Time.values()).add(Data.values()).build(),
- Functions.toStringFunction());
- }
-
- @Override
- public Unit<?> doParse(String raw) {
- Unit<?> unit = unitValues.get(raw);
-
- checkArgument(unit != null, String.format(
- "No Units found matching %s, options: (Time): %s, (Data): %s",
- raw, EnumSet.allOf(Time.class), EnumSet.allOf(Data.class)));
- return unit;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/CachingSupplier.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/CachingSupplier.java b/commons/src/main/java/com/twitter/common/base/CachingSupplier.java
deleted file mode 100644
index d29be7b..0000000
--- a/commons/src/main/java/com/twitter/common/base/CachingSupplier.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-
-import com.twitter.common.quantity.Amount;
-import com.twitter.common.quantity.Time;
-import com.twitter.common.util.Clock;
-
-/**
- * A supplier that caches responses from an underling supplier, expiring the cached value after
- * a fixed expiration time.
- *
- * @param <T> Supplied value type.
- *
- * @author William Farner
- */
-public class CachingSupplier<T> implements Supplier<T> {
-
- private final Supplier<T> wrapped;
- private final long expirationNanos;
- private final Clock clock;
-
- private long lastFetchNanos = -1;
- private T cachedValue;
-
- /**
- * Creates a new caching supplier.
- *
- * @param wrapped The supplier to delegate fetches to.
- * @param expiration The maximum amount of time that a response from {@code supplier} will be
- * cached for. The expiration must be positive.
- */
- public CachingSupplier(Supplier<T> wrapped, Amount<Long, Time> expiration) {
- this(wrapped, expiration, Clock.SYSTEM_CLOCK);
- }
-
- @VisibleForTesting
- CachingSupplier(Supplier<T> wrapped, Amount<Long, Time> expiration, Clock clock) {
- this.wrapped = Preconditions.checkNotNull(wrapped);
- this.expirationNanos = Preconditions.checkNotNull(expiration).as(Time.NANOSECONDS);
- Preconditions.checkArgument(expiration.getValue() > 0, "Expiration must be positive.");
- this.clock = Preconditions.checkNotNull(clock);
- }
-
- @Override
- public synchronized T get() {
- if ((lastFetchNanos == -1) || (clock.nowNanos() - lastFetchNanos > expirationNanos)) {
- cachedValue = wrapped.get();
- lastFetchNanos = clock.nowNanos();
- }
-
- return cachedValue;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/CallableExceptionalSupplier.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/CallableExceptionalSupplier.java b/commons/src/main/java/com/twitter/common/base/CallableExceptionalSupplier.java
deleted file mode 100644
index 6279499..0000000
--- a/commons/src/main/java/com/twitter/common/base/CallableExceptionalSupplier.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import java.util.concurrent.Callable;
-
-/**
- * A supplier that may also be called.
- *
- * @param <T> The supplier type.
- * @param <E> Supplier exception type.
- *
- * @author John Sirois
- */
-public abstract class CallableExceptionalSupplier<T, E extends Exception>
- implements ExceptionalSupplier<T, E>, Callable<T> {
-
- @Override public T call() throws Exception {
- return get();
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Closure.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Closure.java b/commons/src/main/java/com/twitter/common/base/Closure.java
deleted file mode 100644
index f58868f..0000000
--- a/commons/src/main/java/com/twitter/common/base/Closure.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * A closure that does not throw any checked exceptions.
- *
- * @param <T> Closure value type.
- *
- * @author John Sirois
- */
-public interface Closure<T> extends ExceptionalClosure<T, RuntimeException> {
- // convenience typedef
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Closures.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Closures.java b/commons/src/main/java/com/twitter/common/base/Closures.java
deleted file mode 100644
index 1ce360f..0000000
--- a/commons/src/main/java/com/twitter/common/base/Closures.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Utilities for dealing with Closures.
- *
- * @author John Sirois
- */
-public final class Closures {
-
- private static final Closure<?> NOOP = new Closure<Object>() {
- @Override public void execute(Object item) {
- // noop
- }
- };
-
- private Closures() {
- // utility
- }
-
- /**
- * Converts a closure into a function returning {@code null}.
- */
- public static <T> Function<T, Void> asFunction(final ExceptionalClosure<T, ?> closure) {
- checkNotNull(closure);
-
- // CHECKSTYLE:OFF IllegalCatch
- return new Function<T, Void>() {
- @Override public Void apply(T item) {
- try {
- closure.execute(item);
- } catch (Exception e) {
- Throwables.propagate(e);
- }
- return null;
- }
- };
- // CHECKSTYLE:ON IllegalCatch
- }
-
- /**
- * Varargs equivalent of {@link #combine(Iterable)}.
- *
- * @param closures Closures to combine.
- * @param <T> Type accepted by the closures.
- * @return A single closure that will fan out all calls to {@link Closure#execute(Object)} to
- * the wrapped closures.
- */
- public static <T> Closure<T> combine(Closure<T>... closures) {
- return combine(ImmutableList.copyOf(closures));
- }
-
- /**
- * Combines multiple closures into a single closure, whose calls are replicated sequentially
- * in the order that they were provided.
- * If an exception is encountered from a closure it propagates to the top-level closure and the
- * remaining closures are not executed.
- *
- * @param closures Closures to combine.
- * @param <T> Type accepted by the closures.
- * @return A single closure that will fan out all calls to {@link Closure#execute(Object)} to
- * the wrapped closures.
- */
- public static <T> Closure<T> combine(Iterable<Closure<T>> closures) {
- checkNotNull(closures);
- checkArgument(Iterables.all(closures, Predicates.notNull()));
-
- final Iterable<Closure<T>> closuresCopy = ImmutableList.copyOf(closures);
-
- return new Closure<T>() {
- @Override public void execute(T item) {
- for (Closure<T> closure : closuresCopy) {
- closure.execute(item);
- }
- }
- };
- }
-
- /**
- * Applies a filter to a closure, such that the closure will only be called when the filter is
- * satisfied (returns {@code true}}.
- *
- * @param filter Filter to determine when {@code closure} is called.
- * @param closure Closure to filter.
- * @param <T> Type handled by the filter and the closure.
- * @return A filtered closure.
- */
- public static <T> Closure<T> filter(final Predicate<T> filter, final Closure<T> closure) {
- checkNotNull(filter);
- checkNotNull(closure);
-
- return new Closure<T>() {
- @Override public void execute(T item) {
- if (filter.apply(item)) {
- closure.execute(item);
- }
- }
- };
- }
-
- /**
- * Returns a closure that will do nothing.
- *
- * @param <T> The closure argument type.
- * @return A closure that does nothing.
- */
- @SuppressWarnings("unchecked")
- public static <T> Closure<T> noop() {
- return (Closure<T>) NOOP;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Command.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Command.java b/commons/src/main/java/com/twitter/common/base/Command.java
deleted file mode 100644
index 88d0c7f..0000000
--- a/commons/src/main/java/com/twitter/common/base/Command.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * A command that does not throw any checked exceptions.
- *
- * @author John Sirois
- */
-public interface Command extends ExceptionalCommand<RuntimeException> {
- // convenience typedef
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Commands.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Commands.java b/commons/src/main/java/com/twitter/common/base/Commands.java
deleted file mode 100644
index 8f421e3..0000000
--- a/commons/src/main/java/com/twitter/common/base/Commands.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.collect.ImmutableList;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Utility functions for working with commands.
- *
- * @author John Sirois
- */
-public final class Commands {
-
- /**
- * A command that does nothing when executed.
- */
- public static final Command NOOP = new Command() {
- @Override public void execute() {
- // noop
- }
- };
-
- private Commands() {
- // utility
- }
-
- /**
- * Converts a command into a supplier returning null.
- *
- * @return A supplier whose {@link com.twitter.common.base.Supplier#get()} will cause the given
- * {@code command} to be executed and {@code null} to be returned.
- */
- public static <E extends Exception> ExceptionalSupplier<Void, E> asSupplier(
- final ExceptionalCommand<E> command) {
- checkNotNull(command);
-
- return new ExceptionalSupplier<Void, E>() {
- @Override public Void get() throws E {
- command.execute();
- return null;
- }
- };
- }
-
- /**
- * Combines multiple {@code commands} into a single command. A {@link RuntimeException} thrown
- * during the execution of one of the commands will prevent the subsequent commands from being
- * executed.
- *
- * @param commands Commands to compound.
- * @return A command whose {@link Command#execute()} will cause the given {@code commands} to be
- * executed serially.
- */
- public static Command compound(Iterable<Command> commands) {
- final ImmutableList<Command> executableCommands = ImmutableList.copyOf(commands);
- return new Command() {
- @Override public void execute() {
- for (Command command : executableCommands) {
- command.execute();
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Either.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Either.java b/commons/src/main/java/com/twitter/common/base/Either.java
deleted file mode 100644
index d254102..0000000
--- a/commons/src/main/java/com/twitter/common/base/Either.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import javax.annotation.Nullable;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * A value of one of two possible types.
- *
- * <p>Often Either processing is used as an alternative exception flow control. In these uses the
- * left type represents failure by convention and the right type the success path result.
- *
- * @param <L> The left type.
- * @param <R> The right type.
- */
-public final class Either<L, R> {
- private final Optional<L> left;
- private final Optional<R> right;
-
- private Either(Optional<L> left, Optional<R> right) {
- this.left = left;
- this.right = right;
- }
-
- /**
- * Turns a left into a right and vice-versa.
- *
- * @return A new swapped either instance.
- */
- public Either<R, L> swap() {
- return new Either<R, L>(right, left);
- }
-
- /**
- * Returns an optional the will be {@link Optional#isPresent() present} is this is a left
- * instance.
- *
- * @return An optional value for the left.
- */
- public Optional<L> left() {
- return left;
- }
-
- /**
- * Returns an optional the will be {@link Optional#isPresent() present} is this is a right
- * instance.
- *
- * @return An optional value for the right.
- */
- public Optional<R> right() {
- return right;
- }
-
- /**
- * Returns {@code true} if this is a left instance.
- *
- * @return {@code true} if this is a left.
- */
- public boolean isLeft() {
- return left().isPresent();
- }
-
- /**
- * Returns {@code true} if this is a right instance.
- *
- * @return {@code true} if this is a right.
- */
- public boolean isRight() {
- return right().isPresent();
- }
-
- /**
- * Returns the underlying value if this is a left; otherwise, throws.
- *
- * @return The underlying value.
- * @throws IllegalStateException if this is a right instance.
- */
- public L getLeft() {
- return left().get();
- }
-
- /**
- * Returns the underlying value if this is a right; otherwise, throws.
- *
- * @return The underlying value.
- * @throws IllegalStateException if this is a right instance.
- */
- public R getRight() {
- return right().get();
- }
-
- /**
- * If this is a left, maps its value into a new left; otherwise just returns this right.
- *
- * @param transformer The transformation to apply to the left value.
- * @param <M> The type a left value will be mapped to.
- * @return The mapped left or else the right.
- */
- public <M> Either<M, R> mapLeft(Function<? super L, M> transformer) {
- if (isLeft()) {
- return left(transformer.apply(getLeft()));
- } else {
- @SuppressWarnings("unchecked") // I am a right so my left is never accessible
- Either<M, R> self = (Either<M, R>) this;
- return self;
- }
- }
-
- /**
- * If this is a right, maps its value into a new right; otherwise just returns this left.
- *
- * @param transformer The transformation to apply to the left value.
- * @param <M> The type a right value will be mapped to.
- * @return The mapped right or else the left.
- */
- public <M> Either<L, M> mapRight(Function<? super R, M> transformer) {
- if (isRight()) {
- return right(transformer.apply(getRight()));
- } else {
- @SuppressWarnings("unchecked") // I am a left so my right is never accessible
- Either<L, M> self = (Either<L, M>) this;
- return self;
- }
- }
-
- /**
- * Can transform either a left or a right into a result.
- *
- * @param <L> The left type.
- * @param <R> The right type.
- * @param <T> The transformation result type.
- */
- public abstract static class Transformer<L, R, T> implements Function<Either<L, R>, T> {
-
- /**
- * Maps left values to a result.
- *
- * @param left the left value to map.
- * @return The mapped value.
- */
- public abstract T mapLeft(L left);
-
- /**
- * Maps right values to a result.
- *
- * @param right the right value to map.
- * @return The mapped value.
- */
- public abstract T mapRight(R right);
-
- @Override
- public final T apply(Either<L, R> either) {
- return either.map(this);
- }
- }
-
- /**
- * Creates a transformer from left and right transformation functions.
- *
- * @param leftTransformer A transformer to process left values.
- * @param rightTransformer A transformer to process right values.
- * @param <L> The left type.
- * @param <R> The right type.
- * @param <T> The transformation result type.
- * @return A new transformer composed of left and right transformer functions.
- */
- public static <L, R, T> Transformer<L, R, T> transformer(
- final Function<? super L, T> leftTransformer,
- final Function<? super R, T> rightTransformer) {
-
- return new Transformer<L, R, T>() {
- @Override public T mapLeft(L item) {
- return leftTransformer.apply(item);
- }
- @Override public T mapRight(R item) {
- return rightTransformer.apply(item);
- }
- };
- }
-
- /**
- * Transforms this either instance to a value regardless of whether it is a left or a right.
- *
- * @param transformer The transformer to map this either instance.
- * @param <T> The type the transformer produces.
- * @return A value mapped by the transformer from this left or right instance.
- */
- public <T> T map(final Transformer<? super L, ? super R, T> transformer) {
- if (isLeft()) {
- return transformer.mapLeft(getLeft());
- } else {
- return transformer.mapRight(getRight());
- }
- }
-
- @Override
- public boolean equals(@Nullable Object o) {
- if (!(o instanceof Either)) {
- return false;
- }
- Either<?, ?> other = (Either<?, ?>) o;
- return Objects.equal(left, other.left)
- && Objects.equal(right, other.right);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(left, right);
- }
-
- @Override
- public String toString() {
- if (isLeft()) {
- return String.format("Left(%s)", getLeft());
- } else {
- return String.format("Right(%s)", getRight());
- }
- }
-
- /**
- * Creates a left either instance.
- *
- * @param value The left value to wrap - may not be null.
- * @param <L> The left type.
- * @param <R> The right type.
- * @return A left either instance wrapping {@code value}.
- */
- public static <L, R> Either<L, R> left(L value) {
- return new Either<L, R>(Optional.of(value), Optional.<R>absent());
- }
-
- /**
- * Creates a right either instance.
- *
- * @param value The right value to wrap - may not be null.
- * @param <L> The left type.
- * @param <R> The right type.
- * @return A right either instance wrapping {@code value}.
- */
- public static <L, R> Either<L, R> right(R value) {
- return new Either<L, R>(Optional.<L>absent(), Optional.of(value));
- }
-
- /**
- * Extracts all the lefts from a sequence of eithers lazily.
- *
- * @param results A sequence of either's to process.
- * @param <L> The left type.
- * @param <R> The right type.
- * @return A lazy iterable that will produce the lefts present in results in order.
- */
- public static <L, R> Iterable<L> lefts(Iterable<Either<L, R>> results) {
- return Optional.presentInstances(Iterables.transform(results,
- new Function<Either<L, R>, Optional<L>>() {
- @Override public Optional<L> apply(Either<L, R> item) {
- return item.left();
- }
- }));
- }
-
- /**
- * Extracts all the rights from a sequence of eithers lazily.
- *
- * @param results A sequence of either's to process.
- * @param <L> The left type.
- * @param <R> The right type.
- * @return A lazy iterable that will produce the rights present in results in order.
- */
- public static <L, R> Iterable<R> rights(Iterable<Either<L, R>> results) {
- return Optional.presentInstances(Iterables.transform(results,
- new Function<Either<L, R>, Optional<R>>() {
- @Override public Optional<R> apply(Either<L, R> item) {
- return item.right();
- }
- }));
- }
-
- /**
- * A convenience method equivalent to calling {@code guard(work, exceptionType)}.
- */
- public static <X extends Exception, R> Either<X, R> guard(
- Class<X> exceptionType,
- ExceptionalSupplier<R, X> work) {
-
- @SuppressWarnings("unchecked")
- Either<X, R> either = guard(work, exceptionType);
- return either;
- }
-
- /**
- * A convenience method equivalent to calling
- * {@code guard(Lists.asList(execpetionType, rest), work)}.
- */
- public static <X extends Exception, R> Either<X, R> guard(
- ExceptionalSupplier<R, X> work,
- Class<? extends X> exceptionType,
- Class<? extends X>... rest) {
-
- return guard(Lists.asList(exceptionType, rest), work);
- }
-
- /**
- * Thrown when guarded work throws an unguarded exception. The {@link #getCause() cause} will
- * contain the original unguarded exception.
- */
- public static class UnguardedException extends RuntimeException {
- public UnguardedException(Throwable cause) {
- super(cause);
- }
- }
-
- /**
- * Converts work that can throw exceptions into an either with a left exception base type. This
- * can be useful to fold an exception throwing library call into an either processing style
- * pipeline.
- *
- * @param exceptionTypes The expected exception types.
- * @param work The work to perform to get a result produce an error.
- * @param <X> The base error type.
- * @param <R> The success type.
- * @return An either wrapping the result of performing {@code work}.
- * @throws UnguardedException if work throws an unguarded exception type.
- */
- public static <X extends Exception, R> Either<X, R> guard(
- Iterable<Class<? extends X>> exceptionTypes,
- ExceptionalSupplier<R, X> work) {
-
- try {
- return right(work.get());
- // We're explicitly dealing with generic exception types here by design.
- // SUPPRESS CHECKSTYLE RegexpSinglelineJava
- } catch (Exception e) {
- for (Class<? extends X> exceptionType : exceptionTypes) {
- if (exceptionType.isInstance(e)) {
- X exception = exceptionType.cast(e);
- return left(exception);
- }
- }
- throw new UnguardedException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionTransporter.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionTransporter.java b/commons/src/main/java/com/twitter/common/base/ExceptionTransporter.java
deleted file mode 100644
index 03baf82..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionTransporter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.base.Function;
-
-/**
- * A utility for transporting checked exceptions across boundaries that do not allow for checked
- * exception propagation.
- *
- * @param <E> The type of checked exception the ExceptionTransported can transport
- *
- * @author John Sirois
- */
-public class ExceptionTransporter<E extends Exception> {
-
- /**
- * An exception wrapper used to transport checked exceptions. Never leaves an
- * {@link ExceptionTransporter#guard(com.google.common.base.Function)} call.
- */
- private static final class TransportingException extends RuntimeException {
- private TransportingException(Exception cause) {
- super("It is a usage error to see this message!", cause);
- }
- }
-
- /**
- * Guards a unit of work that internally can generate checked exceptions. Callers wrap up the
- * work in a function that rethrows any checked exceptions using the supplied
- * ExceptionTransporter. Guard will ensure the original exception is unwrapped an re-thrown.
- *
- * @param work The unit of work that guards its checked exceptions.
- * @param <T> The type returned by the unit of work when it successfully completes.
- * @param <X> The type of checked exception that the unit of work wishes to guard.
- * @return the result of the unit of work if no excpetions are thrown
- * @throws X when the unit of work uses the ExceptionTransporter to throw a checked exception
- */
- public static <T, X extends Exception> T guard(Function<ExceptionTransporter<X>, T> work)
- throws X {
-
- try {
- return work.apply(new ExceptionTransporter<X>());
- } catch (TransportingException e) {
- @SuppressWarnings("unchecked")
- X cause = (X) e.getCause();
- throw cause;
- }
- }
-
- /**
- * Throws the given {@code checked} exception across a boundary that does not allow checked
- * exceptions. Although a RuntimeException is returned by this method signature, the method never
- * actually completes normally. The return type does allow the following usage idiom however:
- * <pre>
- * public String apply(ExceptionTransporter transporter) {
- * try {
- * return doChecked();
- * } catch (CheckedException e) {
- * // Although transport internally throws and does not return, we satisfy the compiler that
- * // our method returns a value or throws by pretending to throw the RuntimeException that
- * // never actually gets returned by transporter.transport(...)
- * throw transporter.transport(e);
- * }
- * }
- * </pre>
- *
- * @param checked The checked exception to transport.
- * @return A RuntimeException that can be thrown to satisfy the compiler at the call site
- */
- public RuntimeException transport(E checked) {
- throw new TransportingException(checked);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionalClosure.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionalClosure.java b/commons/src/main/java/com/twitter/common/base/ExceptionalClosure.java
deleted file mode 100644
index e7a8f34..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionalClosure.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * An interface that captures a unit of work against an item.
- *
- * @param <T> The closure type.
- * @param <E> The exception type thrown by the closure.
- *
- * @author John Sirois
- */
-public interface ExceptionalClosure<T, E extends Exception> {
-
- /**
- * Performs a unit of work on item, possibly throwing {@code E} in the process.
- *
- * <p>TODO(John Sirois): consider supporting @Nullable
- *
- * @param item the item to perform work against
- * @throws E if there was a problem performing the work
- */
- void execute(T item) throws E;
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionalCommand.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionalCommand.java b/commons/src/main/java/com/twitter/common/base/ExceptionalCommand.java
deleted file mode 100644
index c976d39..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionalCommand.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * An interface that captures a unit of work.
- *
- * @param <E> The type of exception that the command throws.
- *
- * @author John Sirois
- */
-public interface ExceptionalCommand<E extends Exception> {
-
- /**
- * Performs a unit of work, possibly throwing {@code E} in the process.
- *
- * @throws E if there was a problem performing the work
- */
- void execute() throws E;
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionalFunction.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionalFunction.java b/commons/src/main/java/com/twitter/common/base/ExceptionalFunction.java
deleted file mode 100644
index a8e631b..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionalFunction.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * An interface that captures a unit of work against an item.
- *
- * @param <S> The argument type for the function.
- * @param <T> The return type for the function.
- * @param <E> The exception type that the function throws.
- *
- * @author John Sirois
- */
-public interface ExceptionalFunction<S, T, E extends Exception> {
-
- /**
- * Performs a unit of work on item, possibly throwing {@code E} in the process.
- *
- * <p>TODO(John Sirois): consider supporting @Nullable
- *
- * @param item The item to perform work against.
- * @return The result of the computation.
- * @throws E if there was a problem performing the work.
- */
- T apply(S item) throws E;
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionalFunctions.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionalFunctions.java b/commons/src/main/java/com/twitter/common/base/ExceptionalFunctions.java
deleted file mode 100644
index e4c7fce..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionalFunctions.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * Utility functions for working with exceptional functions.
- *
- * @author John Sirois
- */
-public final class ExceptionalFunctions {
-
- private ExceptionalFunctions() {
- // utility
- }
-
- /**
- * Returns an {@link ExceptionalSupplier}/{@link java.util.concurrent.Callable} object that will
- * return the result of {@code function} applied to {@code argument}. Evaluation is lazy and
- * un-memoized.
- */
- public static <S, T, E extends Exception> CallableExceptionalSupplier<T, E> curry(
- final ExceptionalFunction<S, T, E> function, final S argument) {
-
- return new CallableExceptionalSupplier<T, E>() {
- @Override
- public T get() throws E {
- return function.apply(argument);
- }
- };
- }
-
- /**
- * Returns an ExceptionalFunction that is a composition of multiple ExceptionalFunctions.
- */
- public static <T, E extends Exception> ExceptionalFunction<T, T, E> compose(
- final Iterable<ExceptionalFunction<T, T, E>> functions) {
- return new ExceptionalFunction<T, T, E>() {
- @Override
- public T apply(T input) throws E {
- T result = input;
- for (ExceptionalFunction<T, T, E> f : functions) {
- result = f.apply(result);
- }
- return result;
- }
- };
- }
-
- /**
- * Returns a List of ExceptionalFunctions from variable number of ExceptionalFunctions.
- */
- public static <T, E extends Exception> ExceptionalFunction<T, T, E> compose(
- ExceptionalFunction<T, T, E> function, ExceptionalFunction<T, T, E>... functions) {
- return compose(ImmutableList.<ExceptionalFunction<T, T, E>>builder()
- .add(function)
- .add(functions)
- .build());
- }
-
- /**
- * Returns a new ExceptionalFunction which composes two ExceptionalFunctions of compatible types.
- *
- * @param second function to apply to result of first.
- * @param first function to apply to input item.
- * @param <A> input type of first.
- * @param <B> input type of second.
- * @param <C> output type of second.
- * @param <E> exception type.
- * @return new composed ExceptionalFunction.
- */
- public static <A, B, C, E extends Exception> ExceptionalFunction<A, C, E> compose(
- final ExceptionalFunction<B, C, ? extends E> second,
- final ExceptionalFunction<A, ? extends B, ? extends E> first) {
- return new ExceptionalFunction<A, C, E>() {
- @Override
- public C apply(A item) throws E {
- return second.apply(first.apply(item));
- }
- };
- }
-
- /**
- * Builds an ExceptionalFunction from {@link com.google.common.base.Function}.
- *
- * @param function guava Function.
- * @param <S> input type.
- * @param <T> output type.
- * @param <E> exception type.
- * @return new ExceptionalFunction.
- */
- public static <S, T, E extends Exception> ExceptionalFunction<S, T, E> forFunction(
- final com.google.common.base.Function<S, T> function) {
- return new ExceptionalFunction<S, T, E>() {
- @Override
- public T apply(S item) {
- return function.apply(item);
- }
- };
- }
-
- /**
- * Builds an ExceptionalFunction from a return value. The returned ExceptionalFunction will always
- * return the given value.
- *
- * @param value value to return.
- * @param <S> input type.
- * @param <T> output type.
- * @param <E> exception type.
- * @return new ExceptionalFunction.
- */
- public static <S, T, E extends Exception> ExceptionalFunction<S, T, E> constant(
- final T value) {
- return new ExceptionalFunction<S, T, E>() {
- @Override
- public T apply(S item) throws E {
- return value;
- }
- };
- }
-
- /**
- * Builds an ExceptionalFunction from an Exception. The returned ExceptionalFunction will always
- * throw the given Exception.
- *
- * @param exception exception to throw.
- * @param <S> input type.
- * @param <T> output type.
- * @param <E> exception type.
- * @return new ExceptionalFunction.
- */
- public static <S, T, E extends Exception> ExceptionalFunction<S, T, E> forException(
- final E exception) {
- return new ExceptionalFunction<S, T, E>() {
- @Override
- public T apply(S item) throws E {
- throw exception;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/ExceptionalSupplier.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/ExceptionalSupplier.java b/commons/src/main/java/com/twitter/common/base/ExceptionalSupplier.java
deleted file mode 100644
index a7272cc..0000000
--- a/commons/src/main/java/com/twitter/common/base/ExceptionalSupplier.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * An interface that captures a source of data.
- *
- * @param <T> The supplied value type.
- * @param <E> The type of exception that the supplier throws.
- *
- * @author John Sirois
- */
-public interface ExceptionalSupplier<T, E extends Exception> {
-
- /**
- * Supplies an item, possibly throwing {@code E} in the process of obtaining the item.
- *
- * @return the result of the computation
- * @throws E if there was a problem performing the work
- */
- T get() throws E;
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Function.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Function.java b/commons/src/main/java/com/twitter/common/base/Function.java
deleted file mode 100644
index 8ace728..0000000
--- a/commons/src/main/java/com/twitter/common/base/Function.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * A convenience typedef that also ties into google's {@code Function}.
- *
- * @param <S> The argument type for the function.
- * @param <T> The return type for the function.
- *
- * @author John Sirois
- */
-public interface Function<S, T>
- extends ExceptionalFunction<S, T, RuntimeException>, com.google.common.base.Function<S, T> {
-
- @Override
- T apply(S item);
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/MorePreconditions.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/MorePreconditions.java b/commons/src/main/java/com/twitter/common/base/MorePreconditions.java
deleted file mode 100644
index 392ee57..0000000
--- a/commons/src/main/java/com/twitter/common/base/MorePreconditions.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-
-import org.apache.commons.lang.StringUtils;
-
-/**
- * A utility helpful in concisely checking preconditions on arguments. This utility is a complement
- * to {@link com.google.common.base.Preconditions}.
- *
- * @author John Sirois
- */
-public final class MorePreconditions {
-
- private static final String ARG_NOT_BLANK_MSG = "Argument cannot be blank";
-
- private MorePreconditions() {
- // utility
- }
-
- /**
- * Checks that a string is both non-null and non-empty.
- *
- * @see #checkNotBlank(String, String, Object...)
- */
- public static String checkNotBlank(String argument) {
- return checkNotBlank(argument, ARG_NOT_BLANK_MSG);
- }
-
- /**
- * Checks that a string is both non-null and non-empty.
- *
- * @param argument the argument to validate
- * @param message the message template for validation exception messages where %s serves as the
- * sole argument placeholder
- * @param args any arguments needed by the message template
- * @return the argument if it is valid
- * @throws NullPointerException if the argument is null
- * @throws IllegalArgumentException if the argument is the empty string or a pure whitespace
- * string
- */
- public static String checkNotBlank(String argument, String message, Object... args) {
- Preconditions.checkNotNull(argument, message, args);
- Preconditions.checkArgument(!StringUtils.isBlank(argument), message, args);
- return argument;
- }
-
- /**
- * Checks that an Iterable is both non-null and non-empty. This method does not check individual
- * elements in the Iterable.
- *
- * @see #checkNotBlank(Iterable, String, Object...)
- */
- public static <S, T extends Iterable<S>> T checkNotBlank(T argument) {
- return checkNotBlank(argument, ARG_NOT_BLANK_MSG);
- }
-
- /**
- * Checks that an Iterable is both non-null and non-empty. This method does not check individual
- * elements in the Iterable, it just checks that the Iterable has at least one element.
- *
- * @param argument the argument to validate
- * @param message the message template for validation exception messages where %s serves as the
- * sole argument placeholder
- * @param args any arguments needed by the message template
- * @return the argument if it is valid
- * @throws NullPointerException if the argument is null
- * @throws IllegalArgumentException if the argument has no iterable elements
- */
- public static <S, T extends Iterable<S>> T checkNotBlank(T argument, String message,
- Object... args) {
- Preconditions.checkNotNull(argument, message, args);
- Preconditions.checkArgument(!Iterables.isEmpty(argument), message, args);
- return argument;
- }
-
- /**
- * Checks that a double falls within a specified range, inclusive
- *
- * @param argument argument to validate.
- * @param minimum minimum possible valid value for the argument.
- * @param maximum maximum possible valid value for the argument.
- * @param message the message template for validation exception messages where %s serves as the
- * sole argument placeholder.
- * @return the argument if it is valid.
- * @throws IllegalArgumentException if the argument falls outside of the specified range.
- */
- public static double checkArgumentRange(double argument, double minimum, double maximum,
- String message) {
- Preconditions.checkArgument(minimum <= argument, message, argument);
- Preconditions.checkArgument(argument <= maximum, message, argument);
- return argument;
- }
-
- /**
- * Checks that an int falls within a specified range, inclusive
- *
- * @param argument argument to validate.
- * @param minimum minimum possible valid value for the argument.
- * @param maximum maximum possible valid value for the argument.
- * @param message the message template for validation exception messages where %s serves as the
- * sole argument placeholder.
- * @return the argument if it is valid.
- * @throws IllegalArgumentException if the argument falls outside of the specified range.
- */
- public static int checkArgumentRange(int argument, int minimum, int maximum,
- String message) {
- Preconditions.checkArgument(minimum <= argument, message, argument);
- Preconditions.checkArgument(argument <= maximum, message, argument);
- return argument;
- }
-
- /**
- * Checks that at least one of the specified arguments is true.
- *
- * @param message the message for validation exception messages.
- * @param arguments one or more arguments to check.
- * @return true if at least one of the arguments is true.
- * @throws IllegalArgumentException if none of the arguments are true.
- */
- public static boolean checkArguments(String message,
- Boolean... arguments) {
- for (Boolean argument : arguments) {
- if (argument) {
- return true;
- }
- }
- throw new IllegalArgumentException(message);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/MoreSuppliers.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/MoreSuppliers.java b/commons/src/main/java/com/twitter/common/base/MoreSuppliers.java
deleted file mode 100644
index 7593724..0000000
--- a/commons/src/main/java/com/twitter/common/base/MoreSuppliers.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-
-import javax.annotation.Nullable;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Utility methods for working with Suppliers.
- *
- * @author John Sirois
- */
-public final class MoreSuppliers {
-
- private MoreSuppliers() {
- // utility
- }
-
- /**
- * Creates a Supplier that uses the no-argument constructor of {@code type} to supply new
- * instances.
- *
- * @param type the type of object this supplier creates
- * @param <T> the type of object this supplier creates
- * @return a Supplier that created a new obeject of type T on each call to {@link Supplier#get()}
- * @throws IllegalArgumentException if the given {@code type} does not have a no-arg constructor
- */
- public static <T> Supplier<T> of(final Class<? extends T> type) {
- Preconditions.checkNotNull(type);
-
- try {
- final Constructor<? extends T> constructor = getNoArgConstructor(type);
- return new Supplier<T>() {
- @Override public T get() {
- try {
- return constructor.newInstance();
- } catch (InstantiationException e) {
- throw instantiationFailed(e, type);
- } catch (IllegalAccessException e) {
- throw instantiationFailed(e, type);
- } catch (InvocationTargetException e) {
- throw instantiationFailed(e, type);
- }
- }
- };
- } catch (NoSuchMethodException e) {
- throw new IllegalArgumentException("No accessible no-arg constructor for " + type, e);
- }
- }
-
- private static RuntimeException instantiationFailed(Exception cause, Object type) {
- return new RuntimeException("Could not create a new instance of type: " + type, cause);
- }
-
- private static <T> Constructor<T> getNoArgConstructor(Class<T> type)
- throws NoSuchMethodException {
-
- try {
- Constructor<T> constructor = type.getConstructor();
- if (!MoreSuppliers.class.getPackage().equals(type.getPackage())
- && !Modifier.isPublic(type.getModifiers())) {
- // Handle a public no-args constructor in a non-public class
- constructor.setAccessible(true);
- }
- return constructor;
- } catch (NoSuchMethodException e) {
- Constructor<T> declaredConstructor = type.getDeclaredConstructor();
- declaredConstructor.setAccessible(true);
- return declaredConstructor;
- }
- }
-
- /**
- * Returns an {@link ExceptionalSupplier} that always supplies {@code item} without error.
- *
- * @param item The item to supply.
- * @param <T> The type of item being supplied.
- * @return A supplier that will always supply {@code item}.
- */
- public static <T> Supplier<T> ofInstance(@Nullable final T item) {
- return new Supplier<T>() {
- @Override public T get() {
- return item;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/Supplier.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/Supplier.java b/commons/src/main/java/com/twitter/common/base/Supplier.java
deleted file mode 100644
index 84abeb3..0000000
--- a/commons/src/main/java/com/twitter/common/base/Supplier.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * A convenience typedef that also ties into google's {@code Supplier}.
- *
- * @param <T> The supplied type.
- *
- * @author John Sirois
- */
-public interface Supplier<T>
- extends ExceptionalSupplier<T, RuntimeException>, com.google.common.base.Supplier<T> {
-
- @Override
- T get();
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/base/SupplierE.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/base/SupplierE.java b/commons/src/main/java/com/twitter/common/base/SupplierE.java
deleted file mode 100644
index 3ba2f83..0000000
--- a/commons/src/main/java/com/twitter/common/base/SupplierE.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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 com.twitter.common.base;
-
-/**
- * A convenience typedef for suppliers that throw multiple exception types.
- *
- * @param <T> The supplied type.
- *
- * @author John Sirois
- */
-public interface SupplierE<T> extends ExceptionalSupplier<T, Exception> {
- // typedef
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/06ddaadb/commons/src/main/java/com/twitter/common/collections/Bits.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/com/twitter/common/collections/Bits.java b/commons/src/main/java/com/twitter/common/collections/Bits.java
deleted file mode 100644
index 707abaa..0000000
--- a/commons/src/main/java/com/twitter/common/collections/Bits.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * 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 com.twitter.common.collections;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Convenience class for doing bit-level operations on ints and longs.
- *
- * @author William Farner
- */
-public final class Bits {
-
- private static final int LSB = 0;
- private static final int INT_MSB = 31;
- private static final int LONG_MSB = 63;
-
- private Bits() {
- // Utility.
- }
-
- /**
- * Tests whether a bit is set in an int value.
- *
- * @param value The bit field to test.
- * @param bit The index of the bit to test, where bit 0 is the LSB.
- * @return {@code true} if the bit is set, {@code false} otherwise.
- */
- public static boolean isBitSet(int value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= INT_MSB);
- int mask = 1 << bit;
- return (value & mask) != 0;
- }
-
- /**
- * Tests whether a bit is set in a long value.
- *
- * @param value The bit field to test.
- * @param bit The index of the bit to test, where bit 0 is the LSB.
- * @return {@code true} if the bit is set, {@code false} otherwise.
- */
- public static boolean isBitSet(long value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= LONG_MSB);
- long mask = 1L << bit;
- return (value & mask) != 0;
- }
-
- /**
- * Sets a bit in an int value.
- *
- * @param value The bit field to modify.
- * @param bit The index of the bit to set, where bit 0 is the LSB.
- * @return The original value, with the indexed bit set.
- */
- public static int setBit(int value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= INT_MSB);
- int mask = 1 << bit;
- return value | mask;
- }
-
- /**
- * Sets a bit in a long value.
- *
- * @param value The bit field to modify.
- * @param bit The index of the bit to set, where bit 0 is the LSB.
- * @return The original value, with the indexed bit set.
- */
- public static long setBit(long value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= LONG_MSB);
- long mask = 1L << bit;
- return value | mask;
- }
-
- /**
- * Clears a bit in an int value.
- *
- * @param value The bit field to modify.
- * @param bit The index of the bit to clear, where bit 0 is the LSB.
- * @return The original value, with the indexed bit clear.
- */
- public static int clearBit(int value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= INT_MSB);
- int mask = ~setBit(0, bit);
- return value & mask;
- }
-
- /**
- * Clears a bit in a long value.
- *
- * @param value The bit field to modify.
- * @param bit The index of the bit to clear, where bit 0 is the LSB.
- * @return The original value, with the indexed bit clear.
- */
- public static long clearBit(long value, int bit) {
- Preconditions.checkState(bit >= LSB);
- Preconditions.checkState(bit <= LONG_MSB);
- long mask = ~setBit(0L, bit);
- return value & mask;
- }
-}