add sorting utility method

This commit is contained in:
Grahame Grieve 2019-05-13 13:32:25 +10:00
parent 8263b0b5fa
commit 25de65431e
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,66 @@
package org.hl7.fhir.r5.patterns;
import java.util.List;
import org.hl7.fhir.r5.model.Annotation;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.Resource;
public class PatternBaseImpl implements PatternBase {
private Base wrapped;
public PatternBaseImpl(Base wrapped) {
super();
this.wrapped = wrapped;
}
@Override
public String getId() {
if (wrapped instanceof Element)
return ((Element) wrapped).getId();
if (wrapped instanceof Resource)
return ((Resource) wrapped).getId();
return null;
}
@Override
public PatternBase setId(String value) {
if (wrapped instanceof Element)
((Element) wrapped).setId(value);
else if (wrapped instanceof Resource)
((Resource) wrapped).setId(value);
else
throw new Error("this should not happen? wrapped = "+wrapped.getClass().getName());
return this;
}
@Override
public List<Extension> getExtension() {
if (wrapped instanceof Element)
return ((Element) wrapped).getExtension();
if (wrapped instanceof DomainResource)
return ((DomainResource) wrapped).getExtension();
return null;
}
protected Annotation convertStringToAnnotation(String value) {
if (value == null)
return null;
else
return new Annotation().setText(value);
}
protected String convertAnnotationToString(Annotation value) {
if (value == null)
return null;
else
return value.getText();
}
}

View File

@ -64,6 +64,7 @@ import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -1170,6 +1171,13 @@ public class Utilities {
return id.matches("[A-Za-z0-9\\-\\.]{1,64}");
}
public static List<String> sorted(Set<String> set) {
List<String> list = new ArrayList<>();
list.addAll(set);
Collections.sort(list);
return list;
}
}