3853N/A/*
3853N/A * CDDL HEADER START
3853N/A *
3853N/A * The contents of this file are subject to the terms of the
3853N/A * Common Development and Distribution License, Version 1.0 only
3853N/A * (the "License"). You may not use this file except in compliance
3853N/A * with the License.
3853N/A *
3853N/A * You can obtain a copy of the license at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
3853N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3853N/A * See the License for the specific language governing permissions
3853N/A * and limitations under the License.
3853N/A *
3853N/A * When distributing Covered Code, include this CDDL HEADER in each
3853N/A * file and include the License file at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3853N/A * add the following below this CDDL HEADER, with the fields enclosed
3853N/A * by brackets "[]" replaced with your own identifying information:
3853N/A * Portions Copyright [yyyy] [name of copyright owner]
3853N/A *
3853N/A * CDDL HEADER END
3853N/A *
3853N/A *
5035N/A * Copyright 2008-2010 Sun Microsystems, Inc.
3853N/A */
3853N/A
3853N/Apackage org.opends.guitools.controlpanel.datamodel;
3853N/A
3853N/Aimport java.util.Collections;
3853N/Aimport java.util.List;
3853N/A
3853N/Aimport org.opends.server.admin.std.meta.LocalDBVLVIndexCfgDefn.Scope;
3853N/Aimport org.opends.server.types.DN;
3853N/A
3853N/A/**
3853N/A * The class used to describe the VLV index configuration.
3853N/A *
3853N/A */
3853N/Apublic class VLVIndexDescriptor extends AbstractIndexDescriptor
3853N/A{
3853N/A private DN baseDN;
3853N/A private Scope scope;
3853N/A private String filter;
3858N/A private List<VLVSortOrder> sortOrder = Collections.emptyList();
3853N/A private int maxBlockSize;
3853N/A private int hashCode;
3853N/A
3853N/A /**
3853N/A * Constructor for the VLVIndexDescriptor.
3853N/A * @param name the name of the index.
3853N/A * @param backend the backend where the index is defined.
3853N/A * @param baseDN the baseDN of the search indexed by the VLV index.
3853N/A * @param scope the scope of the search indexed by the VLV index.
3853N/A * @param filter the filter or the search indexed by the VLV index.
3853N/A * @param sortOrder the sort order list of the VLV index.
3853N/A * @param maxBlockSize the maximum block size of the VLV index.
3853N/A */
3853N/A public VLVIndexDescriptor(String name, BackendDescriptor backend, DN baseDN,
3853N/A Scope scope, String filter, List<VLVSortOrder> sortOrder,
3853N/A int maxBlockSize)
3853N/A {
3853N/A super(name, backend);
3853N/A this.baseDN = baseDN;
3853N/A this.scope = scope;
3853N/A this.filter = filter;
3858N/A this.sortOrder = Collections.unmodifiableList(sortOrder);
3853N/A this.maxBlockSize = maxBlockSize;
3853N/A
3853N/A recalculateHashCode();
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
5035N/A public int compareTo(AbstractIndexDescriptor o)
3853N/A {
5061N/A return getName().toLowerCase().compareTo(o.getName().toLowerCase());
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public int hashCode()
3853N/A {
3853N/A return hashCode;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the baseDN of the search indexed by the VLV index.
3853N/A * @return the baseDN of the search indexed by the VLV index.
3853N/A */
3853N/A public DN getBaseDN()
3853N/A {
3853N/A return baseDN;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the filter of the search indexed by the VLV index.
3853N/A * @return the filter of the search indexed by the VLV index.
3853N/A */
3853N/A public String getFilter()
3853N/A {
3853N/A return filter;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the scope of the search indexed by the VLV index.
3853N/A * @return the scope of the search indexed by the VLV index.
3853N/A */
3853N/A public Scope getScope()
3853N/A {
3853N/A return scope;
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the sort order list of the VLV index.
3853N/A * @return the sort order list of the VLV index.
3853N/A */
3853N/A public List<VLVSortOrder> getSortOrder()
3853N/A {
3858N/A return sortOrder;
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public boolean equals(Object o)
3853N/A {
3853N/A boolean equals = o == this;
3853N/A if (!equals)
3853N/A {
3853N/A equals = o instanceof VLVIndexDescriptor;
3853N/A if (equals)
3853N/A {
3853N/A VLVIndexDescriptor index = (VLVIndexDescriptor)o;
3853N/A equals = index.getName().equalsIgnoreCase(getName()) &&
3853N/A index.getBaseDN().equals(getBaseDN()) &&
3853N/A index.getFilter().equals(getFilter()) &&
3853N/A index.getScope() == getScope() &&
3853N/A index.getSortOrder().equals(getSortOrder());
3853N/A if (equals)
3853N/A {
3853N/A if ((getBackend() != null) && (index.getBackend() != null))
3853N/A {
3853N/A // Only compare the backend IDs. In this context is better to
3853N/A // do this since the backend object contains some state (like
3853N/A // number entries) that can change.
3853N/A equals = getBackend().getBackendID().equals(
3853N/A index.getBackend().getBackendID());
3853N/A }
3853N/A }
3853N/A }
3853N/A }
3853N/A return equals;
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A protected void recalculateHashCode()
3853N/A {
3853N/A StringBuilder sb = new StringBuilder();
3853N/A for (VLVSortOrder s : sortOrder)
3853N/A {
3853N/A sb.append(s.getAttributeName()+s.isAscending()+",");
3853N/A }
3853N/A if (getBackend() != null)
3853N/A {
3853N/A sb.append(getBackend().getBackendID());
3853N/A }
3853N/A hashCode = (getName()+baseDN+scope+filter+sb+maxBlockSize).hashCode();
3853N/A }
3853N/A
3853N/A /**
3853N/A * Returns the maximum block size of the VLV index.
3853N/A * @return the maximum block size of the VLV index.
3853N/A */
3853N/A public int getMaxBlockSize()
3853N/A {
3853N/A return maxBlockSize;
3853N/A }
3853N/A}