View Javadoc
1   /*
2    * Copyright (C) 2016 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect;
18  
19  import com.google.gwt.user.client.rpc.SerializationException;
20  import com.google.gwt.user.client.rpc.SerializationStreamReader;
21  import com.google.gwt.user.client.rpc.SerializationStreamWriter;
22  
23  /**
24   * This class implements the GWT serialization of {@link Range}.
25   *
26   * @author Dean de Bree
27   */
28  public class Range_CustomFieldSerializer {
29  
30    public static void deserialize(SerializationStreamReader reader, Range<?> instance) {}
31  
32    public static Range<?> instantiate(SerializationStreamReader reader)
33        throws SerializationException {
34  
35      Cut lowerBound;
36      boolean hasLowerBound = reader.readBoolean();
37      if (hasLowerBound) {
38        boolean lowerIsClosed = reader.readBoolean();
39        Comparable lower = (Comparable) reader.readObject();
40  
41        lowerBound = lowerIsClosed ? Cut.belowValue(lower) : Cut.aboveValue(lower);
42      } else {
43        lowerBound = Cut.belowAll();
44      }
45  
46      Cut upperBound;
47      boolean hasUpperBound = reader.readBoolean();
48      if (hasUpperBound) {
49        boolean upperIsClosed = reader.readBoolean();
50        Comparable upper = (Comparable) reader.readObject();
51  
52        upperBound = upperIsClosed ? Cut.aboveValue(upper) : Cut.belowValue(upper);
53      } else {
54        upperBound = Cut.aboveAll();
55      }
56  
57      return Range.create(lowerBound, upperBound);
58    }
59  
60    public static void serialize(SerializationStreamWriter writer, Range<?> instance)
61        throws SerializationException {
62  
63      if (instance.hasLowerBound()) {
64        writer.writeBoolean(true);
65        writer.writeBoolean(instance.lowerBoundType() == BoundType.CLOSED);
66        writer.writeObject(instance.lowerEndpoint());
67      } else {
68        writer.writeBoolean(false);
69      }
70  
71      if (instance.hasUpperBound()) {
72        writer.writeBoolean(true);
73        writer.writeBoolean(instance.upperBoundType() == BoundType.CLOSED);
74        writer.writeObject(instance.upperEndpoint());
75      } else {
76        writer.writeBoolean(false);
77      }
78    }
79  }