001 package org.apache.archiva.rest.api.model; 002 /* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021 import javax.xml.bind.annotation.XmlRootElement; 022 import java.io.Serializable; 023 024 /** 025 * @author Olivier Lamy 026 * @since 1.4-M3 027 */ 028 @XmlRootElement(name = "cacheEntry") 029 public class CacheEntry 030 implements Serializable, Comparable 031 { 032 private String key; 033 034 private long size; 035 036 private long cacheHits; 037 038 private long cacheMiss; 039 040 private String cacheHitRate; 041 042 private long inMemorySize; 043 044 public CacheEntry() 045 { 046 // no op 047 } 048 049 public CacheEntry( String key, long size, long cacheHits, long cacheMiss, String cacheHitRate, long inMemorySize ) 050 { 051 this.key = key; 052 this.size = size; 053 this.cacheHits = cacheHits; 054 this.cacheMiss = cacheMiss; 055 this.cacheHitRate = cacheHitRate; 056 // size is in bytes so use kb 057 this.inMemorySize = inMemorySize / 1024; 058 } 059 060 public String getKey() 061 { 062 return key; 063 } 064 065 public void setKey( String key ) 066 { 067 this.key = key; 068 } 069 070 public long getSize() 071 { 072 return size; 073 } 074 075 public void setSize( long size ) 076 { 077 this.size = size; 078 } 079 080 public long getCacheHits() 081 { 082 return cacheHits; 083 } 084 085 public void setCacheHits( long cacheHits ) 086 { 087 this.cacheHits = cacheHits; 088 } 089 090 public long getCacheMiss() 091 { 092 return cacheMiss; 093 } 094 095 public void setCacheMiss( long cacheMiss ) 096 { 097 this.cacheMiss = cacheMiss; 098 } 099 100 public String getCacheHitRate() 101 { 102 return cacheHitRate; 103 } 104 105 public void setCacheHitRate( String cacheHitRate ) 106 { 107 this.cacheHitRate = cacheHitRate; 108 } 109 110 /** 111 * @return cache size in kb 112 */ 113 public long getInMemorySize() 114 { 115 return inMemorySize; 116 } 117 118 public void setInMemorySize( long inMemorySize ) 119 { 120 this.inMemorySize = inMemorySize; 121 } 122 123 public int compareTo( Object o ) 124 { 125 return this.key.compareTo( ( (CacheEntry) o ).key ); 126 } 127 128 @Override 129 public boolean equals( Object o ) 130 { 131 if ( this == o ) 132 { 133 return true; 134 } 135 if ( o == null || getClass() != o.getClass() ) 136 { 137 return false; 138 } 139 140 CacheEntry that = (CacheEntry) o; 141 142 if ( !key.equals( that.key ) ) 143 { 144 return false; 145 } 146 147 return true; 148 } 149 150 @Override 151 public int hashCode() 152 { 153 return key.hashCode(); 154 } 155 156 @Override 157 public String toString() 158 { 159 final StringBuilder sb = new StringBuilder(); 160 sb.append( "CacheEntry" ); 161 sb.append( "{key='" ).append( key ).append( '\'' ); 162 sb.append( ", size=" ).append( size ); 163 sb.append( ", cacheHits=" ).append( cacheHits ); 164 sb.append( ", cacheMiss=" ).append( cacheMiss ); 165 sb.append( ", cacheHitRate='" ).append( cacheHitRate ).append( '\'' ); 166 sb.append( ", inMemorySize=" ).append( inMemorySize ); 167 sb.append( '}' ); 168 return sb.toString(); 169 } 170 }