001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.file.quota; 029 030import org.opencms.file.CmsResource; 031import org.opencms.util.CmsUUID; 032 033import java.util.ArrayList; 034import java.util.List; 035 036import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 037import org.apache.commons.lang3.builder.ToStringStyle; 038 039/** 040 * Information about the total size of files in a folder (not including any subfolders). 041 */ 042public class CmsFolderSizeEntry { 043 044 /** The root path. */ 045 private String m_rootPath; 046 047 /** The structure id. */ 048 private CmsUUID m_structureId; 049 050 /** The total size (sum of all file sizes). */ 051 private long m_size; 052 053 /** The type of the folder. */ 054 private int m_typeId; 055 056 /** 057 * Creates a new entry. 058 * 059 * @param structureId the structure id of the folder 060 * @param rootPath the root path of the folder 061 * @param size the total file size 062 * @param typeId the type of the folder 063 */ 064 public CmsFolderSizeEntry(CmsUUID structureId, String rootPath, long size, int typeId) { 065 066 super(); 067 m_structureId = structureId; 068 m_rootPath = rootPath.endsWith("/") ? rootPath : rootPath + "/"; 069 m_size = size; 070 m_typeId = typeId; 071 } 072 073 public static void main(String[] args) { 074 075 for (int j = 0; j < 10; j++) { 076 List<CmsFolderSizeEntry> list = new ArrayList<>(); 077 078 for (int i = 0; i < 200000; i++) { 079 list.add( 080 new CmsFolderSizeEntry(new CmsUUID(), "/blah/foo/xyz/quorb/wuz/norg" + i, (371 * i) % 10000, 1)); 081 } 082 long result = 0; 083 long start = System.currentTimeMillis(); 084 for (CmsFolderSizeEntry entry : list) { 085 result += entry.getSize(); 086 String path = entry.getRootPath(); 087 while (path != null) { 088 path = CmsResource.getParentFolder(path); 089 } 090 } 091 long end = System.currentTimeMillis(); 092 System.out.println(end - start); 093 } 094 } 095 096 public String getRootPath() { 097 098 return m_rootPath; 099 } 100 101 /** 102 * Gets the total file size. 103 * 104 * @return the total file size 105 */ 106 public long getSize() { 107 108 return m_size; 109 } 110 111 /** 112 * Gets the structure id of the folder. 113 * 114 * @return the structure id of the folder 115 */ 116 public CmsUUID getStructureId() { 117 118 return m_structureId; 119 } 120 121 /** 122 * Gets the type of the folder. 123 * 124 * @return the type of the folder 125 */ 126 public int getTypeId() { 127 128 return m_typeId; 129 } 130 131 /** 132 * @see java.lang.Object#toString() 133 */ 134 @Override 135 public String toString() { 136 137 return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE); 138 } 139 140}