withOrgId(String)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
eloc 3
1
package unicon.matthews.oneroster.service.repository;
2
3
import org.apache.commons.lang3.StringUtils;
4
import org.apache.commons.lang3.builder.ToStringBuilder;
5
import org.apache.commons.lang3.builder.ToStringStyle;
6
import org.springframework.data.annotation.Id;
7
import org.springframework.data.mongodb.core.index.Indexed;
8
import org.springframework.data.mongodb.core.mapping.Document;
9
10
import unicon.matthews.oneroster.Result;
11
12
@Document
13
public class MongoResult {
14
  @Id private String id;
15
  
16
  private String orgId;
17
  private String tenantId;
18
  
19
  @Indexed private String userSourcedId;
20
  @Indexed private String classSourcedId;
21
  @Indexed private String lineitemSourcedId;
22
  
23
  private Result result;
24
  
25
  private MongoResult() {}
26
27
  public String getId() {
28
    return id;
29
  }
30
31
  public String getOrgId() {
32
    return orgId;
33
  }
34
35
  public String getTenantId() {
36
    return tenantId;
37
  }
38
39
  public String getUserSourcedId() {
40
    return userSourcedId;
41
  }
42
43
  public String getClassSourcedId() {
44
    return classSourcedId;
45
  }
46
47
  public String getLineitemSourcedId() {
48
    return lineitemSourcedId;
49
  }
50
51
  public Result getResult() {
52
    return result;
53
  }
54
  
55
  @Override
56
  public String toString() {
57
    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
58
  }
59
60
  @Override
61
  public int hashCode() {
62
    final int prime = 31;
63
    int result = 1;
0 ignored issues
show
Comprehensibility introduced by
The variable resultshadows a field with the same name declared in line 23. Consider renaming it.
Loading history...
64
    result = prime * result + ((classSourcedId == null) ? 0 : classSourcedId.hashCode());
65
    result = prime * result + ((id == null) ? 0 : id.hashCode());
66
    result = prime * result + ((lineitemSourcedId == null) ? 0 : lineitemSourcedId.hashCode());
67
    result = prime * result + ((orgId == null) ? 0 : orgId.hashCode());
68
    result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
69
    result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
70
    result = prime * result + ((userSourcedId == null) ? 0 : userSourcedId.hashCode());
71
    return result;
72
  }
73
74
  @Override
75
  public boolean equals(Object obj) {
76
    if (this == obj)
77
      return true;
78
    if (obj == null)
79
      return false;
80
    if (getClass() != obj.getClass())
81
      return false;
82
    MongoResult other = (MongoResult) obj;
83
    if (classSourcedId == null) {
84
      if (other.classSourcedId != null)
85
        return false;
86
    } else if (!classSourcedId.equals(other.classSourcedId))
87
      return false;
88
    if (id == null) {
89
      if (other.id != null)
90
        return false;
91
    } else if (!id.equals(other.id))
92
      return false;
93
    if (lineitemSourcedId == null) {
94
      if (other.lineitemSourcedId != null)
95
        return false;
96
    } else if (!lineitemSourcedId.equals(other.lineitemSourcedId))
97
      return false;
98
    if (orgId == null) {
99
      if (other.orgId != null)
100
        return false;
101
    } else if (!orgId.equals(other.orgId))
102
      return false;
103
    if (result == null) {
104
      if (other.result != null)
105
        return false;
106
    } else if (!result.equals(other.result))
107
      return false;
108
    if (tenantId == null) {
109
      if (other.tenantId != null)
110
        return false;
111
    } else if (!tenantId.equals(other.tenantId))
112
      return false;
113
    if (userSourcedId == null) {
114
      if (other.userSourcedId != null)
115
        return false;
116
    } else if (!userSourcedId.equals(other.userSourcedId))
117
      return false;
118
    return true;
119
  }
120
121
  public static class Builder {
122
    MongoResult _mongoResult = new MongoResult();
123
    
124
    public Builder withId(String id) {
125
      _mongoResult.id = id;
126
      return this;
127
    }
128
129
    public Builder withOrgId(String orgId) {
130
      _mongoResult.orgId = orgId;
131
      return this;
132
    }
133
    
134
    public Builder withTenantId(String tenantId) {
135
      _mongoResult.tenantId = tenantId;
136
      return this;
137
    }
138
139
    public Builder withClassSourcedId(String classSourcedId) {
140
      _mongoResult.classSourcedId = classSourcedId;
141
      return this;
142
    }
143
144
    public Builder withUserSourcedId(String userSourcedId) {
145
      _mongoResult.userSourcedId = userSourcedId;
146
      return this;
147
    }
148
    
149
    public Builder withLineitemSourcedId(String lineitemSourcedId) {
150
      _mongoResult.lineitemSourcedId = lineitemSourcedId;
151
      return this;
152
    }
153
    
154
    public Builder withResult(Result result) {
155
      _mongoResult.result = result;
156
      return this;
157
    }
158
    
159
    public MongoResult build() {
160
      if (StringUtils.isBlank(_mongoResult.orgId)
161
          || StringUtils.isBlank(_mongoResult.tenantId)
162
          || StringUtils.isBlank(_mongoResult.classSourcedId)
163
          || StringUtils.isBlank(_mongoResult.lineitemSourcedId)
164
          || _mongoResult.result == null) {
165
        throw new IllegalStateException(_mongoResult.toString());
166
      }
167
      
168
      return _mongoResult;
169
170
    }
171
  }
172
173
}
174