Skip to content

Commit

Permalink
do not hide operation if selection is empty, fix issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkoivanov committed Apr 19, 2016
1 parent 1482b97 commit d7e017e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions sampleModel/src/samplemodel/EachElementVersusTheRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* For a selection of <b>n</b> elements, will return <b>n</b> permutations each starting with
* <b>selection[n]</b> element and followed by the rest of the elements. For example selection
* [1,2,3] produces permutations [[1,2,3],[2,1,3],[3,1,2]]
*
*
*/
public class EachElementVersusTheRest implements OperationInputPermutator
{
Expand All @@ -18,16 +18,24 @@ public List<Object[]> getOperationInputPermutations(Object[] selection)
{

List<Object[]> permutations = new ArrayList<Object[]>();
for (Object o : selection)
// still needs to include one empty selection
if (selection.length == 0)
{
List<Object> permutation = new ArrayList<>();
permutation.add(o);
permutations.add(selection);
}
else
{
for (Object o : selection)
{
List<Object> permutation = new ArrayList<>();
permutation.add(o);

List<Object> rest = new ArrayList<Object>(Arrays.asList(selection));
rest.remove(o);
permutation.addAll(rest);
List<Object> rest = new ArrayList<Object>(Arrays.asList(selection));
rest.remove(o);
permutation.addAll(rest);

permutations.add(permutation.toArray());
permutations.add(permutation.toArray());
}
}

return permutations;
Expand Down

0 comments on commit d7e017e

Please sign in to comment.