001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 016 */ 017 018package org.nuxeo.ecm.quota.size; 019 020/** 021 * Helper class to have easy to display numbers and stats 022 * 023 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 024 * @since 5.6 025 */ 026public class QuotaInfo { 027 028 protected final QuotaDisplayValue innerSize; 029 030 protected final QuotaDisplayValue totalSize; 031 032 protected final QuotaDisplayValue sizeTrash; 033 034 protected final QuotaDisplayValue sizeVersions; 035 036 protected final QuotaDisplayValue maxQuota; 037 038 protected final QuotaDisplayValue liveSize; 039 040 public QuotaInfo(long innerSize, long totalSize, long trashSize, long versionsSize, long maxQuota) { 041 this.innerSize = new QuotaDisplayValue(innerSize, maxQuota); 042 this.totalSize = new QuotaDisplayValue(totalSize, maxQuota); 043 this.sizeTrash = new QuotaDisplayValue(trashSize, maxQuota); 044 this.sizeVersions = new QuotaDisplayValue(versionsSize, maxQuota); 045 this.maxQuota = new QuotaDisplayValue(maxQuota); 046 this.liveSize = new QuotaDisplayValue( 047 (totalSize - trashSize - versionsSize) > 0L ? (totalSize - trashSize - versionsSize) : 0L); 048 } 049 050 public QuotaDisplayValue getInnerSize() { 051 return innerSize; 052 } 053 054 public QuotaDisplayValue getTotalSize() { 055 return totalSize; 056 } 057 058 public QuotaDisplayValue getMaxQuota() { 059 return maxQuota; 060 } 061 062 public QuotaDisplayValue getTrashSize() { 063 return sizeTrash; 064 } 065 066 public QuotaDisplayValue getSizeVersions() { 067 return sizeVersions; 068 } 069 070 public QuotaDisplayValue getLiveSize() { 071 return liveSize; 072 } 073 074 /** 075 * Returns the string representation of this quota informations. 076 * to = total size in bytes 077 * i = inner size in bytes 078 * v = versions' size in bytes 079 * l = live size in bytes 080 * tr = trash size in bytes 081 * m = maximum quota in bytes 082 */ 083 @Override 084 public String toString() { 085 return getClass().getSimpleName() + String.format("(to:%d i:%d v:%d l:%d tr:%d m:%d)", 086 totalSize.getValue(), 087 innerSize.getValue(), 088 sizeVersions.getValue(), 089 liveSize.getValue(), 090 sizeTrash.getValue(), 091 maxQuota.getValue()); 092 } 093}