001/* 002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 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 * Contributors: 017 * <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 018 */ 019 020package org.nuxeo.ecm.quota.size; 021 022/** 023 * Helper class to have easy to display numbers and stats 024 * 025 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 026 * @since 5.6 027 */ 028public class QuotaInfo { 029 030 protected final QuotaDisplayValue innerSize; 031 032 protected final QuotaDisplayValue totalSize; 033 034 protected final QuotaDisplayValue sizeTrash; 035 036 protected final QuotaDisplayValue sizeVersions; 037 038 protected final QuotaDisplayValue maxQuota; 039 040 protected final QuotaDisplayValue liveSize; 041 042 public QuotaInfo(long innerSize, long totalSize, long trashSize, long versionsSize, long maxQuota) { 043 this.innerSize = new QuotaDisplayValue(innerSize, maxQuota); 044 this.totalSize = new QuotaDisplayValue(totalSize, maxQuota); 045 this.sizeTrash = new QuotaDisplayValue(trashSize, maxQuota); 046 this.sizeVersions = new QuotaDisplayValue(versionsSize, maxQuota); 047 this.maxQuota = new QuotaDisplayValue(maxQuota); 048 this.liveSize = new QuotaDisplayValue( 049 (totalSize - trashSize - versionsSize) > 0L ? (totalSize - trashSize - versionsSize) : 0L); 050 } 051 052 public QuotaDisplayValue getInnerSize() { 053 return innerSize; 054 } 055 056 public QuotaDisplayValue getTotalSize() { 057 return totalSize; 058 } 059 060 public QuotaDisplayValue getMaxQuota() { 061 return maxQuota; 062 } 063 064 public QuotaDisplayValue getTrashSize() { 065 return sizeTrash; 066 } 067 068 public QuotaDisplayValue getSizeVersions() { 069 return sizeVersions; 070 } 071 072 public QuotaDisplayValue getLiveSize() { 073 return liveSize; 074 } 075 076 /** 077 * Returns the string representation of this quota informations. 078 * to = total size in bytes 079 * i = inner size in bytes 080 * v = versions' size in bytes 081 * l = live size in bytes 082 * tr = trash size in bytes 083 * m = maximum quota in bytes 084 */ 085 @Override 086 public String toString() { 087 return getClass().getSimpleName() + String.format("(to:%d i:%d v:%d l:%d tr:%d m:%d)", 088 totalSize.getValue(), 089 innerSize.getValue(), 090 sizeVersions.getValue(), 091 liveSize.getValue(), 092 sizeTrash.getValue(), 093 maxQuota.getValue()); 094 } 095}