http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/constraints/RangeNumberVerifier.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/constraints/RangeNumberVerifier.java b/commons/src/main/java/org/apache/aurora/common/args/constraints/RangeNumberVerifier.java deleted file mode 100644 index bec0523..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/constraints/RangeNumberVerifier.java +++ /dev/null @@ -1,70 +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 org.apache.aurora.common.args.constraints; - -import java.lang.annotation.Annotation; -import java.math.BigDecimal; - -import com.google.common.base.Function; -import com.google.common.base.Functions; - -import org.apache.aurora.common.args.Verifier; -import org.apache.aurora.common.args.VerifierFor; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Verifies that a number (inclusively) lies within a range. - * - * @author William Farner - */ -@VerifierFor(Range.class) -public class RangeNumberVerifier implements Verifier<Number> { - @Override - public void verify(Number value, Annotation annotation) { - Range range = getRange(annotation); - - checkArgument(range.lower() < range.upper(), - "Range lower bound must be greater than upper bound."); - - double dblValue = value.doubleValue(); - checkArgument(dblValue >= range.lower() && dblValue <= range.upper(), - String.format("Value must be in range [%f, %f]", range.lower(), range.upper())); - } - - @Override - public String toString(Class<? extends Number> argType, Annotation annotation) { - Range range = getRange(annotation); - - Function<Number, Number> converter; - if (Float.class.isAssignableFrom(argType) - || Double.class.isAssignableFrom(argType) - || BigDecimal.class.isAssignableFrom(argType)) { - - converter = Functions.identity(); - } else { - converter = Number::longValue; - } - - return String.format("must be >= %s and <= %s", - converter.apply(range.lower()), - converter.apply(range.upper())); - } - - private Range getRange(Annotation annotation) { - checkArgument(annotation instanceof Range, "Annotation is not a range: " + annotation); - - return (Range) annotation; - } -}
http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/AmountParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/AmountParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/AmountParser.java deleted file mode 100644 index 1eb42bb..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/AmountParser.java +++ /dev/null @@ -1,86 +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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.google.common.reflect.TypeToken; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.quantity.Amount; -import org.apache.aurora.common.quantity.Unit; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Amount parser. - * - * @author William Farner - */ -@ArgParser -public class AmountParser extends TypeParameterizedParser<Amount<?, ?>> { - - private static final Pattern AMOUNT_PATTERN = Pattern.compile("(\\d+)([A-Za-z]+)"); - - public AmountParser() { - super(2); - } - - @Override - Amount<?, ?> doParse(ParserOracle parserOracle, String raw, List<Type> typeParams) { - Type valueType = typeParams.get(0); - Parser<?> parser = parserOracle.get(TypeToken.of(valueType)); - - Matcher matcher = AMOUNT_PATTERN.matcher(raw); - checkArgument(matcher.matches(), - "Value '" + raw + "' must be of the format 1ns, 4mb, etc."); - - Number number = (Number) parser.parse(parserOracle, valueType, matcher.group(1)); - String unitRaw = matcher.group(2); - - Type unitType = typeParams.get(1); - @SuppressWarnings("rawtypes") - Parser<Unit> unitParser = parserOracle.get(TypeToken.of(Unit.class)); - @SuppressWarnings("rawtypes") - Unit unit = unitParser.parse(parserOracle, unitType, unitRaw); - checkArgument(unit.getClass() == unitType, String.format( - "Unit type (%s) does not match argument type (%s).", - unit.getClass(), unitType)); - - return create(valueType, number, unit); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private static Amount<?, ?> create(Type valueType, Number number, Unit unit) { - if (valueType == Integer.class) { - return Amount.of(number.intValue(), unit); - } else if (valueType == Double.class) { - return Amount.of(number.doubleValue(), unit); - } else if (valueType == Long.class) { - return Amount.of(number.longValue(), unit); - } else if (valueType == Byte.class) { - return Amount.of(number.byteValue(), unit); - } else if (valueType == Short.class) { - return Amount.of(number.shortValue(), unit); - } else if (valueType == Float.class) { - return Amount.of(number.floatValue(), unit); - } - throw new IllegalArgumentException("Unrecognized number class " + valueType); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/BooleanParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/BooleanParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/BooleanParser.java deleted file mode 100644 index 9ceb148..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/BooleanParser.java +++ /dev/null @@ -1,30 +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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Boolean parser. - * - * @author William Farner - */ -@ArgParser -public class BooleanParser extends NonParameterizedTypeParser<Boolean> { - @Override - public Boolean doParse(String raw) { - // Magic boolean syntax, no argument value means true. - return raw.isEmpty() || Boolean.parseBoolean(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/ByteParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/ByteParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/ByteParser.java deleted file mode 100644 index 64ee998..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/ByteParser.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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Byte parser. - * - * @author William Farner - */ -@ArgParser -public class ByteParser extends NumberParser<Byte> { - @Override - Byte parseNumber(String raw) { - return Byte.parseByte(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/CharacterParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/CharacterParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/CharacterParser.java deleted file mode 100644 index c236357..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/CharacterParser.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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Character parser. - * - * @author William Farner - */ -@ArgParser -public class CharacterParser extends NonParameterizedTypeParser<Character> { - @Override - public Character doParse(String raw) { - checkArgument(raw.length() == 1, - "String " + raw + " cannot be assigned to a character."); - return raw.charAt(0); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/ClassParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/ClassParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/ClassParser.java deleted file mode 100644 index 27f71a8..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/ClassParser.java +++ /dev/null @@ -1,48 +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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; - -import com.google.common.base.Preconditions; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.args.TypeUtil; - -/** - * Class parser. - * - * @author William Farner - */ -@ArgParser -public class ClassParser extends TypeParameterizedParser<Class<?>> { - - public ClassParser() { - super(1); - } - - @Override - public Class<?> doParse(ParserOracle parserOracle, String raw, final List<Type> typeParams) { - Class<?> rawClassType = TypeUtil.getRawType(typeParams.get(0)); - try { - Class<?> actualClass = Class.forName(raw); - Preconditions.checkArgument(rawClassType.isAssignableFrom(actualClass)); - return actualClass; - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Could not find class " + raw); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/DateParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/DateParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/DateParser.java deleted file mode 100644 index a2ee8f9..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/DateParser.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 org.apache.aurora.common.args.parsers; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Date parser. - * - * @author William Farner - */ -@ArgParser -public class DateParser extends NonParameterizedTypeParser<Date> { - - private static final String FORMAT = "MM/dd/yyyy HH:mm"; - private static final SimpleDateFormat SIMPLE_FORMAT = new SimpleDateFormat(FORMAT); - - @Override - public Date doParse(String raw) { - try { - return SIMPLE_FORMAT.parse(raw); - } catch (ParseException e) { - throw new IllegalArgumentException("Failed to parse " + raw + " in format " + FORMAT); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/DoubleParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/DoubleParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/DoubleParser.java deleted file mode 100644 index 6232437..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/DoubleParser.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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Double parser. - * - * @author William Farner - */ -@ArgParser -public class DoubleParser extends NumberParser<Double> { - @Override - Double parseNumber(String raw) { - return Double.parseDouble(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/DurationParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/DurationParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/DurationParser.java deleted file mode 100644 index 7bf5578..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/DurationParser.java +++ /dev/null @@ -1,80 +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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.List; -import java.util.StringTokenizer; - -import com.google.common.base.Preconditions; - -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.quantity.Amount; -import org.apache.aurora.common.quantity.Time; - -/** - * Utility class for parsing durations of the form "1d23h59m59s" (as well as subvariants, i.e. - * "10h5s" would also work, as would "2d"). These values are useful representations in HTTP query - * parameters for durations. - * - */ -public class DurationParser extends TypeParameterizedParser<Amount<?, ?>> { - - private static final String SUFFIXES = "dhms"; - private static final Time[] TIME_UNITS = {Time.DAYS, Time.HOURS, Time.MINUTES, Time.SECONDS}; - - public DurationParser() { - super(2); - } - - @Override - Amount<?, ?> doParse(ParserOracle parserOracle, String raw, List<Type> paramParsers) - throws IllegalArgumentException { - Type secondParamClass = paramParsers.get(1); - Preconditions.checkArgument( - secondParamClass == Time.class, - String.format("Expected %s for " - + "second type parameter, but got got %s", Time.class.getName(), - secondParamClass)); - return parse(raw); - } - - /** - * Parses a duration of the form "1d23h59m59s" (as well as subvariants, i.e. "10h5s" would also - * work, as would "2d"). - * - * @param spec the textual duration specification - * @return the parsed form - * @throws IllegalArgumentException if the specification can not be parsed - */ - public static Amount<Long, Time> parse(String spec) { - long time = 0L; - final List<Object> tokens = Collections.list(new StringTokenizer(spec, SUFFIXES, true)); - Preconditions.checkArgument(tokens.size() > 1); - for (int i = 1; i < tokens.size(); i += 2) { - final String token = (String) tokens.get(i); - Preconditions.checkArgument(token.length() == 1, "Too long suffix '%s'", token); - final int suffixIndex = SUFFIXES.indexOf(token.charAt(0)); - Preconditions.checkArgument(suffixIndex != -1, "Unrecognized suffix '%s'", token); - try { - final int value = Integer.parseInt((String) tokens.get(i - 1)); - time += Amount.of(value, TIME_UNITS[suffixIndex]).as(Time.SECONDS); - } catch (NumberFormatException e) { - Preconditions.checkArgument(false, "Invalid number %s", tokens.get(i - 1)); - } - } - return Amount.of(time, Time.SECONDS); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/EnumParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/EnumParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/EnumParser.java deleted file mode 100644 index 1c1e9bf..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/EnumParser.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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; - -/** - * An {@link Enum} parser that matches enum values via {@link Enum#valueOf(Class, String)}. - * - * @author John Sirois - */ -@ArgParser -@SuppressWarnings("unused") -public class EnumParser<T extends Enum<T>> implements Parser<T> { - - @Override - public T parse(ParserOracle parserOracle, Type type, String raw) throws IllegalArgumentException { - @SuppressWarnings("unchecked") - Class<T> enumClass = (Class<T>) type; - return Enum.valueOf(enumClass, raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/FileParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/FileParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/FileParser.java deleted file mode 100644 index c8573f5..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/FileParser.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 org.apache.aurora.common.args.parsers; - -import java.io.File; - -import org.apache.aurora.common.args.ArgParser; - -/** - * File parser. - * - * @author William Farner - */ -@ArgParser -public class FileParser extends NonParameterizedTypeParser<File> { - @Override - public File doParse(String raw) { - return new File(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/FloatParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/FloatParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/FloatParser.java deleted file mode 100644 index 7ceb110..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/FloatParser.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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Float parser. - * - * @author William Farner - */ -@ArgParser -public class FloatParser extends NumberParser<Float> { - @Override - Float parseNumber(String raw) { - return Float.parseFloat(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/InetSocketAddressParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/InetSocketAddressParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/InetSocketAddressParser.java deleted file mode 100644 index dfa441e..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/InetSocketAddressParser.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 org.apache.aurora.common.args.parsers; - -import java.net.InetSocketAddress; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.net.InetSocketAddressHelper; - -/** - * InetSocketAddress parser. - * - * @author William Farner - */ -@ArgParser -public class InetSocketAddressParser extends NonParameterizedTypeParser<InetSocketAddress> { - @Override - public InetSocketAddress doParse(String raw) { - return InetSocketAddressHelper.parse(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/IntegerParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/IntegerParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/IntegerParser.java deleted file mode 100644 index 275d121..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/IntegerParser.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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.common.args.ArgParser; - -/** - * Integer parser. - * - * @author William Farner - */ -@ArgParser -public class IntegerParser extends NumberParser<Integer> { - @Override - Integer parseNumber(String raw) { - return Integer.parseInt(raw); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/ListParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/ListParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/ListParser.java deleted file mode 100644 index c224434..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/ListParser.java +++ /dev/null @@ -1,47 +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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.reflect.TypeToken; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.args.Parsers; - -/** - * List parser. - * - * @author William Farner - */ -@ArgParser -public class ListParser extends TypeParameterizedParser<List<?>> { - - public ListParser() { - super(1); - } - - @Override - List<?> doParse(final ParserOracle parserOracle, String raw, final List<Type> typeParams) { - final Type listType = typeParams.get(0); - final Parser<?> parser = parserOracle.get(TypeToken.of(listType)); - return ImmutableList.copyOf(Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw), - raw1 -> parser.parse(parserOracle, listType, raw1))); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/LongParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/LongParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/LongParser.java deleted file mode 100644 index 95f92b8..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/MapParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/MapParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/MapParser.java deleted file mode 100644 index 3e1c916..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.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 org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/MultimapParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/MultimapParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/MultimapParser.java deleted file mode 100644 index 0c44614..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/MultimapParser.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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; -import com.google.common.reflect.TypeToken; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.args.Parsers; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Multimap parser. - */ -@ArgParser -public class MultimapParser extends TypeParameterizedParser<Multimap<?, ?>> { - - private static final Splitter KEY_VALUE_SPLITTER = - Splitter.on("=").trimResults().omitEmptyStrings(); - - public MultimapParser() { - super(2); - } - - @SuppressWarnings("unchecked") - @Override - Multimap<?, ?> 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)); - - ImmutableMultimap.Builder<Object, Object> multimapBuilder = ImmutableMultimap.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); - multimapBuilder.put( - keyParser.parse(parserOracle, keyType, fields.get(0)), - valueParser.parse(parserOracle, valueType, fields.get(1))); - } - - return multimapBuilder.build(); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/NonParameterizedTypeParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/NonParameterizedTypeParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/NonParameterizedTypeParser.java deleted file mode 100644 index c77543c..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; - -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/NumberParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/NumberParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/NumberParser.java deleted file mode 100644 index a551fa9..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/PairParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/PairParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/PairParser.java deleted file mode 100644 index 3465260..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.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 org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.common.args.Parsers; -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/PatternParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/PatternParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/PatternParser.java deleted file mode 100644 index 0b86a21..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/RangeParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/RangeParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/RangeParser.java deleted file mode 100644 index e861681..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Range; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/SetParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/SetParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/SetParser.java deleted file mode 100644 index 15b6c74..0000000 --- a/commons/src/main/java/org/apache/aurora/common/args/parsers/SetParser.java +++ /dev/null @@ -1,49 +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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.reflect.TypeToken; - -import org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.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), - raw1 -> parser.parse(parserOracle, setType, raw1))); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/ShortParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/ShortParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/ShortParser.java deleted file mode 100644 index 1e1323d..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/StringParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/StringParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/StringParser.java deleted file mode 100644 index 5283992..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/TypeParameterizedParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/TypeParameterizedParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/TypeParameterizedParser.java deleted file mode 100644 index a8455f5..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import java.lang.reflect.Type; -import java.util.List; - -import org.apache.aurora.common.args.Parser; -import org.apache.aurora.common.args.ParserOracle; -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/URIParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/URIParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/URIParser.java deleted file mode 100644 index 6026112..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/URLParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/URLParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/URLParser.java deleted file mode 100644 index c2fd301..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.common.args.parsers; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/args/parsers/UnitParser.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/args/parsers/UnitParser.java b/commons/src/main/java/org/apache/aurora/common/args/parsers/UnitParser.java deleted file mode 100644 index 9109853..0000000 --- a/commons/src/main/java/org/apache/aurora/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 org.apache.aurora.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 org.apache.aurora.common.args.ArgParser; -import org.apache.aurora.common.quantity.Data; -import org.apache.aurora.common.quantity.Time; -import org.apache.aurora.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/519e3df7/commons/src/main/java/org/apache/aurora/common/quantity/Amount.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/quantity/Amount.java b/commons/src/main/java/org/apache/aurora/common/quantity/Amount.java index 11be7f5..091d6b7 100644 --- a/commons/src/main/java/org/apache/aurora/common/quantity/Amount.java +++ b/commons/src/main/java/org/apache/aurora/common/quantity/Amount.java @@ -42,7 +42,7 @@ public abstract class Amount<T extends Number & Comparable<T>, U extends Unit<U> private final Pair<T, U> amount; private final T maxValue; - private Amount(T value, U unit, T maxValue) { + protected Amount(T value, U unit, T maxValue) { Preconditions.checkNotNull(value); Preconditions.checkNotNull(unit); this.maxValue = maxValue; http://git-wip-us.apache.org/repos/asf/aurora/blob/519e3df7/commons/src/test/java/org/apache/aurora/common/args/ArgFiltersTest.java ---------------------------------------------------------------------- diff --git a/commons/src/test/java/org/apache/aurora/common/args/ArgFiltersTest.java b/commons/src/test/java/org/apache/aurora/common/args/ArgFiltersTest.java deleted file mode 100644 index 0390809..0000000 --- a/commons/src/test/java/org/apache/aurora/common/args/ArgFiltersTest.java +++ /dev/null @@ -1,98 +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 org.apache.aurora.common.args; - -import java.io.IOException; -import java.lang.reflect.Field; - -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; - -import org.apache.aurora.common.args.apt.Configuration; -import org.apache.aurora.common.args.argfilterstest.ArgsRoot; -import org.apache.aurora.common.args.argfilterstest.subpackageA.ArgsA; -import org.apache.aurora.common.args.argfilterstest.subpackageA.subsubpackage1.ArgsA1; -import org.apache.aurora.common.args.argfilterstest.subpackageB.ArgsB; -import org.apache.aurora.common.args.argfilterstest.subpackageBwithSuffix.ArgsBWithSuffix; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author John Sirois - */ -public class ArgFiltersTest { - - @CmdLine(name = "a", help = "") - static final Arg<String> A = Arg.create(); - - @CmdLine(name = "b", help = "") - static final Arg<String> B = Arg.create(); - - @Test - public void testpackage() throws IOException { - testFilter(ArgFilters.selectPackage(ArgsRoot.class.getPackage()), - fieldInfo(ArgsRoot.class, "ARGS_ROOT")); - } - - @Test - public void testAllPackagesUnderHere() throws IOException { - testFilter(ArgFilters.selectAllPackagesUnderHere(ArgsRoot.class.getPackage()), - fieldInfo(ArgsRoot.class, "ARGS_ROOT"), - fieldInfo(ArgsA.class, "ARGS_A"), - fieldInfo(ArgsB.class, "ARGS_B"), - fieldInfo(ArgsA1.class, "ARGS_A1"), - fieldInfo(ArgsBWithSuffix.class, "ARGS_B_WITH_SUFFIX")); - - testFilter(ArgFilters.selectAllPackagesUnderHere(ArgsB.class.getPackage()), - fieldInfo(ArgsB.class, "ARGS_B")); - } - - @Test - public void testClass() throws IOException { - testFilter(ArgFilters.selectClass(ArgFiltersTest.class), - fieldInfo(ArgFiltersTest.class, "A"), fieldInfo(ArgFiltersTest.class, "B")); - } - - @Test - public void testClasses() throws IOException { - testFilter(ArgFilters.selectClasses(ArgFiltersTest.class, ArgsA.class), - fieldInfo(ArgFiltersTest.class, "A"), - fieldInfo(ArgFiltersTest.class, "B"), - fieldInfo(ArgsA.class, "ARGS_A")); - } - - @Test - public void testArg() throws IOException { - testFilter(ArgFilters.selectCmdLineArg(ArgFiltersTest.class, "b"), - fieldInfo(ArgFiltersTest.class, "B")); - } - - private static Configuration.ArgInfo fieldInfo(Class<?> declaringClass, String fieldName) { - return new Configuration.ArgInfo(declaringClass.getName(), fieldName); - } - - private void testFilter(final Predicate<Field> filter, Configuration.ArgInfo... expected) - throws IOException { - - Predicate<Optional<Field>> fieldFilter = maybeField -> maybeField.isPresent() && filter.apply(maybeField.get()); - - assertEquals(ImmutableSet.copyOf(expected), - ImmutableSet.copyOf(Iterables.filter(Configuration.load().optionInfo(), - Predicates.compose(fieldFilter, Args.TO_FIELD)))); - } -}
