Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.goda.chronic.repeaters;
  
  
  import java.util.HashMap;
  import java.util.Map;
  
  
  public abstract class RepeaterUnit extends Repeater<Object> {
     private static final String YEAR_PATTERN = "^years?$";
     private static final String SEASON_PATTERN = "^seasons?$";
     private static final String MONTH_PATTERN = "^months?$";
     private static final String FORTNIGHT_PATTERN = "^fortnights?$";
     private static final String WEEK_PATTERN = "^weeks?$";
     private static final String WEEKEND_PATTERN = "^weekends?$";
     private static final String DAY_PATTERN = "^days?$";
     private static final String HOUR_PATTERN = "^hours?$";
     private static final String MINUTE_PATTERN = "^minutes?$";
     private static final String SECOND_PATTERN = "^seconds?$";
     private static final String HOUR_ABBRV_PATTERN = "^hr.?$";
     private static final String MINUTE_ABBRV_PATTERN = "^min.?$";
     
     
     public RepeaterUnit() {
         super(null);
     }
 
     public static RepeaterUnit scan(Token token) {
         try {
             Map<StringRepeaterUnit.UnitNamescanner = new HashMap<StringRepeaterUnit.UnitName>();
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             scanner.put(...);
             
             
             for (String scannerItem : scanner.keySet()) {
                 if (token.getWord()
                              .matches(scannerItem)) {
                     
                     RepeaterUnit.UnitName unitNameEnum = scanner.get(scannerItem);
                     return unitNameEnum.create();
                 }
             }
 
             return null;
         } catch (Throwable t) {
             throw new RuntimeException("Failed to create RepeaterUnit."t);
         }
     }
     public static enum UnitName {
 
         DAY, FORTNIGHT, HOUR, MINUTE, MONTH, SEASON, SECOND, WEEK, WEEKEND, YEAR;
 
         public RepeaterUnit create() {
             switch (this) {
             case :
                 return new RepeaterYear();
 
             case :
                 return new RepeaterSeason();
 
             case :
                 return new RepeaterMonth();
 
             case :
                 return new RepeaterFortnight();
 
             case :
                 return new RepeaterWeek();
 
             case :
                 return new RepeaterWeekend();
 
             case :
                 return new RepeaterDay();
 
             case :
                 return new RepeaterHour();
 
             case :
                 return new RepeaterMinute();
 
             case :
                 return new RepeaterSecond();
 
             default:
                 throw new RuntimeException();
             }
         }
         
    }
New to GrepCode? Check out our FAQ X