1 package com.atlassian.marketplace.client.api;
2
3 import static com.atlassian.marketplace.client.api.QueryProperties.describeOptBoolean;
4 import static com.atlassian.marketplace.client.api.QueryProperties.describeParams;
5 import static com.google.common.base.Preconditions.checkNotNull;
6
7
8
9
10
11
12
13
14 public final class VendorQuery implements QueryProperties.Bounds
15 {
16 private static final VendorQuery DEFAULT_QUERY = builder().build();
17
18 private final QueryBounds bounds;
19 private final boolean forThisUserOnly;
20
21
22
23
24 public static Builder builder()
25 {
26 return new Builder();
27 }
28
29
30
31
32 public static VendorQuery any()
33 {
34 return DEFAULT_QUERY;
35 }
36
37
38
39
40 public static Builder builder(VendorQuery query)
41 {
42 return builder()
43 .bounds(query.getBounds())
44 .forThisUserOnly(query.isForThisUserOnly());
45 }
46
47 private VendorQuery(Builder builder)
48 {
49 bounds = builder.bounds;
50 forThisUserOnly = builder.forThisUserOnly;
51 }
52
53 @Override
54 public QueryBounds getBounds()
55 {
56 return bounds;
57 }
58
59
60
61
62
63
64 public boolean isForThisUserOnly()
65 {
66 return forThisUserOnly;
67 }
68
69 @SuppressWarnings("unchecked")
70 @Override
71 public String toString()
72 {
73 return describeParams("VendorQuery",
74 describeOptBoolean("forThisUserOnly", forThisUserOnly),
75 bounds.describe()
76 );
77 }
78
79 @Override
80 public boolean equals(Object other)
81 {
82 return (other instanceof VendorQuery) ? toString().equals(other.toString()) : false;
83 }
84
85 @Override
86 public int hashCode()
87 {
88 return toString().hashCode();
89 }
90
91
92
93
94 public static class Builder implements QueryBuilderProperties.Bounds<Builder>
95 {
96 private QueryBounds bounds = QueryBounds.defaultBounds();
97 private boolean forThisUserOnly;
98
99
100
101
102 public VendorQuery build()
103 {
104 return new VendorQuery(this);
105 }
106
107 @Override
108 public Builder bounds(QueryBounds bounds)
109 {
110 this.bounds = checkNotNull(bounds);
111 return this;
112 }
113
114
115
116
117
118
119
120
121
122 public Builder forThisUserOnly(boolean forThisUserOnly)
123 {
124 this.forThisUserOnly = forThisUserOnly;
125 return this;
126 }
127 }
128 }