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 */
017
018package org.opends.server.authorization.dseecompat;
019
020/**
021 *  This class provides an enumeration of the valid ACI target operators.
022 */
023public enum EnumTargetOperator {
024
025    /**
026    * This enumeration is returned when the target operator is  "=".
027     */
028    EQUALITY        ("="),
029    /**
030    * This enumeration is returned when the target operator is  "!=".
031     */
032    NOT_EQUALITY    ("!=");
033
034    /** The target operator name. */
035    private final String operator;
036
037    /**
038     * Create an enumeration of the provided operator name.
039     * @param operator The operator name to create.
040     */
041    EnumTargetOperator(String operator){
042        this.operator = operator;
043    }
044
045    /**
046     * Checks if the provided operator name is equal to the enumeration.
047     * @param op The operator name to check for.
048     * @return  True if the operator name is equal to the enumeration.
049     */
050    public boolean isOperator(String op){
051        return op.equalsIgnoreCase(operator);
052    }
053
054    /**
055     * Creates an enumeration of the specified operator type name.
056     * @param op The operator type name to create.
057     * @return  Return an enumeration of the operator type name or null if the
058     * name is invalid.
059     */
060    public static EnumTargetOperator createOperator(String op){
061        if (op != null){
062            for (EnumTargetOperator t : EnumTargetOperator.values()){
063                if (t.isOperator(op)){
064                    return t;
065                }
066            }
067        }
068        return null;
069    }
070}