View Javadoc
1   package com.ljs.ootp.extract.html.ootp5.rating;
2   
3   import com.fasterxml.jackson.annotation.JsonCreator;
4   import com.google.common.base.CharMatcher;
5   import com.ljs.ootp.extract.html.rating.OneToOneHundred;
6   import com.ljs.ootp.extract.html.rating.Rating;
7   import com.ljs.ootp.extract.html.rating.Scale;
8   import java.util.Locale;
9   
10  /**
11   *
12   * @author lstephen
13   */
14  public enum PotentialRating {
15      POOR(10), FAIR(30), AVERAGE(50), GOOD(70), BRILLIANT(90);
16  
17      private final Integer value;
18  
19      private PotentialRating(Integer value) {
20          this.value = value;
21      }
22  
23  	@JsonCreator
24      private static PotentialRating valueOfCaseInsensitive(String potential) {
25          return PotentialRating.valueOf(potential.toUpperCase(Locale.ENGLISH));
26      }
27  
28      public static Rating<PotentialRating, RatingScale> from(String s) {
29          return Rating.create(
30              valueOfCaseInsensitive(CharMatcher.WHITESPACE.trimFrom(s)),
31              RatingScale.INSTANCE);
32      }
33  
34      public static RatingScale scale() {
35          return RatingScale.INSTANCE;
36      }
37  
38      public static final class RatingScale implements Scale<PotentialRating> {
39          private static final RatingScale INSTANCE = new RatingScale();
40  
41          private RatingScale() { }
42  
43          @Override
44          public Rating<PotentialRating, RatingScale> parse(String s) {
45              return PotentialRating.from(s);
46          }
47  
48          @Override
49          public Rating<Integer, OneToOneHundred> normalize(
50              PotentialRating value) {
51  
52              return OneToOneHundred.valueOf(value.value);
53          }
54      }
55  
56  }