java.lang.Object
java.lang.Record
org.jhotdraw8.icollection.PrivateData
This record holds an object that contains private data.
This record is used to allow subclassing of immutable classes that need to create new instances of subclasses, but that do not want to export their internal data structures.
Example:
The module 'foo' exports the package that contains class ImmutableFoo. The module 'foo' does not export the package that contains InternalHashtable used by ImmutableFoo.
To allow subclassing of ImmutableFoo by other modules,
class ImmutableFoo provides a protected constructor and
a protected newInstance method that take an PrivateData object
as parameters.
module org.foo {
exports org.foo;
}
package org.foo.impl;
import java.util.logging.Level;
import java.util.logging.Logger;
public class InternalHashtable {
...
}
package org.foo;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ImmutableFoo {
private final @NonNull InternalHashtable table;
public ImmutableFoo() {
table = new InternalHashtable();
}
protected ImmutableFoo(PrivateData opaque) {
this.table = opaque.get();
}
protected ImmutableFoo newInstance(PrivateData opaque) {
return new ImmutableFoo(opaque);
}
}
module org.bar {
imports org.foo;
exports org.bar;
}
package org.bar;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ImmutableBar extends ImmutableFoo {
private final int bar;
public ImmutableBar(int bar) {
this.bar=bar;
}
protected ImmutableBar(PrivateData opaque, int bar) {
super(opaque);
this.bar=bar;
}
protected newInstance(PrivateData opaque) {
return new ImmutableBar(opaque,this.bar);
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionPrivateData(@Nullable Object object) Creates an instance of aPrivateDatarecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.object()Returns the value of theobjectrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PrivateData
Creates an instance of aPrivateDatarecord class.- Parameters:
object- the value for theobjectrecord component
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
object
Returns the value of theobjectrecord component.- Returns:
- the value of the
objectrecord component
-