001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 * Portions Copyright 2015 ForgeRock AS. 026 */ 027package org.opends.guitools.controlpanel.datamodel; 028 029import java.util.Objects; 030import java.util.Set; 031import java.util.SortedSet; 032import java.util.TreeSet; 033 034/** 035 * This class represent all the objectclass values for a given entry. It is 036 * used by the entry editors (SimplifiedEntryView and TableEntryView) to edit 037 * and display the objectclass. 038 */ 039public class ObjectClassValue 040{ 041 private String structural; 042 private SortedSet<String> auxiliary = new TreeSet<>(); 043 private int hashCode; 044 045 /** 046 * Constructor of the object class value. 047 * @param structural the name of the structural objectclass. 048 * @param auxiliary the auxiliary objectclasses. 049 */ 050 public ObjectClassValue(String structural, Set<String> auxiliary) 051 { 052 this.structural = structural; 053 this.auxiliary.addAll(auxiliary); 054 if (structural != null) 055 { 056 // This can happen when the schema checking is not enabled. 057 hashCode = structural.hashCode(); 058 } 059 for (String oc : auxiliary) 060 { 061 hashCode += oc.hashCode(); 062 } 063 } 064 065 /** 066 * Returns the names of the auxiliary objectclasses. 067 * @return the names of the auxiliary objectclasses. 068 */ 069 public SortedSet<String> getAuxiliary() 070 { 071 return auxiliary; 072 } 073 074 /** 075 * Returns the name of the structural objectclass. 076 * @return the name of the structural objectclass. 077 */ 078 public String getStructural() 079 { 080 return structural; 081 } 082 083 /** {@inheritDoc} */ 084 public int hashCode() 085 { 086 return hashCode; 087 } 088 089 /** {@inheritDoc} */ 090 public boolean equals(Object o) 091 { 092 if (this == o) 093 { 094 return true; 095 } 096 if (o instanceof ObjectClassValue) 097 { 098 ObjectClassValue oc = (ObjectClassValue)o; 099 return Objects.equals(structural, oc.getStructural()) 100 && auxiliary.equals(oc.getAuxiliary()); 101 } 102 return false; 103 } 104}