1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.remoting.cache;
|
11
|
|
12
|
import java.lang.reflect.Field;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
|
20
|
/**
|
21
|
* @author cmathew
|
22
|
* @date 9 Feb 2015
|
23
|
*
|
24
|
*/
|
25
|
public class EntityCacherDebugResult {
|
26
|
|
27
|
private final Map<CdmEntityInfo, CdmEntityInfo> duplicateCdmEntityMap;
|
28
|
|
29
|
private final List<CdmEntityInfo> notInCacheList;
|
30
|
|
31
|
public EntityCacherDebugResult() {
|
32
|
duplicateCdmEntityMap = new HashMap<CdmEntityInfo, CdmEntityInfo>();
|
33
|
notInCacheList = new ArrayList<CdmEntityInfo>();
|
34
|
}
|
35
|
|
36
|
public void addDuplicateEntity(CdmEntityInfo cei, CdmEntityInfo cachedCei) {
|
37
|
duplicateCdmEntityMap.put(cei, cachedCei);
|
38
|
}
|
39
|
|
40
|
public void addEntityNotInCache(CdmEntityInfo cei) {
|
41
|
notInCacheList.add(cei);
|
42
|
}
|
43
|
|
44
|
public void print() {
|
45
|
System.out.println(toString());
|
46
|
}
|
47
|
|
48
|
|
49
|
@Override
|
50
|
public String toString() {
|
51
|
StringBuilder sb = new StringBuilder();
|
52
|
if(duplicateCdmEntityMap.isEmpty()) {
|
53
|
sb.append("No Duplicate CDM Entities.");
|
54
|
} else {
|
55
|
sb.append("Duplicate CDM Entities,");
|
56
|
|
57
|
for (Map.Entry<CdmEntityInfo, CdmEntityInfo> entry : duplicateCdmEntityMap.entrySet())
|
58
|
{
|
59
|
sb.append(System.getProperty("line.separator"));
|
60
|
CdmEntityInfo cei = entry.getKey();
|
61
|
CdmEntityInfo cachedCei = entry.getValue();
|
62
|
sb.append(" - entity : " + cei.getCb().getUserFriendlyTypeName() + "/" + cei.getCb().getId() +
|
63
|
" as field " + cei.getField().getName() +
|
64
|
" of entity" + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
|
65
|
sb.append(System.getProperty("line.separator"));
|
66
|
sb.append(" - cached entity : " + cachedCei.getCb().getUserFriendlyTypeName() + "/" + cachedCei.getCb().getId() +
|
67
|
" as field " + cachedCei.getField().getName());
|
68
|
sb.append("-----------");
|
69
|
}
|
70
|
}
|
71
|
|
72
|
sb.append(System.getProperty("line.separator"));
|
73
|
sb.append(System.getProperty("line.separator"));
|
74
|
|
75
|
if(notInCacheList.isEmpty()) {
|
76
|
sb.append("No Entities found which are not in Cache.");
|
77
|
} else {
|
78
|
sb.append("Not In Cache Entities,");
|
79
|
|
80
|
for(CdmEntityInfo cei : notInCacheList) {
|
81
|
sb.append(System.getProperty("line.separator"));
|
82
|
sb.append(" - entity : " + cei.getCb().getUserFriendlyTypeName() + "/" + cei.getCb().getId() +
|
83
|
" as field " + cei.getField().getName() +
|
84
|
" of entity" + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
|
85
|
}
|
86
|
}
|
87
|
|
88
|
return sb.toString();
|
89
|
}
|
90
|
|
91
|
|
92
|
|
93
|
public class CdmEntityInfo {
|
94
|
|
95
|
private final CdmBase cb;
|
96
|
private final CdmBase cbOwner;
|
97
|
private final Field field;
|
98
|
|
99
|
public CdmEntityInfo(CdmBase cb, CdmBase cbOwner, Field field) {
|
100
|
this.cb = cb;
|
101
|
this.cbOwner = cbOwner;
|
102
|
this.field = field;
|
103
|
}
|
104
|
|
105
|
public CdmBase getCb() {
|
106
|
return cb;
|
107
|
}
|
108
|
|
109
|
public CdmBase getCbOwner() {
|
110
|
return cbOwner;
|
111
|
}
|
112
|
|
113
|
public Field getField() {
|
114
|
return field;
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public boolean equals(Object obj) {
|
119
|
if(obj instanceof CdmEntityInfo & obj == this) {
|
120
|
return true;
|
121
|
} else {
|
122
|
return false;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
public int hashCode() {
|
128
|
return this.cb.hashCode();
|
129
|
}
|
130
|
}
|
131
|
|
132
|
}
|