Skip to content

Commit

Permalink
filter type before cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Hu committed Jul 8, 2022
1 parent 97fe391 commit cc36f65
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ private class FragmentChanges{
@Override
public void validate(ControlledVocabulary newCV, ControlledVocabulary oldCV, ValidatorCallback callback) {

List<FragmentVocabularyTerm> invalidUpdateTerms =newCV.getTerms().stream()
List<FragmentVocabularyTerm> invalidUpdateTerms =newCV.getTerms().stream()
.filter(term-> term instanceof FragmentVocabularyTerm)
.map(term->(FragmentVocabularyTerm)term)
.filter(term->!Optional.ofNullable(term.getFragmentStructure()).isPresent()
|| !Optional.ofNullable(term.getDisplay()).isPresent()
Expand All @@ -58,6 +59,7 @@ public void validate(ControlledVocabulary newCV, ControlledVocabulary oldCV, Val
FragmentChanges changes = getAddedUpdatedDeletedTerms(newCV, oldCV);

Map<String, List<String>> hashLookup = newCV.getTerms().stream()
.filter(term-> term instanceof FragmentVocabularyTerm)
.map(key->(FragmentVocabularyTerm)key)
.map(f->Tuple.of(getHash(f), f.getValue()))
.filter(t->t.k().isPresent())
Expand Down Expand Up @@ -130,7 +132,8 @@ private FragmentChanges getAddedUpdatedDeletedTerms(ControlledVocabulary newCV,

FragmentChanges fragmentChanges = new FragmentChanges();

List<FragmentVocabularyTerm> termsAfterUpdate =newCV.getTerms().stream()
List<FragmentVocabularyTerm> termsAfterUpdate =newCV.getTerms().stream()
.filter(term->term instanceof FragmentVocabularyTerm)
.map(term->(FragmentVocabularyTerm)term)
.collect(Collectors.toList());

Expand All @@ -140,7 +143,8 @@ private FragmentChanges getAddedUpdatedDeletedTerms(ControlledVocabulary newCV,
return fragmentChanges;
}

List<FragmentVocabularyTerm> termsBeforeUpdate = oldCV.getTerms().stream()
List<FragmentVocabularyTerm> termsBeforeUpdate = oldCV.getTerms().stream()
.filter(term-> term instanceof FragmentVocabularyTerm)
.map(term->(FragmentVocabularyTerm)term)
.collect(Collectors.toList());

Expand Down

0 comments on commit cc36f65

Please sign in to comment.