All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.globus.rsl.NameOpValue Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 1999-2006 University of Chicago
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.globus.rsl;

import java.util.*;

/**
 * This class represents a single relation in the RSL string.
 */
public class NameOpValue extends NameValue {

    public static final int EQ    = 1;
    public static final int NEQ   = 2;
    public static final int GT    = 3;
    public static final int GTEQ  = 4;
    public static final int LT    = 5;
    public static final int LTEQ  = 6;

    protected int operator;

    public NameOpValue(String attribute) {
	super(attribute);
    }

    public NameOpValue(String attribute, int op) {
	super(attribute);
	setOperator(op);
    }

    public NameOpValue(String attribute, int op, String strValue) {
	this(attribute, op);
	add(strValue);
    }

    public NameOpValue(String attribute, int op, String [] strValues) {
	this(attribute, op);
	add(strValues);
    }

    public NameOpValue(String attribute, int op, Value value) {
	this(attribute, op);
	add(value);
    }

    /**
     * Sets the relation operator.
     *
     * @param oper the relation operator.
     */
    public void setOperator(int oper) {
	operator = oper;
    }

    /**
     * Returns the relation operator.
     *
     * @return the relation operator.
     */
    public int getOperator() {
	return operator;
    }

    /**
     * Returns the relation operator as a string.
     *
     * @return the relation operator as a string.
     */
    public String getOperatorAsString() {
	return getOperatorAsString(operator);
    }

    /**
     * Returns a string representation of the specified
     * relation operator.
     *
     * @param op the relation operator
     * @return the string representaion of the relation operator.
     */
    public static String getOperatorAsString(int op) {
	switch(op) {
	case EQ:
	    return "=";
	case NEQ:
	    return "!=";
	case GT:
	    return ">";
	case GTEQ:
	    return ">=";
	case LT:
	    return "<";
	case LTEQ:
	    return "<=";
	default: return "??";
	}
    }

    /**
     * Adds a value to the list of values.
     *
     * @param value the value to add.
     */
    public void add(Value value) {
	if (values == null) values = new LinkedList();
	values.add(value);
    }

    /**
     * Adds a value to the list of values.
     * The string value is first converted into
     * a Value object.
     *
     * @param strValue the value to add.
     */
    public void add(String strValue) {
	add(new Value(strValue));
    }

    /**
     * Adds an array of values to the list of values.
     * Each element in the array is converted into a
     * Value object and inserted as a separate value
     * into the list of values.
     *
     * @param strValues the array of values to add.
     */
    public void add(String [] strValues) {
	if (strValues == null) return;
	if (values == null) values = new LinkedList();
	for (int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy