View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  public final class PixelMeasure /*extends Measure*/ {
26  
27    private static final Logger LOG = LoggerFactory.getLogger(PixelMeasure.class);
28  
29    static final PixelMeasure[] PIXEL_CACHE;
30    static final int PIXEL_CACHE_MAX = 4000;
31    
32    static {
33      PIXEL_CACHE = new PixelMeasure[PIXEL_CACHE_MAX + 1];
34      for (int i = 0; i < PIXEL_CACHE.length; i++) {
35        PIXEL_CACHE[i] = new PixelMeasure(i);
36      }
37    }
38    
39    private final int pixel;
40  
41    private PixelMeasure(final int pixel) {
42      this.pixel = pixel;
43    }
44  
45    static PixelMeasure pixelValueOf(final int value) {
46      if (value >= 0 && value <= PixelMeasure.PIXEL_CACHE_MAX) {
47        return PixelMeasure.PIXEL_CACHE[value];
48      }
49      return new PixelMeasure(value);
50    }
51    
52    public int getPixel() {
53      return pixel;
54    }
55  
56    @Override
57    public boolean equals(final Object o) {
58      if (this == o) {
59        return true;
60      }
61      if (o == null || getClass() != o.getClass()) {
62        return false;
63      }
64  
65      final PixelMeasure that = (PixelMeasure) o;
66  
67      if (pixel != that.pixel) {
68        return false;
69      }
70  
71      return true;
72    }
73  
74    @Override
75    public int hashCode() {
76      return pixel;
77    }
78  }