-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnionFindBase.java
More file actions
72 lines (61 loc) · 1.75 KB
/
UnionFindBase.java
File metadata and controls
72 lines (61 loc) · 1.75 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
package common;
import java.util.InputMismatchException;
/**
* Created by nars on 2/24/15.
*/
public class UnionFindBase {
private ReadConsoleInput readConsoleInput = null;
private InputFileParser fileParser = null;
private int[] inputArray = null;
public void setFileParser(String filePath) {
this.fileParser = new InputFileParser(filePath);
}
private int inputSize = 0;
public UnionFindBase() {
this.readConsoleInput = ReadConsoleInput.getInstance();
}
public int getInputSize() {
return inputSize;
}
private void checkArrayBounds(int index) {
assert index < this.getInputSize() && index >=0;
}
public void setInputSize(int inputSize) {
this.inputSize = inputSize;
}
public int getElementAt(int index)
{
checkArrayBounds(index);
return this.inputArray[index];
}
public int readInputSize()
{
assert this.fileParser != null;
return Integer.parseInt(this.fileParser.readNextLine());
}
public String[] readOperation()
{
assert this.fileParser != null;
return (this.fileParser.readNextLine()).split(" ");
}
public Boolean hasOperationsLeft(){
return this.fileParser.hasNext();
}
public void setElementAt(int index, int value)
{
checkArrayBounds(index);
this.inputArray[index] = value;
}
public void getInputArraySize()
{
try {
this.inputSize = this.readConsoleInput.readInput("Input array size");
} catch ( InputMismatchException e) {
System.out.println("Error: Invalid Integer \\n assuming 0");
}
}
public void initInputArraySize()
{
this.inputArray = new int[this.inputSize];
}
}