Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package subscribers;
- import java.util.Comparator;
- public abstract class Subscriber implements Comparator<Subscriber> {
- protected static int idCounter = 0;
- protected int id;
- protected String name;
- public void setID() {
- idCounter += 1;
- this.id = idCounter;
- }
- public int getID( ) {
- return id;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public Subscriber(String name) {
- setID();
- setName(name);
- }
- @Override
- public String toString() {
- return String.format("(%s::%h)\tname=%s\t\tid=%d",
- this.getClass().getName(), this, name, id);
- }
- @Override
- public int compare(Subscriber s1, Subscriber s2) {
- return s1.getName().compareTo(s2.getName());
- }
- }
Add Comment
Please, Sign In to add comment