Skip to content

Commit

Permalink
Swap the names of framesFromTop and framesFromBottom so they're c…
Browse files Browse the repository at this point in the history
…orrect.

I added `framesFromTop` and `framesFromBottom` methods in 03d9578,
but the names of the methods were backwards.

Follow-up for fix for issue square#261.
  • Loading branch information
Zach Klippenstein committed Jul 7, 2017
1 parent 821b495 commit b94f35d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
6 changes: 3 additions & 3 deletions flow/src/main/java/flow/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void set(@NonNull final Object newTopKey) {
int count = 0;
// Search backward to see if we already have newTop on the stack
Object preservedInstance = null;
for (Object entry : history.framesFromTop()) {
for (Object entry : history.framesFromBottom()) {
// If we find newTop on the stack, pop back to it.
if (entry.equals(newTopKey)) {
for (int i = 0; i < history.size() - count; i++) {
Expand Down Expand Up @@ -319,8 +319,8 @@ private void move(PendingTraversal pendingTraversal) {
}

private static History preserveEquivalentPrefix(History current, History proposed) {
Iterator<Object> oldIt = current.framesFromTop().iterator();
Iterator<Object> newIt = proposed.framesFromTop().iterator();
Iterator<Object> oldIt = current.framesFromBottom().iterator();
Iterator<Object> newIt = proposed.framesFromBottom().iterator();

History.Builder preserving = current.buildUpon().clear();

Expand Down
32 changes: 16 additions & 16 deletions flow/src/main/java/flow/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* Describes the history of a {@link Flow} at a specific point in time.
*
* <p><em>Note: use of this class as an {@link Iterable} is deprecated. Use {@link
* #framesFromBottom()}
* and {@link #framesFromTop()} instead.</em>
* #framesFromTop()}
* and {@link #framesFromBottom()} instead.</em>
*/
public final class History implements Iterable<Object> {

Expand All @@ -50,11 +50,11 @@ public final class History implements Iterable<Object> {
return emptyBuilder().push(key).build();
}

private static <T> Iterator<T> iterateFromTop(List<Object> history) {
private static <T> Iterator<T> iterateFromBottom(List<Object> history) {
return new ReadStateIterator<>(history.iterator());
}

private static <T> Iterator<T> iterateFromBottom(List<Object> history) {
private static <T> Iterator<T> iterateFromTop(List<Object> history) {
return new ReadStateIterator<>(new ReverseIterator<>(history));
}

Expand All @@ -63,22 +63,22 @@ private History(List<Object> history) {
this.history = history;
}

@NonNull public <T> Iterable<T> framesFromTop() {
@NonNull public <T> Iterable<T> framesFromBottom() {
return new HistoryIterable<>(history, true);
}

@NonNull public <T> Iterable<T> framesFromBottom() {
@NonNull public <T> Iterable<T> framesFromTop() {
return new HistoryIterable<>(history, false);
}

/** @deprecated Use {@link #framesFromTop()} instead. */
/** @deprecated Use {@link #framesFromBottom()} instead. */
@Deprecated @NonNull public <T> Iterator<T> reverseIterator() {
return iterateFromTop(history);
return iterateFromBottom(history);
}

/** @deprecated Use {@link #framesFromBottom()} instead. */
/** @deprecated Use {@link #framesFromTop()} instead. */
@Deprecated @NonNull @Override public Iterator<Object> iterator() {
return iterateFromBottom(history);
return iterateFromTop(history);
}

public int size() {
Expand Down Expand Up @@ -218,18 +218,18 @@ public Object pop() {

private static class HistoryIterable<T> implements Iterable<T> {
private final List<Object> history;
private final boolean fromTop;
private final boolean fromBottom;

HistoryIterable(List<Object> history, boolean fromTop) {
HistoryIterable(List<Object> history, boolean fromBottom) {
this.history = history;
this.fromTop = fromTop;
this.fromBottom = fromBottom;
}

@NonNull @Override public Iterator<T> iterator() {
if (fromTop) {
return iterateFromTop(history);
} else {
if (fromBottom) {
return iterateFromBottom(history);
} else {
return iterateFromTop(history);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions flow/src/main/java/flow/InternalLifecycleIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public InternalLifecycleIntegration() {
static void addHistoryToIntent(Intent intent, History history, KeyParceler parceler) {
Bundle bundle = new Bundle();
ArrayList<Parcelable> parcelables = new ArrayList<>(history.size());
for (Object key : history.framesFromTop()) {
for (Object key : history.framesFromBottom()) {
parcelables.add(State.empty(key).toBundle(parceler));
}
bundle.putParcelableArrayList(PERSISTENCE_KEY, parcelables);
Expand Down Expand Up @@ -204,7 +204,7 @@ private static History selectHistory(Intent intent, History saved, History defau
private static void save(Bundle bundle, KeyParceler parceler, History history,
KeyManager keyManager) {
ArrayList<Parcelable> parcelables = new ArrayList<>(history.size());
for (Object key : history.framesFromTop()) {
for (Object key : history.framesFromBottom()) {
if (!key.getClass().isAnnotationPresent(NotPersistent.class)) {
parcelables.add(keyManager.getState(key).toBundle(parceler));
}
Expand Down
2 changes: 1 addition & 1 deletion flow/src/main/java/flow/NotPersistentHistoryFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NotPersistentHistoryFilter implements HistoryFilter {
@NonNull @Override public History scrubHistory(@NonNull History history) {
History.Builder builder = History.emptyBuilder();

for (Object key : history.framesFromTop()) {
for (Object key : history.framesFromBottom()) {
if (!key.getClass().isAnnotationPresent(NotPersistent.class)) {
builder.push(key);
}
Expand Down
6 changes: 3 additions & 3 deletions flow/src/test/java/flow/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class Ourrobouros implements Dispatcher {
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback onComplete) {
assertThat(firstHistory).hasSameSizeAs(flow.getHistory());
Iterator<Object> original = firstHistory.framesFromBottom().iterator();
for (Object o : flow.getHistory().framesFromBottom()) {
Iterator<Object> original = firstHistory.framesFromTop().iterator();
for (Object o : flow.getHistory().framesFromTop()) {
assertThat(o).isEqualTo(original.next());
}
onComplete.onTraversalCompleted();
Expand Down Expand Up @@ -460,7 +460,7 @@ static class Picky {
@NonNull @Override public History scrubHistory(@NonNull History history) {
History.Builder builder = History.emptyBuilder();

for (Object key : history.framesFromTop()) {
for (Object key : history.framesFromBottom()) {
if (!key.equals(able)) {
builder.push(key);
}
Expand Down
18 changes: 12 additions & 6 deletions flow/src/test/java/flow/HistoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ public class HistoryTest {
@Test public void framesFromBottom() {
List<Object> paths = new ArrayList<>(Arrays.<Object>asList(ABLE, BAKER, CHARLIE));
History history = History.emptyBuilder().pushAll(paths).build();
for (Object o : history.framesFromBottom()) {
assertThat(o).isSameAs(paths.remove(paths.size() - 1));
}
Iterator<Object> iterator = history.framesFromBottom().iterator();

assertThat(iterator.next()).isSameAs(ABLE);
assertThat(iterator.next()).isSameAs(BAKER);
assertThat(iterator.next()).isSameAs(CHARLIE);
assertThat(iterator.hasNext()).isFalse();
}

@Test public void reverseIterator() {
Expand All @@ -125,9 +128,12 @@ public class HistoryTest {
@Test public void framesFromTop() {
List<Object> paths = new ArrayList<>(Arrays.<Object>asList(ABLE, BAKER, CHARLIE));
History history = History.emptyBuilder().pushAll(paths).build();
for (Object o : history.framesFromTop()) {
assertThat(o).isSameAs(paths.remove(0));
}
Iterator<Object> iterator = history.framesFromTop().iterator();

assertThat(iterator.next()).isSameAs(CHARLIE);
assertThat(iterator.next()).isSameAs(BAKER);
assertThat(iterator.next()).isSameAs(ABLE);
assertThat(iterator.hasNext()).isFalse();
}

@Test public void emptyBuilderPeekIsNullable() {
Expand Down
2 changes: 1 addition & 1 deletion flow/src/test/java/flow/ReentranceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static class Error extends TestKey {

private void verifyHistory(History history, Object... keys) {
List<Object> actualKeys = new ArrayList<>(history.size());
for (Object entry : history.framesFromBottom()) {
for (Object entry : history.framesFromTop()) {
actualKeys.add(entry);
}
assertThat(actualKeys).containsExactly(keys);
Expand Down

0 comments on commit b94f35d

Please sign in to comment.