Skip to content

Commit

Permalink
Pull up into() from LazyIterable to RichIterable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Raab authored and Donald Raab committed Apr 13, 2016
1 parent 8bf091b commit ad7c9c1
Show file tree
Hide file tree
Showing 29 changed files with 219 additions and 15 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTE_DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ New Functionality
* Changed MutableBagIterable.addOccurrences(T item, int occurrences) to return the updated number of occurrences instead of void.
* Implemented Multimap.keySet() to return an unmodifiable SetIterable of keys.
* Implemented MutableMultimap.putAllPairs(Iterable<Pair<K, V>> keyValuePairs).
* Pull up into() from LazyIterable to RichIterable

Optimizations
-------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -1331,6 +1331,13 @@ <P> T detectWithIfNone(
*/
double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? super T> function);

/**
* Adds all the elements in this iterable to the specific target Collection.
*
* @since 8.0
*/
<R extends Collection<T>> R into(R target);

/**
* Converts the collection to a MutableList implementation.
*
Expand Down Expand Up @@ -1740,6 +1747,7 @@ <V, R extends MutableMap<V, T>> R groupByUniqueKey(
* @return a string representation of this RichIterable
* @since 1.0
*/
@Override
String toString();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ final class Immutable<name>ObjectEmptyMap\<V> implements Immutable<name>ObjectMa
return injectedValue;
}

public \<R extends Collection\<V>\> R into(R target)
{
return target;
}

public MutableList\<V> toList()
{
return Lists.mutable.with();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ final class Immutable<name>ObjectHashMap\<V> extends AbstractImmutable<name>Obje
return this.delegate.injectInto(injectedValue, function);
}

public \<R extends Collection\<V>\> R into(R target)
{
return this.delegate.into(target);
}

public MutableList\<V> toList()
{
return this.delegate.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ final class Immutable<name>ObjectSingletonMap\<V> extends AbstractImmutable<name
return function.doubleValueOf(injectedValue, this.value1);
}

public \<R extends Collection\<V>\> R into(R target)
{
return Iterate.addAllTo(this, target);
}

public MutableList\<V> toList()
{
return Lists.mutable.with(this.value1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,11 @@ public class <name>ObjectHashMap\<V> implements Mutable<name>ObjectMap\<V>, Exte
return list;
}

public \<R extends Collection\<V>\> R into(R target)
{
return Iterate.addAllTo(this, target);
}

public MutableList\<V> toSortedList()
{
return this.toList().sortThis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,14 @@ public final class Synchronized<name>ObjectMap\<V>
}
}

public \<R extends Collection\<V>\> R into(R target)
{
synchronized (this.lock)
{
return this.map.into(target);
}
}

public MutableList\<V> toList()
{
synchronized (this.lock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ public final class Unmodifiable<name>ObjectMap\<V>
return this.map.injectInto(injectedValue, function);
}

public \<R extends Collection\<V>\> R into(R target)
{
return this.map.into(target);
}

public MutableList\<V> toList()
{
return this.map.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -475,6 +475,11 @@ public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? su
return procedure.getResult();
}

public <R extends Collection<T>> R into(R target)
{
return Iterate.addAllTo(this, target);
}

public float injectInto(float injectedValue, FloatObjectToFloatFunction<? super T> function)
{
InjectIntoFloatProcedure<T> procedure = new InjectIntoFloatProcedure<T>(injectedValue, function);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -603,6 +603,14 @@ public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? su
}
}

public <R extends Collection<T>> R into(R target)
{
synchronized (this.lock)
{
return this.iterable.into(target);
}
}

