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

org.eclipse.core.expressions.EvaluationResult Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.expressions;

import org.eclipse.core.runtime.Assert;

/**
 * An evaluation result represents the result of an expression
 * evaluation. There are exact three instances of evaluation
 * result. They are: FALSE, TRUE and
 * NOT_LOADED. NOT_LOADED represents
 * the fact that an expression couldn't be evaluated since a
 * plug-in providing certain test expressions isn't loaded yet.
 * 

* In addition the class implements the three operation and * , or and not. The operation are * defined as follows: *

*

* The and operation: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ANDFALSETRUENOT_LOADED
FALSEFALSEFALSEFALSE
TRUEFALSETRUENOT_LOADED
NOT_LOADEDFALSENOT_LOADEDNOT_LOADED
*

* The or operation: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ORFALSETRUENOT_LOADED
FALSEFALSETRUENOT_LOADED
TRUETRUETRUETRUE
NOT_LOADEDNOT_LOADEDTRUENOT_LOADED
*

* The not operation: *

* * * * * * * * * * * * * * * * * * * * * *
NOTFALSETRUENOT_LOADED
TRUEFALSENOT_LOADED
* *

* The class is not intended to be subclassed by clients. *

* @since 3.0 * * @noextend This class is not intended to be subclassed by clients. */ public class EvaluationResult { private int fValue; private static final int FALSE_VALUE= 0; private static final int TRUE_VALUE= 1; private static final int NOT_LOADED_VALUE= 2; /** The evaluation result representing the value FALSE */ public static final EvaluationResult FALSE= new EvaluationResult(FALSE_VALUE); /** The evaluation result representing the value TRUE */ public static final EvaluationResult TRUE= new EvaluationResult(TRUE_VALUE); /** The evaluation result representing the value NOT_LOADED */ public static final EvaluationResult NOT_LOADED= new EvaluationResult(NOT_LOADED_VALUE); private static final EvaluationResult[][] AND= new EvaluationResult[][] { // FALSE //TRUE //NOT_LOADED /* FALSE */ { FALSE, FALSE, FALSE }, /* TRUE */ { FALSE, TRUE, NOT_LOADED }, /* PNL */ { FALSE, NOT_LOADED, NOT_LOADED }, }; private static final EvaluationResult[][] OR= new EvaluationResult[][] { // FALSE //TRUE //NOT_LOADED /* FALSE */ { FALSE, TRUE, NOT_LOADED }, /* TRUE */ { TRUE, TRUE, TRUE }, /* PNL */ { NOT_LOADED, TRUE, NOT_LOADED }, }; private static final EvaluationResult[] NOT= new EvaluationResult[] { //FALSE //TRUE //NOT_LOADED TRUE, FALSE, NOT_LOADED }; /* * No instances outside of EvaluationResult */ private EvaluationResult(int value) { fValue= value; } /** * Returns an EvaluationResult whose value is this && other). * * @param other the right hand side of the and operation. * * @return this && other as defined by the evaluation result */ public EvaluationResult and(EvaluationResult other) { return AND[fValue][other.fValue]; } /** * Returns an EvaluationResult whose value is this || other). * * @param other the right hand side of the or operation. * * @return this || other as defined by the evaluation result */ public EvaluationResult or(EvaluationResult other) { return OR[fValue][other.fValue]; } /** * Returns the inverted value of this evaluation result * * @return the inverted value of this evaluation result */ public EvaluationResult not() { return NOT[fValue]; } /** * Returns an evaluation result instance representing the * given boolean value. If the given boolean value is * true then ExpressionResult.TRUE * is returned. If the value is false then * ExpressionResult.FALSE is returned. * * @param b a boolean value * * @return the expression result representing the boolean * value */ public static EvaluationResult valueOf(boolean b) { return b ? TRUE : FALSE; } /** * Returns a evaluation result instance representing the * given Boolean value. If the given Boolean * value is true then ExpressionResult.TRUE * is returned. If the value is false then * ExpressionResult.FALSE is returned. * * @param b a Boolean value * * @return the expression result representing the Boolean * value */ public static EvaluationResult valueOf(Boolean b) { return b.booleanValue() ? TRUE : FALSE; } /** * For debugging purpose only * * @return a string representing this object. The result is not * human readable */ public String toString() { switch (fValue) { case 0: return "false"; //$NON-NLS-1$ case 1: return "true"; //$NON-NLS-1$ case 2: return "not_loaded"; //$NON-NLS-1$ } Assert.isTrue(false); return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy