123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- package com.rdlze.radializebase.utils;
-
- import java.io.Serializable;
-
- /**
- * This class represents a item id and value, this value may be compared if
- * required to do the sorting.
- *
- * @author Alex Amorim Dutra
- *
- */
- public class AIRecommendedItem implements Comparable<AIRecommendedItem>,
- Serializable {
-
- /**
- * Default Serial version
- */
- private static final long serialVersionUID = 1L;
-
- private long itemId;
-
- private float value;
-
- private float popularity;
-
- private float unknown = 1;
-
- private float age;
-
- private String locality;
-
- private boolean answeredAllFilters;
-
- private String sortBy;
-
- private int intSortBy;
-
- private int searchFeedBack;
-
- /**
- * Class constructor.
- *
- * @param itemId
- * integer with item id.
- * @param value
- * float with value of ranking to item.
- * @param popularity
- * float with popularity of item.
- * @param unknown
- * float with the value of unknown items by user.
- * @param age
- * float with age of item.
- * @param locality
- * String with locality of item.
- * @param sortBy
- * String indicating sort by popularity or unknown or age or
- * locality.
- */
- public AIRecommendedItem(long itemId, float value, float popularity,
- float unknown, float age, String locality, String sortBy) {
- this.itemId = itemId;
- this.value = value;
- this.age = age;
- this.popularity = popularity;
- this.unknown = unknown;
- this.locality = locality;
- this.sortBy = sortBy.toLowerCase();
- if (sortBy.equals("popularity")) {
- intSortBy = 1;
- } else if (sortBy.equals("unknow")) {
- intSortBy = 2;
- } else if (sortBy.equals("age")) {
- intSortBy = 3;
- } else if (sortBy.equals("locality")) {
- intSortBy = 4;
- } else {
- intSortBy = 5;
- }
- }
-
- public long getItemID() {
- return itemId;
- }
-
- /**
- * set doc ID.
- *
- * @param itemId
- * item id to be set
- */
- public void setItemID(int itemId) {
- this.itemId = itemId;
- }
-
- /**
- * Get value times.
- *
- * @return float value times
- */
- public float getValue() {
- return value;
- }
-
- /**
- * set value times.
- *
- * @param newValue
- * times that the item will appear
- */
- public void setValue(float newValue) {
- this.value = newValue;
- }
-
- public float getAge() {
- return age;
- }
-
- public void setAge(float age) {
- this.age = age;
- }
-
- public float getUnknown() {
- return unknown;
- }
-
- public void setUnknown(float unknown) {
- this.unknown = unknown;
- }
-
- public float getPopularity() {
- return popularity;
- }
-
- public void setPopularity(float popularity) {
- this.popularity = popularity;
- }
-
- public String getLocality() {
- return locality;
- }
-
- public void setLocality(String locality) {
- this.locality = locality;
- }
-
- public String getSortBy() {
- return sortBy;
- }
-
- public boolean isAnsweredAllFilters() {
- return answeredAllFilters;
- }
-
- public void setAnsweredAllFilters(boolean answeredAllFilters) {
- this.answeredAllFilters = answeredAllFilters;
- }
-
- public int getSearchFeedBack() {
- return searchFeedBack;
- }
-
- public void setSearchFeedBack(int searchFeedBack) {
- this.searchFeedBack = searchFeedBack;
- }
-
- /**
- * Indicates which feature is used to sorted the list.
- *
- * @param sortBy
- * String with feature to sort by.
- */
- public void setSortBy(String sortBy) {
- this.sortBy = sortBy.toLowerCase();
- if (sortBy.equals("popularity")) {
- intSortBy = 1;
- } else if (sortBy.equals("unknow")) {
- intSortBy = 2;
- } else if (sortBy.equals("age")) {
- intSortBy = 3;
- } else if (sortBy.equals("locality")) {
- intSortBy = 4;
- } else {
- intSortBy = 5;
- }
- }
-
- public int compareTo(AIRecommendedItem item) {
- float value1;
- float value2;
- switch (this.intSortBy) {
- case 1:
- value1 = item.getPopularity();
- value2 = this.getPopularity();
- break;
- case 2:
- value1 = item.getUnknown();
- value2 = this.getUnknown();
- break;
- case 3:
- value1 = item.getAge();
- value2 = this.getAge();
- break;
- case 4:
- value1 = Integer.parseInt(item.getLocality());
- value2 = Integer.parseInt(this.getLocality());
- break;
- default:
- value1 = item.getValue();
- value2 = this.getValue();
- break;
- }
-
- if (value1 > value2)
- return 1;
- else if (value1 < value2)
- return -1;
- else
- return 0;
- }
-
- public String toString() {
- return "ID: " + itemId + ", VALUE.: " + value + " NOVELTY: " + unknown
- + " ISPLAYING: " + searchFeedBack;
- // return "ITEM ID: " + itemId + " VALUE: " + value + " NOVELTY: "
- // + unknown + " POPULARITY: " + popularity
- // + " ANSWERED ALL FILTERS: " + answeredAllFilters+"...... ";
- }
-
- public boolean equals(AIRecommendedItem recItem) {
- if (this.itemId == recItem.itemId)
- return true;
-
- return false;
- }
- }
|