src/java.base/share/classes/java/util/ImmutableCollections.java
changeset 57956 e0b8b019d2f5
parent 54475 805584336738
equal deleted inserted replaced
57955:18863bf3501f 57956:e0b8b019d2f5
   416                 return e1;
   416                 return e1;
   417             }
   417             }
   418             throw outOfBounds(index);
   418             throw outOfBounds(index);
   419         }
   419         }
   420 
   420 
       
   421         @java.io.Serial
   421         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   422         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   422             throw new InvalidObjectException("not serial proxy");
   423             throw new InvalidObjectException("not serial proxy");
   423         }
   424         }
   424 
   425 
       
   426         @java.io.Serial
   425         private Object writeReplace() {
   427         private Object writeReplace() {
   426             if (e1 == null) {
   428             if (e1 == null) {
   427                 return new CollSer(CollSer.IMM_LIST, e0);
   429                 return new CollSer(CollSer.IMM_LIST, e0);
   428             } else {
   430             } else {
   429                 return new CollSer(CollSer.IMM_LIST, e0, e1);
   431                 return new CollSer(CollSer.IMM_LIST, e0, e1);
   496         @Override
   498         @Override
   497         public E get(int index) {
   499         public E get(int index) {
   498             return elements[index];
   500             return elements[index];
   499         }
   501         }
   500 
   502 
       
   503         @java.io.Serial
   501         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   504         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   502             throw new InvalidObjectException("not serial proxy");
   505             throw new InvalidObjectException("not serial proxy");
   503         }
   506         }
   504 
   507 
       
   508         @java.io.Serial
   505         private Object writeReplace() {
   509         private Object writeReplace() {
   506             return new CollSer(CollSer.IMM_LIST, elements);
   510             return new CollSer(CollSer.IMM_LIST, elements);
   507         }
   511         }
   508 
   512 
   509         @Override
   513         @Override
   621                     }
   625                     }
   622                 }
   626                 }
   623             };
   627             };
   624         }
   628         }
   625 
   629 
       
   630         @java.io.Serial
   626         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   631         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   627             throw new InvalidObjectException("not serial proxy");
   632             throw new InvalidObjectException("not serial proxy");
   628         }
   633         }
   629 
   634 
       
   635         @java.io.Serial
   630         private Object writeReplace() {
   636         private Object writeReplace() {
   631             if (e1 == null) {
   637             if (e1 == null) {
   632                 return new CollSer(CollSer.IMM_SET, e0);
   638                 return new CollSer(CollSer.IMM_SET, e0);
   633             } else {
   639             } else {
   634                 return new CollSer(CollSer.IMM_SET, e0, e1);
   640                 return new CollSer(CollSer.IMM_SET, e0, e1);
   804                     idx = 0;
   810                     idx = 0;
   805                 }
   811                 }
   806             }
   812             }
   807         }
   813         }
   808 
   814 
       
   815         @java.io.Serial
   809         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   816         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   810             throw new InvalidObjectException("not serial proxy");
   817             throw new InvalidObjectException("not serial proxy");
   811         }
   818         }
   812 
   819 
       
   820         @java.io.Serial
   813         private Object writeReplace() {
   821         private Object writeReplace() {
   814             Object[] array = new Object[size];
   822             Object[] array = new Object[size];
   815             int dest = 0;
   823             int dest = 0;
   816             for (Object o : elements) {
   824             for (Object o : elements) {
   817                 if (o != null) {
   825                 if (o != null) {
   904         @Override
   912         @Override
   905         public boolean isEmpty() {
   913         public boolean isEmpty() {
   906             return false;
   914             return false;
   907         }
   915         }
   908 
   916 
       
   917         @java.io.Serial
   909         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   918         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   910             throw new InvalidObjectException("not serial proxy");
   919             throw new InvalidObjectException("not serial proxy");
   911         }
   920         }
   912 
   921 
       
   922         @java.io.Serial
   913         private Object writeReplace() {
   923         private Object writeReplace() {
   914             return new CollSer(CollSer.IMM_MAP, k0, v0);
   924             return new CollSer(CollSer.IMM_MAP, k0, v0);
   915         }
   925         }
   916 
   926 
   917         @Override
   927         @Override
  1108                     idx = 0;
  1118                     idx = 0;
  1109                 }
  1119                 }
  1110             }
  1120             }
  1111         }
  1121         }
  1112 
  1122 
       
  1123         @java.io.Serial
  1113         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  1124         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  1114             throw new InvalidObjectException("not serial proxy");
  1125             throw new InvalidObjectException("not serial proxy");
  1115         }
  1126         }
  1116 
  1127 
       
  1128         @java.io.Serial
  1117         private Object writeReplace() {
  1129         private Object writeReplace() {
  1118             Object[] array = new Object[2 * size];
  1130             Object[] array = new Object[2 * size];
  1119             int len = table.length;
  1131             int len = table.length;
  1120             int dest = 0;
  1132             int dest = 0;
  1121             for (int i = 0; i < len; i += 2) {
  1133             for (int i = 0; i < len; i += 2) {
  1136  *
  1148  *
  1137  * @serial
  1149  * @serial
  1138  * @since 9
  1150  * @since 9
  1139  */
  1151  */
  1140 final class CollSer implements Serializable {
  1152 final class CollSer implements Serializable {
       
  1153     @java.io.Serial
  1141     private static final long serialVersionUID = 6309168927139932177L;
  1154     private static final long serialVersionUID = 6309168927139932177L;
  1142 
  1155 
  1143     static final int IMM_LIST = 1;
  1156     static final int IMM_LIST = 1;
  1144     static final int IMM_SET = 2;
  1157     static final int IMM_SET = 2;
  1145     static final int IMM_MAP = 3;
  1158     static final int IMM_MAP = 3;
  1196      * @throws IOException if an I/O error occurs
  1209      * @throws IOException if an I/O error occurs
  1197      * @throws ClassNotFoundException if a serialized class cannot be loaded
  1210      * @throws ClassNotFoundException if a serialized class cannot be loaded
  1198      * @throws InvalidObjectException if the count is negative
  1211      * @throws InvalidObjectException if the count is negative
  1199      * @since 9
  1212      * @since 9
  1200      */
  1213      */
       
  1214     @java.io.Serial
  1201     private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
  1215     private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
  1202         ois.defaultReadObject();
  1216         ois.defaultReadObject();
  1203         int len = ois.readInt();
  1217         int len = ois.readInt();
  1204 
  1218 
  1205         if (len < 0) {
  1219         if (len < 0) {
  1225      *
  1239      *
  1226      * @param oos the ObjectOutputStream to which data is written
  1240      * @param oos the ObjectOutputStream to which data is written
  1227      * @throws IOException if an I/O error occurs
  1241      * @throws IOException if an I/O error occurs
  1228      * @since 9
  1242      * @since 9
  1229      */
  1243      */
       
  1244     @java.io.Serial
  1230     private void writeObject(ObjectOutputStream oos) throws IOException {
  1245     private void writeObject(ObjectOutputStream oos) throws IOException {
  1231         oos.defaultWriteObject();
  1246         oos.defaultWriteObject();
  1232         oos.writeInt(array.length);
  1247         oos.writeInt(array.length);
  1233         for (int i = 0; i < array.length; i++) {
  1248         for (int i = 0; i < array.length; i++) {
  1234             oos.writeObject(array[i]);
  1249             oos.writeObject(array[i]);
  1251      * @throws InvalidObjectException if the tag value is illegal or if an exception
  1266      * @throws InvalidObjectException if the tag value is illegal or if an exception
  1252      *         is thrown during creation of the collection
  1267      *         is thrown during creation of the collection
  1253      * @throws ObjectStreamException if another serialization error has occurred
  1268      * @throws ObjectStreamException if another serialization error has occurred
  1254      * @since 9
  1269      * @since 9
  1255      */
  1270      */
       
  1271    @java.io.Serial
  1256     private Object readResolve() throws ObjectStreamException {
  1272     private Object readResolve() throws ObjectStreamException {
  1257         try {
  1273         try {
  1258             if (array == null) {
  1274             if (array == null) {
  1259                 throw new InvalidObjectException("null array");
  1275                 throw new InvalidObjectException("null array");
  1260             }
  1276             }