-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJPInsert.java
More file actions
75 lines (68 loc) · 1.91 KB
/
JPInsert.java
File metadata and controls
75 lines (68 loc) · 1.91 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
//alias cd = JPInsert.sh
//function JPInsert(){
// argument = $1;
// cd $1;
// path = `pwd`
// java JPInsert $1 path
//}
//class processes arguments to insert key,val pair into HashTable
//must make sure we don't insert bad values
public class JPInsert{
public void insert(String k, String v){
//replace hash with appropriate (saved) hash table
String key = truncate(k);
String value = v;
JPConstructor io = new JPConstructor();
HashTableChained hash = io.retrieveTable();
hash.insert(key, value);
io.storeTable(hash);
}
public String truncate(String x){
String k = x;
for(int i = k.length()-1; i >= 0; i--){
char letter = k.charAt(i);
//if the last letter is / , cut it out
if((letter=='/' || letter == ' ') && i==k.length()-1){
k = k.substring(0, i);
i = k.length();
continue;
}
if( letter=='/' && i!=k.length()-1){
k = k.substring(i+1);
return k;
}
}
return k;
}
public static void main(String[] args){
if(args.length != 2){
System.out.println("wrong number of arguments");
}
String key = args[0];
String val = args[1];
JPInsert adder = new JPInsert();
adder.insert(key, val);
/*
String one = "/usr/local/visit/1";
String two = "/usr/local/visit/2";
String three = "/3";
JPInsert test1 = new JPInsert();
JPInsert test2 = new JPInsert();
JPFind find1 = new JPFind();
JPConstructor testCons = new JPConstructor();
testCons.clearTable();
test1.insert(one, "/usr/1/1");
test1.insert(one, "/usr/1/2");
test1.insert(one, "/usr/1/3");
test2.insert(one, "/usr/1/1");
test2.insert(two, "/usr/2/3");
test2.insert(three, "/3");
//System.out.println("test1 :" + test1.truncate(one));
//System.out.println("test2 :" + test2.truncate(two));
System.out.println(find1.printOptions(one));
String return1 = find1.returnBest(one);
System.out.println("here is the return from the hash : " + return1);
System.out.println(find1.printOptions(one));
*/
}
}