fix for drop() field transformer
This commit is contained in:
parent
38576e881b
commit
0811f397b2
3 changed files with 54 additions and 7 deletions
|
@ -1,3 +1,3 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
version = 1.0.1
|
version = 1.0.2
|
||||||
org.gradle.daemon = true
|
org.gradle.daemon = true
|
||||||
|
|
|
@ -255,11 +255,35 @@ public class MarcFieldTransformer extends LinkedHashMap<String, MarcField> {
|
||||||
|
|
||||||
public Builder fromTo(String a, String b) {
|
public Builder fromTo(String a, String b) {
|
||||||
String[] from = a.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
String[] from = a.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
||||||
|
MarcField.Builder fromBuilder = MarcField.builder();
|
||||||
|
switch (from.length) {
|
||||||
|
case 1:
|
||||||
|
fromBuilder.tag(from[0]);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
fromBuilder.tag(from[0]).indicator(from[1]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
fromBuilder.tag(from[0]).indicator(from[1]).subfields(from[2]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
String[] to = b.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
String[] to = b.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
||||||
MarcField.Builder fromBuilder = MarcField.builder()
|
MarcField.Builder toBuilder = MarcField.builder();
|
||||||
.tag(from[0]).indicator(from[1]).subfields(from[2]);
|
switch (to.length) {
|
||||||
MarcField.Builder toBuilder = MarcField.builder()
|
case 1:
|
||||||
.tag(to[0]).indicator(to[1]).subfields(to[2]);
|
toBuilder.tag(to[0]);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
toBuilder.tag(to[0]).indicator(to[1]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
toBuilder.tag(to[0]).indicator(to[1]).subfields(to[2]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
fromTo(fromBuilder.build(), toBuilder.build());
|
fromTo(fromBuilder.build(), toBuilder.build());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -271,8 +295,20 @@ public class MarcFieldTransformer extends LinkedHashMap<String, MarcField> {
|
||||||
|
|
||||||
public Builder drop(String a) {
|
public Builder drop(String a) {
|
||||||
String[] s = a.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
String[] s = a.split(Pattern.quote(MarcField.KEY_DELIMITER), -1);
|
||||||
MarcField.Builder builder = MarcField.builder()
|
MarcField.Builder builder = MarcField.builder();
|
||||||
.tag(s[0]).indicator(s[1]).subfields(s[2]);
|
switch (s.length) {
|
||||||
|
case 1:
|
||||||
|
builder.tag(s[0]);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
builder.tag(s[0]).indicator(s[1]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
builder.tag(s[0]).indicator(s[1]).subfields(s[2]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
drop(builder.build());
|
drop(builder.build());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,17 @@ public class MarcFieldTransformerTest {
|
||||||
assertEquals(MarcField.EMPTY, b);
|
assertEquals(MarcField.EMPTY, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDropTag() {
|
||||||
|
MarcFieldTransformer marcFieldTransformer = MarcFieldTransformer.builder()
|
||||||
|
.ignoreIndicator()
|
||||||
|
.drop("001")
|
||||||
|
.build();
|
||||||
|
MarcField a = MarcField.builder().tag("001").subfield("a", "Hello").subfield("b", "World").build();
|
||||||
|
MarcField b = marcFieldTransformer.transform(a);
|
||||||
|
assertEquals(MarcField.EMPTY, b);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringSpec() {
|
public void testStringSpec() {
|
||||||
MarcFieldTransformer marcFieldTransformer = MarcFieldTransformer.builder()
|
MarcFieldTransformer marcFieldTransformer = MarcFieldTransformer.builder()
|
||||||
|
|
Loading…
Reference in a new issue