BrightSide Workbench Full Report + Source Code
IndicatorVariable.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.indicator;
20 
21 import java.io.Serializable;
22 import java.util.HashSet;
23 import java.util.Objects;
24 import java.util.Set;
25 import org.turro.string.Strings;
26 
31 public class IndicatorVariable implements Serializable {
32 
33  private final String root, name;
34  private final boolean preprocess, reversed;
35  private final VariableType type;
36  private final Set<String> avoid;
37 
38  public IndicatorVariable(String root, String name, boolean preprocess, VariableType type) {
39  this(root, name, preprocess, type, false, null);
40  }
41 
42  public IndicatorVariable(String root, String name, boolean preprocess, VariableType type, boolean reversed) {
43  this(root, name, preprocess, type, reversed, null);
44  }
45 
46  public IndicatorVariable(String root, String name, boolean preprocess, VariableType type, String avoid) {
47  this(root, name, preprocess, type, false, avoid);
48  }
49 
50  public IndicatorVariable(String root, String name, boolean preprocess, VariableType type, boolean reversed, String avoid) {
51  this.root = root;
52  this.name = name;
53  this.preprocess = preprocess;
54  this.type = type;
55  this.reversed = reversed;
56  this.avoid = Strings.isBlank(avoid) ? null : new HashSet<>(Strings.csvToList(avoid));
57  }
58 
59  @Override
60  public String toString() {
61  return getFullName();
62  }
63 
64  public String getFullName() {
65  return root + ":" + getName();
66  }
67 
68  public String getRoot() {
69  return root;
70  }
71 
72  public String getName() {
73  return name;
74  }
75 
76  public boolean isPreprocess() {
77  return preprocess;
78  }
79 
80  public VariableType getType() {
81  return type;
82  }
83 
84  public boolean isReversed() {
85  return reversed;
86  }
87 
88  public Set<String> getAvoid() {
89  return avoid;
90  }
91 
92  public boolean permits(String root) {
93  return avoid == null || !avoid.contains(root);
94  }
95 
96  public long getMissingValue() {
97  return isReversed() ? Long.MAX_VALUE : 0;
98  }
99 
100  public static IndicatorVariable result(String root, VariableType type) {
101  return new IndicatorVariable(root, "*", false, type);
102  }
103 
104  @Override
105  public int hashCode() {
106  int hash = 3;
107  hash = 97 * hash + Objects.hashCode(this.root);
108  hash = 97 * hash + Objects.hashCode(this.name);
109  hash = 97 * hash + (this.preprocess ? 1 : 0);
110  hash = 97 * hash + Objects.hashCode(this.type);
111  return hash;
112  }
113 
114  @Override
115  public boolean equals(Object obj) {
116  if (this == obj) {
117  return true;
118  }
119  if (obj == null) {
120  return false;
121  }
122  if (getClass() != obj.getClass()) {
123  return false;
124  }
125  final IndicatorVariable other = (IndicatorVariable) obj;
126  if (this.preprocess != other.preprocess) {
127  return false;
128  }
129  if (!Objects.equals(this.root, other.root)) {
130  return false;
131  }
132  if (!Objects.equals(this.name, other.name)) {
133  return false;
134  }
135  if (this.type != other.type) {
136  return false;
137  }
138  return true;
139  }
140 
141 }
static IndicatorVariable result(String root, VariableType type)
IndicatorVariable(String root, String name, boolean preprocess, VariableType type, boolean reversed)
IndicatorVariable(String root, String name, boolean preprocess, VariableType type)
IndicatorVariable(String root, String name, boolean preprocess, VariableType type, String avoid)
IndicatorVariable(String root, String name, boolean preprocess, VariableType type, boolean reversed, String avoid)