Home | History | Annotate | Download | only in util
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 /*
      3  **************************************************************************
      4  * Copyright (C) 2008-2014, Google, International Business Machines
      5  * Corporation and others. All Rights Reserved.
      6  **************************************************************************
      7  */
      8 package android.icu.util;
      9 
     10 import java.io.InvalidObjectException;
     11 import java.io.ObjectStreamException;
     12 
     13 
     14 /**
     15  * Measurement unit for time units.
     16  * @see TimeUnit
     17  * @author markdavis
     18  */
     19 public class TimeUnit extends MeasureUnit {
     20     private static final long serialVersionUID = -2839973855554750484L;
     21 
     22     /**
     23      * Here for serialization backward compatibility only.
     24      */
     25     private final int index;
     26 
     27     TimeUnit(String type, String code) {
     28         super(type, code);
     29         index = 0;
     30     }
     31 
     32     /**
     33      * @return the available values
     34      */
     35     public static TimeUnit[] values() {
     36         return new TimeUnit[] { SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR };
     37     }
     38 
     39     private Object writeReplace() throws ObjectStreamException {
     40         return new MeasureUnitProxy(type, subType);
     41     }
     42 
     43     // For backward compatibility only
     44     private Object readResolve() throws ObjectStreamException {
     45         // The old index field used to uniquely identify the time unit.
     46         switch (index) {
     47         case 6:
     48             return SECOND;
     49         case 5:
     50             return MINUTE;
     51         case 4:
     52             return HOUR;
     53         case 3:
     54             return DAY;
     55         case 2:
     56             return WEEK;
     57         case 1:
     58             return MONTH;
     59         case 0:
     60             return YEAR;
     61         default:
     62             throw new InvalidObjectException("Bad index: " + index);
     63         }
     64     }
     65 }
     66