You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
package de.superx.rest.model; |
|
|
|
public class Item implements Comparable<Item> { |
|
public String label; |
|
public String value; |
|
public boolean selected = false; |
|
public String sortValue = ""; |
|
|
|
public Item(String label, String value) { |
|
this.label = label; |
|
this.value = value; |
|
} |
|
|
|
public Item(String label, String value, String sortValue) { |
|
this.label = label; |
|
this.value = value; |
|
this.sortValue = sortValue; |
|
} |
|
|
|
public Item(String value) { |
|
this.value = value; |
|
} |
|
|
|
public Item() { |
|
super(); |
|
} |
|
|
|
@Override |
|
public boolean equals( Object o ) { |
|
|
|
// If the object is compared with itself then return true |
|
if (o == this) { |
|
return true; |
|
} |
|
|
|
/* Check if o is an instance of Item or not |
|
"null instanceof [type]" also returns false */ |
|
if (!(o instanceof Item)) { |
|
return false; |
|
} |
|
|
|
// typecast o to Complex so that we can compare data members |
|
Item it = (Item) o; |
|
|
|
// equal, if value matches |
|
if (this.value != null && this.value.contentEquals(it.value)) { |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
@Override |
|
public int compareTo(Item another) { |
|
boolean thisHasSortValue = this.sortValue != null && !this.sortValue.isEmpty(); |
|
boolean otherHasSortValue = another.sortValue != null && !another.sortValue.isEmpty(); |
|
|
|
String thisSort = thisHasSortValue ? this.sortValue : this.label; |
|
String otherSort = otherHasSortValue ? another.sortValue : another.label; |
|
|
|
if (thisHasSortValue || otherHasSortValue) { |
|
return thisSort.compareToIgnoreCase(otherSort); |
|
} |
|
|
|
return thisSort.compareTo(otherSort); |
|
} |
|
|
|
@Override |
|
public int hashCode() { |
|
return super.hashCode(); |
|
} |
|
} |
|
|
|
|