Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 109 #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rdipippo
Copy link

Literals can now be case insensitive, which can be specified with a flag in LiteralArgumentBuilder.

if the flag is true, the literal will be put into the literals hash in CommandNode with its key set to all lower case, and it will be gotten from the hash with a lowercased key.

When CommandNode.parse is called, it will check the flag and do a case insensitive check if necessary.

@@ -9,6 +9,8 @@
public class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumentBuilder<S>> {
private final String literal;

private boolean isCaseInsensitive = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be final. Also rename the variable to ignoreCase as that is the convention.

@@ -9,6 +9,8 @@
public class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumentBuilder<S>> {
private final String literal;

private boolean isCaseInsensitive = false;

protected LiteralArgumentBuilder(final String literal) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the additional ignoreCase parameter to the constructor.

Then create the method public static <S> LiteralArgumentBuilder<S> literal(final String name, final boolean ignoreCase) {

Then modify literal(String) to call the created method with false so that old code is still compatible.

@@ -26,9 +28,16 @@ public String getLiteral() {
return literal;
}

public boolean isCaseInsensitive() { return isCaseInsensitive; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to ignoresCase()

@@ -26,9 +28,16 @@ public String getLiteral() {
return literal;
}

public boolean isCaseInsensitive() { return isCaseInsensitive; }

public LiteralArgumentBuilder<S> caseInsensitive(boolean isCaseInsensitive) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be removed as ignoreCase should be final.

@@ -23,11 +23,14 @@
public class LiteralCommandNode<S> extends CommandNode<S> {
private final String literal;
private final String literalLowerCase;
private boolean isCaseInsensitive = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be final, also rename to ignoreCase as that is convention

@@ -39,6 +42,12 @@ public String getName() {
return literal;
}

public boolean isCaseInsensitive() { return isCaseInsensitive; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to ignoresCase()

@@ -39,6 +42,12 @@ public String getName() {
return literal;
}

public boolean isCaseInsensitive() { return isCaseInsensitive; }

public void caseInsensitive(boolean isCaseInsensitive) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method, nodes should never be able to be modified after they have been created, otherwise it is possible to violate the guarantees stipulated in CommandDispatcher#getPath() and CommandDispatcher#findNode()

assertThat(subject.execute(inputWithOffset("/foo", 1), source), is(42));
verify(command).run(any(CommandContext.class));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional tests for using ignoreCase as a command argument should be added. Currently this only these tests only test the base node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants