001package 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 021import javax.xml.bind.annotation.XmlRootElement; 022import java.io.Serializable; 023 024/** 025 * @author Olivier Lamy 026 * @since 1.4-M3 027 */ 028@XmlRootElement(name = "cacheEntry") 029public 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 @Override 124 public int compareTo( Object o ) 125 { 126 return this.key.compareTo( ( (CacheEntry) o ).key ); 127 } 128 129 @Override 130 public boolean equals( Object o ) 131 { 132 if ( this == o ) 133 { 134 return true; 135 } 136 if ( o == null || getClass() != o.getClass() ) 137 { 138 return false; 139 } 140 141 CacheEntry that = (CacheEntry) o; 142 143 if ( !key.equals( that.key ) ) 144 { 145 return false; 146 } 147 148 return true; 149 } 150 151 @Override 152 public int hashCode() 153 { 154 return key.hashCode(); 155 } 156 157 @Override 158 public String toString() 159 { 160 final StringBuilder sb = new StringBuilder(); 161 sb.append( "CacheEntry" ); 162 sb.append( "{key='" ).append( key ).append( '\'' ); 163 sb.append( ", size=" ).append( size ); 164 sb.append( ", cacheHits=" ).append( cacheHits ); 165 sb.append( ", cacheMiss=" ).append( cacheMiss ); 166 sb.append( ", cacheHitRate='" ).append( cacheHitRate ).append( '\'' ); 167 sb.append( ", inMemorySize=" ).append( inMemorySize ); 168 sb.append( '}' ); 169 return sb.toString(); 170 } 171}