1// © 2016 and later: Unicode, Inc. and others. 2// License & terms of use: http://www.unicode.org/copyright.html#License 3/* 4 ******************************************************************************* 5 * Copyright (C) 2008-2015, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9package com.ibm.icu.impl.jdkadapter; 10 11import com.ibm.icu.text.DateFormatSymbols; 12 13/** 14 * DateFormatSymbolsICU is an adapter class which wraps ICU4J DateFormatSymbols and 15 * implements java.text.DateFormatSymbols APIs. 16 */ 17public class DateFormatSymbolsICU extends java.text.DateFormatSymbols { 18 19 private static final long serialVersionUID = -7313618555550964943L; 20 21 private DateFormatSymbols fIcuDfs; 22 23 // Implementation Note: 24 // On OpenJDK/Oracle/IBM Java 8, the super class constructor calls 25 // this.clone(). At this point, fIcuDfs is not yet initialized. 26 // The cloned instance is only used for optimizing Java's 27 // DateFormatSymbols initialization and we'll never have an instance 28 // of DateFormatSymbolsICU with fIcuDfs = null. However, for safety, 29 // all method implementation uses the pattern - 30 // 31 // if (fIcuDfs == null) { 32 // return super.methodX(); 33 // } 34 // return fIcuDfs.methodX(); 35 // 36 // to prevent NPE. For more details, please refer #11733 37 38 private DateFormatSymbolsICU(DateFormatSymbols icuDfs) { 39 fIcuDfs = icuDfs; 40 } 41 42 public static java.text.DateFormatSymbols wrap(DateFormatSymbols icuDfs) { 43 if (icuDfs == null) { 44 icuDfs = new DateFormatSymbols(); 45 } 46 return new DateFormatSymbolsICU(icuDfs); 47 } 48 49 public DateFormatSymbols unwrap() { 50 return fIcuDfs; 51 } 52 53 @Override 54 public Object clone() { 55 DateFormatSymbolsICU other = (DateFormatSymbolsICU)super.clone(); 56 if (fIcuDfs != null) { 57 // fIcuDfs must not be null except for premature instance. 58 // A premature instance might be created by Java DateFormatSymbols' 59 // internal cache. See #11733 for more details. 60 other.fIcuDfs = (DateFormatSymbols)this.fIcuDfs.clone(); 61 } 62 return other; 63 } 64 65 @Override 66 public boolean equals(Object obj) { 67 if (obj == null) { 68 return false; 69 } 70 if (obj instanceof DateFormatSymbolsICU) { 71 if (this.fIcuDfs == null) { 72 return ((DateFormatSymbolsICU)obj).fIcuDfs == null; 73 } 74 return this.fIcuDfs.equals(((DateFormatSymbolsICU)obj).fIcuDfs); 75 } 76 return false; 77 } 78 79 @Override 80 public String[] getAmPmStrings() { 81 if (fIcuDfs == null) { 82 return super.getAmPmStrings(); 83 } 84 return fIcuDfs.getAmPmStrings(); 85 } 86 87 @Override 88 public String[] getEras() { 89 if (fIcuDfs == null) { 90 return super.getEras(); 91 } 92 return fIcuDfs.getEras(); 93 } 94 95 public String getLocalePatternChars() { 96 if (fIcuDfs == null) { 97 return super.getLocalPatternChars(); 98 } 99 return fIcuDfs.getLocalPatternChars(); 100 } 101 102 @Override 103 public String[] getMonths() { 104 if (fIcuDfs == null) { 105 return super.getMonths(); 106 } 107 return fIcuDfs.getMonths(); 108 } 109 110 @Override 111 public String[] getShortMonths() { 112 if (fIcuDfs == null) { 113 return super.getShortMonths(); 114 } 115 return fIcuDfs.getShortMonths(); 116 } 117 118 @Override 119 public String[] getShortWeekdays() { 120 if (fIcuDfs == null) { 121 return super.getShortWeekdays(); 122 } 123 return fIcuDfs.getShortWeekdays(); 124 } 125 126 @Override 127 public String[] getWeekdays() { 128 if (fIcuDfs == null) { 129 return super.getWeekdays(); 130 } 131 return fIcuDfs.getWeekdays(); 132 } 133 134 @Override 135 public String[][] getZoneStrings() { 136 if (fIcuDfs == null) { 137 return super.getZoneStrings(); 138 } 139 return fIcuDfs.getZoneStrings(); 140 } 141 142 @Override 143 public int hashCode() { 144 if (fIcuDfs == null) { 145 return super.hashCode(); 146 } 147 return fIcuDfs.hashCode(); 148 } 149 150 @Override 151 public void setAmPmStrings(String[] newAmpms) { 152 if (fIcuDfs == null) { 153 super.setAmPmStrings(newAmpms); 154 return; 155 } 156 fIcuDfs.setAmPmStrings(newAmpms); 157 } 158 159 @Override 160 public void setEras(String[] newEras) { 161 if (fIcuDfs == null) { 162 super.setEras(newEras); 163 return; 164 } 165 fIcuDfs.setEras(newEras); 166 } 167 168 @Override 169 public void setLocalPatternChars(String newLocalPatternChars) { 170 if (fIcuDfs == null) { 171 super.setLocalPatternChars(newLocalPatternChars); 172 return; 173 } 174 fIcuDfs.setLocalPatternChars(newLocalPatternChars); 175 } 176 177 @Override 178 public void setMonths(String[] newMonths) { 179 if (fIcuDfs == null) { 180 super.setMonths(newMonths); 181 return; 182 } 183 fIcuDfs.setMonths(newMonths); 184 } 185 186 @Override 187 public void setShortMonths(String[] newShortMonths) { 188 if (fIcuDfs == null) { 189 super.setShortMonths(newShortMonths); 190 return; 191 } 192 fIcuDfs.setShortMonths(newShortMonths); 193 } 194 195 @Override 196 public void setShortWeekdays(String[] newShortWeekdays) { 197 if (fIcuDfs == null) { 198 super.setShortWeekdays(newShortWeekdays); 199 return; 200 } 201 fIcuDfs.setShortWeekdays(newShortWeekdays); 202 } 203 204 @Override 205 public void setWeekdays(String[] newWeekdays) { 206 if (fIcuDfs == null) { 207 super.setWeekdays(newWeekdays); 208 return; 209 } 210 fIcuDfs.setWeekdays(newWeekdays); 211 } 212 213 @Override 214 public void setZoneStrings(String[][] newZoneStrings) { 215 if (fIcuDfs == null) { 216 super.setZoneStrings(newZoneStrings); 217 return; 218 } 219 fIcuDfs.setZoneStrings(newZoneStrings); 220 } 221} 222