This repository has been archived by the owner on Jan 4, 2018. It is now read-only.
forked from square/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#234 from square/ray/history-filter-220
Ray/history filter 220
- Loading branch information
Showing
7 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package flow; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
/** | ||
* An object to which gets a chance to scrub the current {@link History} before | ||
* it is persisted. | ||
*/ | ||
public interface HistoryFilter { | ||
@NonNull History scrubHistory(@NonNull History history); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package flow; | ||
|
||
import android.support.annotation.NonNull; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* Default implementation of {@link HistoryFilter}, enforces the contract | ||
* documented on {@link NotPersistent}. | ||
*/ | ||
class NotPersistentHistoryFilter implements HistoryFilter { | ||
@NonNull @Override public History scrubHistory(@NonNull History history) { | ||
History.Builder builder = History.emptyBuilder(); | ||
|
||
final Iterator<Object> keys = history.reverseIterator(); | ||
while (keys.hasNext()) { | ||
Object key = keys.next(); | ||
if (!key.getClass().isAnnotationPresent(NotPersistent.class)) { | ||
builder.push(key); | ||
} | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters