-
Notifications
You must be signed in to change notification settings - Fork 63
/
Team.java
71 lines (54 loc) · 1.96 KB
/
Team.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package indexing;
import com.github.cleverage.elasticsearch.Index;
import com.github.cleverage.elasticsearch.IndexUtils;
import com.github.cleverage.elasticsearch.Indexable;
import com.github.cleverage.elasticsearch.annotations.IndexMapping;
import com.github.cleverage.elasticsearch.annotations.IndexType;
import java.util.*;
/**
* User: nboire
* Date: 20/04/12
*/
@IndexType(name = "team")
@IndexMapping(value = "{ players : { properties : { players : { type : \"nested\" }, name : { type : \"string\", analyzer : \"team_name_analyzer\" } } } }")
public class Team extends Index {
public String name;
public Date dateCreate;
public String level;
public Country country;
public List<Player> players = new ArrayList<Player>();
// Find method static for request
public static Finder<Team> find = new Finder<Team>(Team.class);
@Override
public Map toIndex() {
HashMap map = new HashMap();
map.put("name", name);
map.put("level", level);
map.put("dateCreate", dateCreate);
// Serialize a Indexable Object
map.put("country", country.toIndex());
// Serialize a List of Indexable Object
map.put("players", IndexUtils.toIndex(players));
return map;
}
@Override
public Indexable fromIndex(Map map) {
if (map == null) {
return this;
}
this.name = (String) map.get("name");
this.level = (String) map.get("level");
this.dateCreate = (Date) IndexUtils.convertValue(map.get("dateCreate"), Date.class);
// UnSerialize to a Indexable Object
this.country = IndexUtils.getIndexable(map, "country", Country.class);
// UnSerialize to a List<Indexable> Object
this.players = IndexUtils.getIndexables(map, "players", Player.class);
return this;
}
@Override
public String toString() {
return "Team{" +
"name='" + name + '\'' +
'}';
}
}