Home | History | Annotate | Download | only in impl
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5  **********************************************************************
      6  * Copyright (c) 2002-2014, Google, International Business Machines
      7  * Corporation and others.  All Rights Reserved.
      8  **********************************************************************
      9  * Author: Mark Davis
     10  **********************************************************************
     11  */
     12 package android.icu.impl;
     13 
     14 import android.icu.util.Freezable;
     15 
     16 
     17 /**
     18  * @hide Only a subset of ICU is exposed in Android
     19  */
     20 @SuppressWarnings({ "unchecked", "rawtypes" })
     21 public class Row<C0, C1, C2, C3, C4> implements java.lang.Comparable, Cloneable,
     22                                         Freezable<Row<C0, C1, C2, C3, C4>>{
     23     protected Object[] items;
     24     protected volatile boolean frozen;
     25 
     26     /**
     27      * Convenience Methods
     28      */
     29     public static <C0, C1> R2<C0,C1> of(C0 p0, C1 p1) {
     30         return new R2<C0,C1>(p0,p1);
     31     }
     32     public static <C0, C1, C2> R3<C0,C1,C2> of(C0 p0, C1 p1, C2 p2) {
     33         return new R3<C0,C1,C2>(p0,p1,p2);
     34     }
     35     public static <C0, C1, C2, C3> R4<C0,C1,C2,C3> of(C0 p0, C1 p1, C2 p2, C3 p3) {
     36         return new R4<C0,C1,C2,C3>(p0,p1,p2,p3);
     37     }
     38     public static <C0, C1, C2, C3, C4> R5<C0,C1,C2,C3,C4> of(C0 p0, C1 p1, C2 p2, C3 p3, C4 p4) {
     39         return new R5<C0,C1,C2,C3,C4>(p0,p1,p2,p3,p4);
     40     }
     41 
     42     public static class R2<C0, C1> extends Row<C0, C1, C1, C1, C1> {
     43         public R2(C0 a, C1 b)  {
     44             items = new Object[] {a, b};
     45         }
     46     }
     47     public static class R3<C0, C1, C2> extends Row<C0, C1, C2, C2, C2> {
     48         public R3(C0 a, C1 b, C2 c)  {
     49             items = new Object[] {a, b, c};
     50         }
     51     }
     52     public static class R4<C0, C1, C2, C3> extends Row<C0, C1, C2, C3, C3> {
     53         public R4(C0 a, C1 b, C2 c, C3 d)  {
     54             items = new Object[] {a, b, c, d};
     55         }
     56     }
     57     public static class R5<C0, C1, C2, C3, C4> extends Row<C0, C1, C2, C3, C4> {
     58         public R5(C0 a, C1 b, C2 c, C3 d, C4 e)  {
     59             items = new Object[] {a, b, c, d, e};
     60         }
     61     }
     62 
     63     public Row<C0, C1, C2, C3, C4> set0(C0 item) {
     64         return set(0, item);
     65     }
     66     public C0 get0() {
     67         return (C0) items[0];
     68     }
     69     public Row<C0, C1, C2, C3, C4> set1(C1 item) {
     70         return set(1, item);
     71     }
     72     public C1 get1() {
     73         return (C1) items[1];
     74     }
     75     public Row<C0, C1, C2, C3, C4> set2(C2 item) {
     76         return set(2, item);
     77     }
     78     public C2 get2() {
     79         return (C2) items[2];
     80     }
     81     public Row<C0, C1, C2, C3, C4> set3(C3 item) {
     82         return set(3, item);
     83     }
     84     public C3 get3() {
     85         return (C3) items[3];
     86     }
     87     public Row<C0, C1, C2, C3, C4> set4(C4 item) {
     88         return set(4, item);
     89     }
     90     public C4 get4() {
     91         return (C4) items[4];
     92     }
     93 
     94     protected Row<C0, C1, C2, C3, C4> set(int i, Object item) {
     95         if (frozen) {
     96             throw new UnsupportedOperationException("Attempt to modify frozen object");
     97         }
     98         items[i] = item;
     99         return this;
    100     }
    101 
    102     @Override
    103     public int hashCode() {
    104         int sum = items.length;
    105         for (Object item : items) {
    106             sum = sum*37 + Utility.checkHash(item);
    107         }
    108         return sum;
    109     }
    110 
    111     @Override
    112     public boolean equals(Object other) {
    113         if (other == null) {
    114             return false;
    115         }
    116         if (this == other) {
    117             return true;
    118         }
    119         try {
    120             Row<C0, C1, C2, C3, C4> that = (Row<C0, C1, C2, C3, C4>)other;
    121             if (items.length != that.items.length) {
    122                 return false;
    123             }
    124             int i = 0;
    125             for (Object item : items) {
    126                 if (!Utility.objectEquals(item, that.items[i++])) {
    127                     return false;
    128                 }
    129             }
    130             return true;
    131         } catch (Exception e) {
    132             return false;
    133         }
    134     }
    135 
    136     @Override
    137     public int compareTo(Object other) {
    138         int result;
    139         Row<C0, C1, C2, C3, C4> that = (Row<C0, C1, C2, C3, C4>)other;
    140         result = items.length - that.items.length;
    141         if (result != 0) {
    142             return result;
    143         }
    144         int i = 0;
    145         for (Object item : items) {
    146             result = Utility.checkCompare(((Comparable)item), ((Comparable)that.items[i++]));
    147             if (result != 0) {
    148                 return result;
    149             }
    150         }
    151         return 0;
    152     }
    153 
    154     @Override
    155     public String toString() {
    156         StringBuilder result = new StringBuilder("[");
    157         boolean first = true;
    158         for (Object item : items) {
    159             if (first) {
    160                 first = false;
    161             } else {
    162                 result.append(", ");
    163             }
    164             result.append(item);
    165         }
    166         return result.append("]").toString();
    167     }
    168 
    169     @Override
    170     public boolean isFrozen() {
    171         return frozen;
    172     }
    173 
    174     @Override
    175     public Row<C0, C1, C2, C3, C4> freeze() {
    176         frozen = true;
    177         return this;
    178     }
    179 
    180     @Override
    181     public Object clone() {
    182         if (frozen) return this;
    183         try {
    184             Row<C0, C1, C2, C3, C4> result = (Row<C0, C1, C2, C3, C4>) super.clone();
    185             items = items.clone();
    186             return result;
    187         } catch (CloneNotSupportedException e) {
    188             return null;
    189         }
    190     }
    191 
    192     @Override
    193     public Row<C0, C1, C2, C3, C4> cloneAsThawed() {
    194         try {
    195             Row<C0, C1, C2, C3, C4> result = (Row<C0, C1, C2, C3, C4>) super.clone();
    196             items = items.clone();
    197             result.frozen = false;
    198             return result;
    199         } catch (CloneNotSupportedException e) {
    200             return null;
    201         }
    202     }
    203 }
    204 
    205