Skip to content

Instantly share code, notes, and snippets.

@fge
Created May 9, 2014 14:15
Show Gist options
  • Select an option

  • Save fge/f0b61f7b5e1df73a9f60 to your computer and use it in GitHub Desktop.

Select an option

Save fge/f0b61f7b5e1df73a9f60 to your computer and use it in GitHub Desktop.
@Override
@SuppressWarnings("unchecked")
public void pushAll(final V firstValue, final V... moreValues)
{
// FIXME: hackish :/ Can throw ClassCastException all right
if (firstValue instanceof Iterable
&& moreValues != null
&& moreValues.length == 0) {
pushAll((Iterable<V>) firstValue);
return;
}
final Deque<V> deque = new LinkedList<V>();
// FIXME: null sucks
if (moreValues == null)
deque.push(null);
else
deque.addAll(Arrays.asList(moreValues));
deque.push(firstValue);
pushAll(deque);
}
/**
* Pushes all given elements onto the stack (in the order as given).
*
* @param values the values
*/
@Override
public void pushAll(@Nonnull final Iterable<V> values)
{
final List<V> newStack = Lists.newArrayList(values);
newStack.addAll(stack);
stack = newStack;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment