@Override public String toString() { if (row == null || !row.isAttached()) { return "Invalid object"; } StringBuilder sb = new StringBuilder(row.getTable().getName() + " = ["); String[] fields = getFieldNames(); for (String field : fields) { long columnIndex = row.getColumnIndex(field); ColumnType type = row.getColumnType(columnIndex); sb.append("{"); switch (type) { case BOOLEAN: sb.append(field + ": " + row.getBoolean(columnIndex)); break; case INTEGER: sb.append(field + ": " + row.getLong(columnIndex)); break; case FLOAT: sb.append(field + ": " + row.getFloat(columnIndex)); break; case DOUBLE: sb.append(field + ": " + row.getDouble(columnIndex)); break; case STRING: sb.append(field + ": " + row.getString(columnIndex)); break; case BINARY: sb.append(field + ": " + row.getBinaryByteArray(columnIndex)); break; case DATE: sb.append(field + ": " + row.getDate(columnIndex)); break; case LINK: if (row.isNullLink(columnIndex)) { sb.append("null"); } else { sb.append(field + ": " + row.getTable().getLinkTarget(columnIndex).getName()); } break; case LINK_LIST: String targetType = row.getTable().getLinkTarget(columnIndex).getName(); sb.append( String.format( "%s: RealmList<%s>[%s]", field, targetType, row.getLinkList(columnIndex).size())); break; case TABLE: case MIXED: default: sb.append(field + ": ?"); } sb.append("}, "); } sb.replace(sb.length() - 2, sb.length(), ""); sb.append("]"); return sb.toString(); }
/** * Returns the {@code byte[]} value for a given field. * * @param fieldName the name of field. * @return the byte[] value. * @throws IllegalArgumentException if field name doesn't exists or it doesn't contain binary * data. */ public byte[] getBlob(String fieldName) { long columnIndex = row.getColumnIndex(fieldName); return row.getBinaryByteArray(columnIndex); }