JCash/src/me/teridax/jcash/banking/Owner.java

83 lines
2.1 KiB
Java

package me.teridax.jcash.banking;
import me.teridax.jcash.decode.StringUtils;
import java.util.Objects;
@SuppressWarnings("unused")
public final class Owner {
private int uid;
private String familyName;
private String name;
private String street;
private int zip;
private String city;
private Owner(int uid, String familyName, String name, int zip, String city, String street) {
this.uid = uid;
this.familyName = familyName;
this.name = name;
this.zip = zip;
this.city = city;
this.street = street;
}
public static Owner fromColumns(String... columns) throws IllegalArgumentException, NullPointerException {
Objects.requireNonNull(columns);
if (columns.length != 6)
throw new IllegalArgumentException("Invalid number of columns: " + columns.length);
var uid = StringUtils.decodeUniqueIdentificationNumber(columns[0]);
var familyName = StringUtils.decodeName(columns[1]);
var name = StringUtils.decodeName(columns[2]);
var street = StringUtils.decodeStreet(columns[3]);
var zip = StringUtils.decodeUniqueIdentificationNumber(columns[4]);
var city = StringUtils.decodeName(columns[5]);
return new Owner(uid, familyName, name, zip, city, street);
}
public long getUid() {
return uid;
}
public String getFamilyName() {
return familyName;
}
public String getName() {
return name;
}
public int getZip() {
return zip;
}
public String getCity() {
return city;
}
public String getStreet() {
return street;
}
@Override
public int hashCode() {
return Objects.hash(uid);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Owner) {
return this.uid == ((Owner) obj).getUid();
}
return false;
}
@Override
public String toString() {
return String.format("@Owner[uid=%08x, familyName=%s, name=%s, zip=%s, city=%s, street=%s]", uid, familyName, name, zip, city, street);
}
}