All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.phloc.commons.compare.GlobalCompareSettings Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
package com.phloc.commons.compare;

import com.phloc.commons.state.EChange;

/**
 * Settings for comparison
 * 
 * @author Boris Gregorcic
 */
public class GlobalCompareSettings
{
  private static final class SingletonHolder
  {
    /**
     * The singleton instance
     */
    public static final GlobalCompareSettings INSTANCE = new GlobalCompareSettings ();
  }

  /** By default null values come first */
  public static final boolean DEFAULT_NULL_VALUES_COME_FIRST = true;

  /**
   * By default null values come first for backwards compatibility
   * reasons
   */
  private boolean m_bSortNullValuesFirst = DEFAULT_NULL_VALUES_COME_FIRST;

  /**
   * Ctor for singleton creation
   */
  protected GlobalCompareSettings ()
  {
    // protected
  }

  /**
   * Ctor
   * 
   * @return the singleton instance
   */
  public static GlobalCompareSettings getInstance ()
  {
    return SingletonHolder.INSTANCE;
  }

  /**
   * @return Whether or not null values will be considered smaller
   *         than any other value and therefore will be sorted before other
   *         values
   */
  public boolean isSortNullValuesFirst ()
  {
    return this.m_bSortNullValuesFirst;
  }

  /**
   * This API can be used to influence the comparison behavior concerning
   * null values. By default, null values will be
   * considered smaller than any other value and therefore will be sorted before
   * other values.
   * 
   * @param bNullValuesFirst
   * @return
   */
  public EChange setSortNullValuesFirst (boolean bNullValuesFirst)
  {
    EChange eChange = EChange.valueOf (bNullValuesFirst != this.m_bSortNullValuesFirst);
    this.m_bSortNullValuesFirst = bNullValuesFirst;
    return eChange;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy