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-2016 ForgeRock AS.
016 */
017
018package org.opends.guitools.controlpanel.datamodel;
019
020/** Class used in the combo box models. It is used to have special rendering in the combo boxes. */
021public class CategorizedComboBoxElement
022{
023  private Object value;
024  private Type type;
025  private int hashCode;
026
027  /** The type of the element. */
028  public enum Type
029  {
030    /**
031     * Category type (in a combo box containing base DNs the backends are of
032     * type category, for instance).
033     */
034    CATEGORY,
035    /** Regular type. */
036    REGULAR
037  }
038
039  /**
040   * Constructor.
041   * @param value the value of the element.
042   * @param type the type of the element.
043   */
044  public CategorizedComboBoxElement(Object value, Type type)
045  {
046    this.value = value;
047    this.type = type;
048    this.hashCode = this.value.hashCode() + this.type.hashCode();
049  }
050
051  /**
052   * Returns the value.
053   * @return the value.
054   */
055  public Object getValue()
056  {
057    return value;
058  }
059
060  /**
061   * Returns the type of the element.
062   * @return the type of the element.
063   */
064  public Type getType()
065  {
066    return type;
067  }
068
069  @Override
070  public boolean equals(Object o)
071  {
072    if (o instanceof CategorizedComboBoxElement)
073    {
074      CategorizedComboBoxElement desc = (CategorizedComboBoxElement)o;
075      return desc.getType() == getType()
076          && getValue().equals(desc.getValue());
077    }
078    return false;
079  }
080
081  @Override
082  public int hashCode()
083  {
084    return hashCode;
085  }
086}