1
2
3
4
5 package org.apache.maven.toolchain.model;
6
7 import java.io.Serializable;
8 import java.util.AbstractList;
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Set;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
18 import org.apache.maven.api.annotations.Generated;
19 import org.apache.maven.api.annotations.Nonnull;
20
21 @Generated
22 public class PersistedToolchains
23 extends TrackableBase
24 implements Serializable, Cloneable
25 {
26
27 public PersistedToolchains() {
28 this(org.apache.maven.api.toolchain.PersistedToolchains.newInstance());
29 }
30
31 public PersistedToolchains(org.apache.maven.api.toolchain.PersistedToolchains delegate) {
32 this(delegate, null);
33 }
34
35 public PersistedToolchains(org.apache.maven.api.toolchain.PersistedToolchains delegate, BaseObject parent) {
36 super(delegate, parent);
37 }
38
39 public PersistedToolchains clone(){
40 return new PersistedToolchains(getDelegate());
41 }
42
43 @Override
44 public org.apache.maven.api.toolchain.PersistedToolchains getDelegate() {
45 return (org.apache.maven.api.toolchain.PersistedToolchains) super.getDelegate();
46 }
47
48 @Override
49 public boolean equals(Object o) {
50 if (this == o) {
51 return true;
52 }
53 if (o == null || !(o instanceof PersistedToolchains)) {
54 return false;
55 }
56 PersistedToolchains that = (PersistedToolchains) o;
57 return Objects.equals(this.delegate, that.delegate);
58 }
59
60 @Override
61 public int hashCode() {
62 return getDelegate().hashCode();
63 }
64
65 public String getModelEncoding() {
66 return getDelegate().getModelEncoding();
67 }
68
69 @Nonnull
70 public List<ToolchainModel> getToolchains() {
71 return new WrapperList<ToolchainModel, org.apache.maven.api.toolchain.ToolchainModel>(
72 () -> getDelegate().getToolchains(), l -> update(getDelegate().withToolchains(l)),
73 d -> new ToolchainModel(d, this), ToolchainModel::getDelegate);
74 }
75
76 public void setToolchains(List<ToolchainModel> toolchains) {
77 if (toolchains == null) {
78 toolchains = Collections.emptyList();
79 }
80 if (!Objects.equals(toolchains, getToolchains())) {
81 update(getDelegate().withToolchains(
82 toolchains.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
83 toolchains.forEach(e -> e.childrenTracking = this::replace);
84 }
85 }
86
87 public void addToolchain(ToolchainModel toolchain) {
88 update(getDelegate().withToolchains(
89 Stream.concat(getDelegate().getToolchains().stream(), Stream.of(toolchain.getDelegate()))
90 .collect(Collectors.toList())));
91 toolchain.childrenTracking = this::replace;
92 }
93
94 public void removeToolchain(ToolchainModel toolchain) {
95 update(getDelegate().withToolchains(
96 getDelegate().getToolchains().stream()
97 .filter(e -> !Objects.equals(e, toolchain))
98 .collect(Collectors.toList())));
99 toolchain.childrenTracking = null;
100 }
101
102 protected boolean replace(Object oldDelegate, Object newDelegate) {
103 if (super.replace(oldDelegate, newDelegate)) {
104 return true;
105 }
106 if (getDelegate().getToolchains().contains(oldDelegate)) {
107 List<org.apache.maven.api.toolchain.ToolchainModel> list = new ArrayList<>(getDelegate().getToolchains());
108 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.toolchain.ToolchainModel) newDelegate : d);
109 update(getDelegate().withToolchains(list));
110 return true;
111 }
112 return false;
113 }
114
115 public static List<org.apache.maven.api.toolchain.PersistedToolchains> persistedToolchainsToApiV4(List<PersistedToolchains> list) {
116 return list != null ? new WrapperList<>(list, PersistedToolchains::getDelegate, PersistedToolchains::new) : null;
117 }
118
119 public static List<PersistedToolchains> persistedToolchainsToApiV3(List<org.apache.maven.api.toolchain.PersistedToolchains> list) {
120 return list != null ? new WrapperList<>(list, PersistedToolchains::new, PersistedToolchains::getDelegate) : null;
121 }
122
123 }