forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath.java
More file actions
85 lines (76 loc) · 1.52 KB
/
Copy pathPath.java
File metadata and controls
85 lines (76 loc) · 1.52 KB
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
/*
* Copyright (c) 2004, 2005 TADA AB - Taby Sweden
* Distributed under the terms shown in the file COPYRIGHT
* found in the root folder of this project or at
* http://eng.tada.se/osprojects/COPYRIGHT.html
*/
package org.postgresql.pljava.test;
import java.io.File;
import java.util.ArrayList;
/**
* PL/Java Test harness
*
* @author Thomas Hallgren
*/
public class Path
{
public final ArrayList m_path;
public Path(String path)
{
m_path = new ArrayList();
if(path != null)
{
char pathSep = File.pathSeparatorChar;
int sep = path.indexOf(pathSep);
while(sep >= 0)
{
if(sep > 0)
this.addLast(new File(path.substring(0, sep)));
path = path.substring(sep + 1);
sep = path.indexOf(pathSep);
}
if(path.length() > 0)
this.addLast(new File(path));
}
}
public void addFirst(File dir)
{
int pos = m_path.indexOf(dir);
if(pos >= 0)
{
if(pos == 0)
return;
m_path.remove(pos);
}
m_path.add(0, dir);
}
public void addLast(File dir)
{
int pos = m_path.indexOf(dir);
if(pos >= 0)
{
if(pos == m_path.size() - 1)
return;
m_path.remove(pos);
}
m_path.add(dir);
}
public String toString()
{
int top = m_path.size();
if(top == 0)
return "";
String first = m_path.get(0).toString();
if(top == 1)
return first;
StringBuffer bld = new StringBuffer();
char pathSep = File.pathSeparatorChar;
bld.append(first);
for(int idx = 1; idx < top; ++idx)
{
bld.append(pathSep);
bld.append(m_path.get(idx));
}
return bld.toString();
}
}