52
52
import java .nio .file .Path ;
53
53
import java .util .ArrayList ;
54
54
import java .util .Collections ;
55
+ import java .util .LinkedHashSet ;
55
56
import java .util .List ;
56
57
import java .util .Objects ;
58
+ import java .util .Set ;
59
+
60
+ import org .knime .core .node .NodeLogger ;
57
61
58
62
/**
59
63
* A representation of a PYTHONPATH with Python modules on it. The {@link PythonPath} contains a list of strings which
65
69
*/
66
70
public final class PythonPath {
67
71
68
- private final List <String > m_paths ;
72
+ private final Set <String > m_paths = new LinkedHashSet <>() ;
69
73
70
74
private PythonPath (final List <String > paths ) {
71
- m_paths = paths ;
75
+ m_paths . addAll ( paths ) ;
72
76
}
73
77
74
78
/**
75
79
* @return the list of absolute paths to the folders containing the Python modules
76
80
*/
77
81
public List <String > getPaths () {
78
- return Collections .unmodifiableList (m_paths );
82
+ return Collections .unmodifiableList (new ArrayList <>( m_paths ) );
79
83
}
80
84
81
85
/**
82
86
* @return a string which can be used as the PYTHONPATH environment variable. The paths are separated by the
83
87
* platform specific separator.
84
88
*/
85
89
public String getPythonPath () {
86
- final String seperator = File .pathSeparator ;
87
- return String .join (seperator , m_paths );
90
+ return String .join (File .pathSeparator , m_paths );
88
91
}
89
92
90
93
@ Override
@@ -120,11 +123,13 @@ public static PythonPathBuilder builder() {
120
123
/** A builder for {@link PythonPath}. */
121
124
public static final class PythonPathBuilder {
122
125
123
- private final List <String > m_paths ;
126
+ private final Set <String > m_paths ;
127
+
128
+ private static final NodeLogger LOGGER = NodeLogger .getLogger (PythonPathBuilder .class );
124
129
125
130
/** Create a new builder for {@link PythonPath}. */
126
131
public PythonPathBuilder () {
127
- m_paths = new ArrayList <>();
132
+ m_paths = new LinkedHashSet <>();
128
133
}
129
134
130
135
/**
@@ -144,7 +149,10 @@ public PythonPathBuilder(final PythonPath path) {
144
149
* @return the builder
145
150
*/
146
151
public PythonPathBuilder add (final Path path ) {
147
- m_paths .add (path .toAbsolutePath ().toString ());
152
+ if (!m_paths .add (path .toAbsolutePath ().toString ())) {
153
+ LOGGER .coding (String .format ("The path '%s' is already present." ,
154
+ path .toAbsolutePath ()));
155
+ }
148
156
return this ;
149
157
}
150
158
0 commit comments