com.hammurapi.extract

## Class ExtractorBase<T,V,C>

- java.lang.Object
- - com.hammurapi.extract.ExtractorBase<T,V,C>

- Type Parameters:
    `T` -
    `V` -
  All Implemented Interfaces:
    Extractor<T,V,C>
  Direct Known Subclasses:
    AbstractExtractor, Add, And, CommutativeAnd, CommutativeOr, ComparisonPredicate, CompositeExtractorBase, Constant, Divide, MethodExtractor, Multiply, Or, ScriptingPredicate, Subtract

      public abstract class ExtractorBase<T,V,C>
      extends Object
      implements Extractor<T,V,C>

  Base class for extractors, implements value caching.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected double` | `cost`
    `protected TimeUnit` | `costUnit`
    `protected double` | `initialCost`
    `protected long` | `invocations`
    `protected boolean` | `nanos`
    `protected double` | `totalCost`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ExtractorBase(double initialCost, TimeUnit costUnit)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ComparisonResult` | `compareTo(Extractor<T,V,C> other)` Basic comparisons with True and False.
    `protected Map<Extractor<T,? super V,C>,? super V>` | `createCacheEntry()`
    `boolean` | `equals(Object obj)`
    `V` | `extract(C context, Map<C,Map<Extractor<T,? super V,C>,? super V>> cache, T... obj)` Extracts value.
    `protected abstract V` | `extractInternal(C context, Map<C,Map<Extractor<T,? super V,C>,? super V>> cache, T... obj)`
    `double` | `getCost()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.hammurapi.extract.Extractor

      `isContextDependent, parameterIndices`

- - ### Field Detail

    - #### costUnit

          protected TimeUnit costUnit

    - #### invocations

          protected long invocations

    - #### totalCost

          protected double totalCost

    - #### nanos

          protected boolean nanos

    - #### cost

          protected double cost

    - #### initialCost

          protected double initialCost

  - ### Constructor Detail

    - #### ExtractorBase

          protected ExtractorBase(double initialCost,
                       TimeUnit costUnit)

      Parameters:
        `initialCost` - Initial cost. If positive, this value is added to the calculated cost. If costUnit is null, then cost is always equal to the initial cost. If negative and time unit is not null, then absolute value is used as first measurement of cost.
        `costUnit` - If this argument is not null, then extractor cost is calculated as average time to execute extractInternal() method in specified time unit. If time unit is nanoseconds or microseconds, then System.nanoTime() method is used for measurement, otherwise Systsm.currentTimeMillis() is used.

  - ### Method Detail

    - #### extract

          public V extract(C context,
                  Map<C,Map<Extractor<T,? super V,C>,? super V>> cache,
                  T... obj)

      Description copied from interface: `Extractor`
      Extracts value.
      Specified by:
        `extract` in interface `Extractor<T,V,C>`
      Parameters:
        `context` - Extraction context. Extraction context may provide source for constants for comparison with object values.
        `cache` - Cache of values extracted from the source object for the given context. Composite extractors can use cache to find already extracted values and to store extracted values. For example extractor which extracts object area as obj.getWidth()*obj.getHeight() may find that width was already extracted and getWidth() doesn't have to be invoked. So it invokes getHeight() and stores returned value to the cache. It also calculates object area and stores it to the cache. A particular cache instance is valid only for a particular obj array, i.e. it can be re-used between extractors but not between arguments.
        `obj` - Source objects.
      Returns:
        Extracted value.

    - #### getCost

          public double getCost()

      Specified by:
        `getCost` in interface `Extractor<T,V,C>`
      Returns:
        Extractor evaluation cost. Cost is used for optimization of computation intensive algorithms. E.g. in Store it is used for selection of indices for query operations.

    - #### compareTo

          public ComparisonResult compareTo(Extractor<T,V,C> other)

      Basic comparisons with True and False.
      Specified by:
        `compareTo` in interface `Extractor<T,V,C>`
      Parameters:
        `otherPredicate` -
      Returns:

    - #### extractInternal

          protected abstract V extractInternal(C context,
                          Map<C,Map<Extractor<T,? super V,C>,? super V>> cache,
                          T... obj)

    - #### createCacheEntry

          protected Map<Extractor<T,? super V,C>,? super V> createCacheEntry()

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`