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 private final InputLocation importedFrom;
37
38 public InputSource(String modelId, String location) {
39 this(modelId, location, null);
40 }
41
42 public InputSource(String modelId, String location, InputLocation importedFrom) {
43 this.modelId = modelId;
44 this.location = location;
45 this.inputs = null;
46 this.importedFrom = importedFrom;
47 }
48
49 public InputSource(Collection<InputSource> inputs) {
50 this.modelId = null;
51 this.location = null;
52 this.inputs = ImmutableCollections.copy(inputs);
53 this.importedFrom = null;
54 }
55
56
57
58
59
60
61 public String getLocation() {
62 return this.location;
63 }
64
65
66
67
68
69
70 public String getModelId() {
71 return this.modelId;
72 }
73
74
75
76
77
78
79
80
81 public InputLocation getImportedFrom() {
82 return importedFrom;
83 }
84
85 @Override
86 public boolean equals(Object o) {
87 if (this == o) {
88 return true;
89 }
90 if (o == null || getClass() != o.getClass()) {
91 return false;
92 }
93 InputSource that = (InputSource) o;
94 return Objects.equals(modelId, that.modelId)
95 && Objects.equals(location, that.location)
96 && Objects.equals(inputs, that.inputs);
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(modelId, location, inputs);
102 }
103
104 Stream<InputSource> sources() {
105 return inputs != null ? inputs.stream() : Stream.of(this);
106 }
107
108 @Override
109 public String toString() {
110 if (inputs != null) {
111 return inputs.stream().map(InputSource::toString).collect(Collectors.joining(", ", "merged[", "]"));
112 }
113 return getModelId() + " " + getLocation();
114 }
115
116 public static InputSource merge(InputSource src1, InputSource src2) {
117 return new InputSource(Stream.concat(src1.sources(), src2.sources()).collect(Collectors.toSet()));
118 }
119 }