Revision: 1779
Author:
olso...@gmail.com
Date: Wed Feb 18 18:20:25 2015 UTC
Log: handle null and empty call numbers
https://code.google.com/p/solrmarc/source/detail?r=1779
Modified:
/trunk/lib/solrmarc/src/org/solrmarc/callnum/AbstractCallNumber.java
/trunk/lib/solrmarc/src/org/solrmarc/callnum/CallNumber.java
/trunk/lib/solrmarc/src/org/solrmarc/callnum/DeweyCallNumber.java
/trunk/lib/solrmarc/src/org/solrmarc/callnum/LCCallNumber.java
/trunk/test/src/org/solrmarc/callnum/DeweyCallNumberUnitTests.java
/trunk/test/src/org/solrmarc/callnum/LCCallNumberUnitTests.java
=======================================
--- /trunk/lib/solrmarc/src/org/solrmarc/callnum/AbstractCallNumber.java
Fri Feb 14 21:28:11 2014 UTC
+++ /trunk/lib/solrmarc/src/org/solrmarc/callnum/AbstractCallNumber.java
Wed Feb 18 18:20:25 2015 UTC
@@ -28,7 +28,7 @@
* Unparsed form of call number. If call number is built from
components,
* not initialized from a <code>String</code>, value may be
<code>null</code>.
*/
- protected String raw;
+ protected String rawCallNum;
/**
* Indicates whether call number parsed was a valid. Generally assume
true unless proven otherwise.
=======================================
--- /trunk/lib/solrmarc/src/org/solrmarc/callnum/CallNumber.java Fri Jan 23
19:54:42 2015 UTC
+++ /trunk/lib/solrmarc/src/org/solrmarc/callnum/CallNumber.java Wed Feb 18
18:20:25 2015 UTC
@@ -58,7 +58,7 @@
* Returns a shelf key for the call number.
* The shelf key can be sorted lexicographically, in Unicode order.
*
- * @return sort key
+ * @return sort key, may return null if {@code parse} was not called.
*/
public String getShelfKey();
}
=======================================
--- /trunk/lib/solrmarc/src/org/solrmarc/callnum/DeweyCallNumber.java Fri
Jan 23 19:54:42 2015 UTC
+++ /trunk/lib/solrmarc/src/org/solrmarc/callnum/DeweyCallNumber.java Wed
Feb 18 18:20:25 2015 UTC
@@ -78,7 +78,6 @@
*
*/
public class DeweyCallNumber extends AbstractCallNumber {
- protected String rawCallNum = null;
protected String classification = null;
protected String classDigits = null;
protected String classDecimal = null;
=======================================
--- /trunk/lib/solrmarc/src/org/solrmarc/callnum/LCCallNumber.java Mon Feb
16 20:04:32 2015 UTC
+++ /trunk/lib/solrmarc/src/org/solrmarc/callnum/LCCallNumber.java Wed Feb
18 18:20:25 2015 UTC
@@ -102,7 +102,6 @@
public class LCCallNumber extends AbstractCallNumber {
/* Class variables */
- protected String rawCallNum;
protected String classification;
protected String classLetters;
protected String classDigits;
@@ -255,13 +254,19 @@
@Override
public void parse(String call) {
init();
- this.rawCallNum = call.trim();
+ if (call == null) {
+ this.rawCallNum = null;
+ } else {
+ this.rawCallNum = call.trim();
+ }
parse();
}
protected void parse() {
- parseCallNumber();
- buildShelfKey();
+ if (this.rawCallNum != null) {
+ parseCallNumber();
+ buildShelfKey();
+ }
}
/**
@@ -364,10 +369,12 @@
}
// TODO: better way to deal with trailing . or space in call num,
as in "BF199.",
// causes meaningless class suffix resulting in trailing
space on shelf key
- int i = key.length() - 1;
- char last = key.charAt(i);
- if (last == ' ') {
- key.deleteCharAt(i);
+ if (key.length() > 0) {
+ int i = key.length() - 1;
+ char last = key.charAt(i);
+ if (last == ' ') {
+ key.deleteCharAt(i);
+ }
}
shelfKey = key.toString();
}
=======================================
--- /trunk/test/src/org/solrmarc/callnum/DeweyCallNumberUnitTests.java Fri
Jan 23 19:54:42 2015 UTC
+++ /trunk/test/src/org/solrmarc/callnum/DeweyCallNumberUnitTests.java Wed
Feb 18 18:20:25 2015 UTC
@@ -252,6 +252,46 @@
assertEquals("", new DeweyCallNumber("").getShelfKey());
assertNull(new DeweyCallNumber(null).getShelfKey());
}
+
+ /**
+ * unit test for getShelfKey: check empty string call number
+ */
+ @Test
+ public void testGetShelfKey_emptyCallNumber()
+ {
+ String callnum = "";
+ assertEquals("", new DeweyCallNumber(callnum).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: check whitespace call number
+ */
+ @Test
+ public void testGetShelfKey_whitespaceCallNumber()
+ {
+ String callnum = " ";
+ assertEquals("", new DeweyCallNumber(callnum).getShelfKey());
+ callnum = " "; // suffix with letters
+ assertEquals("", new DeweyCallNumber(callnum).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: check null call number
+ */
+ @Test
+ public void testGetShelfKey_nullCallNumber()
+ {
+ assertNull(new DeweyCallNumber(null).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: parse has not been called
+ */
+ @Test
+ public void testGetShelfKey_notParsed()
+ {
+ assertNull(new LCCallNumber().getShelfKey());
+ }
@Test
public void testDeweyIsValid()
=======================================
--- /trunk/test/src/org/solrmarc/callnum/LCCallNumberUnitTests.java Mon Feb
16 20:04:32 2015 UTC
+++ /trunk/test/src/org/solrmarc/callnum/LCCallNumberUnitTests.java Wed Feb
18 18:20:25 2015 UTC
@@ -1131,6 +1131,46 @@
assertEquals(callnumKey, new
LCCallNumber(callnumUpper).getShelfKey());
assertEquals(callnumKey, new
LCCallNumber(callnumLower).getShelfKey());
}
+
+ /**
+ * unit test for getShelfKey: check empty string call number
+ */
+ @Test
+ public void testGetShelfKey_emptyCallNumber()
+ {
+ String callnum = "";
+ assertEquals("", new LCCallNumber(callnum).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: check whitespace call number
+ */
+ @Test
+ public void testGetShelfKey_whitespaceCallNumber()
+ {
+ String callnum = " ";
+ assertEquals("", new LCCallNumber(callnum).getShelfKey());
+ callnum = " "; // suffix with letters
+ assertEquals("", new LCCallNumber(callnum).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: check null call number
+ */
+ @Test
+ public void testGetShelfKey_nullCallNumber()
+ {
+ assertNull(new LCCallNumber(null).getShelfKey());
+ }
+
+ /**
+ * unit test for getShelfKey: parse has not been called
+ */
+ @Test
+ public void testGetShelfKey_notParsed()
+ {
+ assertNull(new LCCallNumber().getShelfKey());
+ }
/**
* unit test for isValid