Skip to content

Commit

Permalink
Updated UICompleter method signature and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 30, 2013
1 parent 76ab72f commit 38a5cc2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
16 changes: 10 additions & 6 deletions ui/api/src/main/java/org/jboss/forge/ui/UICompleter.java
Expand Up @@ -6,15 +6,19 @@
*/
package org.jboss.forge.ui;

import java.util.List;

/**
* @param VALUETYPE The value type to be provided by completion.
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface UICompleter<VALUETYPE>
public interface UICompleter<T>
{
// FIXME this needs to be thought out, before or after validation?
// Should this take a String or the actual VALUETYPE instead?
List<VALUETYPE> getCompletionProposals(String value);
/**
* Get completion proposals for the provided {@link UIInput} and unconverted partial {@link String} value.
*
* @param input The {@link UIInput} that provided this {@link UICompleter} instance, via
* {@link UIInput#getCompleter()}.
* @param value The user input value requiring completion, or null, if no value yet exists. These values will undergo
* conversion to fit the type required by the corresponding {@link UIInput}.
*/
Iterable<String> getCompletionProposals(UIInput<T> input, String value);
}
Expand Up @@ -6,10 +6,10 @@
*/
package org.jboss.forge.ui.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

import org.jboss.forge.ui.UICompleter;
import org.jboss.forge.ui.UIInput;

/**
* A {@link UICompleter} that always returns zero proposals.
Expand All @@ -20,8 +20,8 @@
public class NoopCompleter implements UICompleter
{
@Override
public List getCompletionProposals(String value)
public Iterable getCompletionProposals(UIInput input, String value)
{
return new ArrayList();
return Collections.emptyList();
}
}
Expand Up @@ -8,7 +8,7 @@
package org.jboss.forge.ui.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Iterator;

import javax.inject.Inject;

Expand Down Expand Up @@ -91,14 +91,20 @@ public void testCompleter()
Assert.assertEquals(firstName, firstName.setCompleter(new UICompleter<String>()
{
@Override
public List<String> getCompletionProposals(String value)
public Iterable<String> getCompletionProposals(UIInput<String> input, String value)
{
return Arrays.asList("foo", "bar", "baz");
return Arrays.asList("one", "two", "three");
}
}));
Assert.assertNotEquals(originalCompleter, firstName.getCompleter());
Assert.assertEquals(3, firstName.getCompleter().getCompletionProposals(null).size());
Assert.assertEquals(0, originalCompleter.getCompletionProposals(null).size());

Iterator<String> iterator = firstName.getCompleter().getCompletionProposals(null, null).iterator();
Assert.assertEquals("one", iterator.next());
Assert.assertEquals("two", iterator.next());
Assert.assertEquals("three", iterator.next());
Assert.assertFalse(iterator.hasNext());

Assert.assertFalse(originalCompleter.getCompletionProposals(null, null).iterator().hasNext());
}

@Test
Expand Down

0 comments on commit 38a5cc2

Please sign in to comment.