Module openj9.dtfj

Class PHDJavaObject.Builder

java.lang.Object
com.ibm.dtfj.phd.PHDJavaObject.Builder
Enclosing class:
PHDJavaObject

public static class PHDJavaObject.Builder extends Object
The constructors for PHDJavaObject used to take up to 11 arguments, many of which were ints. This made it hard to tie up which argument corresponded to which parameter and invited errors since there can be no type checking.

This is now fixed by the use of the Builder pattern as described in Effective Java Second Edition by Joshua Bloch (http://cyclo.ps/books/Prentice.Hall.Effective.Java.2nd.Edition.May.2008.pdf), item 2 "Consider a builder when faced with many constructor parameters".

The only way to construct a PHDJavaObject is now using this Builder. Required arguments are set with a call to the Builder constructor, then optional arguments are set, then build() is called, usually all in one line using a fluent interface.

  • Constructor Details

    • Builder

      public Builder(com.ibm.dtfj.phd.PHDJavaHeap heap, long address, JavaClass cls, int flags, int hashCode)
      Initialize a Builder for a PHDJavaClass with the five required parameters.
      Parameters:
      heap -
      address -
      cls -
      flags -
      hashCode -
  • Method Details

    • refs

      public PHDJavaObject.Builder refs(LongEnumeration refs, int skipped)
      Add the refs attribute to a PHDJavaObject before building it.
      Parameters:
      refs -
      skipped -
      Returns:
      the builder for further attributes or a call to build()
    • refsAsArray

      public PHDJavaObject.Builder refsAsArray(long[] refs, int skipped)
      Add the refs attribute to a PHDJavaObject before building it.
      Parameters:
      refs -
      skipped -
      Returns:
      the builder for further attributes or a call to build()
    • length

      public PHDJavaObject.Builder length(int length)
      Add the length attribute to a PHDJavaObject before building it.
      Parameters:
      length -
      Returns:
    • instanceSize

      public PHDJavaObject.Builder instanceSize(long instanceSize)
      Add the instance size attribute to a PHDJavaObject before building it.
      Parameters:
      instance - size
      Returns:
    • build

      public PHDJavaObject build()
      Build the PHDJavaObject using all the required and optional values given so far.
      Returns:
      the PHDJavaObject