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 */
017package org.opends.guitools.controlpanel.datamodel;
018
019import java.util.Objects;
020import java.util.Set;
021import java.util.SortedSet;
022import java.util.TreeSet;
023
024/**
025 * This class represent all the objectclass values for a given entry.  It is
026 * used by the entry editors (SimplifiedEntryView and TableEntryView) to edit
027 * and display the objectclass.
028 */
029public class ObjectClassValue
030{
031  private String structural;
032  private SortedSet<String> auxiliary = new TreeSet<>();
033  private int hashCode;
034
035  /**
036   * Constructor of the object class value.
037   * @param structural the name of the structural objectclass.
038   * @param auxiliary the auxiliary objectclasses.
039   */
040  public ObjectClassValue(String structural, Set<String> auxiliary)
041  {
042    this.structural = structural;
043    this.auxiliary.addAll(auxiliary);
044    if (structural != null)
045    {
046      // This can happen when the schema checking is not enabled.
047      hashCode = structural.hashCode();
048    }
049    for (String oc : auxiliary)
050    {
051      hashCode += oc.hashCode();
052    }
053  }
054
055  /**
056   * Returns the names of the auxiliary objectclasses.
057   * @return the names of the auxiliary objectclasses.
058   */
059  public SortedSet<String> getAuxiliary()
060  {
061    return auxiliary;
062  }
063
064  /**
065   * Returns the name of the structural objectclass.
066   * @return the name of the structural objectclass.
067   */
068  public String getStructural()
069  {
070    return structural;
071  }
072
073  @Override
074  public int hashCode()
075  {
076    return hashCode;
077  }
078
079  @Override
080  public boolean equals(Object o)
081  {
082    if (this == o)
083    {
084      return true;
085    }
086    if (o instanceof ObjectClassValue)
087    {
088      ObjectClassValue oc = (ObjectClassValue)o;
089      return Objects.equals(structural, oc.getStructural())
090          && auxiliary.equals(oc.getAuxiliary());
091    }
092    return false;
093  }
094}