/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* ident "%Z%%M% %I% %E% SMI"
*/
/**
* This class provides the base implementation of an Expression. All
* types of Expression must inherit from this class.
*
* An objective is always specified in terms of an expression. The
* only recognized expressions are those known by this class. An
* expression is create using the valueOf() factory method, which is
* why Expressions must be known to this class.
*/
abstract class Expression
{
/**
* Expression importance
*/
/**
* Expression name
*/
/**
* Sole constructor. (For invocation by subclass constructors)
*/
{
}
/**
* Return the name of the expression.
*/
{
return (this.name);
}
/**
* Return the importance of the expression.
*/
long getImportance()
{
return (imp);
}
/**
* Returns the supplied string as an expression.
*
* This utility function attempts to identify the supplied
* string as an expression. It tries in turn each of the known
* sub-classes until finally, if none can be recognized, an
* exception is thrown. This function is not immune to
* mistakenly mis-classifying an expression. It is the
* responsibility of the concrete Exrpession classes to ensure
* that syntactic integrity is maintained with respect to
* potential cases of mistaken identity.
*
* @param raw The candidate expression
* @throws IllegalArgumentException If no valid expression can
* be found
*/
{
/*
* TODO It would be better if subclasses registered,
* but this hard coded list will do until such a time
*/
throw new IllegalArgumentException(
"unrecognized expression: " + raw);
return (exp);
}
/**
* Ensure that the supplied importance is a valid value.
*
* @param imps String representation of the importance.
*
* @throws IllegalArgumentException if the importance is not
* valid.
*/
throws IllegalArgumentException
{
long imp;
try {
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("importance value " +
imps + " is not legal");
}
if (imp < 0)
throw new IllegalArgumentException("importance value " +
imps + " is not legal (must be positive)");
return (imp);
}
/**
* Ensure that the supplied keyword is a member of the
* supplied keys.
*
* @param keys Array of valid key strings.
* @param key Key sought.
*
* @throws IllegalArgumentException if the sought key is not
* a member of the keys array.
*/
throws IllegalArgumentException
{
return;
}
" is not recognized");
}
/**
* Return true if the supplied expression "contradicts" this
* expression. The definition of contradiction is left down to
* each implementing sub-class.
*
* @param o Expression to examine for contradiction.
*/
}
/**
* This class implements the functionality for a key-value-operator
* expression.
*
* The general form of this expression is defined in the pattern
* member. A simplified rendition of which is:
*
* [[imp]:] <key> <op> <value>
*
* key is a string which identifies the expression
* op is the operator for the expression ( < | > | ~)
* value is the value of the expression
*
* For example:
*
* 10: utilization < 80
*/
{
/**
* The operator for this expression.
*/
private char op;
/**
* The value of this expression.
*/
private int val;
/**
* The pattern used to recognize this type of expression.
*/
"\\s*((\\d+)\\s*:)?\\s*(\\w+)\\s*([~<>])\\s*(\\d+)\\s*");
/**
* The array of valid keys for this type of expression.
*/
/**
* A greater than operator.
*/
/**
* A less than operator.
*/
/**
* A near to operator.
*/
/**
* Private constructor used in the valueOf() factory method.
*
* @param imp The importance of this expression.
* @param name The name of this expression.
* @param op The operator of this expression.
* @param val The value of this expression.
*/
{
}
/**
* Create and return an expression from the input string.
*
* Determine if the input string matches the syntax defined by
* this expression. If the expression cannot be matched, an
* exception will be thrown.
*
* @param raw Candidate expression string.
*
* @throws IllegalArgumentExpression if the string is not a
* valid expression of this type.
*/
{
if (m.matches()) {
long imp = 1;
throw new IllegalArgumentException(
"expression value " + val +
" is outside the legal range (0-100)");
}
return (exp);
}
/**
* Return the operator for this expression.
*/
char getOp()
{
return (op);
}
/**
* Return the value of this expression.
*/
int getValue()
{
return (val);
}
/**
* Return a string representation of this expresssion.
*/
{
}
/**
* Indicates whether some other KVOpExpression is "equal to
* this one.
* @param o the reference object with which to compare.
* @return <code>true</code> if this object is the same as the
* o argument; <code>false</code> otherwise.
* @see #hashCode()
*/
{
if (o == this)
return (true);
if (!(o instanceof KVOpExpression))
return (false);
return (false);
return (true);
}
/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>.
*
* @return a hash code value for this object.
* @see #equals(java.lang.Object)
* @see java.util.Hashtable
*/
public int hashCode()
{
}
/**
* Return true if the supplied expression "contradicts" this
* expression. If the supplied expression is not of the same
* type, then it cannot contradict it. If the names are
* different then there can be no contradiction.
*
* Contradiction occurs if the operator is the same or if they
* aren't the same and the operator is < or > and the values
* aren't simultanteously achievable.
*
* @param o Expression to examine for contradiction.
*/
{
if (!(o instanceof KVOpExpression))
return (false);
return (false);
return (false);
} else {
return (false);
}
} else
return (false);
}
return (true);
}
}
/**
* This class implements the functionality for a key-value expression.
*
* The general form of this expression is defined in the pattern
* member. A simplified rendition of which is:
*
* [[imp]:] <key> <value>
*
* key is a string which identifies the expression
* value is the value of the expression
*
* For example:
*
* 10: locality tight
*/
{
/**
* The value of this expression.
*/
/**
* The pattern used to recognize this type of expression.
*/
"\\s*((\\d+)\\s*:)?\\s*(\\w+)\\s+(tight|loose|none)\\s*");
/**
* The array of valid keys for this type of expression.
*/
/**
* Private constructor used in the valueOf() factory method.
*
* @param imp The importance of this expression.
* @param name The name of this expression.
* @param val The value of this expression.
*/
{
}
/**
* Create and return an expression from the input string.
*
* Determine if the input string matches the syntax defined by
* this expression. If the expression cannot be matched, an
* exception will be thrown.
*
* @param raw Candidate expression string.
*
* @throws IllegalArgumentExpression if the string is not a
* valid expression of this type.
*/
{
if (m.matches()) {
long imp = 1;
}
return (exp);
}
/**
* Return the value of this expression.
*/
{
return (val);
}
/**
* Return a string representation of this expresssion.
*/
{
}
/**
* Indicates whether some other KVExpression is "equal to
* this one.
* @param o the reference object with which to compare.
* @return <code>true</code> if this object is the same as the
* o argument; <code>false</code> otherwise.
* @see #hashCode()
*/
{
if (o == this)
return (true);
if (!(o instanceof KVExpression))
return (false);
return (false);
return (true);
}
/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>.
*
* @return a hash code value for this object.
* @see #equals(java.lang.Object)
* @see java.util.Hashtable
*/
public int hashCode()
{
}
/**
* Return true if the supplied expression "contradicts" this
* expression. If the supplied expression is not of the same
* type, then it cannot contradict it. If the names are
* different then there can be no contradiction.
*
* Contradiction occurs if the value is different.
*
* @param o Expression to examine for contradiction.
*/
{
if (!(o instanceof KVExpression))
return (false);
return (false);
return (false);
return (true);
}
}
/**
* This class implements the functionality for a key expression.
*
* The general form of this expression is defined in the pattern
* member. A simplified rendition of which is:
*
* [[imp]:] <key>
*
* key is a string which identifies the expression
*
* For example:
*
* 10: wt-load
*/
{
/**
* The pattern used to recognize this type of expression.
*/
"\\s*((\\d+)\\s*:)?\\s*([\\w-]+)\\s*");
/**
* The array of valid keys for this type of expression.
*/
/**
* Private constructor used in the valueOf() factory method.
*
* @param imp The importance of this expression.
* @param name The name of this expression.
*/
{
}
/**
* Create and return an expression from the input string.
*
* Determine if the input string matches the syntax defined by
* this expression. If the expression cannot be matched, an
* exception will be thrown.
*
* @param raw Candidate expression string.
*
* @throws IllegalArgumentExpression if the string is not a
* valid expression of this type.
*/
{
if (m.matches()) {
long imp = 1;
}
return (exp);
}
/**
* Return a string representation of this expresssion.
*/
{
}
/**
* Indicates whether some other KExpression is "equal to
* this one.
* @param o the reference object with which to compare.
* @return <code>true</code> if this object is the same as the
* o argument; <code>false</code> otherwise.
* @see #hashCode()
*/
{
if (o == this)
return (true);
if (!(o instanceof KExpression))
return (false);
return (false);
return (true);
}
/**
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>.
*
* @return a hash code value for this object.
* @see #equals(java.lang.Object)
* @see java.util.Hashtable
*/
public int hashCode()
{
}
/**
* Return true if the supplied expression "contradicts" this
* expression. If the supplied expression is not of the same
* type, then it cannot contradict it. If the names are
* different then there can be no contradiction.
*
* @param o Expression to examine for contradiction.
*/
{
if (!(o instanceof KExpression))
return (false);
return (false);
return (true);
}
}