package org.qcri.rheem.basic.data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

/**
 * A Type that represents a record with a schema, might be replaced with something standard like JPA entity.
 */
public class Record implements Serializable {

    private Object[] values;

    public Record(Object... values) {
        this.values = values;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) return false;
        Record record2 = (Record) o;
        return Arrays.equals(this.values, record2.values);
    }

    @Override
    public int hashCode() {
        return Objects.hash(Arrays.hashCode(values));
    }

    @Override
    public String toString() {
        return "Record" + Arrays.toString(this.values);
    }

    public Object getField(int index) {
        return this.values[index];
    }

}

@@ -935,10 +935,2366 @@
 %0A    %7D%0A%0A
+    /**%0A     * Retrieve a field as a %7B@code double%7D. It must be castable as such.%0A     *%0A     * @param index the index of the field%0A     * @return the %7B@code double%7D representation of the field%0A     */%0A    public double getDouble(int index) %7B%0A        Object field = this.values%5Bindex%5D;%0A        if (field instanceof Double) return (Double) field;%0A        else if (field instanceof Integer) return (Integer) field;%0A        else if (field instanceof Float) return (Float) field;%0A        else if (field instanceof Long) return (Long) field;%0A        else if (field instanceof Short) return (Short) field;%0A        else if (field instanceof Byte) return (Byte) field;%0A        throw new IllegalStateException(String.format(%22%25s cannot be retrieved as double.%22, field));%0A    %7D%0A%0A    /**%0A     * Retrieve a field as a %7B@code long%7D. It must be castable as such.%0A     *%0A     * @param index the index of the field%0A     * @return the %7B@code long%7D representation of the field%0A     */%0A    public long getLong(int index) %7B%0A        Object field = this.values%5Bindex%5D;%0A        if (field instanceof Integer) return (Integer) field;%0A        else if (field instanceof Long) return (Long) field;%0A        else if (field instanceof Short) return (Short) field;%0A        else if (field instanceof Byte) return (Byte) field;%0A        throw new IllegalStateException(String.format(%22%25s cannot be retrieved as double.%22, field));%0A    %7D%0A%0A    /**%0A     * Retrieve a field as a %7B@code int%7D. It must be castable as such.%0A     *%0A     * @param index the index of the field%0A     * @return the %7B@code int%7D representation of the field%0A     */%0A    public int getInt(int index) %7B%0A        Object field = this.values%5Bindex%5D;%0A        if (field instanceof Integer) return (Integer) field;%0A        else if (field instanceof Short) return (Short) field;%0A        else if (field instanceof Byte) return (Byte) field;%0A        throw new IllegalStateException(String.format(%22%25s cannot be retrieved as double.%22, field));%0A    %7D%0A%0A    /**%0A     * Retrieve a field as a %7B@link String%7D.%0A     *%0A     * @param index the index of the field%0A     * @return the field as a %7B@link String%7D (obtained via %7B@link Object#toString()%7D) or %7B@code null%7D if the field is %7B@code null%7D%0A     */%0A    public String getString(int index) %7B%0A        Object field = this.values%5Bindex%5D;%0A        return field == null ? null : field.toString();%0A    %7D%0A%0A
 %7D%0A

add specialized get***(...) methods to Record