summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/UnaryFieldAction.java
blob: c13d1014769916ee3a5d9327dd68d9003c969e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.onap.sdc.dcae.composition.restmodels.ruleeditor;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class UnaryFieldAction extends BaseAction {

	private From from;

	public From getFrom() {
		return from;
	}

	public void setFrom(From from) {
		this.from = from;
	}

	public void setFrom(String from) {
		this.from = new From(from);
	}

	public void setFrom(List<String> from) {
		this.from = new From(from);
	}

	public void setFrom(String from, String regex) {
		this.from = new From(from, regex);
	}

	protected class From extends FromField {

		private String regex;
		// UI state of the regex field
		private String state;
		private List<FromField> values;

		public String getRegex() {
			return regex;
		}

		public void setRegex(String regex) {
			this.regex = regex;
		}

		public String getState() {
			return state;
		}

		public void setState(String state) {
			this.state = state;
		}

		public List<FromField> getValues() {
			return values;
		}

		public void setValues(List<FromField> values) {
			this.values = values;
		}

		protected From(String value, String regex){
			super(value);
			setRegex(regex);
		}

		protected From(List<String> valuesList) {
			List<FromField> allValues = valuesList.stream().map(FromField::new).collect(Collectors.toList());
			setValues(allValues);
		}

		protected From(String value){
			super(value);
		}

		@Override
		public boolean equals(Object obj) {
			return super.equals(obj) && Objects.equals(regex, ((From) obj).regex)
					&& Objects.equals(state, ((From) obj).state)
					&& Objects.equals(values, ((From) obj).values);
		}

		@Override
		public int hashCode(){
			return Objects.hash(this.regex,this.state,this.values);
		}

	}

	public List<String> fromValues() {
		return null == from || CollectionUtils.isEmpty(from.values) ? new ArrayList<>() : from.values.stream().map(FromField::getValue).collect(Collectors.toList());
	}

	@Override
	public boolean equals(Object obj) {
		return super.equals(obj) && Objects.equals(from, ((UnaryFieldAction)obj).from);
	}

	@Override
	public int hashCode(){
		return Objects.hash(this.from);
	}


	public boolean referencesTarget(BaseAction other){
		return false;
	}

	public String strippedTarget(){return "";}

	public String regexState() {
		return from.state;
	}

	public void regexState(String state) {
		from.state = state;
	}
}