/** * Recode the incoming object to a String, compacting it into a BCF2 string if the value is a * list. * * @param value a String or List<String> to encode, or null * @return a non-null string to encode */ private String javaStringToBCF2String(final Object value) { if (value == null) return ""; else if (value instanceof List) { final List<String> l = (List<String>) value; return BCF2Utils.collapseStringList(l); } else if (value.getClass().isArray()) { final List<String> l = new ArrayList<String>(); Collections.addAll(l, (String[]) value); return BCF2Utils.collapseStringList(l); } else return (String) value; }
@Override public void encodeValue( final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; for (final Integer i : BCF2Utils.toList(Integer.class, value)) { if (i != null) { // necessary because .,. => [null, null] in VC encoder.encodeRawInt(i, type); count++; } } for (; count < minValues; count++) encoder.encodeRawMissingValue(type); }
private BCF2FieldEncoder( final VCFCompoundHeaderLine headerLine, final Map<String, Integer> dict, final BCF2Type staticType) { this.headerLine = headerLine; this.staticType = staticType; final Integer offset = dict.get(getField()); if (offset == null) throw new IllegalStateException( "Format error: could not find string " + getField() + " in header as required by BCF"); this.dictionaryOffset = offset; dictionaryOffsetType = BCF2Utils.determineIntegerType(offset); }
@Override public void encodeValue( final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; // TODO -- can be restructured to avoid toList operation if (isAtomic) { // fast path for fields with 1 fixed float value if (value != null) { encoder.encodeRawFloat((Double) value); count++; } } else { // handle generic case final List<Double> doubles = BCF2Utils.toList(Double.class, value); for (final Double d : doubles) { if (d != null) { // necessary because .,. => [null, null] in VC encoder.encodeRawFloat(d); count++; } } } for (; count < minValues; count++) encoder.encodeRawMissingValue(type); }
@Override public BCF2Type getDynamicType(final Object value) { return value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType(BCF2Utils.toList(Integer.class, value)); }
@Override public BCF2Type getDynamicType(final Object value) { return value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType((Integer) value); }