| 137 | } |
| 138 | |
| 139 | public static final class EmptyTarget<T> implements Target<T> { |
| 140 | |
| 141 | private final Class<T> type; |
| 142 | private final String name; |
| 143 | |
| 144 | EmptyTarget(Class<T> type, String name) { |
| 145 | this.type = checkNotNull(type, "type"); |
| 146 | this.name = checkNotNull(emptyToNull(name), "name"); |
| 147 | } |
| 148 | |
| 149 | public static <T> EmptyTarget<T> create(Class<T> type) { |
| 150 | return new EmptyTarget<T>(type, "empty:" + type.getSimpleName()); |
| 151 | } |
| 152 | |
| 153 | public static <T> EmptyTarget<T> create(Class<T> type, String name) { |
| 154 | return new EmptyTarget<T>(type, name); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public Class<T> type() { |
| 159 | return type; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public String name() { |
| 164 | return name; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String url() { |
| 169 | throw new UnsupportedOperationException("Empty targets don't have URLs"); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public Request apply(RequestTemplate input) { |
| 174 | if (input.url().indexOf("http") != 0) { |
| 175 | throw new UnsupportedOperationException( |
| 176 | "Request with non-absolute URL not supported with empty target"); |
| 177 | } |
| 178 | return input.request(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public boolean equals(Object obj) { |
| 183 | if (obj instanceof EmptyTarget) { |
| 184 | EmptyTarget<?> other = (EmptyTarget) obj; |
| 185 | return type.equals(other.type) && name.equals(other.name); |
| 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public int hashCode() { |
| 192 | int result = 17; |
| 193 | result = 31 * result + type.hashCode(); |
| 194 | result = 31 * result + name.hashCode(); |
| 195 | return result; |
| 196 | } |
nothing calls this directly
no outgoing calls
no test coverage detected