filter and sort in one call
This commit is contained in:
parent
52b4462332
commit
375afbd85d
1 changed files with 40 additions and 6 deletions
|
@ -19,6 +19,8 @@ import static org.xbib.marc.json.MarcJsonWriter.FORMAT_TAG;
|
||||||
import static org.xbib.marc.json.MarcJsonWriter.LEADER_TAG;
|
import static org.xbib.marc.json.MarcJsonWriter.LEADER_TAG;
|
||||||
import static org.xbib.marc.json.MarcJsonWriter.TYPE_TAG;
|
import static org.xbib.marc.json.MarcJsonWriter.TYPE_TAG;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.xbib.marc.label.RecordLabel;
|
import org.xbib.marc.label.RecordLabel;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -159,9 +161,45 @@ public class MarcRecord implements Map<String, Object> {
|
||||||
return recordLabel;
|
return recordLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filterFields(Predicate<? super MarcField> predicate) {
|
public void filterFields(Comparator<MarcField> comparator) {
|
||||||
if (marcFields != null) {
|
if (marcFields != null) {
|
||||||
marcFields = marcFields.stream().filter(predicate).toList();
|
Stream<MarcField> stream = marcFields.stream();
|
||||||
|
if (comparator != null) {
|
||||||
|
stream = stream.sorted(comparator);
|
||||||
|
}
|
||||||
|
marcFields = stream.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filterFields(Predicate<? super MarcField> predicate,
|
||||||
|
Comparator<MarcField> comparator) {
|
||||||
|
if (marcFields != null) {
|
||||||
|
Stream<MarcField> stream = marcFields.stream();
|
||||||
|
if (predicate != null) {
|
||||||
|
stream = stream.filter(predicate);
|
||||||
|
}
|
||||||
|
if (comparator != null) {
|
||||||
|
stream = stream.sorted(comparator);
|
||||||
|
}
|
||||||
|
marcFields = stream.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filterFields(Predicate<? super MarcField> predicate,
|
||||||
|
Stream<MarcField> marcFieldStream,
|
||||||
|
Comparator<MarcField> comparator) {
|
||||||
|
if (marcFields != null) {
|
||||||
|
Stream<MarcField> stream = marcFields.stream();
|
||||||
|
if (predicate != null) {
|
||||||
|
stream = stream.filter(predicate);
|
||||||
|
}
|
||||||
|
if (marcFieldStream != null) {
|
||||||
|
stream = Stream.concat(stream, marcFieldStream);
|
||||||
|
}
|
||||||
|
if (comparator != null) {
|
||||||
|
stream = stream.sorted(comparator);
|
||||||
|
}
|
||||||
|
marcFields = stream.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,10 +420,6 @@ public class MarcRecord implements Map<String, Object> {
|
||||||
this.delegate = createMapFromMarcFields(Comparator.naturalOrder());
|
this.delegate = createMapFromMarcFields(Comparator.naturalOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sortFields(Comparator<MarcField> comparator) {
|
|
||||||
this.marcFields.sort(comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return delegate.size();
|
return delegate.size();
|
||||||
|
|
Loading…
Reference in a new issue