public MutableList<T> toList()
{
synchronized (this.lock)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -506,6 +506,11 @@ public <V> ObjectDoubleMap<V> sumByDouble(Function<T, V> groupBy, DoubleFunction
return this.iterable.sumByDouble(groupBy, function);
}

public <R extends Collection<T>> R into(R target)
{
return this.iterable.into(target);
}

public MutableList<T> toList()
{
return this.iterable.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -182,6 +182,11 @@ public RichIterable<Pair<K, V>> keyValuesView()
return this.getDelegate().keyValuesView();
}

public <R extends Collection<V>> R into(R target)
{
return this.getDelegate().into(target);
}

public MutableList<V> toList()
{
return this.getDelegate().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -502,6 +502,14 @@ public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? su
}
}

public <R extends Collection<T>> R into(R target)
{
synchronized (this.lock)
{
return this.delegate.into(target);
}
}

public MutableList<T> toList()
{
synchronized (this.lock)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -581,6 +581,11 @@ public <IV, P> IV injectIntoWith(
return Iterate.injectIntoWith(injectValue, this.getDelegate(), function, parameter);
}

public <R extends Collection<T>> R into(R target)
{
return Iterate.addAllTo(this.getDelegate(), target);
}

public MutableList<T> toList()
{
return Lists.mutable.withAll(this.getDelegate());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -245,6 +245,19 @@ public <P> boolean anySatisfyWith(
}
}

public <R extends Collection<T>> R into(R target)
{
this.acquireReadLock();
try
{
return this.getDelegate().into(target);
}
finally
{
this.unlockReadLock();
}
}

public MutableList<T> toList()
{
this.acquireReadLock();
Expand Down Expand Up @@ -1566,6 +1579,11 @@ public <P> boolean anySatisfyWith(
return this.delegate.anySatisfyWith(predicate, parameter);
}

public <R extends Collection<T>> R into(R target)
{
return this.delegate.into(target);
}

public MutableList<T> toList()
{
return this.delegate.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -620,6 +620,11 @@ public <IV, P> IV injectIntoWith(
return this.getMutableCollection().injectIntoWith(injectValue, function, parameter);
}

public <R extends Collection<T>> R into(R target)
{
return this.getMutableCollection().into(target);
}

public MutableList<T> toList()
{
return this.getMutableCollection().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -457,6 +457,11 @@ public LazyIterable<V> asLazy()
return this.getMutableMap().asLazy();
}

public <R extends Collection<V>> R into(R target)
{
return this.getMutableMap().into(target);
}

public MutableList<V> toList()
{
return this.getMutableMap().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -472,6 +472,11 @@ public LazyIterable<V> asLazy()
return this.getMutableSortedMap().asLazy();
}

public <R extends Collection<V>> R into(R target)
{
return this.getMutableSortedMap().into(target);
}

public MutableList<V> toList()
{
return this.getMutableSortedMap().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -539,6 +539,11 @@ public float injectInto(float injectedValue, FloatObjectToFloatFunction<? super
return this.delegate.asReversed().injectInto(injectedValue, floatObjectToFloatFunction);
}

public <R extends Collection<T>> R into(R target)
{
return this.delegate.asReversed().into(target);
}

public MutableList<T> toList()
{
return this.delegate.asReversed().toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,11 @@ public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
this.delegate.asReversed().forEachWithIndex(objectIntProcedure);
}

public <R extends Collection<T>> R into(R target)
{
return this.delegate.asReversed().into(target);
}

public MutableList<T> toList()
{
return this.delegate.asReversed().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -699,6 +699,14 @@ public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? su
}
}

public <R extends Collection<T>> R into(R target)
{
synchronized (this.lock)
{
return this.delegate.into(target);
}
}

public MutableList<T> toList()
{
synchronized (this.lock)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -447,6 +447,11 @@ public double injectInto(double injectedValue, DoubleObjectToDoubleFunction<? su
return this.mutableStack.injectInto(injectedValue, doubleObjectToDoubleFunction);
}

public <R extends Collection<T>> R into(R target)
{
return this.mutableStack.into(target);
}

public MutableList<T> toList()
{
return this.mutableStack.toList();
Expand Down
Loading

0 comments on commit ad7c9c1

Please sign in to comment.