Skip to content

Commit 4aa9612

Browse files
committed
DirectoryPath: introduced directory path as a wrapper API for the file paths
1 parent 38f5f04 commit 4aa9612

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2023-2024, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'Electrostatic-Sandbox' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package electrostatic4j.snaploader.filesystem;
34+
35+
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
36+
37+
/**
38+
* A class denotes and provides a directory absolute path.
39+
*
40+
* @author pavl_g
41+
*/
42+
public final class DirectoryPath {
43+
44+
/**
45+
* An alias object for the current working directory absolute path.
46+
*/
47+
public static final DirectoryPath USER_DIR =
48+
new DirectoryPath(PropertiesProvider.USER_DIR.getSystemProperty());
49+
50+
/**
51+
* An alias object for the root user home directory absolute path.
52+
*/
53+
public static final DirectoryPath USER_HOME =
54+
new DirectoryPath(PropertiesProvider.USER_DIR.getSystemProperty());
55+
56+
private String path;
57+
58+
/**
59+
* Instantiates a directory path from a string path (not null).
60+
*
61+
* @param path the directory path
62+
*/
63+
public DirectoryPath(final String path) {
64+
this.path = path;
65+
}
66+
67+
/**
68+
* Instantiates a directory path from a string path (not null) using
69+
* the platform-specific file separators.
70+
*
71+
* @param root the root directory path
72+
* @param entries the filesystem entries after the root path
73+
*/
74+
public DirectoryPath(final String root, final String... entries) {
75+
this(root);
76+
for (String entry: entries) {
77+
if (entry == null) {
78+
continue;
79+
}
80+
path = getPath() + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + entry;
81+
}
82+
}
83+
84+
/**
85+
* Retrieves the absolute path to the specified directory path.
86+
*
87+
* @return a path in strings.
88+
*/
89+
public String getPath() {
90+
return path;
91+
}
92+
}

0 commit comments

Comments
 (0)