Skip to content

Commit 764f345

Browse files
committed
provide simple implementation of ADR contracts
1 parent 17eace1 commit 764f345

File tree

3 files changed

+329
-0
lines changed

3 files changed

+329
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright 2014-2025 TNG Technology Consulting GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.tngtech.archunit.library.adr.simples;
17+
18+
import com.tngtech.archunit.PublicAPI;
19+
import com.tngtech.archunit.library.adr.Adr;
20+
import com.tngtech.archunit.library.adr.Metadata;
21+
import com.tngtech.archunit.library.adr.OptionProsAndCons;
22+
23+
import java.util.List;
24+
import java.util.Optional;
25+
26+
import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;
27+
28+
@PublicAPI(usage = ACCESS)
29+
public final class SimpleAdr implements Adr {
30+
31+
private Metadata metadata;
32+
private final String title;
33+
private final String contextAndProblemStatement;
34+
private List<String> decisionDrivers;
35+
private final List<String> consideredOptions;
36+
private final String decisionOutcome;
37+
private List<String> consequences;
38+
private String confirmation;
39+
private List<OptionProsAndCons> optionProsAndCons;
40+
private String moreInformation;
41+
42+
@PublicAPI(usage = ACCESS)
43+
public SimpleAdr(final String title, final String contextAndProblemStatement, final List<String> consideredOptions, final String decisionOutcome) {
44+
this.title = title;
45+
this.contextAndProblemStatement = contextAndProblemStatement;
46+
this.consideredOptions = consideredOptions;
47+
this.decisionOutcome = decisionOutcome;
48+
}
49+
50+
@PublicAPI(usage = ACCESS)
51+
@Override
52+
public Optional<Metadata> metadata() {
53+
return Optional.ofNullable(this.metadata);
54+
}
55+
56+
@PublicAPI(usage = ACCESS)
57+
@Override
58+
public Adr withMetadata(final Metadata metadata) {
59+
this.metadata = metadata;
60+
return this;
61+
}
62+
63+
@PublicAPI(usage = ACCESS)
64+
@Override
65+
public String title() {
66+
return this.title;
67+
}
68+
69+
@PublicAPI(usage = ACCESS)
70+
@Override
71+
public String contextAndProblemStatement() {
72+
return this.contextAndProblemStatement;
73+
}
74+
75+
@PublicAPI(usage = ACCESS)
76+
@Override
77+
public Optional<List<String>> decisionDrivers() {
78+
return Optional.ofNullable(this.decisionDrivers);
79+
}
80+
81+
@PublicAPI(usage = ACCESS)
82+
@Override
83+
public Adr withDecisionDrivers(final List<String> decisionDrivers) {
84+
this.decisionDrivers = decisionDrivers;
85+
return this;
86+
}
87+
88+
@PublicAPI(usage = ACCESS)
89+
@Override
90+
public List<String> consideredOptions() {
91+
return this.consideredOptions;
92+
}
93+
94+
@PublicAPI(usage = ACCESS)
95+
@Override
96+
public String decisionOutcome() {
97+
return this.decisionOutcome;
98+
}
99+
100+
@PublicAPI(usage = ACCESS)
101+
@Override
102+
public Optional<List<String>> consequences() {
103+
return Optional.ofNullable(this.consequences);
104+
}
105+
106+
@PublicAPI(usage = ACCESS)
107+
@Override
108+
public Adr withConsequences(final List<String> consequences) {
109+
this.consequences = consequences;
110+
return this;
111+
}
112+
113+
@PublicAPI(usage = ACCESS)
114+
@Override
115+
public Optional<String> confirmation() {
116+
return Optional.ofNullable(this.confirmation);
117+
}
118+
119+
@PublicAPI(usage = ACCESS)
120+
@Override
121+
public Adr withConfirmation(final String confirmation) {
122+
this.confirmation = confirmation;
123+
return this;
124+
}
125+
126+
@PublicAPI(usage = ACCESS)
127+
@Override
128+
public Optional<List<OptionProsAndCons>> optionProsAndCons() {
129+
return Optional.ofNullable(this.optionProsAndCons);
130+
}
131+
132+
@PublicAPI(usage = ACCESS)
133+
@Override
134+
public Adr withOptionProsAndCons(final List<OptionProsAndCons> optionProsAndCons) {
135+
this.optionProsAndCons = optionProsAndCons;
136+
return this;
137+
}
138+
139+
@PublicAPI(usage = ACCESS)
140+
@Override
141+
public Optional<String> moreInformation() {
142+
return Optional.ofNullable(this.moreInformation);
143+
}
144+
145+
@PublicAPI(usage = ACCESS)
146+
@Override
147+
public Adr withMoreInformation(final String moreInformation) {
148+
this.moreInformation = moreInformation;
149+
return this;
150+
}
151+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2014-2025 TNG Technology Consulting GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.tngtech.archunit.library.adr.simples;
17+
18+
import com.tngtech.archunit.PublicAPI;
19+
import com.tngtech.archunit.library.adr.Metadata;
20+
21+
import java.util.List;
22+
import java.util.Optional;
23+
24+
import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;
25+
26+
@PublicAPI(usage = ACCESS)
27+
public final class SimpleMetadata implements Metadata {
28+
29+
private String status;
30+
private String date;
31+
private List<String> decisionMakers;
32+
private List<String> consulted;
33+
private List<String> informed;
34+
35+
@PublicAPI(usage = ACCESS)
36+
public SimpleMetadata() {}
37+
38+
@PublicAPI(usage = ACCESS)
39+
@Override
40+
public Optional<String> status() {
41+
return Optional.ofNullable(this.status);
42+
}
43+
44+
@PublicAPI(usage = ACCESS)
45+
@Override
46+
public Metadata withStatus(final String status) {
47+
this.status = status;
48+
return this;
49+
}
50+
51+
@PublicAPI(usage = ACCESS)
52+
@Override
53+
public Optional<String> date() {
54+
return Optional.ofNullable(this.date);
55+
}
56+
57+
@PublicAPI(usage = ACCESS)
58+
@Override
59+
public Metadata withDate(final String date) {
60+
this.date = date;
61+
return this;
62+
}
63+
64+
@PublicAPI(usage = ACCESS)
65+
@Override
66+
public Optional<List<String>> decisionMakers() {
67+
return Optional.ofNullable(this.decisionMakers);
68+
}
69+
70+
@PublicAPI(usage = ACCESS)
71+
@Override
72+
public Metadata withDecisionMakers(final List<String> decisionMakers) {
73+
this.decisionMakers = decisionMakers;
74+
return this;
75+
}
76+
77+
@PublicAPI(usage = ACCESS)
78+
@Override
79+
public Optional<List<String>> consulted() {
80+
return Optional.ofNullable(this.consulted);
81+
}
82+
83+
@PublicAPI(usage = ACCESS)
84+
@Override
85+
public Metadata withConsulted(final List<String> consulted) {
86+
this.consulted = consulted;
87+
return this;
88+
}
89+
90+
@PublicAPI(usage = ACCESS)
91+
@Override
92+
public Optional<List<String>> informed() {
93+
return Optional.ofNullable(this.informed);
94+
}
95+
96+
@PublicAPI(usage = ACCESS)
97+
@Override
98+
public Metadata withInformed(final List<String> informed) {
99+
this.informed = informed;
100+
return this;
101+
}
102+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2014-2025 TNG Technology Consulting GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.tngtech.archunit.library.adr.simples;
17+
18+
import com.tngtech.archunit.PublicAPI;
19+
import com.tngtech.archunit.library.adr.OptionProsAndCons;
20+
21+
import java.util.List;
22+
import java.util.Optional;
23+
24+
import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;
25+
26+
@PublicAPI(usage = ACCESS)
27+
public final class SimpleOptionProsAndCons implements OptionProsAndCons {
28+
private final String title;
29+
private String description;
30+
private String example;
31+
private final List<String> prosAndCons;
32+
33+
@PublicAPI(usage = ACCESS)
34+
public SimpleOptionProsAndCons(final String title, final List<String> prosAndCons) {
35+
this.title = title;
36+
this.prosAndCons = prosAndCons;
37+
}
38+
39+
@PublicAPI(usage = ACCESS)
40+
@Override
41+
public String title() {
42+
return this.title;
43+
}
44+
45+
@PublicAPI(usage = ACCESS)
46+
@Override
47+
public Optional<String> description() {
48+
return Optional.ofNullable(this.description);
49+
}
50+
51+
@PublicAPI(usage = ACCESS)
52+
@Override
53+
public OptionProsAndCons withDescription(final String description) {
54+
this.description = description;
55+
return this;
56+
}
57+
58+
@PublicAPI(usage = ACCESS)
59+
@Override
60+
public Optional<String> example() {
61+
return Optional.ofNullable(this.example);
62+
}
63+
64+
@PublicAPI(usage = ACCESS)
65+
@Override
66+
public OptionProsAndCons withExample(final String example) {
67+
this.example = example;
68+
return this;
69+
}
70+
71+
@PublicAPI(usage = ACCESS)
72+
@Override
73+
public List<String> prosAndCons() {
74+
return this.prosAndCons;
75+
}
76+
}

0 commit comments

Comments
 (0)