Skip to content

Commit

Permalink
Fix formatting and update some versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauriichan committed Mar 23, 2021
1 parent 9c8c5fe commit 964d732
Show file tree
Hide file tree
Showing 326 changed files with 21,219 additions and 20,593 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/
public abstract class ArgumentIdentifier {

public static final ArgumentIdentifier DEFAULT = new DefaultArgumentIdentifier();
public static final ArgumentIdentifier DEFAULT = new DefaultArgumentIdentifier();

/**
* @param rawArguments array of raw arguments
* @return list of complex arguments
*/
public abstract ArrayList<BaseArgument> process(String... rawArguments);
/**
* @param rawArguments array of raw arguments
* @return list of complex arguments
*/
public abstract ArrayList<BaseArgument> process(String... rawArguments);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,104 +11,112 @@

public final class ArgumentMap {

public static final ArgumentMap EMPTY = new ArgumentMap(Collections.emptyMap());

protected final Map<String, BaseArgument> arguments = Collections.synchronizedMap(new HashMap<>());

private final boolean locked;

public ArgumentMap() {
locked = true;
}

public ArgumentMap(Map<String, BaseArgument> arguments) {
this.arguments.putAll(arguments);
locked = false;
}

final Map<String, BaseArgument> getHandle() {
return arguments;
}

public final boolean isLocked() {
return locked;
}

public final boolean set(String key, BaseArgument value) {
return !locked && !arguments.containsKey(key) && arguments.put(key, value) == null;
}

public final Optional<BaseArgument> get(String key) {
return Optional.ofNullable(arguments.get(key));
}

public final Optional<BaseArgument> get(String key, ArgumentType type) {
return get(key).filter(argument -> argument.getType() == type);
}

public final Optional<BaseArgument> get(String key, ArgumentSuperType type) {
return get(key).filter(argument -> argument.getSuperType() == type);
}

@SuppressWarnings("unchecked")
public final <E extends Number> Optional<E> number(String key, E sample) {
return number(key, (Class<E>) sample.getClass());
}

@SuppressWarnings("unchecked")
public final <E extends Number> Optional<E> number(String key, Class<E> sample) {
Optional<BaseArgument> optional = get(key, ArgumentSuperType.NUMBER);
if (!optional.isPresent())
return Optional.empty();
Optional<NumberEnum> option = NumberEnum.of(sample);
if (!option.isPresent())
return Optional.empty();
NumericArgument argument = optional.get().asNumeric();
boolean primitive = Primitives.isPrimitive(sample);
switch (option.get()) {
case BYTE:
if (argument.getType() == ArgumentType.BYTE)
return option(primitive ? argument.asByte().getValue().byteValue() : argument.asByte().getValue(), sample);
byte value = argument.asNumber().byteValue();
return option(primitive ? value : Byte.valueOf(value), sample);
case SHORT:
if (argument.getType() == ArgumentType.SHORT)
return option(primitive ? argument.asShort().getValue().shortValue() : argument.asShort().getValue(), sample);
short value0 = argument.asNumber().shortValue();
return option(primitive ? value0 : Short.valueOf(value0), sample);
case INTEGER:
if (argument.getType() == ArgumentType.INTEGER)
return option(primitive ? argument.asInteger().getValue().intValue() : argument.asInteger().getValue(), sample);
int value1 = argument.asNumber().intValue();
return option(primitive ? value1 : Integer.valueOf(value1), sample);
case LONG:
if (argument.getType() == ArgumentType.LONG)
return option(primitive ? argument.asLong().getValue().longValue() : argument.asLong().getValue(), sample);
long value2 = argument.asNumber().longValue();
return option(primitive ? value2 : Long.valueOf(value2), sample);
case FLOAT:
if (argument.getType() == ArgumentType.FLOAT)
return option(primitive ? argument.asFloat().getValue().floatValue() : argument.asFloat().getValue(), sample);
float value3 = argument.asNumber().floatValue();
return option(primitive ? value3 : Float.valueOf(value3), sample);
case DOUBLE:
if (argument.getType() == ArgumentType.DOUBLE)
return option(primitive ? argument.asDouble().getValue().doubleValue() : argument.asDouble().getValue(), sample);
double value4 = argument.asNumber().doubleValue();
return option(primitive ? value4 : Double.valueOf(value4), sample);
case BIG_INTEGER:
return (Optional<E>) Optional
.of(argument.getType() == ArgumentType.BIG_INTEGER ? argument.asBigInteger().getValue() : new BigInteger(argument.asNumber().toString()));
case BIG_DECIMAL:
return (Optional<E>) Optional
.of(argument.getType() == ArgumentType.BIG_DECIMAL ? argument.asBigDecimal().getValue() : new BigDecimal(argument.asNumber().toString()));
}
return Optional.empty();
}

@SuppressWarnings("unchecked")
private final <T, E> Optional<E> option(T value, Class<E> sample) {
return Optional.of(value).map(internal -> (E) internal);
}
public static final ArgumentMap EMPTY = new ArgumentMap(Collections.emptyMap());

protected final Map<String, BaseArgument> arguments = Collections.synchronizedMap(new HashMap<>());

private final boolean locked;

public ArgumentMap() {
locked = true;
}

public ArgumentMap(Map<String, BaseArgument> arguments) {
this.arguments.putAll(arguments);
locked = false;
}

final Map<String, BaseArgument> getHandle() {
return arguments;
}

public final boolean isLocked() {
return locked;
}

public final boolean set(String key, BaseArgument value) {
return !locked && !arguments.containsKey(key) && arguments.put(key, value) == null;
}

public final Optional<BaseArgument> get(String key) {
return Optional.ofNullable(arguments.get(key));
}

public final Optional<BaseArgument> get(String key, ArgumentType type) {
return get(key).filter(argument -> argument.getType() == type);
}

public final Optional<BaseArgument> get(String key, ArgumentSuperType type) {
return get(key).filter(argument -> argument.getSuperType() == type);
}

@SuppressWarnings("unchecked")
public final <E extends Number> Optional<E> number(String key, E sample) {
return number(key, (Class<E>) sample.getClass());
}

@SuppressWarnings("unchecked")
public final <E extends Number> Optional<E> number(String key, Class<E> sample) {
Optional<BaseArgument> optional = get(key, ArgumentSuperType.NUMBER);
if (!optional.isPresent()) {
return Optional.empty();
}
Optional<NumberEnum> option = NumberEnum.of(sample);
if (!option.isPresent()) {
return Optional.empty();
}
NumericArgument argument = optional.get().asNumeric();
boolean primitive = Primitives.isPrimitive(sample);
switch (option.get()) {
case BYTE:
if (argument.getType() == ArgumentType.BYTE) {
return option(primitive ? argument.asByte().getValue().byteValue() : argument.asByte().getValue(), sample);
}
byte value = argument.asNumber().byteValue();
return option(primitive ? value : Byte.valueOf(value), sample);
case SHORT:
if (argument.getType() == ArgumentType.SHORT) {
return option(primitive ? argument.asShort().getValue().shortValue() : argument.asShort().getValue(), sample);
}
short value0 = argument.asNumber().shortValue();
return option(primitive ? value0 : Short.valueOf(value0), sample);
case INTEGER:
if (argument.getType() == ArgumentType.INTEGER) {
return option(primitive ? argument.asInteger().getValue().intValue() : argument.asInteger().getValue(), sample);
}
int value1 = argument.asNumber().intValue();
return option(primitive ? value1 : Integer.valueOf(value1), sample);
case LONG:
if (argument.getType() == ArgumentType.LONG) {
return option(primitive ? argument.asLong().getValue().longValue() : argument.asLong().getValue(), sample);
}
long value2 = argument.asNumber().longValue();
return option(primitive ? value2 : Long.valueOf(value2), sample);
case FLOAT:
if (argument.getType() == ArgumentType.FLOAT) {
return option(primitive ? argument.asFloat().getValue().floatValue() : argument.asFloat().getValue(), sample);
}
float value3 = argument.asNumber().floatValue();
return option(primitive ? value3 : Float.valueOf(value3), sample);
case DOUBLE:
if (argument.getType() == ArgumentType.DOUBLE) {
return option(primitive ? argument.asDouble().getValue().doubleValue() : argument.asDouble().getValue(), sample);
}
double value4 = argument.asNumber().doubleValue();
return option(primitive ? value4 : Double.valueOf(value4), sample);
case BIG_INTEGER:
return (Optional<E>) Optional.of(argument.getType() == ArgumentType.BIG_INTEGER ? argument.asBigInteger().getValue()
: new BigInteger(argument.asNumber().toString()));
case BIG_DECIMAL:
return (Optional<E>) Optional.of(argument.getType() == ArgumentType.BIG_DECIMAL ? argument.asBigDecimal().getValue()
: new BigDecimal(argument.asNumber().toString()));
}
return Optional.empty();
}

@SuppressWarnings("unchecked")
private final <T, E> Optional<E> option(T value, Class<E> sample) {
return Optional.of(value).map(internal -> (E) internal);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

public abstract class ArgumentRangeIdentifier {

public static final ArgumentRangeIdentifier DEFAULT = new DefaultArgumentRangeIdentifier();
public static final ArgumentRangeIdentifier DEFAULT = new DefaultArgumentRangeIdentifier();

/**
* @param rawRanges array of raw ranges
* @return list of complex ranges
*/
public abstract ArrayList<BaseArgumentRange> process(String... rawRanges);
/**
* @param rawRanges array of raw ranges
* @return list of complex ranges
*/
public abstract ArrayList<BaseArgumentRange> process(String... rawRanges);

}
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
package com.syntaxphoenix.syntaxapi.command;

import com.syntaxphoenix.syntaxapi.command.range.*;
import com.syntaxphoenix.syntaxapi.command.range.CollectionSizeRange;
import com.syntaxphoenix.syntaxapi.command.range.NumberChooseRange;
import com.syntaxphoenix.syntaxapi.command.range.NumberValueRange;
import com.syntaxphoenix.syntaxapi.command.range.StateRange;
import com.syntaxphoenix.syntaxapi.command.range.TextChooseRange;
import com.syntaxphoenix.syntaxapi.command.range.TextSizeRange;

public abstract class ArgumentRangeSerializer {

public static final ArgumentRangeSerializer DEFAULT = new DefaultArgumentRangeSerializer();

public String toString(BaseArgumentRange range) {
RangeType type = range.getType();
String output = "";
switch (type) {
case TEXT_SIZE_RANGE:
output = toString(range.asTextSize());
break;
case TEXT_CHOOSE_RANGE:
output = toString(range.asTextChoose());
break;
case STATE_RANGE:
output = toString(range.asState());
break;
case COLLECTION_SIZE_RANGE:
output = toString(range.asCollectionSize());
break;
case NUMBER_VALUE_RANGE:
output = toString(range.asNumberValue());
break;
case NUMBER_CHOOSE_RANGE:
output = toString(range.asNumberChoose());
break;
case CUSTOM:
output = range.toString();
break;
}
return output;
}

public abstract String toString(CollectionSizeRange<?> range);

public abstract String toString(NumberValueRange range);

public abstract String toString(NumberChooseRange range);

public abstract String toString(StateRange range);

public abstract String toString(TextSizeRange range);

public abstract String toString(TextChooseRange range);

/**
* @param ranges array of complex ranges
* @return array of raw ranges
*/
public abstract String[] asStringArray(BaseArgumentRange... ranges);
public static final ArgumentRangeSerializer DEFAULT = new DefaultArgumentRangeSerializer();

public String toString(BaseArgumentRange range) {
RangeType type = range.getType();
String output = "";
switch (type) {
case TEXT_SIZE_RANGE:
output = toString(range.asTextSize());
break;
case TEXT_CHOOSE_RANGE:
output = toString(range.asTextChoose());
break;
case STATE_RANGE:
output = toString(range.asState());
break;
case COLLECTION_SIZE_RANGE:
output = toString(range.asCollectionSize());
break;
case NUMBER_VALUE_RANGE:
output = toString(range.asNumberValue());
break;
case NUMBER_CHOOSE_RANGE:
output = toString(range.asNumberChoose());
break;
case CUSTOM:
output = range.toString();
break;
}
return output;
}

public abstract String toString(CollectionSizeRange<?> range);

public abstract String toString(NumberValueRange range);

public abstract String toString(NumberChooseRange range);

public abstract String toString(StateRange range);

public abstract String toString(TextSizeRange range);

public abstract String toString(TextChooseRange range);

/**
* @param ranges array of complex ranges
* @return array of raw ranges
*/
public abstract String[] asStringArray(BaseArgumentRange... ranges);

}
Loading

0 comments on commit 964d732

Please sign in to comment.