![JAR search and dependency download from the Maven repository](/logo.png)
com.github.andyshao.lang.number.SimpleByteSize Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.lang.number;
import java.io.Serial;
import java.io.Serializable;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) 21 Jun 2017
* Encoding:UNIX UTF-8
* @author Andy.Shao
*
*/
public class SimpleByteSize implements ByteSize, Serializable, Comparable {
@Serial
private static final long serialVersionUID = 64729209707050872L;
/**l*/
private long l = 0L;
/**{@link ByteLevel}*/
private ByteLevel level = ByteLevel.MB;
/**
* build {@link SimpleByteSize}
* @param l size number
* @param level {@link ByteLevel}
*/
public SimpleByteSize(long l, ByteLevel level) {
this.l = l;
this.level = level;
}
/**
* No arg construction
*/
public SimpleByteSize() {
}
@Override
public void setSize(long l , ByteLevel level) {
if(l < 0) throw new IllegalArgumentException();
this.l = l;
this.level = level;
}
@Override
public long getSize(ByteLevel level) {
int range = level.getLevel() - this.level.getLevel();
if(range == 0) return this.getSize();
else if(range > 0) {
long tmp = this.l;
for(int i=0; i>> 32));
result = prime * result + ((level == null) ? 0 : level.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
SimpleByteSize other = (SimpleByteSize) obj;
if (l != other.l) return false;
if (level != other.level) return false;
return true;
}
@Override
public ByteLevel getLevel() {
return this.level;
}
@Override
public int compareTo(SimpleByteSize that) {
if(that == null) return 1;
ByteLevel minLevel = ByteLevel.min(that.getLevel() , this.getLevel());
long thatSize = that.getSize(minLevel);
long thisSize = this.getSize(minLevel);
if(thisSize > thatSize) return 1;
else if(thisSize < thatSize) return -1;
else return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy