001 /* 002 * Copyright 2001-2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.commons.cache.remote; 017 018 import java.io.Serializable; 019 import org.apache.commons.cache.CacheStat; 020 021 /** 022 * tk. 023 * 024 * @version $Id: GetCacheStatRequest.java 155435 2005-02-26 13:17:27Z dirkv $ 025 * @author Rodney Waldhoff 026 */ 027 public class GetCacheStatRequest implements CacheRequest { 028 protected CacheStat[] _stats = null; 029 030 public GetCacheStatRequest(CacheStat stat) { 031 this(new CacheStat[] { stat } ); 032 } 033 034 public GetCacheStatRequest(CacheStat[] stats) { 035 _stats = stats; 036 } 037 038 public CacheStat[] getCacheStats() { 039 return _stats; 040 } 041 042 public boolean equals(GetCacheStatRequest req) { 043 if(null == req) { 044 return false; 045 } else if(null == req.getCacheStats()) { 046 return (null == _stats); 047 } else if(null == _stats) { 048 return false; 049 } else if(req.getCacheStats().length != _stats.length) { 050 return false; 051 } else { 052 for(int i=0;i<_stats.length;i++) { 053 if(! (_stats[i] == null ? ( null == (req.getCacheStats())[i] ) : _stats[i].equals(req.getCacheStats()[i]) )) { 054 return false; 055 } 056 } 057 return true; 058 } 059 } 060 061 public int hashCode() { 062 if(null == _stats) { 063 return this.getClass().getName().hashCode(); 064 } else { 065 int hc = 0; 066 for(int i=0;i<_stats.length;i++) { 067 try { 068 hc ^= _stats[i].hashCode(); 069 } catch(NullPointerException e) { 070 // ignored 071 } 072 } 073 return hc; 074 } 075 } 076 }