Commit 4e991126 authored by Rob Tomsick's avatar Rob Tomsick

Normalize partial NDCs

parent 120eb3c7
......@@ -258,17 +258,13 @@ public final class NDC
/**
* Produce a normalized (5-4-2) representation of this NDC. If the NDC
* is not complete, will simply return the NDC as-is.
* is not complete, the labeler and product codes will be normalized.
*
* @return normalized NDC in 5-4-2 format (if possible)
*/
public NDC
normalize()
{
if (! this.complete())
{
return this;
}
if (this.normalized())
{
......@@ -288,7 +284,7 @@ public final class NDC
this.packageCode);
}
if (this.packageCode.length == 1)
if (this.packageCode != null && this.packageCode.length == 1)
{
return new NDC(this.labelerCode,
this.productCode,
......@@ -311,7 +307,7 @@ public final class NDC
{
return this.labelerCode.length == 5
&& this.productCode.length == 4
&& this.packageCode.length == 2;
&& (this.packageCode.length == 0 || this.packageCode.length == 2);
}
@Override
......
......@@ -89,6 +89,11 @@ public class NDCTest
test.accept("50242-040-62", "50242-0040-62");
/* 5-4-1 -> 5-4-2 */
test.accept("60575-4112-1", "60575-4112-01");
/* partial NDC normalization */
test.accept("50242-040", "50242-0040");
test.accept("0002-7597", "00002-7597");
test.accept("60575-4112", "60575-4112");
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment