@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 object being linked to from this field. * * @param fieldName Name of field. * @return the {@link DynamicRealmObject} representation of the linked object or {@code null} if * no object is linked. * @throws IllegalArgumentException if field name doesn't exists or it doesn't contain links to * other objects. */ public DynamicRealmObject getObject(String fieldName) { long columnIndex = row.getColumnIndex(fieldName); if (row.isNullLink(columnIndex)) { return null; } else { long linkRowIndex = row.getLink(columnIndex); CheckedRow linkRow = row.getTable().getCheckedRow(linkRowIndex); return new DynamicRealmObject(realm, linkRow); } }
/** * Checks if the value of a given field is {@code null}. * * @param fieldName the name of field. * @return {@code true} if field value is null, {@code false} otherwise. * @throws IllegalArgumentException if field name doesn't exists. */ public boolean isNull(String fieldName) { long columnIndex = row.getColumnIndex(fieldName); ColumnType type = row.getColumnType(columnIndex); switch (type) { case LINK: case LINK_LIST: return row.isNullLink(columnIndex); case BOOLEAN: case INTEGER: case FLOAT: case DOUBLE: case STRING: case BINARY: case DATE: case TABLE: case MIXED: default: return false; } }