forked from terrywbrady/File-Analyzer
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Georgetown-University-Libraries/master
Synch changes back to terrywbrady
- Loading branch information
Showing
134 changed files
with
8,178 additions
and
1,798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package gov.nara.nwts.ftapp.counter; | ||
|
||
import java.text.NumberFormat; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class Cell { | ||
int row = 0; | ||
int col = 0; | ||
boolean valid = false; | ||
|
||
static Pattern pCell = Pattern.compile("^([A-Z]+)(\\d+)$"); | ||
|
||
Cell(int row, int col) { | ||
this.row = row; | ||
this.col = col; | ||
valid = true; | ||
} | ||
|
||
Cell(String cellname) { | ||
Matcher m = pCell.matcher(cellname); | ||
if (!m.matches()) return; | ||
String colstr=m.group(1); | ||
int row = Integer.parseInt(m.group(2)) - 1; | ||
int col = -1; //offset -1 for vector ref | ||
for(int i=0;i<colstr.length();i++) { | ||
int ii = colstr.length() - i - 1; | ||
int x = (colstr.charAt(ii) - 'A') + 1; | ||
col += Math.pow(26,i)*x; | ||
} | ||
this.row = row; | ||
this.col = col; | ||
valid = true; | ||
} | ||
|
||
static Cell at(String cellname) { | ||
return new Cell(cellname); | ||
} | ||
|
||
public String getCellname() { | ||
if (!valid) return "Invalid Cell Name"; | ||
String rowstr = ""+(row+1); | ||
StringBuffer colstr = new StringBuffer(); | ||
|
||
int val = col; //A=0 for last digit | ||
int rem = val % 26; | ||
|
||
colstr.append((char)('A'+rem)); | ||
|
||
for(val = val / 26; val > 0; val = val / 26) { | ||
val--; //A=1 if not last digit | ||
rem = val % 26; | ||
colstr.append((char)('A'+rem)); | ||
} | ||
return colstr.reverse().toString() + rowstr; | ||
} | ||
|
||
public static final NumberFormat nf = NumberFormat.getIntegerInstance(); | ||
static { | ||
nf.setMinimumIntegerDigits(6); | ||
nf.setGroupingUsed(false); | ||
} | ||
|
||
public String getCellSort() { | ||
return nf.format(row) + "," + nf.format(col); | ||
} | ||
|
||
public static List<Cell> makeRange(int srow, int scol, int endrow, int endcol) { | ||
ArrayList<Cell> cells = new ArrayList<Cell>(); | ||
for(int r=srow; r<=endrow; r++) { | ||
for(int c=scol; c<=endcol; c++) { | ||
cells.add(new Cell(r, c)); | ||
} | ||
} | ||
return cells; | ||
} | ||
|
||
public static void test(String s) { | ||
Cell c = new Cell(s); | ||
System.out.println(s+" "+c.getCellname()+" "+c.row+","+c.col); | ||
} | ||
|
||
public static void main(String[] argv) { | ||
test("A1"); | ||
test("A2"); | ||
test("B1"); | ||
test("B10"); | ||
test("Z1"); | ||
test("Z99"); | ||
test("AA1"); | ||
test("AA1000"); | ||
test("AZ1"); | ||
test("AZ2"); | ||
test("BA1"); | ||
test("BA2"); | ||
test("ZA1"); | ||
test("ZA2"); | ||
test("ZZ1"); | ||
test("ZZ2"); | ||
test("AAA1"); | ||
test("AAA2"); | ||
test("YYY1"); | ||
test("YYY2"); | ||
test("YZZ1"); | ||
test("YZZ2"); | ||
test("ZYZ1"); | ||
test("ZYZ2"); | ||
test("ZZZ1"); | ||
test("ZZZ2"); | ||
test("AAAA1"); | ||
test("AAAA2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package gov.nara.nwts.ftapp.counter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CellCheck { | ||
ArrayList<Cell> cells = new ArrayList<Cell>(); | ||
|
||
CounterCheck check; | ||
CellCheck(CounterCheck check) { | ||
this.check = check; | ||
} | ||
CellCheck(CounterCheck check, Cell cell) { | ||
this.check = check; | ||
cells.add(cell); | ||
} | ||
CellCheck(CounterCheck check, List<Cell> acell) { | ||
this.check = check; | ||
for(Cell cell: acell){ | ||
cells.add(cell); | ||
} | ||
} | ||
List<CheckResult> performCheck(CounterData cd) { | ||
ArrayList<CheckResult> results = new ArrayList<CheckResult>(); | ||
for(Cell cell: cells) { | ||
CheckResult res = check.performCheck(cd, cell, cd.getCellValue(cell)); | ||
results.add(res); | ||
if (res.stat.ordinal() >= CounterStat.ERROR.ordinal()) { | ||
break; | ||
} | ||
} | ||
return results; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
core/src/main/gov/nara/nwts/ftapp/counter/CheckResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package gov.nara.nwts.ftapp.counter; | ||
|
||
public class CheckResult { | ||
CounterRec rec; | ||
public Cell cell; | ||
public CounterStat stat; | ||
public String message = ""; | ||
public String newVal; | ||
|
||
CheckResult(Cell cell, CounterStat stat) { | ||
this.rec = CounterRec.CELL; | ||
this.cell = cell; | ||
this.stat = stat; | ||
} | ||
|
||
CheckResult(CounterStat stat) { | ||
this.rec = CounterRec.FILE; | ||
this.stat = stat; | ||
} | ||
|
||
CheckResult setMessage(String message) { | ||
this.message = message; | ||
return this; | ||
} | ||
|
||
CheckResult setNewVal(String newVal) { | ||
this.newVal = newVal; | ||
return this; | ||
} | ||
|
||
static CheckResult createFileStatus(CounterStat stat) { | ||
return new CheckResult(stat); | ||
} | ||
static CheckResult createCellStatus(Cell cell, CounterStat stat) { | ||
return new CheckResult(cell, stat); | ||
} | ||
static CheckResult createCellValid(Cell cell) { | ||
return createCellStatus(cell, CounterStat.VALID); | ||
} | ||
static CheckResult createCellWarning(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.WARNING).setMessage(message); | ||
} | ||
static CheckResult createCellInvalid(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.INVALID).setMessage(message); | ||
} | ||
static CheckResult createCellInvalidCase(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.WARNING_CASE).setMessage(message); | ||
} | ||
static CheckResult createCellInvalidPunct(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.WARNING_PUNCT).setMessage(message); | ||
} | ||
static CheckResult createCellInvalidTrim(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.WARNING_TRIM).setMessage(message); | ||
} | ||
static CheckResult createCellInvalidDate(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.WARNING_DATE).setMessage(message); | ||
} | ||
static CheckResult createCellInvalidSum(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.INVALID_SUM).setMessage(message); | ||
} | ||
static CheckResult createCellError(Cell cell, String message) { | ||
return createCellStatus(cell, CounterStat.ERROR).setMessage(message); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/gov/nara/nwts/ftapp/counter/ColSumCounterCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gov.nara.nwts.ftapp.counter; | ||
|
||
public class ColSumCounterCheck extends SumCounterCheck { | ||
String val; | ||
int sr; | ||
int er; | ||
public ColSumCounterCheck(int sr, int er, String message) { | ||
super(message); | ||
this.sr = sr; | ||
this.er = er; | ||
} | ||
|
||
public int getRangeSum(CounterData cd, Cell cell) { | ||
int rangesum = 0; | ||
for(int r=sr; r<=er; r++) { | ||
rangesum += getIntValue(cd.getCellValue(new Cell(r, cell.col)), 0); | ||
} | ||
return rangesum; | ||
} | ||
|
||
} | ||
|
27 changes: 27 additions & 0 deletions
27
core/src/main/gov/nara/nwts/ftapp/counter/CounterCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gov.nara.nwts.ftapp.counter; | ||
|
||
public class CounterCheck { | ||
String message = "Cell does not match specifications"; | ||
CounterStat stat = CounterStat.INVALID; | ||
boolean allowNull = false; | ||
|
||
public CheckResult performCheck(CounterData cd, Cell cell, String cellval) { | ||
return CheckResult.createCellValid(cell); | ||
} | ||
|
||
public CounterCheck setMessage(String message) { | ||
this.message = message; | ||
return this; | ||
} | ||
|
||
public CounterCheck setCounterStat(CounterStat stat) { | ||
this.stat = stat; | ||
return this; | ||
} | ||
|
||
public CounterCheck setAllowNull(boolean b) { | ||
allowNull = b; | ||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.