Skip to content

Commit

Permalink
FORGE-2017: Supporting selection as Iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 17, 2014
1 parent a1c9993 commit 3b530e3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ui/api/src/main/java/org/jboss/forge/addon/ui/util/Selections.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;

import org.jboss.forge.addon.ui.context.UISelection;
import org.jboss.forge.furnace.util.Lists;

/**
* Possible {@link UISelection} implementations
Expand All @@ -31,6 +32,26 @@ public static <SELECTIONTYPE> UISelection<SELECTIONTYPE> from(SELECTIONTYPE... t
return emptySelection();
}
else
{
if (type.length == 1 && type[0] instanceof Iterable)
{
return new SelectionImpl((Iterable<SELECTIONTYPE>) type[0]);
}
else
{
return new SelectionImpl(type);
}
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <SELECTIONTYPE> UISelection<SELECTIONTYPE> from(Iterable<SELECTIONTYPE> type)
{
if (type == null || Lists.toList(type).isEmpty())
{
return emptySelection();
}
else
{
return new SelectionImpl(type);
}
Expand All @@ -55,6 +76,14 @@ public SelectionImpl(SELECTIONTYPE... type)
selection = Collections.emptyList();
}

public SelectionImpl(Iterable<SELECTIONTYPE> type)
{
if (type != null)
this.selection = Lists.toList(type);
else
selection = Collections.emptyList();
}

@Override
public Iterator<SELECTIONTYPE> iterator()
{
Expand Down

0 comments on commit 3b530e3

Please sign in to comment.