-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from hms-dbmi/QA
1.2.2 Release
- Loading branch information
Showing
4 changed files
with
791 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/main/java/edu/harvard/hms/dbmi/bd2k/irct/ri/scidb/SciDBDataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package edu.harvard.hms.dbmi.bd2k.irct.ri.scidb; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonObjectBuilder; | ||
|
||
import edu.harvard.hms.dbmi.bd2k.irct.model.ontology.DataType; | ||
import edu.harvard.hms.dbmi.bd2k.irct.model.resource.PrimitiveDataType; | ||
|
||
public enum SciDBDataType implements DataType { | ||
ARRAY { | ||
@Override | ||
public String getName() { | ||
return "array"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Array"; | ||
} | ||
|
||
@Override | ||
public byte[] toBytes(Object value) { | ||
if (value == null) { | ||
return new byte[] { (byte) Character.MIN_VALUE }; | ||
} | ||
|
||
String data = ((String) value).trim(); | ||
return (data).getBytes(StandardCharsets.UTF_16); | ||
} | ||
|
||
@Override | ||
public Object fromBytes(byte[] bytes) { | ||
if ((bytes.length == 1) | ||
&& (bytes[0] == Character.reverseBytes(Character.MIN_VALUE))) { | ||
return null; | ||
} | ||
return new String(bytes, StandardCharsets.UTF_16).trim(); | ||
} | ||
}, | ||
ATTRIBUTE { | ||
@Override | ||
public String getName() { | ||
return "attribute"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Attribute"; | ||
} | ||
|
||
@Override | ||
public byte[] toBytes(Object value) { | ||
if (value == null) { | ||
return new byte[] { (byte) Character.MIN_VALUE }; | ||
} | ||
|
||
String data = ((String) value).trim(); | ||
return (data).getBytes(StandardCharsets.UTF_16); | ||
} | ||
|
||
@Override | ||
public Object fromBytes(byte[] bytes) { | ||
if ((bytes.length == 1) | ||
&& (bytes[0] == Character.reverseBytes(Character.MIN_VALUE))) { | ||
return null; | ||
} | ||
return new String(bytes, StandardCharsets.UTF_16).trim(); | ||
} | ||
}, | ||
DIMENSION { | ||
@Override | ||
public String getName() { | ||
return "dimension"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "DIMENSION"; | ||
} | ||
|
||
@Override | ||
public byte[] toBytes(Object value) { | ||
if (value == null) { | ||
return new byte[] { (byte) Character.MIN_VALUE }; | ||
} | ||
|
||
String data = ((String) value).trim(); | ||
return (data).getBytes(StandardCharsets.UTF_16); | ||
} | ||
|
||
@Override | ||
public Object fromBytes(byte[] bytes) { | ||
if ((bytes.length == 1) | ||
&& (bytes[0] == Character.reverseBytes(Character.MIN_VALUE))) { | ||
return null; | ||
} | ||
return new String(bytes, StandardCharsets.UTF_16).trim(); | ||
} | ||
}; | ||
|
||
@Override | ||
public Pattern getPattern() { | ||
return Pattern.compile("^.*$", Pattern.CASE_INSENSITIVE); | ||
} | ||
|
||
@Override | ||
public DataType typeOf() { | ||
return PrimitiveDataType.STRING; | ||
} | ||
|
||
@Override | ||
public byte[] fromString(String value) { | ||
return value.getBytes(); | ||
} | ||
|
||
@Override | ||
public String toString(byte[] bytes) { | ||
return new String(bytes); | ||
} | ||
|
||
@Override | ||
public boolean validate(String value) { | ||
return getPattern().matcher(value).matches(); | ||
} | ||
|
||
@Override | ||
public JsonObject toJson() { | ||
JsonObjectBuilder build = Json.createObjectBuilder(); | ||
build.add("name", getName()); | ||
build.add("pattern", getPattern().toString()); | ||
build.add("description", getDescription()); | ||
if (typeOf() != null) { | ||
build.add("typeof", typeOf().getName()); | ||
} | ||
return build.build(); | ||
} | ||
} |
Oops, something went wrong.