diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:28:15 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:28:15 -0500 |
| commit | f3814a84f8471684cd483347db4fb7b107c2e635 (patch) | |
| tree | 7ed1061ee69ef50cd1494cfacc866b271b8d1163 /base | |
| parent | a2c7425458f645802a352abc4783e0afc73dba13 (diff) | |
Rename interfaces to match Java style
Rename several interfaces that were in the style IWhatever, which Java
doesn't use
Diffstat (limited to 'base')
13 files changed, 131 insertions, 131 deletions
diff --git a/base/src/main/java/bjc/utils/components/ComponentDescription.java b/base/src/main/java/bjc/utils/components/ComponentDescription.java index 189ef90..2feed8d 100644 --- a/base/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/base/src/main/java/bjc/utils/components/ComponentDescription.java @@ -5,7 +5,7 @@ package bjc.utils.components; * * @author ben */ -public class ComponentDescription implements IDescribedComponent { +public class ComponentDescription implements DescribedComponent { /* Check arguments are good. */ @SuppressWarnings("unused") private static void sanityCheckArgs(final String name, final String author, @@ -58,7 +58,7 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getAuthor() { if (author == null) { - return IDescribedComponent.super.getAuthor(); + return DescribedComponent.super.getAuthor(); } return author; @@ -67,7 +67,7 @@ public class ComponentDescription implements IDescribedComponent { @Override public String getDescription() { if (description == null) { - return IDescribedComponent.super.getDescription(); + return DescribedComponent.super.getDescription(); } return description; diff --git a/base/src/main/java/bjc/utils/components/IComponentRepository.java b/base/src/main/java/bjc/utils/components/ComponentRepository.java index 7a40541..120edc8 100644 --- a/base/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/base/src/main/java/bjc/utils/components/ComponentRepository.java @@ -5,14 +5,14 @@ import bjc.funcdata.MapEx; /** * A collection of implementations of a particular type of - * {@link IDescribedComponent}. + * {@link DescribedComponent}. * * @author ben * * @param <ComponentType> * The type of components contained in this repository. */ -public interface IComponentRepository<ComponentType extends IDescribedComponent> { +public interface ComponentRepository<ComponentType extends DescribedComponent> { /** * Get all of the components this repository knows about. * diff --git a/base/src/main/java/bjc/utils/components/IDescribedComponent.java b/base/src/main/java/bjc/utils/components/DescribedComponent.java index ae3e06c..dcbaf59 100644 --- a/base/src/main/java/bjc/utils/components/IDescribedComponent.java +++ b/base/src/main/java/bjc/utils/components/DescribedComponent.java @@ -7,7 +7,7 @@ package bjc.utils.components; * @author ben * */ -public interface IDescribedComponent extends Comparable<IDescribedComponent> { +public interface DescribedComponent extends Comparable<DescribedComponent> { /** * Get the author of this component. * @@ -52,7 +52,7 @@ public interface IDescribedComponent extends Comparable<IDescribedComponent> { } @Override - default int compareTo(final IDescribedComponent o) { + default int compareTo(final DescribedComponent o) { int res = getName().compareTo(o.getName()); if (res == 0) { diff --git a/base/src/main/java/bjc/utils/components/FileComponentRepository.java b/base/src/main/java/bjc/utils/components/FileComponentRepository.java index fa98d03..e0e929f 100644 --- a/base/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/base/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -24,8 +24,8 @@ import bjc.utils.funcutils.FileUtils; * @param <ComponentType> * The type of component being read in. */ -public class FileComponentRepository<ComponentType extends IDescribedComponent> - implements IComponentRepository<ComponentType> { +public class FileComponentRepository<ComponentType extends DescribedComponent> + implements ComponentRepository<ComponentType> { /* The logger to use for storing data about this class. */ private static final Logger CLASS_LOGGER = Logger.getLogger("FileComponentRepository"); diff --git a/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java index 2e11616..f83c293 100644 --- a/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java +++ b/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java @@ -10,8 +10,8 @@ import bjc.funcdata.MapEx; * @param <ComponentType> * The type of component stored in the repository. */ -public class MemoryComponentRepository<ComponentType extends IDescribedComponent> - implements IComponentRepository<ComponentType> { +public class MemoryComponentRepository<ComponentType extends DescribedComponent> + implements ComponentRepository<ComponentType> { private final MapEx<String, ComponentType> repo; private final String source; diff --git a/base/src/main/java/bjc/utils/funcutils/IBuilder.java b/base/src/main/java/bjc/utils/funcutils/Builder.java index b1a2020..72c045d 100644 --- a/base/src/main/java/bjc/utils/funcutils/IBuilder.java +++ b/base/src/main/java/bjc/utils/funcutils/Builder.java @@ -8,7 +8,7 @@ package bjc.utils.funcutils; * @param <E> * The type of object being built. */ -public interface IBuilder<E> { +public interface Builder<E> { /** * Build the object this builder is building. * diff --git a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java b/base/src/main/java/bjc/utils/parserutils/Precedent.java index eb164b3..33b032c 100644 --- a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java +++ b/base/src/main/java/bjc/utils/parserutils/Precedent.java @@ -7,7 +7,7 @@ package bjc.utils.parserutils; * */ @FunctionalInterface -public interface IPrecedent { +public interface Precedent { /** * Create a new object with set precedence * @@ -15,7 +15,7 @@ public interface IPrecedent { * The precedence of the object to handle * @return A new object with set precedence */ - public static IPrecedent newSimplePrecedent(final int precedence) { + public static Precedent newSimplePrecedent(final int precedence) { return () -> precedence; } diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index f73c315..f0475ff 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -25,7 +25,7 @@ public class ShuntingYard<TokenType> { * @author ben * */ - public static enum Operator implements IPrecedent { + public static enum Operator implements Precedent { /** * Represents addition. */ @@ -59,7 +59,7 @@ public class ShuntingYard<TokenType> { /* * Holds all the shuntable operations. */ - private MapEx<String, IPrecedent> operators; + private MapEx<String, Precedent> operators; /** * Create a new shunting yard with a default set of operators. @@ -95,7 +95,7 @@ public class ShuntingYard<TokenType> { /* * Create the precedence marker */ - final IPrecedent prec = IPrecedent.newSimplePrecedent(precedence); + final Precedent prec = Precedent.newSimplePrecedent(precedence); this.addOp(operator, prec); } @@ -109,7 +109,7 @@ public class ShuntingYard<TokenType> { * @param precedence * The precedence of the operator. */ - public void addOp(final String operator, final IPrecedent precedence) { + public void addOp(final String operator, final Precedent precedence) { /* * Complain about trying to add an incorrect operator */ diff --git a/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java b/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java index 5a214d3..e370fa0 100644 --- a/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/FunctionalPatternMatcher.java @@ -11,7 +11,7 @@ import bjc.functypes.*; * @param <InputType> The type to match against. */ public class FunctionalPatternMatcher<ReturnType, InputType> - implements IPatternMatcher<ReturnType, InputType> { + implements PatternMatcher<ReturnType, InputType> { private final ThrowFunction<InputType, ReturnType, NonExhaustiveMatch> matcher; diff --git a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java b/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java deleted file mode 100644 index b688a47..0000000 --- a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java +++ /dev/null @@ -1,85 +0,0 @@ -package bjc.utils.patterns; - -import java.util.function.*; - -import bjc.functypes.*; - -/** - * Represents a pattern matcher against a series of patterns. - * - * @author Ben Culkin - * - * @param <ReturnType> The type returned from matching the patterns. - * @param <InputType> The type to match against. - */ -@FunctionalInterface -public interface IPatternMatcher<ReturnType, InputType> { - /** - * Match an input object against a set of patterns. - * - * @param input The object to match against. - * - * @return The result of matching against the object. - * - * @throws NonExhaustiveMatch If none of the patterns in this set match - */ - ReturnType matchFor(InputType input) throws NonExhaustiveMatch; - - /** - * Create a pattern matcher against a static set of patterns. - * - * @param <RetType> The type returned from matching the patterns. - * @param <InpType> The type to match against. - * - * @param patterns The set of patterns to match on. - * - * @return A pattern matcher which matches on the given patterns. - */ - @SafeVarargs - static <RetType, InpType> IPatternMatcher<RetType, InpType> matchingOn( - ComplexPattern<RetType, ?, InpType>... patterns) { - return new PatternMatcher<>(patterns); - } - - /** - * Create a pattern matcher from a handler function. - * - * @param <RetType> The type returned by the matcher. - * @param <InpType> The type to match against. - * - * @param handler The handler function. - * - * @return A pattern matcher defined by the given handler. - */ - static <RetType, InpType> IPatternMatcher<RetType, InpType> from( - ThrowFunction<InpType, RetType, NonExhaustiveMatch> handler) { - return new FunctionalPatternMatcher<>(handler); - } - - /** - * Create a pattern matcher which applies a transform to its input. - * - * @param <NewInput> The new input type to use. - * @param transformer The function to convert from the new input to the old input. - * - * @return A pattern matcher which takes values of the new type instead. - */ - default <NewInput> IPatternMatcher<ReturnType, NewInput> transformInput( - Function<NewInput, InputType> transformer) { - return from(inp -> matchFor(transformer.apply(inp))); - } - - /** - * Create a pattern matcher which applies a transform to its output. - * - * @param <NewOutput> The new output type to use. - * - * @param transformer The function to convert from the new output to the old output. - * - * @return A pattern matcher which takes values of the new type instead. - */ - default <NewOutput> IPatternMatcher<NewOutput, InputType> transformOutput( - Function<ReturnType, NewOutput> transformer) { - return from(inp -> transformer.apply(matchFor(inp))); - } -}
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java index 17de37a..28e9cd7 100644 --- a/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/MutablePatternMatcher.java @@ -16,7 +16,7 @@ import bjc.data.*; * @param <InputType> The type of the input to match against. */ public class MutablePatternMatcher<ReturnType, InputType> - implements IPatternMatcher<ReturnType, InputType> { + implements PatternMatcher<ReturnType, InputType> { private final List<ComplexPattern<ReturnType, Object, InputType>> patterns; /** diff --git a/base/src/main/java/bjc/utils/patterns/PatternMatcher.java b/base/src/main/java/bjc/utils/patterns/PatternMatcher.java index f144d36..40bf42b 100644 --- a/base/src/main/java/bjc/utils/patterns/PatternMatcher.java +++ b/base/src/main/java/bjc/utils/patterns/PatternMatcher.java @@ -1,41 +1,85 @@ package bjc.utils.patterns; -import bjc.data.*; +import java.util.function.*; + +import bjc.functypes.*; /** - * Implements pattern-matching (of a sort) against a collection of patterns. + * Represents a pattern matcher against a series of patterns. * * @author Ben Culkin - * - * @param <ReturnType> The type returned by the pattern. + * + * @param <ReturnType> The type returned from matching the patterns. + * @param <InputType> The type to match against. */ -public class PatternMatcher<ReturnType, InputType> - implements IPatternMatcher<ReturnType, InputType> { - private final ComplexPattern<ReturnType, Object, InputType>[] patterns; +@FunctionalInterface +public interface PatternMatcher<ReturnType, InputType> { + /** + * Match an input object against a set of patterns. + * + * @param input The object to match against. + * + * @return The result of matching against the object. + * + * @throws NonExhaustiveMatch If none of the patterns in this set match + */ + ReturnType matchFor(InputType input) throws NonExhaustiveMatch; /** - * Create a new pattern matcher. + * Create a pattern matcher against a static set of patterns. * - * @param patterns The set of patterns to match against. + * @param <RetType> The type returned from matching the patterns. + * @param <InpType> The type to match against. + * + * @param patterns The set of patterns to match on. + * + * @return A pattern matcher which matches on the given patterns. */ - @SuppressWarnings("unchecked") @SafeVarargs - public PatternMatcher(ComplexPattern<ReturnType, ?, InputType>...patterns) { - // Note: this may seem a somewhat questionable cast, but because we never - // actually do anything with the value who has a type matching the second - // parameter, this should be safe - this.patterns = (ComplexPattern<ReturnType, Object, InputType>[]) patterns; + static <RetType, InpType> PatternMatcher<RetType, InpType> matchingOn( + ComplexPattern<RetType, ?, InpType>... patterns) { + return new SimplePatternMatcher<>(patterns); + } + + /** + * Create a pattern matcher from a handler function. + * + * @param <RetType> The type returned by the matcher. + * @param <InpType> The type to match against. + * + * @param handler The handler function. + * + * @return A pattern matcher defined by the given handler. + */ + static <RetType, InpType> PatternMatcher<RetType, InpType> from( + ThrowFunction<InpType, RetType, NonExhaustiveMatch> handler) { + return new FunctionalPatternMatcher<>(handler); + } + + /** + * Create a pattern matcher which applies a transform to its input. + * + * @param <NewInput> The new input type to use. + * @param transformer The function to convert from the new input to the old input. + * + * @return A pattern matcher which takes values of the new type instead. + */ + default <NewInput> PatternMatcher<ReturnType, NewInput> transformInput( + Function<NewInput, InputType> transformer) { + return from(inp -> matchFor(transformer.apply(inp))); } - @Override - public ReturnType matchFor(InputType input) throws NonExhaustiveMatch { - for (ComplexPattern<ReturnType, Object, InputType> pattern : patterns) { - Pair<Boolean, Object> matches = pattern.matches(input); - if (matches.getLeft()) { - pattern.apply(input, matches.getRight()); - } - } - - throw new NonExhaustiveMatch("Non-exhaustive match against " + input); + /** + * Create a pattern matcher which applies a transform to its output. + * + * @param <NewOutput> The new output type to use. + * + * @param transformer The function to convert from the new output to the old output. + * + * @return A pattern matcher which takes values of the new type instead. + */ + default <NewOutput> PatternMatcher<NewOutput, InputType> transformOutput( + Function<ReturnType, NewOutput> transformer) { + return from(inp -> transformer.apply(matchFor(inp))); } -} +}
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java new file mode 100644 index 0000000..fea947a --- /dev/null +++ b/base/src/main/java/bjc/utils/patterns/SimplePatternMatcher.java @@ -0,0 +1,41 @@ +package bjc.utils.patterns; + +import bjc.data.*; + +/** + * Implements pattern-matching (of a sort) against a collection of patterns. + * + * @author Ben Culkin + * + * @param <ReturnType> The type returned by the pattern. + */ +public class SimplePatternMatcher<ReturnType, InputType> + implements PatternMatcher<ReturnType, InputType> { + private final ComplexPattern<ReturnType, Object, InputType>[] patterns; + + /** + * Create a new pattern matcher. + * + * @param patterns The set of patterns to match against. + */ + @SuppressWarnings("unchecked") + @SafeVarargs + public SimplePatternMatcher(ComplexPattern<ReturnType, ?, InputType>...patterns) { + // Note: this may seem a somewhat questionable cast, but because we never + // actually do anything with the value who has a type matching the second + // parameter, this should be safe + this.patterns = (ComplexPattern<ReturnType, Object, InputType>[]) patterns; + } + + @Override + public ReturnType matchFor(InputType input) throws NonExhaustiveMatch { + for (ComplexPattern<ReturnType, Object, InputType> pattern : patterns) { + Pair<Boolean, Object> matches = pattern.matches(input); + if (matches.getLeft()) { + pattern.apply(input, matches.getRight()); + } + } + + throw new NonExhaustiveMatch("Non-exhaustive match against " + input); + } +} |
