Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit 429512c

Browse files
committed
Created interfaces for values with extended capabilities
1 parent 9f204c5 commit 429512c

7 files changed

Lines changed: 176 additions & 122 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value;
18+
19+
import clientapi.util.interfaces.Toggleable;
20+
21+
/**
22+
* @author Brady
23+
* @since 9/27/2018
24+
*/
25+
public interface IBooleanValue extends IValue<Boolean>, Toggleable {
26+
27+
@Override
28+
default void setState(boolean state) {
29+
this.setValue(state);
30+
31+
if (this.getState()) {
32+
this.onEnable();
33+
} else {
34+
this.onDisable();
35+
}
36+
}
37+
38+
@Override
39+
default boolean getState() {
40+
return this.getValue();
41+
}
42+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value;
18+
19+
import clientapi.util.interfaces.Cycleable;
20+
import org.apache.commons.lang3.ArrayUtils;
21+
22+
/**
23+
* @author Brady
24+
* @since 9/27/2018
25+
*/
26+
public interface ICycleableValue<T> extends IValue<T>, Cycleable<T> {
27+
28+
@Override
29+
default T current() {
30+
return this.getValue();
31+
}
32+
33+
@Override
34+
default T next() {
35+
T value = peekNext();
36+
this.setValue(value);
37+
return value;
38+
}
39+
40+
@Override
41+
default T last() {
42+
T value = peekLast();
43+
this.setValue(value);
44+
return value;
45+
}
46+
47+
@Override
48+
default T peekNext() {
49+
T[] values = getElements();
50+
int index = ArrayUtils.indexOf(values, getValue());
51+
if (++index >= values.length)
52+
index = 0;
53+
return values[index];
54+
}
55+
56+
@Override
57+
default T peekLast() {
58+
T[] values = getElements();
59+
int index = ArrayUtils.indexOf(values, getValue());
60+
if (--index < 0)
61+
index = values.length - 1;
62+
return values[index];
63+
}
64+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value;
18+
19+
import clientapi.value.type.number.AbstractNumberType;
20+
21+
/**
22+
* @author Brady
23+
* @since 9/27/2018
24+
*/
25+
public interface INumberValue<T extends Number> extends IValue<T> {
26+
27+
/**
28+
* @return The minimum value of the number
29+
*/
30+
T getMinimum();
31+
32+
/**
33+
* @return The maximum value of this number
34+
*/
35+
T getMaximum();
36+
37+
/**
38+
* @return The interval of change for this number value
39+
*/
40+
T getInterval();
41+
42+
/**
43+
* Increments the value of this {@link AbstractNumberType}
44+
* by {@code 1/10th} the range, multiplied by the parameter.
45+
*
46+
* @param multiplier The incrementation multiplier
47+
*/
48+
void increment(float multiplier);
49+
50+
/**
51+
* Decrements the value of this {@link AbstractNumberType}
52+
* by {@code 1/10th} the range, multiplied by the parameter.
53+
*
54+
* @param multiplier The decrementation multiplier
55+
*/
56+
void decrement(float multiplier);
57+
}

src/main/java/clientapi/value/type/BooleanType.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package clientapi.value.type;
1818

19-
import clientapi.util.interfaces.Toggleable;
19+
import clientapi.value.IBooleanValue;
2020
import clientapi.value.Value;
2121
import clientapi.value.annotation.BooleanValue;
2222

@@ -30,25 +30,9 @@
3030
* @author Brady
3131
* @since 1/23/2017
3232
*/
33-
public final class BooleanType extends Value<Boolean> implements Toggleable {
33+
public final class BooleanType extends Value<Boolean> implements IBooleanValue {
3434

3535
public BooleanType(String name, String parent, String id, String description, Object object, Field field) {
3636
super(name, parent, id, description, object, field);
3737
}
38-
39-
@Override
40-
public final void setState(boolean state) {
41-
this.setValue(state);
42-
43-
if (this.getState()) {
44-
this.onEnable();
45-
} else {
46-
this.onDisable();
47-
}
48-
}
49-
50-
@Override
51-
public final boolean getState() {
52-
return super.getValue();
53-
}
5438
}

src/main/java/clientapi/value/type/EnumType.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
package clientapi.value.type;
1818

19-
import clientapi.util.interfaces.Cycleable;
19+
import clientapi.value.ICycleableValue;
2020
import clientapi.value.Value;
2121
import clientapi.value.annotation.EnumValue;
22-
import org.apache.commons.lang3.ArrayUtils;
2322

2423
import java.lang.reflect.Field;
2524

@@ -31,7 +30,7 @@
3130
* @author Brady
3231
* @since 12/1/2017
3332
*/
34-
public final class EnumType<T extends Enum<?>> extends Value<T> implements Cycleable<T> {
33+
public final class EnumType<T extends Enum<?>> extends Value<T> implements ICycleableValue<T> {
3534

3635
private final T[] values;
3736

@@ -40,41 +39,6 @@ public EnumType(String name, String parent, String id, String description, Objec
4039
this.values = enumClass.getEnumConstants();
4140
}
4241

43-
@Override
44-
public final T current() {
45-
return this.getValue();
46-
}
47-
48-
@Override
49-
public final T next() {
50-
T value = peekNext();
51-
this.setValue(value);
52-
return value;
53-
}
54-
55-
@Override
56-
public final T last() {
57-
T value = peekLast();
58-
this.setValue(value);
59-
return value;
60-
}
61-
62-
@Override
63-
public final T peekNext() {
64-
int index = ArrayUtils.indexOf(values, getValue());
65-
if (++index >= values.length)
66-
index = 0;
67-
return values[index];
68-
}
69-
70-
@Override
71-
public final T peekLast() {
72-
int index = ArrayUtils.indexOf(values, getValue());
73-
if (--index < 0)
74-
index = values.length - 1;
75-
return values[index];
76-
}
77-
7842
@Override
7943
public final T[] getElements() {
8044
return this.values;

src/main/java/clientapi/value/type/MultiType.java

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
package clientapi.value.type;
1818

19-
import clientapi.util.ClientAPIUtils;
20-
import clientapi.util.interfaces.Cycleable;
19+
import clientapi.value.ICycleableValue;
2120
import clientapi.value.Value;
22-
import org.apache.commons.lang3.ArrayUtils;
2321

2422
import java.lang.reflect.Field;
2523

@@ -29,7 +27,7 @@
2927
* @author Brady
3028
* @since 2/24/2017
3129
*/
32-
public final class MultiType extends Value<String> implements Cycleable<String> {
30+
public final class MultiType extends Value<String> implements ICycleableValue<String> {
3331

3432
/**
3533
* Different values
@@ -42,46 +40,6 @@ public MultiType(String name, String parent, String id, String description, Obje
4240
this.setValue(values[0]);
4341
}
4442

45-
@Override
46-
public final void setValue(String value) {
47-
super.setValue(ClientAPIUtils.objectFrom(value, values));
48-
}
49-
50-
@Override
51-
public final String current() {
52-
return this.getValue();
53-
}
54-
55-
@Override
56-
public final String next() {
57-
String value = peekNext();
58-
this.setValue(value);
59-
return value;
60-
}
61-
62-
@Override
63-
public final String last() {
64-
String value = peekLast();
65-
this.setValue(value);
66-
return value;
67-
}
68-
69-
@Override
70-
public final String peekNext() {
71-
int index = ArrayUtils.indexOf(values, getValue());
72-
if (++index >= values.length)
73-
index = 0;
74-
return values[index];
75-
}
76-
77-
@Override
78-
public final String peekLast() {
79-
int index = ArrayUtils.indexOf(values, getValue());
80-
if (--index < 0)
81-
index = values.length - 1;
82-
return values[index];
83-
}
84-
8543
@Override
8644
public final String[] getElements() {
8745
return this.values;

0 commit comments

Comments
 (0)