Created
November 14, 2013 19:49
-
-
Save UnquietCode/7473178 to your computer and use it in GitHub Desktop.
Revisions
-
UnquietCode created this gist
Nov 14, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,107 @@ public enum API { @Deprecated Version1, Version2( add(Feature.BLUE_ICONS) ), Version3( parent(Version2), add(Feature.ACTIVITY_FEED) ), Version4( parent(Version3), remove(Feature.BLUE_ICONS) ) ; private final Set<Feature> featureSet = new HashSet<Feature>(); API(FeatureWrapper...features) { // parents first for (FeatureWrapper wrapped : features) { if (wrapped.operation == FeatureWrapper.Operation.PARENT) { featureSet.addAll(wrapped.parent.featureSet); } } // then modifications for (FeatureWrapper wrapped : features) { if (wrapped.operation == FeatureWrapper.Operation.ADD) { featureSet.add(wrapped.feature); } else if (wrapped.operation == FeatureWrapper.Operation.REMOVE) { featureSet.remove(wrapped.feature); } } } boolean isGreaterThan(API other) { return this.ordinal() > other.ordinal(); } boolean isGreaterOrEqualTo(API other) { return this.ordinal() >= other.ordinal(); } boolean isLesserThan(API other) { return this.ordinal() < other.ordinal(); } boolean isLesserOrEqualTo(API other) { return this.ordinal() <= other.ordinal(); } boolean hasFeature(Feature feature) { return featureSet.contains(feature); } boolean hasFeatures(Feature...features) { for (Feature feature : features) { if (!hasFeature(feature)) { return false; } } return true; } // ---------------------------------------------------------------- // private static FeatureWrapper add(Feature feature) { return new FeatureWrapper(feature, FeatureWrapper.Operation.ADD); } private static FeatureWrapper remove(Feature feature) { return new FeatureWrapper(feature, FeatureWrapper.Operation.REMOVE); } private static FeatureWrapper parent(API parent) { return new FeatureWrapper(parent); } private static class FeatureWrapper { final Feature feature; final Operation operation; final API parent; private FeatureWrapper(Feature feature, Operation operation) { this.feature = feature; this.operation = operation; this.parent = null; } private FeatureWrapper(API parent) { this.feature = null; this.operation = Operation.PARENT; this.parent = parent; } enum Operation { ADD, REMOVE, PARENT } } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ public enum Feature { BLUE_ICONS, ACTIVITY_FEED }