This project has retired. For details please refer to its Attic page.
MapEntryArrayValues xref
View Javadoc

1   /*
2    * $Id: MapEntryArrayValues.java 1064782 2011-01-28 17:08:52Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.request.collection;
22  
23  
24  import java.util.Map;
25  
26  
27  /**
28   * Multi-valued map entry.
29   *
30   * @version $Rev: 1064782 $ $Date: 2011-01-29 04:08:52 +1100 (Sat, 29 Jan 2011) $
31   * @param <K> The key type.
32   * @param <V> The value type.
33   */
34  
35  public class MapEntryArrayValues<K, V> extends MapEntry<K, V[]> {
36  
37      /**
38       * Constructor.
39       *
40       * @param key The key of the entry.
41       * @param value The array of values.
42       * @param modifiable If <code>true</code> the entry is modifiable.
43       */
44      public MapEntryArrayValues(K key, V[] value, boolean modifiable) {
45          super(key, value, modifiable);
46      }
47  
48  
49      /**
50       * <p>Returns the hashcode for this entry.</p>
51       *
52       * @return The and'ed hashcode of the key and value
53       */
54      @Override
55      public int hashCode() {
56          int valueHash = 0;
57          V[] value = getValue();
58          if (value != null) {
59              for (int i = 0; i < value.length; i++) {
60                  valueHash += value[i].hashCode();
61              }
62          }
63  
64          return (this.getKey() == null ? 0 : this.getKey().hashCode())
65                  ^ valueHash;
66      }
67  
68      /**
69       * <p>Determines if this entry is equal to the passed object.</p>
70       *
71       * @param o The object to test
72       * @return True if equal, else false
73       */
74      @Override
75      @SuppressWarnings("unchecked")
76      public boolean equals(Object o) {
77          if (o != null && o instanceof Map.Entry) {
78              Map.Entry<K, V[]> entry = (Map.Entry<K, V[]>) o;
79              if (this.getKey() == null ? entry.getKey() == null : this
80                      .getKey().equals(entry.getKey())) {
81                  V[] values = getValue();
82                  V[] otherValues = entry.getValue();
83                  if (values != null) {
84                      if (otherValues != null) {
85                          if (values.length == otherValues.length) {
86                              boolean same = true;
87                              for (int i = 0; i < values.length && same; i++) {
88                                  same = values[i] == null ? otherValues[i] == null
89                                          : values[i].equals(otherValues[i]);
90                              }
91                              return same;
92                          }
93                      } else {
94                          return false;
95                      }
96                  } else {
97                      return otherValues == null;
98                  }
99              }
100         }
101         return false;
102     }
103 }