001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015 ForgeRock AS.
016 */
017package org.opends.guitools.controlpanel.datamodel;
018
019/**
020 * Class that describes the VLV sort order.
021 */
022public class VLVSortOrder
023{
024  private String attributeName;
025  private boolean isAscending;
026  private int hashCode;
027
028  /**
029   * Constructor of the VLVSortOrder.
030   * @param attributeName the attribute name to be used to sort.
031   * @param isAscending whether the sorting is ascending or descending.
032   */
033  public VLVSortOrder(String attributeName, boolean isAscending)
034  {
035    this.attributeName = attributeName;
036    this.isAscending = isAscending;
037    hashCode = ("vlvsortorder"+attributeName+isAscending).hashCode();
038  }
039
040  /**
041   * Returns the name of the attribute.
042   * @return the name of the attribute.
043   */
044  public String getAttributeName()
045  {
046    return attributeName;
047  }
048
049  /**
050   * Returns whether the sorting is ascending or descending.
051   * @return <CODE>true</CODE> if the sorting is ascending and
052   * <CODE>false</CODE> otherwise.
053   */
054  public boolean isAscending()
055  {
056    return isAscending;
057  }
058
059  /** {@inheritDoc} */
060  public int hashCode()
061  {
062    return hashCode;
063  }
064
065  /** {@inheritDoc} */
066  public boolean equals(Object o)
067  {
068    if (o == this) {
069      return  true;
070    }
071    if (o instanceof VLVSortOrder)
072    {
073      VLVSortOrder sortOrder = (VLVSortOrder)o;
074      return sortOrder.getAttributeName().equalsIgnoreCase(attributeName)
075          && sortOrder.isAscending() == isAscending;
076    }
077    return false;
078  }
079}