1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api.model;
20
21 import java.io.Serializable;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27
28
29
30
31 public class InputSource implements Serializable {
32
33 private final String modelId;
34 private final String location;
35 private final List<InputSource> inputs;
36
37 public InputSource(String modelId, String location) {
38 this.modelId = modelId;
39 this.location = location;
40 this.inputs = null;
41 }
42
43 public InputSource(Collection<InputSource> inputs) {
44 this.modelId = null;
45 this.location = null;
46 this.inputs = ImmutableCollections.copy(inputs);
47 }
48
49
50
51
52
53
54 public String getLocation() {
55 return this.location;
56 }
57
58
59
60
61
62
63 public String getModelId() {
64 return this.modelId;
65 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) {
70 return true;
71 }
72 if (o == null || getClass() != o.getClass()) {
73 return false;
74 }
75 InputSource that = (InputSource) o;
76 return Objects.equals(modelId, that.modelId)
77 && Objects.equals(location, that.location)
78 && Objects.equals(inputs, that.inputs);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(modelId, location, inputs);
84 }
85
86 Stream<InputSource> sources() {
87 return inputs != null ? inputs.stream() : Stream.of(this);
88 }
89
90 @Override
91 public String toString() {
92 if (inputs != null) {
93 return inputs.stream().map(InputSource::toString).collect(Collectors.joining(", ", "merged[", "]"));
94 }
95 return getModelId() + " " + getLocation();
96 }
97
98 public static InputSource merge(InputSource src1, InputSource src2) {
99 return new InputSource(Stream.concat(src1.sources(), src2.sources()).collect(Collectors.toSet()));
100 }
101 }