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

cz.cuni.mff.d3s.spl.formula.SplFormula Maven / Gradle / Ivy

Go to download

Stochastice Performance Logic is a formalism for capturing performance assumptions. It is, for example, possible to capture assumption that newer version of a function bar is faster than the previous version or that library foobar is faster than library barfoo when rendering antialiased text. The purpose of this framework is to allow evaluation of SPL formulas inside Java applications.

There is a newer version: 1.0.4
Show newest version
/*
 * Copyright 2015 Charles University in Prague
 * Copyright 2015 Vojtech Horky
 * 
 * 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 cz.cuni.mff.d3s.spl.formula;

/** Wrapper for parsing an SPL formula.
 *
 */
public class SplFormula {
	public static Formula create(String formula) throws FormulaParsingException {
		return FormulaParser.parse(formula);
	}
	
	public static class SplParseException extends Exception {
		private static final long serialVersionUID = 1L;
		
		public SplParseException(Throwable cause) {
			super(cause);
		}
		
		SplParseException(ParseException cause, String formula) {
			super(String.format("Parsing error in \"%s\" near %s (line %d, column %d).",
					getFirstCharacters(formula, 15),
					cause.currentToken.image,
					cause.currentToken.endLine,
					cause.currentToken.endColumn), cause);
		}
		
		SplParseException(TokenMgrError cause, String formula) {
			super(String.format("Lexical error in \"%s\" caused by \"%s\".",
					getFirstCharacters(formula, 15),
					cause.getMessage()), cause);
			
		}
		
		private static String getFirstCharacters(String input, int recommendedLength) {
			if (input.length() + 1 <= recommendedLength) {
				return input;
			} else {
				return input.substring(0, recommendedLength - 3) + "...";
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy