78 lines
1.6 KiB
Java
Executable File
78 lines
1.6 KiB
Java
Executable File
package tk.artikus.assets;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.TreeMap;
|
|
|
|
import lombok.EqualsAndHashCode;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
import lombok.ToString;
|
|
import tk.artikus.assets.tools.YearMonth;
|
|
|
|
@ToString
|
|
@EqualsAndHashCode
|
|
public class Asset implements AssetDepreciationInfo {
|
|
|
|
@Getter
|
|
private final TreeMap<Integer, AssetDepreciationMethod> depreciationMethods = new TreeMap<>();
|
|
|
|
@Getter
|
|
@Setter
|
|
private YearMonth startOfDepreciation;
|
|
|
|
@Getter
|
|
@Setter
|
|
private String inventoryNumber;
|
|
|
|
@Getter
|
|
@Setter
|
|
private String kst;
|
|
|
|
private AssetLife life = new AssetLife();
|
|
|
|
public AssetLife getLife() {
|
|
return life;
|
|
}
|
|
|
|
public void setLife( AssetLife life ) {
|
|
this.life = life;
|
|
}
|
|
|
|
public Asset() {
|
|
}
|
|
|
|
public Asset(String inventoryNumber, String kst) {
|
|
this.inventoryNumber = inventoryNumber;
|
|
this.kst = kst;
|
|
}
|
|
|
|
public AssetDepreciationMethod getDepreciationMethod( int year ) {
|
|
|
|
List<AssetDepreciationMethod> methods = new ArrayList<>( depreciationMethods.values() );
|
|
|
|
List<Integer> years = new ArrayList<>( depreciationMethods.keySet() );
|
|
|
|
int index = Collections.binarySearch( years, year );
|
|
if( index < 0 ) {
|
|
index = -index - 1;
|
|
if( 0 == index ) {
|
|
return null;
|
|
}
|
|
index--;
|
|
}
|
|
|
|
return methods.get( index );
|
|
}
|
|
|
|
public void setFromYearDepreciationMethod( Integer year, AssetDepreciationMethod depreciationMethod ) {
|
|
depreciationMethods.put( year, depreciationMethod );
|
|
}
|
|
|
|
public void removeMethodForYear( int year ) {
|
|
depreciationMethods.remove( year );
|
|
}
|
|
|
|
}
|