View Javadoc
1   /*
2    * Copyright (C) 2010 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 2.1 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  
20  package org.exoplatform.services.portletcache;
21  
22  import java.io.Serializable;
23  
24  import java.util.Locale;
25  import java.util.Map;
26  
27  import javax.portlet.PortletMode;
28  import javax.portlet.WindowState;
29  
30  /**
31   * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
32   * @version $Revision$
33   */
34  class WindowKey implements Serializable
35  {
36  
37    private static final long serialVersionUID = 924996837199587159L;
38  
39    /** . */
40    private final String windowId;
41  
42    /** . */
43    private final String windowState;
44  
45    /** . */
46    private final String portletMode;
47  
48    /** . */
49    private final Locale locale;
50  
51    /** . */
52    private final Map<String, String[]> parameters;
53  
54    /** . */
55    private final Map<String, String[]> query;
56  
57    /** . */
58    private final int hashCode;
59  
60    WindowKey(String windowId,
61              WindowState windowState,
62              PortletMode portletMode,
63              Locale locale,
64              Map<String, String[]> parameters,
65              Map<String, String[]> query)
66    {
67  
68      // Clone parameter map
69      parameters = Util.clone(parameters);
70      query = Util.clone(query);
71  
72      // Compute hashCode;
73      int hashCode =
74        windowId.hashCode() ^
75        windowState.hashCode() ^
76        portletMode.hashCode() ^
77        locale.hashCode() ^
78        Util.hashCode(parameters) ^
79        Util.hashCode(query);
80  
81      //
82      this.windowId = windowId;
83      this.windowState = windowState.toString();
84      this.portletMode = portletMode.toString();
85      this.parameters = parameters;
86      this.locale = locale;
87      this.hashCode = hashCode;
88      this.query = query;
89    }
90  
91    public String getWindowId()
92    {
93      return windowId;
94    }
95  
96    @Override
97    public boolean equals(Object obj)
98    {
99      if (obj == this)
100     {
101       return true;
102     }
103     if (obj instanceof WindowKey)
104     {
105       WindowKey that = (WindowKey)obj;
106       return windowId.equals(that.windowId) &&
107       windowState.equals(that.windowState) &&
108       portletMode.equals(that.portletMode) &&
109       locale.equals(that.locale) &&
110       Util.equals(parameters, that.parameters) &&
111       Util.equals(query, that.query);
112     }
113     return false;
114   }
115 
116   @Override
117   public int hashCode()
118   {
119     return hashCode;
120   }
121 
122   @Override
123   public String toString()
124   {
125     StringBuilder sb = new StringBuilder("WindowKey[");
126     sb.append("windowId").append('=').append(windowId).append(',');
127     sb.append("windowState").append('=').append(windowState).append(',');
128     sb.append("portletMode").append('=').append(portletMode).append(',');
129     sb.append("locale").append('=').append(locale).append(',');
130     sb.append("parameters").append('=');
131     Util.toString(parameters, sb);
132     sb.append(',');
133     sb.append("query").append('=');
134     Util.toString(query, sb);
135     sb.append(']');
136     return sb.toString();
137   }
138 }