mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-26 19:23:19 +01:00
Squashed History
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open WhisperSystems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class IterablePair <T1, T2> implements Iterable<IterablePair.Pair<T1,T2>> {
|
||||
private final List<T1> first;
|
||||
private final List<T2> second;
|
||||
|
||||
public IterablePair(List<T1> first, List<T2> second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Pair<T1, T2>> iterator(){
|
||||
return new ParallelIterator<>( first.iterator(), second.iterator() );
|
||||
}
|
||||
|
||||
public static class Pair<T1, T2> {
|
||||
private final T1 v1;
|
||||
private final T2 v2;
|
||||
|
||||
Pair(T1 v1, T2 v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
}
|
||||
|
||||
public T1 first(){
|
||||
return v1;
|
||||
}
|
||||
|
||||
public T2 second(){
|
||||
return v2;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ParallelIterator <T1, T2> implements Iterator<Pair<T1, T2>> {
|
||||
|
||||
private final Iterator<T1> it1;
|
||||
private final Iterator<T2> it2;
|
||||
|
||||
public ParallelIterator(Iterator<T1> it1, Iterator<T2> it2) {
|
||||
this.it1 = it1; this.it2 = it2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() { return it1.hasNext() && it2.hasNext(); }
|
||||
|
||||
@Override
|
||||
public Pair<T1, T2> next() {
|
||||
return new Pair<>(it1.next(), it2.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(){
|
||||
it1.remove();
|
||||
it2.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user