View Javadoc
1   /*
2    * dpkg - Debian Package library and the Debian Package Maven plugin
3    * (c) Copyright 2015 Gerrit Hohl
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package net.sourceforge.javadpkg.control;
20  
21  
22  /**
23   * <p>
24   * The size of data.
25   * </p>
26   *
27   * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
28   * @version <b>1.0</b>, 31.12.2015 by Gerrit Hohl
29   */
30  public class Size {
31  
32  
33  	/** The size in bytes. */
34  	private long size;
35  
36  
37  	/**
38  	 * <p>
39  	 * Creates a size of 0 bytes.
40  	 * </p>
41  	 */
42  	public Size() {
43  		super();
44  
45  		this.size = 0;
46  	}
47  
48  
49  	/**
50  	 * <p>
51  	 * Creates a size in bytes.
52  	 * </p>
53  	 *
54  	 * @param size
55  	 *            The size in bytes.
56  	 */
57  	public Size(long size) {
58  		super();
59  
60  		this.size = size;
61  	}
62  
63  
64  	/**
65  	 * <p>
66  	 * Returns the size in bytes.
67  	 * </p>
68  	 *
69  	 * @return The size.
70  	 */
71  	public long getBytes() {
72  		return this.size;
73  	}
74  	
75  	
76  	/**
77  	 * <p>
78  	 * Returns the size in kilobytes.
79  	 * </p>
80  	 * <p>
81  	 * The size is divided by 1024 and rounded up.
82  	 * </p>
83  	 *
84  	 * @return The size.
85  	 */
86  	public long getKiloBytes() {
87  		long result;
88  		
89  		
90  		result = (this.size / 1024) + ((this.size % 1024) > 0 ? 1 : 0);
91  		return result;
92  	}
93  
94  
95  	/**
96  	 * <p>
97  	 * Returns the size for the specified number of bytes.
98  	 * </p>
99  	 * 
100 	 * @param size
101 	 *            The size in bytes.
102 	 * @return The size.
103 	 */
104 	public static Size getSizeInBytes(long size) {
105 		Size result;
106 
107 
108 		result = new Size(size);
109 		return result;
110 	}
111 	
112 	
113 	/**
114 	 * <p>
115 	 * Returns the size for the specified number of kilobytes.
116 	 * </p>
117 	 * 
118 	 * @param size
119 	 *            The size in kilobytes.
120 	 * @return The size.
121 	 */
122 	public static Size getSizeInKiloBytes(long size) {
123 		Size result;
124 
125 
126 		result = new Size(size * 1024);
127 		return result;
128 	}
129 
130 
131 }