41 lines
961 B
Java
41 lines
961 B
Java
package elements;
|
|
|
|
import elements.exceptions.ReadErrorListException;
|
|
|
|
/**
|
|
* Created by Guillermo Serrahima on 10/9/16.
|
|
*/
|
|
public class ChatListItem {
|
|
private String name;
|
|
private Integer value;
|
|
|
|
|
|
public ChatListItem(String name, int value) {
|
|
this.name = name;
|
|
this.value = value;
|
|
}
|
|
|
|
public ChatListItem(String line) throws ReadErrorListException {
|
|
loadItem(line);
|
|
}
|
|
|
|
public int compareTo(ChatListItem c) {
|
|
return name.compareTo(c.name);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return name + ": " + value;
|
|
}
|
|
|
|
public String saveItem() {
|
|
return name + ";" + value;
|
|
}
|
|
|
|
private void loadItem(String line) throws ReadErrorListException {
|
|
String[] reading = line.split(";");
|
|
if(reading.length > 2) throw new ReadErrorListException("Unidentified item.");
|
|
this.name = reading[0];
|
|
this.value = Integer.parseInt(reading[1]);
|
|
}
|
|
}
|