ValueRecord#

The base class of the record types in org.dhtmlx.plen: input data, options, change sets and results. It adds a shallow copy() and replaces equals, hashCode and toString with versions that read the record's public fields. Application code doesn't create a ValueRecord directly. It meets the class through subclasses such as TaskData, SolveOptions or ScheduleResult.

Declaration#

package org.dhtmlx.plen;

public class ValueRecord implements Cloneable

Every member below reads the public instance fields of the runtime class, inherited ones included. Static, private, protected and package-private fields are ignored. A subclass can override any of these methods, and its own page says so when it does.

Methods#

copy#

public ValueRecord copy()

Returns a shallow copy made with Object.clone(). Field values are copied as they are, so the copy and the original share lists (Vec), maps and nested records. Most subclasses override copy() with their own return type (TaskData copy()), so no cast is needed. For a copy that shares nothing mutable, use deepClone() from DeepCloneable<T>.

Returns - a new instance of the same runtime class.

equals#

@Override
public boolean equals(Object other)

Structural equality. Returns true when other is the same object, or when it has exactly the same runtime class and every public field is equal by Objects.deepEquals. An instance of a subclass is never equal to an instance of its parent class.

Field values compare as follows:

Field value Compared by
null equal only to null
double, Double Double.equals: -0.0 and 0.0 differ, NaN equals NaN
Vec, other lists the list's equals: same size, same elements in the same order
nested record its own equals, recursively
array element by element (Arrays.deepEquals)
anything else the value's equals

Returns - true if the records are equal.

hashCode#

@Override
public int hashCode()

A hash over the same public fields, consistent with equals: equal records have equal hash codes.

Records are mutable, so the hash code changes when a field changes. Don't modify a record while it's a key in a HashMap or an element of a HashSet.

Returns - the hash code.

toString#

@Override
public String toString()

Returns the simple class name followed by every public field as name=value, for example Pause{at=2.0, length=1.0, by=null}. Each value is formatted with String.valueOf, so nested records and lists print recursively. Field order follows Class.getFields(), which the JVM doesn't guarantee. Use the string for logs and debugging only; it isn't a serialization format.

Returns - the text form of the record.

Example#

import org.dhtmlx.plen.*;

public class ValueRecordExample {
    public static void main(String[] args) throws Exception {
        Pause a = new Pause(2.0, 1.0);
        Pause b = a.copy();

        System.out.println(a.equals(b));                  // true
        System.out.println(a.hashCode() == b.hashCode()); // true

        b.withLength(3.0);
        System.out.println(a.equals(b));                  // false
        System.out.println(b);                            // Pause{at=2.0, length=3.0, by=null}

        System.out.println(new Pause(0.0, 1.0).equals(new Pause(-0.0, 1.0))); // false
    }
}