libformula-1.1.7/0000755000175000017500000000000011636174536012334 5ustar renerenelibformula-1.1.7/common_build.xml0000644000175000017500000020225611401240110015500 0ustar renerene ------------------------------------------------------------------------------- Common Build file provides tasks needed to perform a project build. It is typically not used directly but imported by each project's build.xml file. The build.xml file can override tasks when customization is required. MAIN TARGETS ============ * clean / clean-all : remove all artifacts of the build, clean-all adds the removal of any library or jar dependencies downloaded as part of the build * resolve : download/refresh library or jar dependencies needed for the build (uses Apache IVY) * compile : run javac on the project's source * jar : creates a jar file * dist : creates all project distributables * test : runs JUnit tests from your project's test source SPECIAL TARGETS ============ * publish-local : builds a jar for your project and registers it with the local artifact repository isolated to your machine at $HOME/.ivy2/local. Further executions of the the resolve target by this or other projects will find your published jar. * ivy-clean* : this family of targets helps reset your IVY environment in the event that you are having difficulty resolving dependencies TYPICAL TARGET SEQUENCE ============ * clean-all resolve dist : a good start to build all project distributables from scratch. Note that jar dependencies will not be downloaded unless you explicitly run the resolve target. We made the resolution and retrieval completely discretionary since there are many situations in which you will not want to get or refresh dependencies, e.g. if you are offline with no Internet access. In such case, you could just run "dist" if the set of jars you already have are sufficient. libformula-1.1.7/.project0000644000175000017500000000060211401240104013750 0ustar renerene libformula org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature libformula-1.1.7/ChangeLog.txt0000644000175000017500000003362311401240110014677 0ustar renerene--------------- 1. WHAT's NEW --------------- A list of changes in recent versions: 1.1.7: * [BUG] PRD-2717: A copy/paste error prevented quoting in CSVTEXT function from working. 1.1.6: (2010-04-27) * PRD-2345, PRD-2435: Messages and evaluation errors must be human readable and localizable. * [BUG] TRIM function failed on empty strings * [BUG] PRD-2576: Number-parsing was not strict enough causing the EXACT function to fail on certain strings. * [BUG] PRD-2611: CSVArray function used CSVTokenizer and thus auto-trimmed the text it was given to parse. 0.1.18.4: (2010-04-07) * Backported new Exception handling for more performance. 1.1.5: (2010-01-15) * PRD-2378: Added PARSEDATE function. * Converting CLOBs into Strings was buggy due to a 1-index error. 1.1.4: (2009-12-15) * Added IFNA() function. * PRD-2367: Enabled strict date parsing so that we can parse strings into dates and can be sure we do not accidentally interpret numbers as dates. 1.1.3: (2009-11-13) * [BUG] PRD-2289: TextFunction now accepts a second parameter as format string so that the string-conversion can be more controlled. * [BUG] Quote-handling inside references was handled in a invalid way by the parser * [BUG] Value-function returned the wrong function category. * [BUG] When a formula was parsed but not initialized, any call to query a Term's child values failed with a NullPointerException. * PRD-2240: Moved NumberSequence to parent package to resolve circular dependency issue * PRD-2242: Created "InvalidFunction" category to make parsing and introspecting of functions more reliable. * PRD-2239: Move DivideOperator.divide() to NumberUtil class, as it is also reused from the functions. * Added MESSAGE function. * Added NORMALIZEARRAY function. * Type registry now also accepts java.util.Collections as array and sequence sources. * PRD-2235: CSVARRAY function added. 1.1.2: (2009-09-25) * The parser contained code to escape special characters via backslashes. The standard does not mention such a mechanism. The only escape that is mentioned is the quote quotes by printing them twice. * Removed the obsolete and defunctional PARAMETER function. 1.1.1: (2009-08-21) * Reworked the Exception handling and Exception generation. We now reuse a single Exception per formula instance for improved performance. 1.1.0: (2009-07-29) * [API] Added a helper method to FormulaUtil to extract all external references a Formula has. * [BUG] Term#getOperands and Term#getOperators were totally wrong. * [BUG] DATEDIF must return the absolute values; and must be more faster. * [BUG] Parser did not handle empty parameters correctly, so that "IF(TRUE();;7)" was returned as "IF(TRUE();7)". * [BUG] Replace and Find now check the indexes for negative values so that we catch these errors as Index-Errors instead of Unexpected errors. * [BUG] Date-conversion was invalid and did not return the same numbers as OpenOffice. The reworked version can handle the various Excel implementation quirks (see KB-214326) correctly. * All arithmetics use BigDecimals now. Before doing any calculations we convert the various numbers into BigDecimals so that we work with the highest level of precision possible. * Added new translations based on OpenOffice 3.0 formula function descriptions. * [BUG] The formula parser must reject extra content at the end of the parsing. A trailing semicolon is as invalid as a trailing term or text. * [BUG] MID function must not die if it has invalid start values. * [BUG] PRD-502: Right-Function description was invalid. * [BUG] Hour and Minute functions suffered from inexact calculations * [BUG] Trim function returned "LOWER" as canonical name. * [API] FunctionDescription now carries the canonical name of the formula function it describes, so that we can match the description with an implementation. * Converted all TestNG testcases into JUnit tests so that they integrate better with the established tools. * Added open-formula like NumberSequence support. * Added CSVText, Index, Choose, Value, Power, CountA, CountBlank, Hour and Minute function. * Added ACos, ACosH, ASin, ATan, ATan2, Cos, Exp, Ln, Log, Log10, Pi, Sin, Sqrt and Var function. * Moved all code from org.jfree.repository to the new package space org.pentaho.reporting.libraries.repository 0.1.18.3: (2008-09-12) (Note: This version was released after version 0.2.0) * [BUG] Comparing values was slow as we tried to convert all values into Dates or Numbers instead of comparing without type conversion (as requested by the standard). 0.1.18.2: (2008-09-12) (Note: This version was released after version 0.2.0) * [BUG] PRE-381: MID function used a wrong index and thus produced invalid results * [BUG] ODD and EVEN functions suffered from inexact calculations * [BUG] NullPointerException was raised if a invalid locale was specified for the date-formats 0.2.0: (30-May-2008) * Switched from JCommon to LibBase. All version information is now contained in the manifest. The Project-Info implementation reads the version numbers from the Jar's Manifest or the compiler-output-directory. * Formulas can now define inline arrays using the OpenFormula syntax. * CLOB objects are now properly converted into Strings. * SUBST function now uses a single Stringbuffer instead of creating new temporary strings all the time resulting in less memory consumption and a slightly higher performance. * Error handling is now more consistent. Instead of returning error tokens, all formula functions now throw exceptions. Parse errors in the formula-parser now return the location of the error so that it is easier to find out why a function is rejected by the parser. * Function now always use BigDecimals when creating new Number-Instances. This reduces the number of objects created during conversion operations and improves performance. * Creating Dates from Numbers is now more performant as we reduce the reliance on Calendard-Operations. * [API] MappedFunction and ArrayConverter classes have been removed, as these classes were never implemented and are no longer needed anyway. * [BUG] MOD function declared to have 12 parameters, but only requires 2. * [BUG] ISREF function had no valid metadata due to a typo in a filename. * [BUG] PRE-361 - ODD and EVEN functions failed to produce correct results. * [BUG] REPT function did not handle null-values according to the specification. * [BUG] SUBSTITUTE function did not handle empty strings as second parameter according to the spec. * [BUG] PRE-363 - Extra comma on "Checks whether" comments and descriptions removed. 0.1.18: (21-Feb-2008) * PRE-257 - Properly escaped double-quotes in a formula were not translated into proper quotes in the parsed formula-tree afterwards. 0.1.17: (04-Feb-2008) * PRE-231 - Fixed bug where parsing of numerics stopped after first non-numeric (including a decimal). 0.1.16: (30-Nov-2007) * PRE-161 - Fixed a bug with MIN() and MAX() functions not handling strings correctly * PRE-162 - Fixed a bug with the minus sign operation (-) and percentage operator (%) returning the wrong type if the wrong type is supplied 0.1.15: (02-Nov-2007) * Upgraded to jcommon-1.0.12 0.1.14: (16-Oct-2007) * Automatic fixes as reported by IntelliJ-IDEA's inspections * Updated the copyright header on all java-files 0.1.13: (12-Oct-2007) * [BUG] Fixed divide operations that nad no defined scale. 0.1.12: (24-Sep-2007) * All releases are now built with JDK 1.4. However, we are still compatible with JDK 1.2.2 and all releases run and compile under that release. * [BUG] The boot-class always reconfigured the logging system to use System.out logging, even if the user configured something else. * [BUG] The DefaultFunctionRegistry should have cached the loaded class-objects to avoid resource-contentions in the JDK's classloader. 0.1.11: (15-Aug-2007) * Added MIN, MAX, and MOD functions * [BUG] NumberSequence and Arrays from ranges should now work * Marked unimplemented methods with UnsupportedOperationException * Removed use of System.out in favor of JCommon logging * [BUG] Reworked some functionality that was not Java 1.2 compliant * Removed some old CVS artifacts 0.1.10: (30-Jul-2007) * [BUG] A misplaced instanceof test prevented the distinction between java.sql.Date and java.sql.Time objects. * [BUG] A rouge System.out statement was left in the generated formula parser and caused funny messages. 0.1.9: (24-Jun-2007) * [BUG] Percentage Operator did not set the scale correctly * [BUG] Divide operator did not remove unneccessary trailing zeros. * [BUG] Fixed a NullPointerException in the Numeric-Operators. * [BUG] Some operations returned 'null' instead of a NA()-TypeValue-Pair. * [BUG] The parser did not handle parenthesis correctly resulting in invalid results in computations. * Added support for inline arrays to the parser. * NULL-Values (aka NA()) are now treated like in Excel. Any operation performed on an NA() value results in NA(). There is no implicit conversion into ZERO for numeric operations anymore. 0.1.8: (21-May-2007) * [BUG] The automatic type conversion was not always working. * [BUG] The 'greater equal', 'lower equal' and 'not equal' operators did not work as expected. * The date-formats used in the automatic conversion can now be configured using the global configuration. * New functions added Date: - DAY() - HOUR() - MONTH() - WEEKDAY() - YEAR() Math: - EVEN() - ODD() - AVERAGE() Information: - ISNONTEXTFUNCTION() - ISEVEN() - ISODD() - ISNUMBER() - ISREF() 0.1.7: (27-Apr-2007) * [BUG] Fixed a couple of type-conversion issues when converting from and to numeric types. Now, if a value is not convertible, a TypeConversionException will be thrown. 0.1.6: (01-Apr-2007) * [BUG] Comparing two untyped (Any-Type) values always failed. The new implementation now tries to convert these values into Numbers, Dates, and Strings to compare them. (This is a quick-fix for Bug #1680148; however, it needs more testing before we can close that bug.) * New functions added Date: - NOW() - TODAY() 0.1.5: (07-Mar-2007) * Exposed some previously private variables to allow proper inspection of formulas. 0.1.4: (01-Mar-2007) * [BUG] The parser did not accept empty parameters so that syntactilly valid formulas like "IF(;;;)" failed to parse. * [BUG] The TRIM(..) function was invalid. TRIM has to remove all leading, trailing and all duplicate inner whitespaces from the give text. * New functions added Text: - REPLACE( - SUBSTITUTE(text, old_text, new_text, nth_appearance ) Math: - ABS(number) Date: - DATEDIF(date1,date2,interval) 0.1.3: (25-Jan-2007) * [BUG] The power operator was not registered. * [BUG] The 'minus' prefix operator did not work. * New functions added Text: - LEFT(text[,length=1]) - EXACT(text1,text2) - FIND(needle,hay[,startIndex]) - LEN(text) - LOWER(text) - MID(text,start,length) - REPT(text,count) - TEXT(value) - T(value) - TRIM(text) - UPPER(text) - URLENCODE(text[,encoding]) Information: - NA - ISNA(value) - ISTEXT(value) - ISLOGICAL(value) - ISERROR(value) - CHOOSE(condition,value[,..]) - ISBLANK(value) 0.1.2: (22-Dec-2006) * [BUG] The parser failed when being faced with functions that have no parameters. * New function NULL allows to return a NULL-reference. * Added the 'ISBLANK' function from OpenFormula. 0.1.1: (11-Dec-2006) * The FormulaContext now is able to signal errors using Exceptions. The To-Do list has grown a bit after studying the holy books of Formula-computation. Version 0.2 will see some major internal API changes. 0.1.0: (03-Dec-2006) * Initial version. This version happily deals with plain types and somehow it even handles arrays without crashing. Code for database support exists, but is not in a usable state (yet). I don't even think about OLAP cubes now. * Functions use a parameter callback now. This way, we avoid to pre- evaluate all the parameters and therefore optimize the evaluation of the whole formula. libformula-1.1.7/todo/0000755000175000017500000000000011401240110013245 5ustar renerenelibformula-1.1.7/todo/FORECAST-Function.properties0000644000175000017500000000054711401240110020362 0ustar renerenedisplay-name=FORECAST description=Returns a value along a linear regression parameter.0.display-name=value parameter.0.description=The X value for which the Y value on the regression linear is to be calculated. parameter.1.display-name=data_Y parameter.1.description=The Y data array. parameter.2.display-name=data_X parameter.2.description=The X data array. libformula-1.1.7/todo/MDETERM-Function.properties0000644000175000017500000000026011401240110020241 0ustar renerenedisplay-name=MDETERM description=Returns the array determinant. parameter.0.display-name=array parameter.0.description=The array for which the determinant is to be determined. libformula-1.1.7/todo/DB-Function.properties0000644000175000017500000000143511401240110017436 0ustar renerenedisplay-name=DB description=Returns the real depreciation of an asset for a specified period using the fixed-declining balance method. parameter.0.display-name=Cost parameter.0.description=Acquisition costs: The initial cost of the asset. parameter.1.display-name=Salvage parameter.1.description=Salvage: The remaining value of the asset at the end of its life. parameter.2.display-name=Life parameter.2.description=Useful life. The number of periods in the useful life of the asset. parameter.3.display-name=Period parameter.3.description=Periods: The period for which the depreciation is calculated. The time unit used for period must be the same as that for the useful life. parameter.4.display-name=month parameter.4.description=Months: The number of months in the first year of depreciation. libformula-1.1.7/todo/COSH-Function.properties0000644000175000017500000000027611401240110017707 0ustar renerenedisplay-name=COSH description=Returns the hyperbolic cosine of a number. parameter.0.display-name=Number parameter.0.description=The value for which the hyperbolic cosine is to be returned. libformula-1.1.7/todo/CONCATENATE-Function.properties0000644000175000017500000000023711401240110020674 0ustar renerenedisplay-name=CONCATENATE description=Combines several text items into one. parameter.0.display-name=text parameter.0.description=Text for the concatentation. libformula-1.1.7/todo/MUNIT-Function.properties0000644000175000017500000000025611401240110020045 0ustar renerenedisplay-name=MUNIT description=Returns the unitary square array of a certain size. parameter.0.display-name=Dimensions parameter.0.description=The size of the unitary array. libformula-1.1.7/todo/ZGZ-Function.properties0000644000175000017500000000063611401240110017625 0ustar renerenedisplay-name=ZGZ description=Interest. Calculates the interest rate which represents the rate of return from an investment. parameter.0.display-name=P parameter.0.description=The number of periods used in the calculation. parameter.1.display-name=pv parameter.1.description=Present value. The current value of the investment. parameter.2.display-name=FV parameter.2.description=The future value of the investment. libformula-1.1.7/todo/ROUNDDOWN-Function.properties0000644000175000017500000000043611401240110020530 0ustar renerenedisplay-name=ROUNDDOWN description=Rounds a number down to a predefined accuracy. parameter.0.display-name=number parameter.0.description=The number to be rounded down. parameter.1.display-name=count parameter.1.description=The number of places down to which a number is to be rounded. libformula-1.1.7/todo/COUNTIF-Function.properties0000644000175000017500000000047111401240110020257 0ustar renerenedisplay-name=COUNTIF description=Counts the arguments which meet the set conditions. parameter.0.display-name=range parameter.0.description=The range of cells on which the criteria are to be applied. parameter.1.display-name=criteria parameter.1.description=The cell range in which the search criteria are given. libformula-1.1.7/todo/SIGN-Function.properties0000644000175000017500000000027311401240110017710 0ustar renerenedisplay-name=SIGN description=Returns the algebraic sign of a number. parameter.0.display-name=Number parameter.0.description=The number for which the algebraic sign is to be determined. libformula-1.1.7/todo/LARGE-Function.properties0000644000175000017500000000037011401240110020000 0ustar renerenedisplay-name=LARGE description=Returns the k-th largest value of a sample. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=Rank_c parameter.1.description=The ranking of the value. libformula-1.1.7/todo/PDURATION-Function.properties0000644000175000017500000000063611401240110020520 0ustar renerenedisplay-name=PDURATION description=Duration. Calculates the number of periods required by an investment to attain the desired value. parameter.0.display-name=RATE parameter.0.description=The constant rate of interest. parameter.1.display-name=pv parameter.1.description=The present value. The current value of the investment. parameter.2.display-name=FV parameter.2.description=The future value of the investment. libformula-1.1.7/todo/PERCENTRANK-Function.properties0000644000175000017500000000044711401240110020727 0ustar renerenedisplay-name=PERCENTRANK description=Returns the percentage rank of a value in a sample. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=value parameter.1.description=The value for which percentage ranking is to be determined. libformula-1.1.7/todo/LOGEST-Function.properties0000644000175000017500000000110211401240110020135 0ustar renerenedisplay-name=LOGEST description=Calculates the parameters of the exponential regression curve as an array. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. parameter.2.display-name=Function_type parameter.2.description=If type = 0 then the functions will be calculated in the form of y=m^x, or also functions y=b*m^x. parameter.3.display-name=stats parameter.3.description=If parameter = 0 then only the regression coefficient will be calculated, otherwise other values as well. libformula-1.1.7/todo/SINH-Function.properties0000644000175000017500000000027411401240110017712 0ustar renerenedisplay-name=SINH description=Returns the hyperbolic sine of a number. parameter.0.display-name=number parameter.0.description=The value for which the hyperbolic sine is to be calculated. libformula-1.1.7/todo/ASINH-Function.properties0000644000175000017500000000031311401240110020005 0ustar renerenedisplay-name=ASINH description=Returns the inverse hyperbolic sine of a number. parameter.0.display-name=Number parameter.0.description=The value for which the inverse hyperbolic sine is to be returned. libformula-1.1.7/todo/DMIN-Function.properties0000644000175000017500000000075211401240110017701 0ustar renerenedisplay-name=DMIN description=Returns the minimum of all cells of a data range where the contents correspond to the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/SUBTOTAL-Function.properties0000644000175000017500000000047411401240110020410 0ustar renerenedisplay-name=SUBTOTAL description=Calculates subtotals in a spreadsheet. parameter.0.display-name=Function parameter.0.description=Function index. Is an index of the possible functions Total, Max, ... parameter.1.display-name=range parameter.1.description=The cells of the range which are to be taken into account. libformula-1.1.7/todo/ISFORMULA-Function.properties0000644000175000017500000000024211401240110020505 0ustar renerenedisplay-name=ISFORMULA description=Returns TRUE if the cell is a formula cell. parameter.0.display-name=reference parameter.0.description=The cell to be checked. libformula-1.1.7/todo/KURT-Function.properties0000644000175000017500000000034311401240110017733 0ustar renerenedisplay-name=KURT description=Returns the kurtosis of a distribution. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments, representing a sample of the distribution. libformula-1.1.7/todo/FIXED-Function.properties0000644000175000017500000000101511401240110020002 0ustar renerenedisplay-name=FIXED description=Formats a number with a fixed number of places after the decimal point and thousands separator. parameter.0.display-name=number parameter.0.description=The number to be formatted. parameter.1.display-name=Decimals parameter.1.description=Decimal places. The number of fixed decimal places that are to be displayed. parameter.2.display-name=No thousands separators parameter.2.description=No thousands separator. True value, if existing and TRUE (unequal to 0), no thousands separators are set. libformula-1.1.7/todo/STDEVP-Function.properties0000644000175000017500000000037311401240110020156 0ustar renerenedisplay-name=STDEVP description=Calculates the standard deviation based on the entire population. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample of a population. libformula-1.1.7/todo/WEIBULL-Function.properties0000644000175000017500000000102211401240110020244 0ustar renerenedisplay-name=WEIBULL description=Returns the values of the Weibull distribution. parameter.0.display-name=Number parameter.0.description=The value for which the Weibull distribution is to be calculated. parameter.1.display-name=Alpha parameter.1.description=The Alpha parameter of the Weibull distribution. parameter.2.display-name=beta parameter.2.description=The Beta parameter of the Weibull distribution. parameter.3.display-name=C parameter.3.description=Cumulated. C=0 calculates the density function, C=1 the distribution. libformula-1.1.7/todo/FTEST-Function.properties0000644000175000017500000000032711401240110020035 0ustar renerenedisplay-name=FTEST description=Calculates the F test. parameter.0.display-name=data_1 parameter.0.description=The first record array. parameter.1.display-name=data_2 parameter.1.description=The second record array. libformula-1.1.7/todo/POISSON-Function.properties0000644000175000017500000000063611401240110020305 0ustar renerenedisplay-name=POISSON description=Returns the Poisson distribution. parameter.0.display-name=Number parameter.0.description=The value for which the Poisson distribution is to be calculated. parameter.1.display-name=mean parameter.1.description=Mean. The mean value of the Poisson distribution. parameter.2.display-name=C parameter.2.description=Cumulated. C=0 calculates the density function, C=1 the distribution. libformula-1.1.7/todo/PMT-Function.properties0000644000175000017500000000134211401240110017606 0ustar renerenedisplay-name=PMT description=Regular payments. Returns the periodic payment of an annuity, based on regular payments and a fixed periodic interest rate. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=NPER parameter.1.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.2.display-name=PV parameter.2.description=Present value. The current value of a series of payments parameter.3.display-name=FV parameter.3.description=Future value. The value (end value) to be attained after the final payment. parameter.4.display-name=Type parameter.4.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/DECIMAL-Function.properties0000644000175000017500000000047211401240110020207 0ustar renerenedisplay-name=DECIMAL description=Converts a text of a specified number system to a positive integer in the base given. parameter.0.display-name=text parameter.0.description=The text to be converted. parameter.1.display-name=radix parameter.1.description=The base number for conversion must be in the range 2 - 36. libformula-1.1.7/todo/MMULT-Function.properties0000644000175000017500000000047511401240110020052 0ustar renerenedisplay-name=MMULT description=Array multiplication. Returns the product of two arrays. parameter.0.display-name=array parameter.0.description=The first array for the array product. parameter.1.display-name=array parameter.1.description=The second array having the same number of rows as the first array has columns. libformula-1.1.7/todo/DEGREES-Function.properties0000644000175000017500000000021411401240110020221 0ustar renerenedisplay-name=DEGREES description=Converts a radian to degrees parameter.0.display-name=Number parameter.0.description=The angle in a radian libformula-1.1.7/todo/DDB-Function.properties0000644000175000017500000000143511401240110017542 0ustar renerenedisplay-name=DDB description=Calculates the depreciation of an asset for a specific period using the double-declining balance method or declining balance factor. parameter.0.display-name=Cost parameter.0.description=Acquisition costs. The initial cost of the asset. parameter.1.display-name=Salvage parameter.1.description=Salvage: The remaining value of the asset at the end of its life. parameter.2.display-name=Life parameter.2.description=Useful life. The number of periods in the useful life of the asset. parameter.3.display-name=Period parameter.3.description=Period. The depreciation period in the same time unit as the average useful life entry. parameter.4.display-name=Factor parameter.4.description=Factor. The factor for balance decline. F = 2 means a double declining balance factor libformula-1.1.7/todo/SUMSQ-Function.properties0000644000175000017500000000035411401240110020060 0ustar renerenedisplay-name=SUMSQ description=Returns the sum of the squares of the arguments. parameter.0.display-name=number parameter.0.description=Number 1, number 2,... are 1 to 30 arguments for which the sum of the squares is to be calculated. libformula-1.1.7/todo/GETPIVOTDATA-Function.properties0000644000175000017500000000063711401240110021047 0ustar renerenedisplay-name=GETPIVOTDATA description=Extracts value(s) from a DataPilot table. parameter.0.display-name=Data Field parameter.0.description=The name of the data pilot field to extract. parameter.1.display-name=DataPilot parameter.1.description=A reference to a cell or range in the DataPilot table. parameter.2.display-name=Field Name / Item parameter.2.description=Field name/value pair to filter the target data. libformula-1.1.7/todo/CUMIPMT-Function.properties0000644000175000017500000000162511401240110020270 0ustar renerenedisplay-name=CUMIPMT description=Cumulative compounded interest. Calculates the total amount of the interest share in a period for an investment with a constant interest rate. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=NPER parameter.1.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.2.display-name=pv parameter.2.description=The present value. The present value or the amount the annuity is currently worth. parameter.3.display-name=S parameter.3.description=The start period. The first period to be taken into account. A = 1 denotes the very first period. parameter.4.display-name=E parameter.4.description=The end period. The last period to be taken into account. parameter.5.display-name=Type parameter.5.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/TRIMMEAN-Function.properties0000644000175000017500000000047611401240110020371 0ustar renerenedisplay-name=TRIMMEAN description=Returns the mean of a sample without including the marginal values. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=Alpha parameter.1.description=The percentage of marginal data that is not to be taken into account. libformula-1.1.7/todo/INDEX-Function.properties0000644000175000017500000000070211401240110020014 0ustar renerenedisplay-name=INDEX description=Returns a reference to a cell from a defined range. parameter.0.display-name=reference parameter.0.description=The reference to a (multiple) range. parameter.1.display-name=row parameter.1.description=The row in the range. parameter.2.display-name=column parameter.2.description=The column in the range. parameter.3.display-name=range parameter.3.description=The index of the subrange if referring to a multiple range. libformula-1.1.7/todo/DCOUNT-Function.properties0000644000175000017500000000072011401240110020141 0ustar renerenedisplay-name=DCOUNT description=Counts the cells of a data range whose contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/LEGACY.NORMSINV-Function.properties0000644000175000017500000000036311401240110021366 0ustar renerenedisplay-name=LEGACY.NORMSINV description=Values of the inverse standard normal distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse standard normal distribution is to be calculated. libformula-1.1.7/todo/DEVSQ-Function.properties0000644000175000017500000000035411401240110020032 0ustar renerenedisplay-name=DEVSQ description=Returns the sum of squares of deviations from the sample mean value parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample. libformula-1.1.7/todo/PRODUCT-Function.properties0000644000175000017500000000031211401240110020262 0ustar renerenedisplay-name=PRODUCT description=Multiplies the arguments. parameter.0.display-name=Number parameter.0.description=Number 1, number 2, ... are 1 to 30 arguments to be multiplied and a result returned. libformula-1.1.7/todo/SUMX2PY2-Function.properties0000644000175000017500000000050511401240110020357 0ustar renerenedisplay-name=SUMX2PY2 description=Returns the total of the square sum of two arrays. parameter.0.display-name=array_x parameter.0.description=First array where the square of the arguments are totalled. parameter.1.display-name=array_y parameter.1.description=Second array where the square of the arguments is to be totalled. libformula-1.1.7/todo/CODE-Function.properties0000644000175000017500000000034011401240110017655 0ustar renerenedisplay-name=CODE description=Returns a numeric code for the first character in a text string. parameter.0.display-name=text parameter.0.description=This is the text for which the code of the first character is to be found. libformula-1.1.7/todo/NORMDIST-Function.properties0000644000175000017500000000104611401240110020406 0ustar renerenedisplay-name=NORMDIST description=Values of the normal distribution. parameter.0.display-name=Number parameter.0.description=The value for which the normal distribution is to be calculated. parameter.1.display-name=mean parameter.1.description=The mean value. The mean value of the normal distribution. parameter.2.display-name=STDEV parameter.2.description=Standard deviation. The standard deviation of the normal distribution. parameter.3.display-name=C parameter.3.description=Cumulated. C=0 calculates the density function, C=1 the distribution. libformula-1.1.7/todo/AREAS-Function.properties0000644000175000017500000000031211401240110017775 0ustar renerenedisplay-name=AREAS description=Returns the number of individual ranges that belong to a (multiple) range. parameter.0.display-name=reference parameter.0.description=The reference to a (multiple) range. libformula-1.1.7/todo/SHEET-Function.properties0000644000175000017500000000034411401240110020017 0ustar renerenedisplay-name=SHEET description=Returns the internal sheet number of a reference or a string. parameter.0.display-name=reference parameter.0.description=The reference to a cell or a range or the character string of a sheet name. libformula-1.1.7/todo/PROPER-Function.properties0000644000175000017500000000032111401240110020151 0ustar renerenedisplay-name=PROPER description=Capitalizes the first letter in all words. parameter.0.display-name=text parameter.0.description=The text in which the beginning of words are to be replaced by capital letters. libformula-1.1.7/todo/CHOOSE-Function.properties0000644000175000017500000000047211401240110020131 0ustar renerenedisplay-name=CHOOSE description=Selects a value from a list of up to 30 value arguments. parameter.0.display-name=Index parameter.0.description=The index of the value (1..30) selected. parameter.1.display-name=value parameter.1.description=Value 1, value 2,... The list of arguments from which a value is chosen. libformula-1.1.7/todo/BINOMDIST-Function.properties0000644000175000017500000000073611401240110020504 0ustar renerenedisplay-name=BINOMDIST description=Values of the binomial distribution. parameter.0.display-name=X parameter.0.description=The number of successes in a series of trials. parameter.1.display-name=trials parameter.1.description=The total number of trials. parameter.2.display-name=SP parameter.2.description=The success probability of a trial. parameter.3.display-name=C parameter.3.description=Cumulated. C=0 calculates the individual probability, C=1 the cumulated probability. libformula-1.1.7/todo/POWER-Function.properties0000644000175000017500000000043511401240110020044 0ustar renerenedisplay-name=POWER description=Raises a number to the power of another. parameter.0.display-name=Base parameter.0.description=The number that is to be raised to the power of another. parameter.1.display-name=Power parameter.1.description=The power by which the number is to be raised. libformula-1.1.7/todo/MINVERSE-Function.properties0000644000175000017500000000022411401240110020374 0ustar renerenedisplay-name=MINVERSE description=Returns the inverse of an array. parameter.0.display-name=array parameter.0.description=The array to be inverted. libformula-1.1.7/todo/HARMEAN-Function.properties0000644000175000017500000000032111401240110020215 0ustar renerenedisplay-name=HARMEAN description=Returns the harmonic mean of a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample. libformula-1.1.7/todo/CELL-Function.properties0000644000175000017500000000047111401240110017667 0ustar renerenedisplay-name=CELL description=Determines information about address, formatting or contents of a cell. parameter.0.display-name=info_type parameter.0.description=String that specifies the type of information. parameter.1.display-name=Reference parameter.1.description=The position of the cell you want to examine. libformula-1.1.7/todo/PPMT-Function.properties0000644000175000017500000000172711401240110017735 0ustar renerenedisplay-name=PPMT description=Repayment. Calculates the repayment amount for a period for an investment whereby the payments are at regular intervals and the interest rate constant. parameter.0.display-name=Rate parameter.0.description=The interest rate per period. parameter.1.display-name=Period parameter.1.description=Period. The period for which the repayments are to be calculated. Per = 1 denotes for the first period, P = NPER for the last parameter.2.display-name=NPER parameter.2.description=The payment period. The total number of periods in which the annuity (pension) is paid. parameter.3.display-name=PV parameter.3.description=The present value. The present value or the amount the annuity is currently worth. parameter.4.display-name=FV parameter.4.description=Future value. The value (end value) attained after the last payment has been made. parameter.5.display-name=Type parameter.5.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/COVAR-Function.properties0000644000175000017500000000033311401240110020017 0ustar renerenedisplay-name=COVAR description=Calculates the covariance. parameter.0.display-name=Data_1 parameter.0.description=The first record array. parameter.1.display-name=Data_2 parameter.1.description=The second record array. libformula-1.1.7/todo/EUROCONVERT-Function.properties0000644000175000017500000000147011401240110020763 0ustar renerenedisplay-name=EUROCONVERT description=Converts a value from one to another Euro currency. parameter.0.display-name=value parameter.0.description=The value to be converted. parameter.1.display-name=from_currency parameter.1.description=ISO 4217 code of the currency from which is converted, case-sensitive. parameter.2.display-name=to_currency parameter.2.description=ISO 4217 code of the currency into which is converted, case-sensitive. parameter.3.display-name=full_precision parameter.3.description=If omitted or 0 or FALSE, the result is rounded to the decimals of to_currency. Else the result is not rounded. parameter.4.display-name=triangulation_precision parameter.4.description=If given and >=3, the intermediate result of a triangular conversion is rounded to that precision. If omitted, the result is not rounded. libformula-1.1.7/todo/EASTERSUNDAY-Function.properties0000644000175000017500000000035511401240110021060 0ustar renerenedisplay-name=EASTERSUNDAY description=Calculates the date of Easter Sunday in a given year. parameter.0.display-name=year parameter.0.description=An interger between 1583 and 9956, or 0 and 99 (19xx or 20xx depending on the option set). libformula-1.1.7/todo/FLOOR-Function.properties0000644000175000017500000000072211401240110020030 0ustar renerenedisplay-name=FLOOR description=Rounds number down to the nearest multiple of significance. parameter.0.display-name=Number parameter.0.description=The number to be rounded down. parameter.1.display-name=Significance parameter.1.description=The number to whose multiple the value is to be rounded down. parameter.2.display-name=Mode parameter.2.description=If given and not equal to zero then rounded down according to amount when a negative number and significance. libformula-1.1.7/todo/VALUE-Function.properties0000644000175000017500000000022611401240110020022 0ustar renerenedisplay-name=VALUE description=Converts text to a number. parameter.0.display-name=text parameter.0.description=The text to be converted to a number. libformula-1.1.7/todo/GAMMAINV-Function.properties0000644000175000017500000000064211401240110020347 0ustar renerenedisplay-name=GAMMAINV description=Values of the inverse gamma distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse gamma distribution is to be calculated. parameter.1.display-name=alpha parameter.1.description=The Alpha parameter of the Gamma distribution. parameter.2.display-name=beta parameter.2.description=The Beta parameter of the Gamma distribution. libformula-1.1.7/todo/ISOWEEKNUM-Function.properties0000644000175000017500000000047211401240110020637 0ustar renerenedisplay-name=ISOWEEKNUM description=Calculates the calendar week corresponding to the given date. parameter.0.display-name=Number parameter.0.description=The internal number of the date. parameter.1.display-name=mode parameter.1.description=Indicates the first day of the week (1 = Sunday, other values = Monday). libformula-1.1.7/todo/ROUND-Function.properties0000644000175000017500000000041311401240110020033 0ustar renerenedisplay-name=ROUND description=Rounds a number to a predefined accuracy. parameter.0.display-name=number parameter.0.description=The number to be rounded. parameter.1.display-name=count parameter.1.description=The number of places to which a number is to be rounded. libformula-1.1.7/todo/ORG.OPENOFFICE.CONVERT-Function.properties0000644000175000017500000000066011401240110022332 0ustar renerenedisplay-name=ORG.OPENOFFICE.CONVERT description=Converts a value according to a conversion table in the configuration (calc.xcu). parameter.0.display-name=value parameter.0.description=The value to be converted. parameter.1.display-name=text parameter.1.description=Unit from which something is converted, case-sensitive. parameter.2.display-name=text parameter.2.description=Unit into which something is converted, case-sensitive. libformula-1.1.7/todo/SUMX2MY2-Function.properties0000644000175000017500000000052011401240110020351 0ustar renerenedisplay-name=SUMX2MY2 description=Returns the sum of the difference of squares of two arrays. parameter.0.display-name=array_x parameter.0.description=First array where the square of the arguments are totalled. parameter.1.display-name=array_y parameter.1.description=Second array where the square of the arguments is to be subtracted. libformula-1.1.7/todo/LEGACY.CHIDIST-Function.properties0000644000175000017500000000050411401240110021177 0ustar renerenedisplay-name=LEGACY.CHIDIST description=Values of the chi square distribution. parameter.0.display-name=Number parameter.0.description=The value for which the chi square distribution is to be calculated. parameter.1.display-name=degrees_freedom parameter.1.description=The degrees of freedom of the chi square distribution. libformula-1.1.7/todo/NOMINAL-Function.properties0000644000175000017500000000045611401240110020250 0ustar renerenedisplay-name=NOMINAL description=Calculates the yearly nominal interest rate as an effective interest rate. parameter.0.display-name=effect_rate parameter.0.description=The effective interest rate parameter.1.display-name=npery parameter.1.description=Periods. The number of interest payment per year. libformula-1.1.7/todo/TTEST-Function.properties0000644000175000017500000000070111401240110020047 0ustar renerenedisplay-name=TTEST description=Calculates the T test. parameter.0.display-name=data_1 parameter.0.description=The first record array. parameter.1.display-name=data_2 parameter.1.description=The second record array. parameter.2.display-name=mode parameter.2.description=Mode specifies the number of distribution tails to return. 1= one-tailed, 2 = two-tailed distribution parameter.3.display-name=Type parameter.3.description=The type of the T test. libformula-1.1.7/todo/ADDRESS-Function.properties0000644000175000017500000000113511401240110020233 0ustar renerenedisplay-name=ADDRESS description=Returns the reference to a cell as text. parameter.0.display-name=row parameter.0.description=The row number of the cell. parameter.1.display-name=column parameter.1.description=The column number of the cell. parameter.2.display-name=ABS parameter.2.description=Specifies whether absolute or relative referencing is to be used. parameter.3.display-name=A1 parameter.3.description=The reference style: 0 or FALSE means R1C1 style, any other value or omitted means A1 style. parameter.4.display-name=sheet parameter.4.description=The spreadsheet name of the cell reference. libformula-1.1.7/todo/ATANH-Function.properties0000644000175000017500000000034011401240110017776 0ustar renerenedisplay-name=ATANH description=Returns the inverse hyperbolic tangent of a number. parameter.0.display-name=Number parameter.0.description=A value between -1 and 1 for which the inverse hyperbolic tangent is to be returned. libformula-1.1.7/todo/GAMMADIST-Function.properties0000644000175000017500000000100011401240110020443 0ustar renerenedisplay-name=GAMMADIST description=Values of the gamma distribution. parameter.0.display-name=Number parameter.0.description=The value for which the gamma distribution is to be calculated. parameter.1.display-name=alpha parameter.1.description=The Alpha parameter of the Gamma distribution. parameter.2.display-name=beta parameter.2.description=The Beta parameter of the Gamma distribution. parameter.3.display-name=C parameter.3.description=Cumulated. C=0 calculates the density function, C=1 the distribution. libformula-1.1.7/todo/ROMAN-Function.properties0000644000175000017500000000055711401240110020031 0ustar renerenedisplay-name=ROMAN description=Converts a number to a Roman numeral. parameter.0.display-name=Number parameter.0.description=The number to be converted to a Roman numeral must be in the 0 - 3999 range. parameter.1.display-name=Mode parameter.1.description=The more this value increases, the more the Roman numeral is simplified. The value must be in the 0 - 4 range. libformula-1.1.7/todo/ACOS-Function.properties0000644000175000017500000000027511401240110017677 0ustar renerenedisplay-name=ACOS description=Returns the arccosine of a number. parameter.0.display-name=Number parameter.0.description=A value between -1 and 1 for which the arccosine is to be returned. libformula-1.1.7/todo/CORREL-Function.properties0000644000175000017500000000034611401240110020137 0ustar renerenedisplay-name=CORREL description=Returns the correlation coefficient. parameter.0.display-name=Data_1 parameter.0.description=The first record array. parameter.1.display-name=Data_2 parameter.1.description=The second record array. libformula-1.1.7/todo/SMALL-Function.properties0000644000175000017500000000037111401240110020017 0ustar renerenedisplay-name=SMALL description=Returns the k-th smallest value of a sample. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=Rank_c parameter.1.description=The ranking of the value. libformula-1.1.7/todo/DSTDEVP-Function.properties0000644000175000017500000000077711401240110020272 0ustar renerenedisplay-name=DSTDEVP description=Returns the standard deviation with regards to the population of all cells of a data range matching the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/OFFSET-Function.properties0000644000175000017500000000121611401240110020134 0ustar renerenedisplay-name=OFFSET description=Returns a reference which has been moved in relation to the starting point. parameter.0.display-name=reference parameter.0.description=The reference (cell) from which to base the movement. parameter.1.display-name=rows parameter.1.description=The number of rows to be moved either up or down. parameter.2.display-name=columns parameter.2.description=The number of columns that are to be moved to the left or to the right. parameter.3.display-name=height parameter.3.description=The number of rows of the moved reference. parameter.4.display-name=width parameter.4.description=The number of columns in the moved reference. libformula-1.1.7/todo/IRR-Function.properties0000644000175000017500000000060511401240110017603 0ustar renerenedisplay-name=IRR description=Returns the actuarial rate of interest of an investment excluding costs or profits. parameter.0.display-name=Values parameter.0.description=An array or reference to cells whose contents correspond to the payments. parameter.1.display-name=Guess parameter.1.description=Guess. An estimated value of the rate of return to be used for the iteration calculation. libformula-1.1.7/todo/ARABIC-Function.properties0000644000175000017500000000025111401240110020065 0ustar renerenedisplay-name=ARABIC description=Calculates the value of a Roman numeral. parameter.0.display-name=Text parameter.0.description=The text that represents a Roman numeral. libformula-1.1.7/todo/BETADIST-Function.properties0000644000175000017500000000115111401240110020343 0ustar renerenedisplay-name=BETADIST description=Values of the beta distribution. parameter.0.display-name=number parameter.0.description=The value for which the beta distribution is to be calculated. parameter.1.display-name=alpha parameter.1.description=The Alpha parameter of the Beta distribution. parameter.2.display-name=beta parameter.2.description=The Beta parameter of the Beta distribution. parameter.3.display-name=Start parameter.3.description=The starting value for the value interval of the distribution. parameter.4.display-name=End parameter.4.description=The final value for the value interval of the distribution. libformula-1.1.7/todo/GEOMEAN-Function.properties0000644000175000017500000000032211401240110020216 0ustar renerenedisplay-name=GEOMEAN description=Returns the geometric mean of a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample. libformula-1.1.7/todo/RSQ-Function.properties0000644000175000017500000000037311401240110017616 0ustar renerenedisplay-name=RSQ description=Returns the square of the Pearson product moment correlation coefficient. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. libformula-1.1.7/todo/SLOPE-Function.properties0000644000175000017500000000034411401240110020031 0ustar renerenedisplay-name=SLOPE description=Returns the slope of the linear regression line. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. libformula-1.1.7/todo/EXPONDIST-Function.properties0000644000175000017500000000065111401240110020525 0ustar renerenedisplay-name=EXPONDIST description=Values of the exponential distribution. parameter.0.display-name=Number parameter.0.description=The value to which the exponential distribution is to be calculated. parameter.1.display-name=lambda parameter.1.description=The parameters of the exponential distribution. parameter.2.display-name=C parameter.2.description=Cumulated. C=0 calculates the density function, C=1 the distribution. libformula-1.1.7/todo/LINEST-Function.properties0000644000175000017500000000105011401240110020140 0ustar renerenedisplay-name=LINEST description=Calculates parameters of the linear regression as an array. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. parameter.2.display-name=Linear_type parameter.2.description=If type = 0 the linears will be calculated through the zero point, or else moved linears. parameter.3.display-name=stats parameter.3.description=If parameter = 0 then only the regression coefficient will be calculated, otherwise other values as well. libformula-1.1.7/todo/TINV-Function.properties0000644000175000017500000000047311401240110017732 0ustar renerenedisplay-name=TINV description=Values of the inverse t-distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse T distribution is to be calculated. parameter.1.display-name=degrees_freedom parameter.1.description=The degrees of freedom of the T distribution. libformula-1.1.7/todo/ZTEST-Function.properties0000644000175000017500000000050211401240110020054 0ustar renerenedisplay-name=ZTEST description=Returns the two-tailed P value of a z test. parameter.0.display-name=data parameter.0.description=The data array. parameter.1.display-name=Number parameter.1.description=The value to be tested. parameter.2.display-name=sigma parameter.2.description=The standard deviation of the population. libformula-1.1.7/todo/SUMIF-Function.properties0000644000175000017500000000062611401240110020035 0ustar renerenedisplay-name=SUMIF description=Totals the arguments that meet the conditions. parameter.0.display-name=range parameter.0.description=The range to be evaluated by the criteria given. parameter.1.display-name=criteria parameter.1.description=The cell range in which the search criteria are given. parameter.2.display-name=sum_range parameter.2.description=The range from which the values are to be totalled. libformula-1.1.7/todo/PERMUTATIONA-Function.properties0000644000175000017500000000047311401240110021062 0ustar renerenedisplay-name=PERMUTATIONA description=Returns the number of permutations for a given number of objects (repetition allowed). parameter.0.display-name=Count_1 parameter.0.description=The total number of elements. parameter.1.display-name=Count_2 parameter.1.description=The selection number taken from the elements. libformula-1.1.7/todo/STANDARDIZE-Function.properties0000644000175000017500000000054311401240110020720 0ustar renerenedisplay-name=STANDARDIZE description=Converts a random variable to a normalized value. parameter.0.display-name=Number parameter.0.description=The value to be standardized. parameter.1.display-name=mean parameter.1.description=The mean value used for moving. parameter.2.display-name=STDEV parameter.2.description=The standard deviation used for scaling. libformula-1.1.7/todo/PERMUT-Function.properties0000644000175000017500000000046411401240110020166 0ustar renerenedisplay-name=PERMUT description=Returns the number of permutations for a given number of elements without repetition. parameter.0.display-name=Count_1 parameter.0.description=The total number of elements. parameter.1.display-name=Count_2 parameter.1.description=The selection number taken from the elements. libformula-1.1.7/todo/LEGACY.CHITEST-Function.properties0000644000175000017500000000036411401240110021217 0ustar renerenedisplay-name=LEGACY.CHITEST description=Returns the chi square independence test. parameter.0.display-name=Data_B parameter.0.description=The observed data array. parameter.1.display-name=data_E parameter.1.description=The expected data array. libformula-1.1.7/todo/NUMBERVALUE-Function.properties0000644000175000017500000000045111401240110020733 0ustar renerenedisplay-name=NUMBERVALUE description=Converts text to a number, in a locale-independent way. parameter.0.display-name=text parameter.0.description=The text to be converted to a number. parameter.1.display-name=decimal_point parameter.1.description=Defines the character used as the decimal point. libformula-1.1.7/todo/BETAINV-Function.properties0000644000175000017500000000120411401240110020233 0ustar renerenedisplay-name=BETAINV description=Values of the inverse beta distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse beta distribution is to be calculated. parameter.1.display-name=alpha parameter.1.description=The Alpha parameter of the Beta distribution. parameter.2.display-name=beta parameter.2.description=The Beta parameter of the Beta distribution. parameter.3.display-name=Start parameter.3.description=The starting value for the value interval of the distribution. parameter.4.display-name=End parameter.4.description=The final value for the value interval of the distribution. libformula-1.1.7/todo/AVEDEV-Function.properties0000644000175000017500000000036011401240110020117 0ustar renerenedisplay-name=AVEDEV description=Returns the average of the absolute deviations of a sample from the mean. parameter.0.display-name=number parameter.0.description=Number 1, number 2;...are 1 to 30 numerical arguments representing a sample. libformula-1.1.7/todo/VARA-Function.properties0000644000175000017500000000037711401240110017706 0ustar renerenedisplay-name=VARA description=Returns the variance based on a sample. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;.. .are 1 to 30 arguments representing a sample taken from a basic total population. libformula-1.1.7/todo/NPER-Function.properties0000644000175000017500000000132711401240110017715 0ustar renerenedisplay-name=NPER description=Payment period. Calculates the number of payment periods for an investment based on regular payments and a constant interest rate. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=PMT parameter.1.description=Regular payments. The constant annuity to be paid in each period. parameter.2.display-name=PV parameter.2.description=Present value. The current value of a series of payments parameter.3.display-name=FV parameter.3.description=Future value. The value (end value) to be attained after the final payment. parameter.4.display-name=Type parameter.4.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/SUMXMY2-Function.properties0000644000175000017500000000045511401240110020276 0ustar renerenedisplay-name=SUMXMY2 description=Returns the sum of squares of differences of two arrays. parameter.0.display-name=array_x parameter.0.description=First array for forming argument differences. parameter.1.display-name=array_y parameter.1.description=Second array for forming the argument differences. libformula-1.1.7/todo/CRITBINOM-Function.properties0000644000175000017500000000055211401240110020476 0ustar renerenedisplay-name=CRITBINOM description=Border arguments of the binomial distribution. parameter.0.display-name=trials parameter.0.description=The total number of trials. parameter.1.display-name=SP parameter.1.description=The success probability of a trial. parameter.2.display-name=alpha parameter.2.description=The border probability that is attained or exceeded. libformula-1.1.7/todo/BASE-Function.properties0000644000175000017500000000072011401240110017657 0ustar renerenedisplay-name=BASE description=Converts a positive integer to text from a number system to the base defined. parameter.0.display-name=number parameter.0.description=The number to be converted. parameter.1.display-name=radix parameter.1.description=The base number for conversion must be in the range 2 - 36. parameter.2.display-name=Minimum length parameter.2.description=If the text is shorter than the specified length, zeros are added to the left of the string. libformula-1.1.7/todo/SYD-Function.properties0000644000175000017500000000115511401240110017607 0ustar renerenedisplay-name=SYD description=Calulates the arithmetically declining value of an asset (depreciation) for a specified period. parameter.0.display-name=Cost parameter.0.description=Acquisition costs. The initial cost of the asset. parameter.1.display-name=Salvage parameter.1.description=Salvage: The remaining value of the asset at the end of its life. parameter.2.display-name=Life parameter.2.description=Useful life. The number of periods in the useful life of the asset. parameter.3.display-name=Period parameter.3.description=Period. The depreciation period which must have the same time unit as average useful life. libformula-1.1.7/todo/COMBINA-Function.properties0000644000175000017500000000043411401240110020217 0ustar renerenedisplay-name=COMBINA description=Calculates the number of combinations of elements including repetition. parameter.0.display-name=number_1 parameter.0.description=The total number of elements. parameter.1.display-name=number_2 parameter.1.description=The number of elements selected. libformula-1.1.7/todo/VDB-Function.properties0000644000175000017500000000201411401240110017556 0ustar renerenedisplay-name=VDB description=Variable declining balance. Returns the declining balance depreciation for a particular period. parameter.0.display-name=Cost parameter.0.description=Cost. The initial cost of the asset. parameter.1.display-name=Salvage parameter.1.description=Salvage. The salvage value of an asset at the end of its useful life. parameter.2.display-name=Life parameter.2.description=Useful life. The number of periods in the useful life of the asset. parameter.3.display-name=S parameter.3.description=Start. The first period for depreciation in the same time unit as the useful life. parameter.4.display-name=end parameter.4.description=End. The last period of the depreciation using the same time unit as for the useful life. parameter.5.display-name=Factor parameter.5.description=Factor. The factor for the reduction of the depreciation. F = 2 denotes double rate depreciation. parameter.6.display-name=Type parameter.6.description=Do not alter. Type = 1 denotes switch to linear depreciation, type = 0 do not switch. libformula-1.1.7/todo/DAYS360-Function.properties0000644000175000017500000000074611401240110020146 0ustar renerenedisplay-name=DAYS360 description=Calculates the number of days between two dates based on a 360-day year. parameter.0.display-name=Date_1 parameter.0.description=The start date for calculating the difference in days. parameter.1.display-name=Date_2 parameter.1.description=The end date for calculating the difference in days. parameter.2.display-name=Type parameter.2.description=Method used to form differences: Type = 0 denotes US method (NASD), Type = 1 denotes the European method. libformula-1.1.7/todo/STDEVA-Function.properties0000644000175000017500000000041311401240110020132 0ustar renerenedisplay-name=STDEVA description=Returns the standard deviation based on a sample. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;.. .are 1 to 30 arguments representing a sample taken from a basic total population. libformula-1.1.7/todo/RATE-Function.properties0000644000175000017500000000153311401240110017703 0ustar renerenedisplay-name=RATE description=Calculates the constant interest rate of an investment with regular payments. parameter.0.display-name=NPER parameter.0.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.1.display-name=PMT parameter.1.description=Regular payments. The constant annuity to be paid in each period. parameter.2.display-name=PV parameter.2.description=Present value. The current value of a series of payments parameter.3.display-name=FV parameter.3.description=Future value. The value (end value) to be attained after the final payment. parameter.4.display-name=Type parameter.4.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. parameter.5.display-name=Guess parameter.5.description=Guess. The estimate of the interest rate for the iterative calculating method. libformula-1.1.7/todo/DVAR-Function.properties0000644000175000017500000000075211401240110017706 0ustar renerenedisplay-name=DVAR description=Determines the variance of all the cells in a data range where the contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/VLOOKUP-Function.properties0000644000175000017500000000102511401240110020303 0ustar renerenedisplay-name=VLOOKUP description=Vertical search and reference to indicated cells. parameter.0.display-name=Search criterion parameter.0.description=The value to be found in the first column. parameter.1.display-name=array parameter.1.description=The array or range for referencing. parameter.2.display-name=Index parameter.2.description=Column index number in the array. parameter.3.display-name=sort order parameter.3.description=if the value is TRUE or not given, the search column of the array must be sorted in ascending order. libformula-1.1.7/todo/GAUSS-Function.properties0000644000175000017500000000040311401240110020025 0ustar renerenedisplay-name=GAUSS description=Returns the integral values of the standard normal cumulative distribution. parameter.0.display-name=Number parameter.0.description=The value for which the integral value of the standard normal distribution is to be calculated. libformula-1.1.7/todo/INDIRECT-Function.properties0000644000175000017500000000060311401240110020346 0ustar renerenedisplay-name=INDIRECT description=Returns the contents of a cell that is referenced in text form. parameter.0.display-name=ref parameter.0.description=The cell whose contents are to be evaluated is to be referenced in text form (e.g. "A1"). parameter.1.display-name=A1 parameter.1.description=The reference style: 0 or FALSE means R1C1 style, any other value or omitted means A1 style. libformula-1.1.7/todo/PHI-Function.properties0000644000175000017500000000034711401240110017572 0ustar renerenedisplay-name=PHI description=Values of the distribution function for a standard normal distribution. parameter.0.display-name=number parameter.0.description=The value for which the standard normal distribution is to be calculated. libformula-1.1.7/todo/PV-Function.properties0000644000175000017500000000127611401240110017501 0ustar renerenedisplay-name=PV description=Present value. Calculates the present value of an investment. parameter.0.display-name=Rate parameter.0.description=The rate of interest for the period given. parameter.1.display-name=NPER parameter.1.description=The payment period. The total number of periods in which the annuity is paid. parameter.2.display-name=PMT parameter.2.description=Regular payments. The constant amount of annuity that is paid in each period. parameter.3.display-name=FV parameter.3.description=Future value. The value (final value) to be attained after the last payment. parameter.4.display-name=Type parameter.4.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/COM.MICROSOFT.BAHTTEXT-Function.properties0000644000175000017500000000024111401240110022347 0ustar renerenedisplay-name=COM.MICROSOFT.BAHTTEXT description=Converts a number to text (Baht). parameter.0.display-name=Number parameter.0.description=The number to convert. libformula-1.1.7/todo/ORG.OPENOFFICE.ERRORTYPE-Function.properties0000644000175000017500000000031711401240110022604 0ustar renerenedisplay-name=ORG.OPENOFFICE.ERRORTYPE description=Returns a number corresponding to an error type parameter.0.display-name=reference parameter.0.description=The reference (cell) in which the error occurred. libformula-1.1.7/todo/DVARP-Function.properties0000644000175000017500000000076511401240110020032 0ustar renerenedisplay-name=DVARP description=Determines variance of a population based on all cells in a data range where contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/DGET-Function.properties0000644000175000017500000000072711401240110017677 0ustar renerenedisplay-name=DGET description=Defines the contents of the cell of a data range which matches the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/SEARCH-Function.properties0000644000175000017500000000057711401240110020124 0ustar renerenedisplay-name=SEARCH description=Looks for one text value within another (not case-sensitive). parameter.0.display-name=find_text parameter.0.description=The text to be found. parameter.1.display-name=text parameter.1.description=The text in which a search is to be made. parameter.2.display-name=position parameter.2.description=The position in the text where the search is started. libformula-1.1.7/todo/TANH-Function.properties0000644000175000017500000000030211401240110017673 0ustar renerenedisplay-name=TANH description=Returns the hyperbolic tangent of a number. parameter.0.display-name=number parameter.0.description=The value for which the hyperbolic tangent is to be calculated. libformula-1.1.7/todo/QUARTILE-Function.properties0000644000175000017500000000043611401240110020377 0ustar renerenedisplay-name=QUARTILE description=Returns the quartile of a sample. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=Type parameter.1.description=The type of the quartile (0 = MIN, 1 = 25%, 2 = 50 %, 3 = 75 %, 4 =MAX). libformula-1.1.7/todo/ACOTH-Function.properties0000644000175000017500000000036511401240110020010 0ustar renerenedisplay-name=ACOTH description=Returns the inverse hyperbolic cotangent of a number. parameter.0.display-name=Number parameter.0.description=A value smaller than -1 or greater than 1 for which the inverse hyperbolic cotangent is to be returned. libformula-1.1.7/todo/ASC-Function.properties0000644000175000017500000000025111401240110017552 0ustar renerenedisplay-name=ASC description=Converts full-width ASCII and katakana characters to half-width. parameter.0.display-name=text parameter.0.description=The text to convert. libformula-1.1.7/todo/INFO-Function.properties0000644000175000017500000000030111401240110017673 0ustar renerenedisplay-name=INFO description=Returns information about the environment. parameter.0.display-name=Text parameter.0.description=Can be "osversion", "system", "release", "numfile", and "recalc". libformula-1.1.7/todo/HYPERLINK-Function.properties0000644000175000017500000000025511401240110020515 0ustar renerenedisplay-name=HYPERLINK description=Hyperlink. parameter.0.display-name=URL parameter.0.description=URL parameter.1.display-name=CellText parameter.1.description=Cell Text libformula-1.1.7/todo/NORMINV-Function.properties0000644000175000017500000000071011401240110020274 0ustar renerenedisplay-name=NORMINV description=Values of the inverse normal distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse normal distribution is to be calculated. parameter.1.display-name=mean parameter.1.description=The mean value. The mean value of the normal distribution. parameter.2.display-name=STDEV parameter.2.description=Standard deviation. The standard deviation of the normal distribution. libformula-1.1.7/todo/COLUMN-Function.properties0000644000175000017500000000026211401240110020143 0ustar renerenedisplay-name=COLUMN description=Returns the internal column number of a reference. parameter.0.display-name=reference parameter.0.description=The reference to a cell or a range. libformula-1.1.7/todo/EFFECT-Function.properties0000644000175000017500000000042111401240110020077 0ustar renerenedisplay-name=EFFECT description=Calculates the annual net interest rate for a nominal interest rate. parameter.0.display-name=NOM parameter.0.description=Nominal Interest parameter.1.display-name=P parameter.1.description=Periods. The number of interest payments per year. libformula-1.1.7/todo/COT-Function.properties0000644000175000017500000000026611401240110017577 0ustar renerenedisplay-name=COT description=Returns the cotangent of a number. parameter.0.display-name=Number parameter.0.description=The angle in radians whose cotangent value is to be returned. libformula-1.1.7/todo/FACT-Function.properties0000644000175000017500000000026411401240110017665 0ustar renerenedisplay-name=FACT description=Calculates the factorial of a number. parameter.0.display-name=Number parameter.0.description=The number for which the factorial is to be calculated. libformula-1.1.7/todo/FV-Function.properties0000644000175000017500000000131411401240110017460 0ustar renerenedisplay-name=FV description=Future value. Returns the future value of an investment based on regular payments and a constant interest rate. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=NPER parameter.1.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.2.display-name=PMT parameter.2.description=Regular payments. The constant annuity to be paid in each period. parameter.3.display-name=PV parameter.3.description=Present value. The current value of a series of payments parameter.4.display-name=Type parameter.4.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/SLN-Function.properties0000644000175000017500000000064711401240110017611 0ustar renerenedisplay-name=SLN description=Calculates the linear depreciation per period. parameter.0.display-name=Cost parameter.0.description=Acquisition cost. The initial cost of an asset. parameter.1.display-name=Salvage parameter.1.description=Salvage: The remaining value of the asset at the end of its life. parameter.2.display-name=Life parameter.2.description=Useful life. The number of periods in the useful life of the asset. libformula-1.1.7/todo/ORG.OPENOFFICE.STYLE-Function.properties0000644000175000017500000000060211401240110022106 0ustar renerenedisplay-name=ORG.OPENOFFICE.STYLE description=Applies a Style to the formula cell. parameter.0.display-name=Style parameter.0.description=The name of the Style to be applied. parameter.1.display-name=Time parameter.1.description=The time (in seconds) that the Style is to remain valid. parameter.2.display-name=Style2 parameter.2.description=The Style to be applied after time expires. libformula-1.1.7/todo/FISHERINV-Function.properties0000644000175000017500000000026711401240110020510 0ustar renerenedisplay-name=FISHERINV description=Returns the inverse of the Fisher transformation. parameter.0.display-name=Number parameter.0.description=The value that is to be transformed back. libformula-1.1.7/todo/DMAX-Function.properties0000644000175000017500000000075411401240110017705 0ustar renerenedisplay-name=DMAX description=Returns the maximum value from all of the cells of a data range which correspond to the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/FORMULA-Function.properties0000644000175000017500000000022511401240110020252 0ustar renerenedisplay-name=FORMULA description=Returns the formula of a formula cell. parameter.0.display-name=Reference parameter.0.description=The formula cell. libformula-1.1.7/todo/ISPMT-Function.properties0000644000175000017500000000076311401240110020050 0ustar renerenedisplay-name=ISPMT description=Returns the amount of interest for constant amortization rates. parameter.0.display-name=rate parameter.0.description=Interest rate for a single amortization rate. parameter.1.display-name=Period parameter.1.description=Number of amortization periods for the calculation of the interest. parameter.2.display-name=total_periods parameter.2.description=Sum total of amortization periods. parameter.3.display-name=invest parameter.3.description=Amount of the investment. libformula-1.1.7/todo/B-Function.properties0000644000175000017500000000071011401240110017325 0ustar renerenedisplay-name=B description=Returns the probability of a trial result using binomial distribution. parameter.0.display-name=trials parameter.0.description=The number of trials. parameter.1.display-name=SP parameter.1.description=The individual probability of a trial result. parameter.2.display-name=T_1 parameter.2.description=Lower limit for the number of trials. parameter.3.display-name=T_2 parameter.3.description=Upper limit for the number of trials. libformula-1.1.7/todo/FREQUENCY-Function.properties0000644000175000017500000000037611401240110020515 0ustar renerenedisplay-name=FREQUENCY description=Returns a frequency distribution as a vertical array. parameter.0.display-name=data parameter.0.description=The array of the data. parameter.1.display-name=classes parameter.1.description=The array for forming classes. libformula-1.1.7/todo/LEGACY.NORMSDIST-Function.properties0000644000175000017500000000034711401240110021477 0ustar renerenedisplay-name=LEGACY.NORMSDIST description=The values of the standard normal cumulative distribution. parameter.0.display-name=Number parameter.0.description=The value for which the standard normal distribution is to be calculated. libformula-1.1.7/todo/DCOUNTA-Function.properties0000644000175000017500000000074711401240110020253 0ustar renerenedisplay-name=DCOUNTA description=Counts all non-blank cells of a data range where the content corresponds to the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/COTH-Function.properties0000644000175000017500000000032111401240110017677 0ustar renerenedisplay-name=COTH description=Returns the hyperbolic cotangent of a number. parameter.0.display-name=Number parameter.0.description=A value not equal to 0 for which the hyperbolic cotangent is to be returned. libformula-1.1.7/todo/CHAR-Function.properties0000644000175000017500000000025311401240110017663 0ustar renerenedisplay-name=CHAR description=Converts a code number into a character or letter. parameter.0.display-name=number parameter.0.description=The code value for the character. libformula-1.1.7/todo/TREND-Function.properties0000644000175000017500000000100311401240110020014 0ustar renerenedisplay-name=TREND description=Calculates points along a regression line. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array as the basis for the regression. parameter.2.display-name=new data_X parameter.2.description=The array of X data for recalculating the values. parameter.3.display-name=Linear_type parameter.3.description=If type = 0 the linears will be calculated through the zero point, or else moved linears. libformula-1.1.7/todo/LEGACY.FDIST-Function.properties0000644000175000017500000000071211401240110020762 0ustar renerenedisplay-name=LEGACY.FDIST description=Values of the F probability distribution. parameter.0.display-name=Number parameter.0.description=The value for which the F distribution is to be calculated. parameter.1.display-name=degrees_freedom_1 parameter.1.description=The degrees of freedom in the numerator of the F distribution. parameter.2.display-name=degrees_freedom_2 parameter.2.description=The degrees of freedom in the denominator of the F distribution. libformula-1.1.7/todo/DDE-Function.properties0000644000175000017500000000064211401240110017544 0ustar renerenedisplay-name=DDE description=Result of a DDE link. parameter.0.display-name=server parameter.0.description=The name of the server application. parameter.1.display-name=File parameter.1.description=The name of the file. parameter.2.display-name=range parameter.2.description=The range from which data is to be taken. parameter.3.display-name=mode parameter.3.description=Defines how data is to be converted to numbers. libformula-1.1.7/todo/STDEVPA-Function.properties0000644000175000017500000000037511401240110020261 0ustar renerenedisplay-name=STDEVPA description=Returns the standard deviation based on the entire population. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;... are 1 to 30 arguments corresponding to a population. libformula-1.1.7/todo/ROUNDUP-Function.properties0000644000175000017500000000042511401240110020303 0ustar renerenedisplay-name=ROUNDUP description=Rounds a number up to the predefined accuracy. parameter.0.display-name=number parameter.0.description=The number to be rounded up. parameter.1.display-name=count parameter.1.description=The number of places to which a number is to be rounded. libformula-1.1.7/todo/ROWS-Function.properties0000644000175000017500000000032111401240110017734 0ustar renerenedisplay-name=ROWS description=Returns the number of rows in a reference or array. parameter.0.display-name=array parameter.0.description=The array (reference) for which the number of rows is to be determined. libformula-1.1.7/todo/DSTDEV-Function.properties0000644000175000017500000000075611401240110020147 0ustar renerenedisplay-name=DSTDEV description=Calculates the standard deviation of all cells in a data range whose contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/PERCENTILE-Function.properties0000644000175000017500000000042311401240110020577 0ustar renerenedisplay-name=PERCENTILE description=Returns the alpha quantile of a sample. parameter.0.display-name=data parameter.0.description=The array of the data in the sample. parameter.1.display-name=Alpha parameter.1.description=The percentage rate of the quantile between 0 and 1. libformula-1.1.7/todo/VARP-Function.properties0000644000175000017500000000034111401240110017714 0ustar renerenedisplay-name=VARP description=Calculates variance based on the entire population. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which represent a population. libformula-1.1.7/todo/CONFIDENCE-Function.properties0000644000175000017500000000056711401240110020553 0ustar renerenedisplay-name=CONFIDENCE description=Returns a (1 alpha) confidence interval for a normal distribution. parameter.0.display-name=alpha parameter.0.description=The level of the confidence interval. parameter.1.display-name=STDEV parameter.1.description=The standard deviation of the population. parameter.2.display-name=size parameter.2.description=The size of the population. libformula-1.1.7/todo/STDEV-Function.properties0000644000175000017500000000035511401240110020036 0ustar renerenedisplay-name=STDEV description=Calculates the standard deviation based on a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample of a population. libformula-1.1.7/todo/INTERCEPT-Function.properties0000644000175000017500000000037311401240110020506 0ustar renerenedisplay-name=INTERCEPT description=Returns the intercept of the linear regression line and the Y axis. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. libformula-1.1.7/todo/CUMPRINC-Function.properties0000644000175000017500000000160511401240110020370 0ustar renerenedisplay-name=CUMPRINC description=Cumulative Capital. Calculates the total amount of the repayment share in a period for an investment with constant interest rate. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=NPER parameter.1.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.2.display-name=PV parameter.2.description=The present value. The present value or the amount the annuity is currently worth. parameter.3.display-name=S parameter.3.description=The start period. The first period to be taken into account. A = 1 denotes the very first period. parameter.4.display-name=E parameter.4.description=End period. The last period to be taken into account. parameter.5.display-name=Type parameter.5.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/MATCH-Function.properties0000644000175000017500000000070611401240110020005 0ustar renerenedisplay-name=MATCH description=Defines a position in a array after comparing values. parameter.0.display-name=Search criterion parameter.0.description=The value to be used for comparison. parameter.1.display-name=lookup_array parameter.1.description=The array (range) in which the search is made. parameter.2.display-name=Type parameter.2.description=Type can take the value 1, 0 or -1 and determines the criteria are to be used for comparison purposes. libformula-1.1.7/todo/JIS-Function.properties0000644000175000017500000000025111401240110017571 0ustar renerenedisplay-name=JIS description=Converts half-width ASCII and katakana characters to full-width. parameter.0.display-name=text parameter.0.description=The text to convert. libformula-1.1.7/todo/VARPA-Function.properties0000644000175000017500000000035511401240110020022 0ustar renerenedisplay-name=VARPA description=Returns the variance based on the entire population. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;... are 1 to 30 arguments representing a population. libformula-1.1.7/todo/MODE-Function.properties0000644000175000017500000000032211401240110017667 0ustar renerenedisplay-name=MODE description=Returns the most common value in a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample. libformula-1.1.7/todo/SUMPRODUCT-Function.properties0000644000175000017500000000036111401240110020653 0ustar renerenedisplay-name=SUMPRODUCT description=(Inner products) Returns the sum of the products of array arguments. parameter.0.display-name=Array parameter.0.description=Array 1, array 2, ... are up to 30 arrays whose arguments are to be multiplied. libformula-1.1.7/todo/RAND-Function.properties0000644000175000017500000000010711401240110017670 0ustar renerenedisplay-name=RAND description=Returns a random number between 0 and 1. libformula-1.1.7/todo/PROB-Function.properties0000644000175000017500000000100111401240110017700 0ustar renerenedisplay-name=PROB description=Returns the discreet probability of an interval. parameter.0.display-name=data parameter.0.description=The sample data array. parameter.1.display-name=probability parameter.1.description=The array of the associated probabilities. parameter.2.display-name=Start parameter.2.description=The start of the value interval whose probabilities is to be totalled. parameter.3.display-name=End parameter.3.description=The end of the value interval where the probabilities are to be totalled. libformula-1.1.7/todo/TAN-Function.properties0000644000175000017500000000026611401240110017574 0ustar renerenedisplay-name=TAN description=Returns the tangent of a number. parameter.0.display-name=number parameter.0.description=The angle in radians for which the tangent is to be calculated. libformula-1.1.7/todo/LOGNORMDIST-Function.properties0000644000175000017500000000067411401240110020756 0ustar renerenedisplay-name=LOGNORMDIST description=Values of the log normal distribution. parameter.0.display-name=Number parameter.0.description=The value for which the log normal distribution is to be calculated. parameter.1.display-name=mean parameter.1.description=Mean value. The mean value of the log normal distribution. parameter.2.display-name=STDEV parameter.2.description=Standard deviation. The standard deviation of the log normal distribution. libformula-1.1.7/todo/NPV-Function.properties0000644000175000017500000000057611401240110017621 0ustar renerenedisplay-name=NPV description=Net present value. Calculates the net present value of an investment based on a series of periodic payments and a discount rate. parameter.0.display-name=RATE parameter.0.description=The rate of discount for one period. parameter.1.display-name=value parameter.1.description=Value 1, value 2,... are 1 to 30 arguments representing payments and income. libformula-1.1.7/todo/COLUMNS-Function.properties0000644000175000017500000000033311401240110020265 0ustar renerenedisplay-name=COLUMNS description=Returns the number of columns in an array or reference. parameter.0.display-name=array parameter.0.description=The array (reference) for which the number of columns is to be determined. libformula-1.1.7/todo/ACOT-Function.properties0000644000175000017500000000027611401240110017701 0ustar renerenedisplay-name=ACOT description=Returns the inverse cotangent of a number. parameter.0.display-name=Number parameter.0.description=The value for which the inverse cotangent is to be returned. libformula-1.1.7/todo/STEYX-Function.properties0000644000175000017500000000035011401240110020060 0ustar renerenedisplay-name=STEYX description=Returns the standard error of the linear regression. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array. libformula-1.1.7/todo/LCM-Function.properties0000644000175000017500000000031011401240110017553 0ustar renerenedisplay-name=LCM description=Lowest common multiple parameter.0.display-name=Integer parameter.0.description=Integer 1; integer 2,... are integers whose smallest common multiple is to be calculated. libformula-1.1.7/todo/HYPGEOMDIST-Function.properties0000644000175000017500000000066511401240110020751 0ustar renerenedisplay-name=HYPGEOMDIST description=Values of the hypergeometric distribution. parameter.0.display-name=X parameter.0.description=The number of successes in the sample. parameter.1.display-name=n_sample parameter.1.description=The size of the sample. parameter.2.display-name=successes parameter.2.description=The number of successes in the population. parameter.3.display-name=n_population parameter.3.description=The population size. libformula-1.1.7/todo/DAVERAGE-Function.properties0000644000175000017500000000075411401240110020332 0ustar renerenedisplay-name=DAVERAGE description=Returns the average value of all the cells of a data range whose contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/RADIANS-Function.properties0000644000175000017500000000021311401240110020223 0ustar renerenedisplay-name=RADIANS description=Converts degrees to radians parameter.0.display-name=Number parameter.0.description=The angle in degrees. libformula-1.1.7/todo/DPRODUCT-Function.properties0000644000175000017500000000073211401240110020374 0ustar renerenedisplay-name=DPRODUCT description=Multiplies all cells of a data range where the contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/GROWTH-Function.properties0000644000175000017500000000103611401240110020160 0ustar renerenedisplay-name=GROWTH description=Calculates points on the exponential regression function. parameter.0.display-name=data_Y parameter.0.description=The Y data array. parameter.1.display-name=data_X parameter.1.description=The X data array as the basis for the regression. parameter.2.display-name=new_data_X parameter.2.description=The array of X data for recalculating the values. parameter.3.display-name=Function_type parameter.3.description=If type = 0 then the functions will be calculated in the form of y=m^x, or also functions y=b*m^x. libformula-1.1.7/todo/HLOOKUP-Function.properties0000644000175000017500000000102411401240110020264 0ustar renerenedisplay-name=HLOOKUP description=Horizontal search and reference to the cells located below. parameter.0.display-name=search_criteria parameter.0.description=The value to be found in the first row. parameter.1.display-name=array parameter.1.description=The array or the range for the reference. parameter.2.display-name=Index parameter.2.description=The row index in the array. parameter.3.display-name=sorted parameter.3.description=If the value is TRUE or not given, the search row of the array must be sorted in ascending order. libformula-1.1.7/todo/TRANSPOSE-Function.properties0000644000175000017500000000033011401240110020520 0ustar renerenedisplay-name=TRANSPOSE description=Array transposition. Exchanges the rows and columns of an aray. parameter.0.display-name=array parameter.0.description=The array in which the rows and columns have been transposed. libformula-1.1.7/todo/IPMT-Function.properties0000644000175000017500000000171111401240110017717 0ustar renerenedisplay-name=IPMT description=Compounded interest. Calculates the interest payment on the principal for an investment with regular payments and a constant interest rate for a given period. parameter.0.display-name=Rate parameter.0.description=The rate of interest per period. parameter.1.display-name=Period parameter.1.description=Periods. The periods for which the compounded interest is to be calculated. P = 1 denotes for the first period, P = NPER for the last one. parameter.2.display-name=NPER parameter.2.description=Payment period. The total number of periods in which the annuity (pension) is paid. parameter.3.display-name=pv parameter.3.description=Present value. The current value of a series of payments parameter.4.display-name=FV parameter.4.description=Future value. The value (end value) to be attained after the final payment. parameter.5.display-name=Type parameter.5.description=Type = 1 denotes due at the beginning of the period, = 0 at the end. libformula-1.1.7/todo/FISHER-Function.properties0000644000175000017500000000025111401240110020124 0ustar renerenedisplay-name=FISHER description=Returns the Fisher transformation. parameter.0.display-name=Number parameter.0.description=The value to be transformed (-1 < VALUE < 1). libformula-1.1.7/todo/NEGBINOMDIST-Function.properties0000644000175000017500000000055411401240110021034 0ustar renerenedisplay-name=NEGBINOMDIST description=Values of the negative binomial distribution. parameter.0.display-name=X parameter.0.description=The number of failures in the trial range. parameter.1.display-name=R parameter.1.description=The number of successes in the trial sequence. parameter.2.display-name=SP parameter.2.description=The success probability of a trial. libformula-1.1.7/todo/COMBIN-Function.properties0000644000175000017500000000043211401240110020114 0ustar renerenedisplay-name=COMBIN description=Calculates the number of combinations for elements without repetition. parameter.0.display-name=number_1 parameter.0.description=The total number of elements. parameter.1.display-name=number_2 parameter.1.description=The number of elements selected. libformula-1.1.7/todo/GCD-Function.properties0000644000175000017500000000032011401240110017536 0ustar renerenedisplay-name=GCD description=Greatest Common Divisor parameter.0.display-name=Integer parameter.0.description=Integer 1; integer 2,... are integers for which the greatest common divisor is to be calculated. libformula-1.1.7/todo/MEDIAN-Function.properties0000644000175000017500000000031711401240110020104 0ustar renerenedisplay-name=MEDIAN description=Returns the median of a given sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample. libformula-1.1.7/todo/SKEW-Function.properties0000644000175000017500000000034011401240110017714 0ustar renerenedisplay-name=SKEW description=Returns the skewness of a distribution. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments portraying a sample of the distribution. libformula-1.1.7/todo/LOOKUP-Function.properties0000644000175000017500000000070211401240110020156 0ustar renerenedisplay-name=LOOKUP description=Determines a value in a vector by comparison to values in another vector. parameter.0.display-name=Search criterion parameter.0.description=The value to be used for comparison. parameter.1.display-name=Search vector parameter.1.description=The vector (row or column) in which to search. parameter.2.display-name=result_vector parameter.2.description=The vector (row or range) from which the value is to be determined. libformula-1.1.7/todo/CLEAN-Function.properties0000644000175000017500000000030311401240110017764 0ustar renerenedisplay-name=CLEAN description=Removes all nonprintable characters from text. parameter.0.display-name=text parameter.0.description=The text from which nonprintable characters are to be removed. libformula-1.1.7/todo/PEARSON-Function.properties0000644000175000017500000000037611401240110020263 0ustar renerenedisplay-name=PEARSON description=Returns the Pearson product moment correlation coefficient. parameter.0.display-name=Data_1 parameter.0.description=The first record array. parameter.1.display-name=Data_2 parameter.1.description=The second record array. libformula-1.1.7/todo/CEILING-Function.properties0000644000175000017500000000070511401240110020222 0ustar renerenedisplay-name=CEILING description=Rounds a number up to the nearest multiple of significance. parameter.0.display-name=Number parameter.0.description=The number to be rounded up. parameter.1.display-name=Significance parameter.1.description=The number to whose multiple the value is rounded. parameter.2.display-name=Mode parameter.2.description=If given and not equal to zero then rounded up according to amount when a negative number and significance. libformula-1.1.7/todo/TRUNC-Function.properties0000644000175000017500000000043711401240110020045 0ustar renerenedisplay-name=TRUNC description=Truncates the decimal places of a number. parameter.0.display-name=number parameter.0.description=The number to be truncated. parameter.1.display-name=count parameter.1.description=The number of places after the decimal point that are not to be truncated. libformula-1.1.7/todo/ROW-Function.properties0000644000175000017500000000025411401240110017616 0ustar renerenedisplay-name=ROW description=Defines the internal row number of a reference. parameter.0.display-name=reference parameter.0.description=The reference to a cell or a range. libformula-1.1.7/todo/TYPE-Function.properties0000644000175000017500000000025611401240110017732 0ustar renerenedisplay-name=TYPE description=Defines the data type of a value. parameter.0.display-name=value parameter.0.description=The value for which the data type is to be determined. libformula-1.1.7/todo/DSUM-Function.properties0000644000175000017500000000072411401240110017721 0ustar renerenedisplay-name=DSUM description=Adds all the cells of a data range where the contents match the search criteria. parameter.0.display-name=Database parameter.0.description=The range of cells containing data. parameter.1.display-name=Database field parameter.1.description=Indicates which database field (column) is to be used for the search criteria. parameter.2.display-name=Search criteria parameter.2.description=Defines the cell range containing the search criteria. libformula-1.1.7/todo/ORG.OPENOFFICE.CURRENT-Function.properties0000644000175000017500000000016611401240110022335 0ustar renerenedisplay-name=ORG.OPENOFFICE.CURRENT description=Calculates the current value of the formula at the present location. libformula-1.1.7/todo/SHEETS-Function.properties0000644000175000017500000000041411401240110020140 0ustar renerenedisplay-name=SHEETS description=Returns the number of sheets of a given reference. If no parameter has been entered, the total number of sheets in the document is returned. parameter.0.display-name=reference parameter.0.description=The reference to a cell or a range. libformula-1.1.7/todo/LEGACY.FINV-Function.properties0000644000175000017500000000073111401240110020654 0ustar renerenedisplay-name=LEGACY.FINV description=Values of the inverse F distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse F distribution is to be calculated. parameter.1.display-name=degrees_freedom_1 parameter.1.description=The degrees of freedom in the numerator of the F distribution. parameter.2.display-name=degrees_freedom_2 parameter.2.description=The degrees of freedom in the denominator of the F distribution. libformula-1.1.7/todo/N-Function.properties0000644000175000017500000000023111401240110017337 0ustar renerenedisplay-name=N description=Converts a value to a number. parameter.0.display-name=value parameter.0.description=The value to be interpreted as a number. libformula-1.1.7/todo/GAMMALN-Function.properties0000644000175000017500000000034311401240110020222 0ustar renerenedisplay-name=GAMMALN description=Returns the natural logarithm of the gamma function. parameter.0.display-name=Number parameter.0.description=The value for which the natural logarithm of the gamma function is to be calculated. libformula-1.1.7/todo/LOGINV-Function.properties0000644000175000017500000000073111401240110020145 0ustar renerenedisplay-name=LOGINV description=Values of the inverse of the lognormal distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse log normal distribution is to be calculated. parameter.1.display-name=mean parameter.1.description=Mean value. The mean value of the log normal distribution. parameter.2.display-name=STDEV parameter.2.description=Standard deviation. The standard deviation of the log normal distribution. libformula-1.1.7/todo/MIRR-Function.properties0000644000175000017500000000075311401240110017724 0ustar renerenedisplay-name=MIRR description=Returns the modified internal rate of return for a series of investments. parameter.0.display-name=Values parameter.0.description=An array or reference to cells whose contents correspond to the payments. parameter.1.display-name=investment parameter.1.description=Interest rate for investments (the negative values in the array). parameter.2.display-name=reinvest_rate parameter.2.description=interest rate for reinvestments (the positive values in the array). libformula-1.1.7/todo/RANK-Function.properties0000644000175000017500000000063311401240110017703 0ustar renerenedisplay-name=RANK description=Returns the ranking of a value in a sample. parameter.0.display-name=value parameter.0.description=The value for which the rank is to be determined. parameter.1.display-name=Data parameter.1.description=The array of the data in the sample. parameter.2.display-name=Type parameter.2.description=Sequence order: 0 or omitted means descending, any other value than 0 means ascending. libformula-1.1.7/todo/LEGACY.CHIINV-Function.properties0000644000175000017500000000054011401240110021070 0ustar renerenedisplay-name=LEGACY.CHIINV description=Values of the inverse chi-squared distribution. parameter.0.display-name=number parameter.0.description=The probability value for which the inverse chi square distribution is to be calculated. parameter.1.display-name=degrees_freedom parameter.1.description=The degrees of freedom of the chi square distribution. libformula-1.1.7/todo/DOLLAR-Function.properties0000644000175000017500000000056311401240110020127 0ustar renerenedisplay-name=DOLLAR description=Converts a number to text in currency format. parameter.0.display-name=value parameter.0.description=Value is a number, a reference to a cell containing a number or a formula that results in a number. parameter.1.display-name=decimals parameter.1.description=Decimal places. Denotes the number of digits to the right of the decimal point. libformula-1.1.7/todo/TDIST-Function.properties0000644000175000017500000000063111401240110020035 0ustar renerenedisplay-name=TDIST description=Returns the t-distribution. parameter.0.display-name=Number parameter.0.description=The value for which the T distribution is to be calculated. parameter.1.display-name=degrees_freedom parameter.1.description=The degrees of freedom of the T distribution. parameter.2.display-name=mode parameter.2.description=Mode = 1calculates the one-tailed test, 2 = two-tailed distribution. libformula-1.1.7/devresource/0000755000175000017500000000000011401240104014631 5ustar renerenelibformula-1.1.7/devresource/META-INF/0000755000175000017500000000000011401240104015771 5ustar renerenelibformula-1.1.7/devresource/META-INF/MANIFEST.MF0000644000175000017500000000033111401240104017420 0ustar renereneImplementation-Title: LibFormula Implementation-Vendor: Pentaho Corporation Implementation-ProductID: libformula Release-Major-Number: 0 Release-Minor-Number: 2 Release-Milestone-Number: 0 Release-Candidate-Token: GA libformula-1.1.7/ivysettings.xml0000644000175000017500000000174311401240104015422 0ustar renerene libformula-1.1.7/build.properties0000644000175000017500000000042511401240110015516 0ustar renereneproject.revision=1.1-SNAPSHOT ivy.artifact.group=pentaho-library ivy.artifact.id=libformula impl.title=LibFormula impl.productID=libformula src.dir=${basedir}/source dependency.libbase.revision=1.1.6 testsrc.dir=${basedir}/test javacchome=/Volumes/Datastorex/source/ext/javacc libformula-1.1.7/ant/0000755000175000017500000000000011401240104013065 5ustar renerenelibformula-1.1.7/ant/build-lib.xml0000644000175000017500000006224211401240104015460 0ustar renerene libformula-1.1.7/dev-lib/0000755000175000017500000000000011401240104013625 5ustar renerenelibformula-1.1.7/licence-LGPL.txt0000644000175000017500000006347611401240110015217 0ustar renerene GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! libformula-1.1.7/source/0000755000175000017500000000000011401240104013603 5ustar renerenelibformula-1.1.7/source/org/0000755000175000017500000000000011401240104014372 5ustar renerenelibformula-1.1.7/source/org/pentaho/0000755000175000017500000000000011401240104016030 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/0000755000175000017500000000000011401240104020041 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/0000755000175000017500000000000011401240104022015 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/0000755000175000017500000000000011401240110023457 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/Formula.java0000644000175000017500000001140211401240110025725 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.io.Serializable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.parser.FormulaParseException; import org.pentaho.reporting.libraries.formula.parser.FormulaParser; import org.pentaho.reporting.libraries.formula.parser.ParseException; import org.pentaho.reporting.libraries.formula.parser.TokenMgrError; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.StaticArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Creation-Date: 31.10.2006, 14:43:05 * * @author Thomas Morgner */ public class Formula implements Serializable, Cloneable { private static final Log logger = LogFactory.getLog(Formula.class); private LValue rootReference; private static final long serialVersionUID = -1176925812499923546L; public Formula(final String formulaText) throws ParseException { if (formulaText == null) { throw new NullPointerException(); } try { final FormulaParser parser = new FormulaParser(); this.rootReference = parser.parse(formulaText.trim()); } catch (TokenMgrError tokenMgrError) { // This is ugly. throw new FormulaParseException(tokenMgrError); } } public Formula(final LValue rootReference) { if (rootReference == null) { throw new NullPointerException(); } this.rootReference = rootReference; } public void initialize(final FormulaContext context) throws EvaluationException { if (context == null) { throw new NullPointerException(); } rootReference.initialize(context); } /** * Returns the root reference for this formula. This allows external programms * to modify the formula directly. * * @return */ public LValue getRootReference() { return rootReference; } public TypeValuePair evaluateTyped() { try { final TypeValuePair typeValuePair = rootReference.evaluate(); if (typeValuePair == null) { // Should no longer happen.. return new TypeValuePair(ErrorType.TYPE, LibFormulaErrorValue.ERROR_NA_VALUE); } final Type type = typeValuePair.getType(); if (type.isFlagSet(Type.ERROR_TYPE)) { logger.debug("Error: " + typeValuePair.getValue()); } else if (type.isFlagSet(Type.ARRAY_TYPE)) { final Object value = typeValuePair.getValue(); if (value instanceof ArrayCallback) { return new TypeValuePair(type, new StaticArrayCallback((ArrayCallback) value)); } } else { final Object value = typeValuePair.getValue(); if (value instanceof Number) { return new TypeValuePair(type, NumberUtil.performTuneRounding(NumberUtil.getAsBigDecimal((Number) value))); } } return typeValuePair; } catch (EvaluationException ee) { return new TypeValuePair(ErrorType.TYPE, ee.getErrorValue()); } catch (Exception e) { logger.warn("Evaluation failed unexpectedly: ", e); return new TypeValuePair(ErrorType.TYPE, LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } } public Object evaluate() { final TypeValuePair pair = evaluateTyped(); final Object value = pair.getValue(); if (LibFormulaErrorValue.ERROR_NA_VALUE.equals(value)) { return null; } return value; } public Object clone() throws CloneNotSupportedException { final Formula o = (Formula) super.clone(); o.rootReference = (LValue) rootReference.clone(); return o; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/messages.properties0000644000175000017500000000065411401240106027416 0ustar renereneErrorValue.499=Reference not resolveable ErrorValue.501=Invalid Character ErrorValue.505=Invalid Function ErrorValue.502=Invalid Argument ErrorValue.666=Invalid Automatic Argument ErrorValue.667=Illegal Array ErrorValue.503=Arithmetic Error ErrorValue.1=Invalid number of arguments ErrorValue.504=Not Found ErrorValue.522=NA ErrorValue.0=Unexpected ErrorValue.511=Missing Variable ErrorValue.Generic=Formula Evaluation Error {0}libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/DefaultFormulaContext.java0000644000175000017500000000772211401240110030611 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.util.HashMap; import java.util.TimeZone; import java.util.Locale; import org.pentaho.reporting.libraries.formula.function.DefaultFunctionRegistry; import org.pentaho.reporting.libraries.formula.function.FunctionRegistry; import org.pentaho.reporting.libraries.formula.operators.DefaultOperatorFactory; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; import org.pentaho.reporting.libraries.formula.typing.DefaultTypeRegistry; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.base.config.Configuration; /** * Creation-Date: 31.10.2006, 16:32:32 * * @author Thomas Morgner */ public class DefaultFormulaContext implements FormulaContext { private DefaultTypeRegistry typeRegistry; private DefaultFunctionRegistry functionRegistry; private DefaultOperatorFactory operatorFactory; private DefaultLocalizationContext localizationContext; private Configuration config; private HashMap references; public DefaultFormulaContext() { this(LibFormulaBoot.getInstance().getGlobalConfig()); } public DefaultFormulaContext(final Configuration config) { this(config, null, null); } public DefaultFormulaContext(final Configuration config, final Locale locale, final TimeZone timeZone) { if (config == null) { throw new NullPointerException(); } this.config = config; localizationContext = new DefaultLocalizationContext(); localizationContext.initialize(config, locale, timeZone); typeRegistry = new DefaultTypeRegistry(); typeRegistry.initialize(this); functionRegistry = new DefaultFunctionRegistry(); functionRegistry.initialize(config); operatorFactory = new DefaultOperatorFactory(); operatorFactory.initalize(config); } public OperatorFactory getOperatorFactory() { return operatorFactory; } public void defineReference(final Object name, final Object value) { if (name == null) { throw new NullPointerException(); } if (value == null) { if (references == null) { return; } references.remove(name); return; } if (references == null) { references = new HashMap(); } references.put(name, value); } public Object resolveReference(final Object name) { if (name == null) { throw new NullPointerException(); } if (references == null) { return null; } return references.get(name); } public Configuration getConfiguration() { return config; } public FunctionRegistry getFunctionRegistry() { return functionRegistry; } public Type resolveReferenceType(final Object name) { return AnyType.TYPE; } public TypeRegistry getTypeRegistry() { return typeRegistry; } public LocalizationContext getLocalizationContext() { return localizationContext; } public boolean isReferenceDirty(final Object name) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/libformula.properties0000644000175000017500000007517511401240110027750 0ustar renerene# # Used to convert serial date number to java Date using a 1904 date system # else using a 1900 date system # org.pentaho.reporting.libraries.formula.datesystem.1904=true #org.pentaho.reporting.libraries.formula.locale = en_US #org.pentaho.reporting.libraries.formula.timezone = America/Los_Angeles # # A list of all known functions. # ## # Date/Time functions org.pentaho.reporting.libraries.formula.functions.datetime.Date.class=org.pentaho.reporting.libraries.formula.function.datetime.DateFunction org.pentaho.reporting.libraries.formula.functions.datetime.Date.description=org.pentaho.reporting.libraries.formula.function.datetime.DateFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.DateDif.class=org.pentaho.reporting.libraries.formula.function.datetime.DateDifFunction org.pentaho.reporting.libraries.formula.functions.datetime.DateDif.description=org.pentaho.reporting.libraries.formula.function.datetime.DateDifFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.DateValue.class=org.pentaho.reporting.libraries.formula.function.datetime.DateValueFunction org.pentaho.reporting.libraries.formula.functions.datetime.DateValue.description=org.pentaho.reporting.libraries.formula.function.datetime.DateValueFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Day.class=org.pentaho.reporting.libraries.formula.function.datetime.DayFunction org.pentaho.reporting.libraries.formula.functions.datetime.Day.description=org.pentaho.reporting.libraries.formula.function.datetime.DayFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Days.class=org.pentaho.reporting.libraries.formula.function.datetime.DaysFunction org.pentaho.reporting.libraries.formula.functions.datetime.Days.description=org.pentaho.reporting.libraries.formula.function.datetime.DaysFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Hour.class=org.pentaho.reporting.libraries.formula.function.datetime.HourFunction org.pentaho.reporting.libraries.formula.functions.datetime.Hour.description=org.pentaho.reporting.libraries.formula.function.datetime.HourFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Minute.class=org.pentaho.reporting.libraries.formula.function.datetime.MinuteFunction org.pentaho.reporting.libraries.formula.functions.datetime.Minute.description=org.pentaho.reporting.libraries.formula.function.datetime.MinuteFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Month.class=org.pentaho.reporting.libraries.formula.function.datetime.MonthFunction org.pentaho.reporting.libraries.formula.functions.datetime.Month.description=org.pentaho.reporting.libraries.formula.function.datetime.MonthFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Now.class=org.pentaho.reporting.libraries.formula.function.datetime.NowFunction org.pentaho.reporting.libraries.formula.functions.datetime.Now.description=org.pentaho.reporting.libraries.formula.function.datetime.NowFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Second.class=org.pentaho.reporting.libraries.formula.function.datetime.SecondFunction org.pentaho.reporting.libraries.formula.functions.datetime.Second.description=org.pentaho.reporting.libraries.formula.function.datetime.SecondFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Time.class=org.pentaho.reporting.libraries.formula.function.datetime.TimeFunction org.pentaho.reporting.libraries.formula.functions.datetime.Time.description=org.pentaho.reporting.libraries.formula.function.datetime.TimeFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.TimeValue.class=org.pentaho.reporting.libraries.formula.function.datetime.TimeValueFunction org.pentaho.reporting.libraries.formula.functions.datetime.TimeValue.description=org.pentaho.reporting.libraries.formula.function.datetime.TimeValueFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Today.class=org.pentaho.reporting.libraries.formula.function.datetime.TodayFunction org.pentaho.reporting.libraries.formula.functions.datetime.Today.description=org.pentaho.reporting.libraries.formula.function.datetime.TodayFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.WeekDay.class=org.pentaho.reporting.libraries.formula.function.datetime.WeekDayFunction org.pentaho.reporting.libraries.formula.functions.datetime.WeekDay.description=org.pentaho.reporting.libraries.formula.function.datetime.WeekDayFunctionDescription org.pentaho.reporting.libraries.formula.functions.datetime.Year.class=org.pentaho.reporting.libraries.formula.function.datetime.YearFunction org.pentaho.reporting.libraries.formula.functions.datetime.Year.description=org.pentaho.reporting.libraries.formula.function.datetime.YearFunctionDescription ## # Logical functions org.pentaho.reporting.libraries.formula.functions.logical.And.class=org.pentaho.reporting.libraries.formula.function.logical.AndFunction org.pentaho.reporting.libraries.formula.functions.logical.And.description=org.pentaho.reporting.libraries.formula.function.logical.AndFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.False.class=org.pentaho.reporting.libraries.formula.function.logical.FalseFunction org.pentaho.reporting.libraries.formula.functions.logical.False.description=org.pentaho.reporting.libraries.formula.function.logical.FalseFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.If.class=org.pentaho.reporting.libraries.formula.function.logical.IfFunction org.pentaho.reporting.libraries.formula.functions.logical.If.description=org.pentaho.reporting.libraries.formula.function.logical.IfFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.IfNa.class=org.pentaho.reporting.libraries.formula.function.logical.IfNaFunction org.pentaho.reporting.libraries.formula.functions.logical.IfNa.description=org.pentaho.reporting.libraries.formula.function.logical.IfNaFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.Not.class=org.pentaho.reporting.libraries.formula.function.logical.NotFunction org.pentaho.reporting.libraries.formula.functions.logical.Not.description=org.pentaho.reporting.libraries.formula.function.logical.NotFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.Or.class=org.pentaho.reporting.libraries.formula.function.logical.OrFunction org.pentaho.reporting.libraries.formula.functions.logical.Or.description=org.pentaho.reporting.libraries.formula.function.logical.OrFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.True.class=org.pentaho.reporting.libraries.formula.function.logical.TrueFunction org.pentaho.reporting.libraries.formula.functions.logical.True.description=org.pentaho.reporting.libraries.formula.function.logical.TrueFunctionDescription org.pentaho.reporting.libraries.formula.functions.logical.Xor.class=org.pentaho.reporting.libraries.formula.function.logical.XorFunction org.pentaho.reporting.libraries.formula.functions.logical.Xor.description=org.pentaho.reporting.libraries.formula.function.logical.XorFunctionDescription ## # Rounding functions org.pentaho.reporting.libraries.formula.functions.rounding.Int.class=org.pentaho.reporting.libraries.formula.function.rounding.IntFunction org.pentaho.reporting.libraries.formula.functions.rounding.Int.description=org.pentaho.reporting.libraries.formula.function.rounding.IntFunctionDescription ## # Mathematical functions org.pentaho.reporting.libraries.formula.functions.math.Abs.class=org.pentaho.reporting.libraries.formula.function.math.AbsFunction org.pentaho.reporting.libraries.formula.functions.math.Abs.description=org.pentaho.reporting.libraries.formula.function.math.AbsFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Acos.class=org.pentaho.reporting.libraries.formula.function.math.AcosFunction org.pentaho.reporting.libraries.formula.functions.math.Acos.description=org.pentaho.reporting.libraries.formula.function.math.AcosFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Acosh.class=org.pentaho.reporting.libraries.formula.function.math.AcoshFunction org.pentaho.reporting.libraries.formula.functions.math.Acosh.description=org.pentaho.reporting.libraries.formula.function.math.AcoshFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Asin.class=org.pentaho.reporting.libraries.formula.function.math.AsinFunction org.pentaho.reporting.libraries.formula.functions.math.Asin.description=org.pentaho.reporting.libraries.formula.function.math.AsinFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Atan2.class=org.pentaho.reporting.libraries.formula.function.math.Atan2Function org.pentaho.reporting.libraries.formula.functions.math.Atan2.description=org.pentaho.reporting.libraries.formula.function.math.Atan2FunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Atan.class=org.pentaho.reporting.libraries.formula.function.math.AtanFunction org.pentaho.reporting.libraries.formula.functions.math.Atan.description=org.pentaho.reporting.libraries.formula.function.math.AtanFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Average.class=org.pentaho.reporting.libraries.formula.function.math.AverageFunction org.pentaho.reporting.libraries.formula.functions.math.Average.description=org.pentaho.reporting.libraries.formula.function.math.AverageFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.AverageA.class=org.pentaho.reporting.libraries.formula.function.math.AverageAFunction org.pentaho.reporting.libraries.formula.functions.math.AverageA.description=org.pentaho.reporting.libraries.formula.function.math.AverageAFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Cos.class=org.pentaho.reporting.libraries.formula.function.math.CosFunction org.pentaho.reporting.libraries.formula.functions.math.Cos.description=org.pentaho.reporting.libraries.formula.function.math.CosFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Even.class=org.pentaho.reporting.libraries.formula.function.math.EvenFunction org.pentaho.reporting.libraries.formula.functions.math.Even.description=org.pentaho.reporting.libraries.formula.function.math.EvenFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Exp.class=org.pentaho.reporting.libraries.formula.function.math.ExpFunction org.pentaho.reporting.libraries.formula.functions.math.Exp.description=org.pentaho.reporting.libraries.formula.function.math.ExpFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Ln.class=org.pentaho.reporting.libraries.formula.function.math.LnFunction org.pentaho.reporting.libraries.formula.functions.math.Ln.description=org.pentaho.reporting.libraries.formula.function.math.LnFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Log10.class=org.pentaho.reporting.libraries.formula.function.math.Log10Function org.pentaho.reporting.libraries.formula.functions.math.Log10.description=org.pentaho.reporting.libraries.formula.function.math.Log10FunctionDescription org.pentaho.reporting.libraries.formula.functions.math.MaxA.class=org.pentaho.reporting.libraries.formula.function.math.MaxAFunction org.pentaho.reporting.libraries.formula.functions.math.MaxA.description=org.pentaho.reporting.libraries.formula.function.math.MaxAFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Max.class=org.pentaho.reporting.libraries.formula.function.math.MaxFunction org.pentaho.reporting.libraries.formula.functions.math.Max.description=org.pentaho.reporting.libraries.formula.function.math.MaxFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.MinA.class=org.pentaho.reporting.libraries.formula.function.math.MinAFunction org.pentaho.reporting.libraries.formula.functions.math.MinA.description=org.pentaho.reporting.libraries.formula.function.math.MinAFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Min.class=org.pentaho.reporting.libraries.formula.function.math.MinFunction org.pentaho.reporting.libraries.formula.functions.math.Min.description=org.pentaho.reporting.libraries.formula.function.math.MinFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Mod.class=org.pentaho.reporting.libraries.formula.function.math.ModFunction org.pentaho.reporting.libraries.formula.functions.math.Mod.description=org.pentaho.reporting.libraries.formula.function.math.ModFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Odd.class=org.pentaho.reporting.libraries.formula.function.math.OddFunction org.pentaho.reporting.libraries.formula.functions.math.Odd.description=org.pentaho.reporting.libraries.formula.function.math.OddFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Pi.class=org.pentaho.reporting.libraries.formula.function.math.PiFunction org.pentaho.reporting.libraries.formula.functions.math.Pi.description=org.pentaho.reporting.libraries.formula.function.math.PiFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Power.class=org.pentaho.reporting.libraries.formula.function.math.PowerFunction org.pentaho.reporting.libraries.formula.functions.math.Power.description=org.pentaho.reporting.libraries.formula.function.math.PowerFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Sin.class=org.pentaho.reporting.libraries.formula.function.math.SinFunction org.pentaho.reporting.libraries.formula.functions.math.Sin.description=org.pentaho.reporting.libraries.formula.function.math.SinFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Sqrt.class=org.pentaho.reporting.libraries.formula.function.math.SqrtFunction org.pentaho.reporting.libraries.formula.functions.math.Sqrt.description=org.pentaho.reporting.libraries.formula.function.math.SqrtFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.SumA.class=org.pentaho.reporting.libraries.formula.function.math.SumAFunction org.pentaho.reporting.libraries.formula.functions.math.SumA.description=org.pentaho.reporting.libraries.formula.function.math.SumAFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Sum.class=org.pentaho.reporting.libraries.formula.function.math.SumFunction org.pentaho.reporting.libraries.formula.functions.math.Sum.description=org.pentaho.reporting.libraries.formula.function.math.SumFunctionDescription org.pentaho.reporting.libraries.formula.functions.math.Var.class=org.pentaho.reporting.libraries.formula.function.math.VarFunction org.pentaho.reporting.libraries.formula.functions.math.Var.description=org.pentaho.reporting.libraries.formula.function.math.VarFunctionDescription ## # Text functions org.pentaho.reporting.libraries.formula.functions.text.Exact.class=org.pentaho.reporting.libraries.formula.function.text.ExactFunction org.pentaho.reporting.libraries.formula.functions.text.Exact.description=org.pentaho.reporting.libraries.formula.function.text.ExactFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Find.class=org.pentaho.reporting.libraries.formula.function.text.FindFunction org.pentaho.reporting.libraries.formula.functions.text.Find.description=org.pentaho.reporting.libraries.formula.function.text.FindFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Left.class=org.pentaho.reporting.libraries.formula.function.text.LeftFunction org.pentaho.reporting.libraries.formula.functions.text.Left.description=org.pentaho.reporting.libraries.formula.function.text.LeftFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Len.class=org.pentaho.reporting.libraries.formula.function.text.LenFunction org.pentaho.reporting.libraries.formula.functions.text.Len.description=org.pentaho.reporting.libraries.formula.function.text.LenFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Lower.class=org.pentaho.reporting.libraries.formula.function.text.LowerFunction org.pentaho.reporting.libraries.formula.functions.text.Lower.description=org.pentaho.reporting.libraries.formula.function.text.LowerFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Message.class=org.pentaho.reporting.libraries.formula.function.text.MessageFunction org.pentaho.reporting.libraries.formula.functions.text.Message.description=org.pentaho.reporting.libraries.formula.function.text.MessageFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Mid.class=org.pentaho.reporting.libraries.formula.function.text.MidFunction org.pentaho.reporting.libraries.formula.functions.text.Mid.description=org.pentaho.reporting.libraries.formula.function.text.MidFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Replace.class=org.pentaho.reporting.libraries.formula.function.text.ReplaceFunction org.pentaho.reporting.libraries.formula.functions.text.Replace.description=org.pentaho.reporting.libraries.formula.function.text.ReplaceFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Rept.class=org.pentaho.reporting.libraries.formula.function.text.ReptFunction org.pentaho.reporting.libraries.formula.functions.text.Rept.description=org.pentaho.reporting.libraries.formula.function.text.ReptFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Right.class=org.pentaho.reporting.libraries.formula.function.text.RightFunction org.pentaho.reporting.libraries.formula.functions.text.Right.description=org.pentaho.reporting.libraries.formula.function.text.RightFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Substitute.class=org.pentaho.reporting.libraries.formula.function.text.SubstituteFunction org.pentaho.reporting.libraries.formula.functions.text.Substitute.description=org.pentaho.reporting.libraries.formula.function.text.SubstituteFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Text.class=org.pentaho.reporting.libraries.formula.function.text.TextFunction org.pentaho.reporting.libraries.formula.functions.text.Text.description=org.pentaho.reporting.libraries.formula.function.text.TextFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.T.class=org.pentaho.reporting.libraries.formula.function.text.TFunction org.pentaho.reporting.libraries.formula.functions.text.T.description=org.pentaho.reporting.libraries.formula.function.text.TFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Trim.class=org.pentaho.reporting.libraries.formula.function.text.TrimFunction org.pentaho.reporting.libraries.formula.functions.text.Trim.description=org.pentaho.reporting.libraries.formula.function.text.TrimFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Unichar.class=org.pentaho.reporting.libraries.formula.function.text.UnicharFunction org.pentaho.reporting.libraries.formula.functions.text.Unichar.description=org.pentaho.reporting.libraries.formula.function.text.UnicharFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Unicode.class=org.pentaho.reporting.libraries.formula.function.text.UnicodeFunction org.pentaho.reporting.libraries.formula.functions.text.Unicode.description=org.pentaho.reporting.libraries.formula.function.text.UnicodeFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.Upper.class=org.pentaho.reporting.libraries.formula.function.text.UpperFunction org.pentaho.reporting.libraries.formula.functions.text.Upper.description=org.pentaho.reporting.libraries.formula.function.text.UpperFunctionDescription org.pentaho.reporting.libraries.formula.functions.text.UrlEncode.class=org.pentaho.reporting.libraries.formula.function.text.URLEncodeFunction org.pentaho.reporting.libraries.formula.functions.text.UrlEncode.description=org.pentaho.reporting.libraries.formula.function.text.URLEncodeFunctionDescription ## # Information functions org.pentaho.reporting.libraries.formula.functions.information.Choose.class=org.pentaho.reporting.libraries.formula.function.information.ChooseFunction org.pentaho.reporting.libraries.formula.functions.information.Choose.description=org.pentaho.reporting.libraries.formula.function.information.ChooseFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.Count.class=org.pentaho.reporting.libraries.formula.function.information.CountFunction org.pentaho.reporting.libraries.formula.functions.information.Count.description=org.pentaho.reporting.libraries.formula.function.information.CountFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.CountA.class=org.pentaho.reporting.libraries.formula.function.information.CountAFunction org.pentaho.reporting.libraries.formula.functions.information.CountA.description=org.pentaho.reporting.libraries.formula.function.information.CountAFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.CountBlank.class=org.pentaho.reporting.libraries.formula.function.information.CountBlankFunction org.pentaho.reporting.libraries.formula.functions.information.CountBlank.description=org.pentaho.reporting.libraries.formula.function.information.CountBlankFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.HasChanged.class=org.pentaho.reporting.libraries.formula.function.information.HasChangedFunction org.pentaho.reporting.libraries.formula.functions.information.HasChanged.description=org.pentaho.reporting.libraries.formula.function.information.HasChangedFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.Index.class=org.pentaho.reporting.libraries.formula.function.information.IndexFunction org.pentaho.reporting.libraries.formula.functions.information.Index.description=org.pentaho.reporting.libraries.formula.function.information.IndexFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsBlank.class=org.pentaho.reporting.libraries.formula.function.information.IsBlankFunction org.pentaho.reporting.libraries.formula.functions.information.IsBlank.description=org.pentaho.reporting.libraries.formula.function.information.IsBlankFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsErr.class=org.pentaho.reporting.libraries.formula.function.information.IsErrFunction org.pentaho.reporting.libraries.formula.functions.information.IsErr.description=org.pentaho.reporting.libraries.formula.function.information.IsErrFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsError.class=org.pentaho.reporting.libraries.formula.function.information.IsErrorFunction org.pentaho.reporting.libraries.formula.functions.information.IsError.description=org.pentaho.reporting.libraries.formula.function.information.IsErrorFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsEven.class=org.pentaho.reporting.libraries.formula.function.information.IsEvenFunction org.pentaho.reporting.libraries.formula.functions.information.IsEven.description=org.pentaho.reporting.libraries.formula.function.information.IsEvenFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsLogical.class=org.pentaho.reporting.libraries.formula.function.information.IsLogicalFunction org.pentaho.reporting.libraries.formula.functions.information.IsLogical.description=org.pentaho.reporting.libraries.formula.function.information.IsLogicalFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsNa.class=org.pentaho.reporting.libraries.formula.function.information.IsNaFunction org.pentaho.reporting.libraries.formula.functions.information.IsNa.description=org.pentaho.reporting.libraries.formula.function.information.IsNaFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsNonText.class=org.pentaho.reporting.libraries.formula.function.information.IsNonTextFunction org.pentaho.reporting.libraries.formula.functions.information.IsNonText.description=org.pentaho.reporting.libraries.formula.function.information.IsNonTextFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsNumber.class=org.pentaho.reporting.libraries.formula.function.information.IsNumberFunction org.pentaho.reporting.libraries.formula.functions.information.IsNumber.description=org.pentaho.reporting.libraries.formula.function.information.IsNumberFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsOdd.class=org.pentaho.reporting.libraries.formula.function.information.IsOddFunction org.pentaho.reporting.libraries.formula.functions.information.IsOdd.description=org.pentaho.reporting.libraries.formula.function.information.IsOddFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsRef.class=org.pentaho.reporting.libraries.formula.function.information.IsRefFunction org.pentaho.reporting.libraries.formula.functions.information.IsRef.description=org.pentaho.reporting.libraries.formula.function.information.IsRefFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.IsText.class=org.pentaho.reporting.libraries.formula.function.information.IsTextFunction org.pentaho.reporting.libraries.formula.functions.information.IsText.description=org.pentaho.reporting.libraries.formula.function.information.IsTextFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.Na.class=org.pentaho.reporting.libraries.formula.function.information.NaFunction org.pentaho.reporting.libraries.formula.functions.information.Na.description=org.pentaho.reporting.libraries.formula.function.information.NaFunctionDescription org.pentaho.reporting.libraries.formula.functions.information.Value.class=org.pentaho.reporting.libraries.formula.function.information.ValueFunction org.pentaho.reporting.libraries.formula.functions.information.Value.description=org.pentaho.reporting.libraries.formula.function.information.ValueFunctionDescription org.pentaho.reporting.libraries.formula.functions.userdefined.Null.class=org.pentaho.reporting.libraries.formula.function.userdefined.NullFunction org.pentaho.reporting.libraries.formula.functions.userdefined.Null.description=org.pentaho.reporting.libraries.formula.function.userdefined.NullFunctionDescription org.pentaho.reporting.libraries.formula.functions.userdefined.CsvText.class=org.pentaho.reporting.libraries.formula.function.userdefined.CsvTextFunction org.pentaho.reporting.libraries.formula.functions.userdefined.CsvText.description=org.pentaho.reporting.libraries.formula.function.userdefined.CsvTextFunctionDescription org.pentaho.reporting.libraries.formula.functions.userdefined.CsvArray.class=org.pentaho.reporting.libraries.formula.function.userdefined.CsvArrayFunction org.pentaho.reporting.libraries.formula.functions.userdefined.CsvArray.description=org.pentaho.reporting.libraries.formula.function.userdefined.CsvArrayFunctionDescription org.pentaho.reporting.libraries.formula.functions.userdefined.NormalizeArray.class=org.pentaho.reporting.libraries.formula.function.userdefined.NormalizeArrayFunction org.pentaho.reporting.libraries.formula.functions.userdefined.NormalizeArray.description=org.pentaho.reporting.libraries.formula.function.userdefined.NormalizeArrayFunctionDescription org.pentaho.reporting.libraries.formula.functions.userdefined.ParseDate.class=org.pentaho.reporting.libraries.formula.function.userdefined.ParseDateFunction org.pentaho.reporting.libraries.formula.functions.userdefined.ParseDate.description=org.pentaho.reporting.libraries.formula.function.userdefined.ParseDateFunctionDescription # # Known Operators. Operators are not hardcoded, so it is rather easy to replace # the operator implementations if needed. Adding operators is not possible # without touching the parser; but this should be a rare requirement as the # functions model is very powerfull. org.pentaho.reporting.libraries.formula.operators.infix.Add.token=+ org.pentaho.reporting.libraries.formula.operators.infix.Add.class=org.pentaho.reporting.libraries.formula.operators.AddOperator org.pentaho.reporting.libraries.formula.operators.infix.Subtract.token=- org.pentaho.reporting.libraries.formula.operators.infix.Subtract.class=org.pentaho.reporting.libraries.formula.operators.SubtractOperator org.pentaho.reporting.libraries.formula.operators.infix.Multiply.token=* org.pentaho.reporting.libraries.formula.operators.infix.Multiply.class=org.pentaho.reporting.libraries.formula.operators.MultiplyOperator org.pentaho.reporting.libraries.formula.operators.infix.Divide.token=/ org.pentaho.reporting.libraries.formula.operators.infix.Divide.class=org.pentaho.reporting.libraries.formula.operators.DivideOperator org.pentaho.reporting.libraries.formula.operators.infix.Equal.token== org.pentaho.reporting.libraries.formula.operators.infix.Equal.class=org.pentaho.reporting.libraries.formula.operators.EqualOperator org.pentaho.reporting.libraries.formula.operators.infix.NotEqual.token=<> org.pentaho.reporting.libraries.formula.operators.infix.NotEqual.class=org.pentaho.reporting.libraries.formula.operators.NotEqualOperator org.pentaho.reporting.libraries.formula.operators.infix.Lesser.token=< org.pentaho.reporting.libraries.formula.operators.infix.Lesser.class=org.pentaho.reporting.libraries.formula.operators.LesserOperator org.pentaho.reporting.libraries.formula.operators.infix.Greater.token=> org.pentaho.reporting.libraries.formula.operators.infix.Greater.class=org.pentaho.reporting.libraries.formula.operators.GreaterOperator org.pentaho.reporting.libraries.formula.operators.infix.LesserEqual.token=<= org.pentaho.reporting.libraries.formula.operators.infix.LesserEqual.class=org.pentaho.reporting.libraries.formula.operators.LesserEqualOperator org.pentaho.reporting.libraries.formula.operators.infix.GreaterEqual.token=>= org.pentaho.reporting.libraries.formula.operators.infix.GreaterEqual.class=org.pentaho.reporting.libraries.formula.operators.GreaterEqualOperator org.pentaho.reporting.libraries.formula.operators.infix.Concat.token=& org.pentaho.reporting.libraries.formula.operators.infix.Concat.class=org.pentaho.reporting.libraries.formula.operators.ConcatOperator org.pentaho.reporting.libraries.formula.operators.infix.Power.token=^ org.pentaho.reporting.libraries.formula.operators.infix.Power.class=org.pentaho.reporting.libraries.formula.operators.PowerOperator org.pentaho.reporting.libraries.formula.operators.postfix.Percentage.token=% org.pentaho.reporting.libraries.formula.operators.postfix.Percentage.class=org.pentaho.reporting.libraries.formula.operators.PercentageOperator org.pentaho.reporting.libraries.formula.operators.prefix.Plus.token=+ org.pentaho.reporting.libraries.formula.operators.prefix.Plus.class=org.pentaho.reporting.libraries.formula.operators.PlusSignOperator org.pentaho.reporting.libraries.formula.operators.prefix.Minus.token=- org.pentaho.reporting.libraries.formula.operators.prefix.Minus.class=org.pentaho.reporting.libraries.formula.operators.MinusSignOperator libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/LocalizationContext.java0000644000175000017500000000247511401240110030327 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.TimeZone; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 03.11.2006, 14:26:26 * * @author Thomas Morgner */ public interface LocalizationContext { public Locale getLocale(); public ResourceBundle getBundle (String id); public TimeZone getTimeZone(); public List getDateFormats(Type type); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/Messages.java0000644000175000017500000000054411401240106026101 0ustar renerenepackage org.pentaho.reporting.libraries.formula; import java.util.Locale; import org.pentaho.reporting.libraries.base.util.ResourceBundleSupport; public class Messages extends ResourceBundleSupport { /** * Creates a new instance. */ public Messages(final Locale locale) { super("org.pentaho.reporting.libraries.formula.messages"); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/0000755000175000017500000000000011401240106024776 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/TypeConversionException.java0000644000175000017500000000337111401240106032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * Creation-Date: 10.04.2007, 14:13:40 * * @author Thomas Morgner */ public class TypeConversionException extends EvaluationException { private static final long serialVersionUID = -12507914833915502L; private static ThreadLocal localInstance = new ThreadLocal(); protected TypeConversionException() { super(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } public static TypeConversionException getInstance() { final TypeConversionException o = (TypeConversionException) localInstance.get(); if (o == null) { final TypeConversionException retval = new TypeConversionException(); localInstance.set(retval); return retval; } o.fillInStackTrace(); return o; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/ArrayCallback.java0000644000175000017500000000256411401240106030343 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.LValue; /** * * @author Cedric Pronzato */ public interface ArrayCallback { public LValue getRaw (int row, int column) throws EvaluationException; public Object getValue (int row, int column) throws EvaluationException; public Type getType (int row, int column) throws EvaluationException; public int getColumnCount(); public int getRowCount(); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/Sequence.java0000644000175000017500000000242311401240106027412 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.LValue; /** * Todo: Document Me * * @author Thomas Morgner */ public interface Sequence { public boolean hasNext() throws EvaluationException; public Object next() throws EvaluationException; public LValue nextRawValue() throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/StaticArrayCallback.java0000644000175000017500000000473111401240106031511 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; /** * An array call-back that copies all contents of the source into a private buffer. * * @author Thomas Morgner */ public class StaticArrayCallback implements ArrayCallback { private TypeValuePair[][] backend; private int rowCount; private int colCount; public StaticArrayCallback(final ArrayCallback source) throws EvaluationException { rowCount = source.getRowCount(); colCount = source.getColumnCount(); backend = new TypeValuePair[rowCount][colCount]; for (int row = 0; row < rowCount; row += 1) { for (int col = 0; col < colCount; col += 1) { final Type type = source.getType(row, col); final Object value = source.getValue(row, col); backend[row][col] = new TypeValuePair(type, value); } } } public LValue getRaw(final int row, final int column) throws EvaluationException { return new StaticValue(getValue(row, column), getType(row, column)); } public Object getValue(final int row, final int column) throws EvaluationException { return backend[row][column].getValue(); } public Type getType(final int row, final int column) throws EvaluationException { return backend[row][column].getType(); } public int getColumnCount() { return colCount; } public int getRowCount() { return rowCount; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/DefaultTypeRegistry.java0000644000175000017500000005571511401240106031635 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.Clob; import java.sql.Time; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.text.ParsePosition; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.util.IOUtils; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.lvalues.DefaultDataTable; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; import org.pentaho.reporting.libraries.formula.typing.sequence.AnyNumberSequence; import org.pentaho.reporting.libraries.formula.typing.sequence.AnySequence; import org.pentaho.reporting.libraries.formula.typing.sequence.DefaultNumberSequence; import org.pentaho.reporting.libraries.formula.util.DateUtil; import org.pentaho.reporting.libraries.formula.util.HSSFDateUtil; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Creation-Date: 02.11.2006, 12:46:08 * * @author Thomas Morgner */ public class DefaultTypeRegistry implements TypeRegistry { private static final Log logger = LogFactory.getLog(DefaultTypeRegistry.class); private static class ArrayConverterCallback implements ArrayCallback { private Object retval; private Type targetType; private ArrayConverterCallback(final Object retval, final Type targetType) { this.retval = retval; this.targetType = targetType; } public LValue getRaw(final int row, final int column) { return new StaticValue(retval, targetType); } public Object getValue(final int row, final int column) throws EvaluationException { if (row == 0 && column == 0) { return retval; } return null; } public Type getType(final int row, final int column) throws EvaluationException { if (row == 0 && column == 0) { return targetType; } return null; } public int getColumnCount() { return 1; } public int getRowCount() { return 1; } } private static final BigDecimal NUM_TRUE = new BigDecimal("1"); private static final BigDecimal NUM_FALSE = new BigDecimal("0"); private static final BigDecimal ZERO = NUM_FALSE; private FormulaContext context; private NumberFormat[] numberFormats; public DefaultTypeRegistry() { } /** * Returns an comparator for the given types. * * @param type1 * @param type2 * @return */ public ExtendedComparator getComparator(final Type type1, final Type type2) { final DefaultComparator comparator = new DefaultComparator(); comparator.inititalize(context); return comparator; } /** * converts the object of the given type into a number. If the object is not convertible, a NumberFormatException is * thrown. If the given value is null or not parsable as number, return null. * * @param sourceType * @param value * @return * @throws NumberFormatException if the type cannot be represented as number. */ public Number convertToNumber(final Type sourceType, final Object value) throws EvaluationException { final LocalizationContext localizationContext = context.getLocalizationContext(); if (value == null) { // there's no point in digging deeper - there *is* no value .. throw TypeConversionException.getInstance(); } final boolean isAnyType = sourceType.isFlagSet(Type.ANY_TYPE); if (sourceType.isFlagSet(Type.NUMERIC_TYPE) || isAnyType) { if (sourceType.isFlagSet(Type.DATETIME_TYPE) || sourceType.isFlagSet(Type.TIME_TYPE) || sourceType.isFlagSet(Type.DATE_TYPE) || isAnyType) { if (value instanceof Date) { final BigDecimal serial = HSSFDateUtil.getExcelDate((Date) value); return DateUtil.normalizeDate(serial, sourceType); } } if (value instanceof Number) { return (Number) value; } } if (sourceType.isFlagSet(Type.LOGICAL_TYPE) || isAnyType) { if (value instanceof Boolean) { if (Boolean.TRUE.equals(value)) { return NUM_TRUE; } else { return NUM_FALSE; } } } if (sourceType.isFlagSet(Type.TEXT_TYPE) || isAnyType) { final String val = computeStringValue(value); // first, try to parse the value as a big-decimal. try { return new BigDecimal(val); } catch (NumberFormatException e) { // ignore .. } // then checking for datetimes final Iterator datetimeIterator = localizationContext.getDateFormats(DateTimeType.DATETIME_TYPE).iterator(); while (datetimeIterator.hasNext()) { final DateFormat df = (DateFormat) datetimeIterator.next(); final Date date = parse(df, val); if (date != null) { return HSSFDateUtil.getExcelDate(date); } } // then checking for datetimes final Iterator dateIterator = localizationContext.getDateFormats(DateTimeType.DATE_TYPE).iterator(); while (dateIterator.hasNext()) { final DateFormat df = (DateFormat) dateIterator.next(); final Date date = parse(df, val); if (date != null) { return HSSFDateUtil.getExcelDate(date); } } // then checking for datetimes final Iterator timeIterator = localizationContext .getDateFormats(DateTimeType.TIME_TYPE).iterator(); while (timeIterator.hasNext()) { final DateFormat df = (DateFormat) timeIterator.next(); final Date date = parse(df, val); if (date != null) { return HSSFDateUtil.getExcelDate(date); } } // then checking for numbers for (int i = 0; i < numberFormats.length; i++) { final NumberFormat format = numberFormats[i]; final Number number = parse(format, val); if (number != null) { return number; } } } throw TypeConversionException.getInstance(); } private static Number parse(final NumberFormat format, final String source) { final ParsePosition parsePosition = new ParsePosition(0); final Number result = format.parse(source, parsePosition); if (parsePosition.getIndex() == 0 || parsePosition.getIndex() != source.length()) { return null; } return result; } private static Date parse(final DateFormat format, final String source) { final ParsePosition parsePosition = new ParsePosition(0); final Date result = format.parse(source, parsePosition); if (parsePosition.getIndex() == 0 || parsePosition.getIndex() != source.length()) { return null; } return result; } /** * @param configuration * @param formulaContext * @deprecated Use the single-argument function instead. */ public void initialize(final Configuration configuration, final FormulaContext formulaContext) { this.initialize(formulaContext); } public void initialize(final FormulaContext formulaContext) { if (formulaContext == null) { throw new NullPointerException(); } this.context = formulaContext; this.numberFormats = loadNumberFormats(); } protected NumberFormat[] loadNumberFormats() { final ArrayList formats = new ArrayList(); final DecimalFormat defaultFormat = new DecimalFormat("#0.###", new DecimalFormatSymbols(Locale.US)); activateBigDecimalMode(defaultFormat); formats.add(defaultFormat); return (NumberFormat[]) formats.toArray(new NumberFormat[formats.size()]); } private void activateBigDecimalMode(final DecimalFormat format) { if (ObjectUtilities.isJDK14()) { try { final Method method = DecimalFormat.class.getMethod("setParseBigDecimal", new Class[]{Boolean.TYPE}); method.invoke(format, new Object[]{Boolean.TRUE}); } catch (Exception e) { // ignore it, as it will always fail on JDK 1.4 or lower .. } } } public String convertToText(final Type type1, final Object value) throws EvaluationException { if (value == null) { return ""; } // already converted or compatible if (type1.isFlagSet(Type.TEXT_TYPE)) { // no need to check whatever it is a String return computeStringValue(value); } if (type1.isFlagSet(Type.LOGICAL_TYPE)) { if (value instanceof Boolean) { final Boolean b = (Boolean) value; if (Boolean.TRUE.equals(b)) { return "TRUE"; } else { return "FALSE"; } } else { throw TypeConversionException.getInstance(); } } // 2 types of numeric : numbers and dates if (type1.isFlagSet(Type.NUMERIC_TYPE)) { if (type1.isFlagSet(Type.DATETIME_TYPE) || type1.isFlagSet(Type.DATE_TYPE) || type1.isFlagSet(Type.TIME_TYPE)) { final Date d = convertToDate(type1, value); final List dateFormats = context.getLocalizationContext() .getDateFormats(type1); if (dateFormats != null && dateFormats.size() >= 1) { final DateFormat format = (DateFormat) dateFormats.get(0); return format.format(d); } else { // fallback return DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL).format(d); } } else { try { final Number n = convertToNumber(type1, value); final NumberFormat format = getDefaultNumberFormat(); return format.format(n); } catch (EvaluationException nfe) { // ignore .. } } } return computeStringValue(value); } private String computeStringValue(final Object retval) { if (retval instanceof Clob) { return IOUtils.getInstance().readClob((Clob) retval); } if (retval != null) { return retval.toString(); } return null; } public Boolean convertToLogical(final Type type1, final Object value) throws TypeConversionException { if (value == null) { return Boolean.FALSE; } // already converted or compatible if (type1.isFlagSet(Type.LOGICAL_TYPE) || type1.isFlagSet(Type.ANY_TYPE)) { if (value instanceof Boolean) { return (Boolean) value; } // fallback if ("true".equalsIgnoreCase(String.valueOf(value))) { return Boolean.TRUE; } return Boolean.FALSE; } if (type1.isFlagSet(Type.NUMERIC_TYPE)) { // no need to check between different types of numeric if (value instanceof Number) { final Number num = (Number) value; if (!ZERO.equals(num)) { return Boolean.TRUE; } } // fallback return Boolean.FALSE; } if (type1.isFlagSet(Type.TEXT_TYPE)) { // no need to convert it to String final String str = computeStringValue(value); if ("TRUE".equalsIgnoreCase(str)) { return Boolean.TRUE; } else if ("FALSE".equalsIgnoreCase(str)) { return Boolean.FALSE; } } throw TypeConversionException.getInstance(); } public Date convertToDate(final Type type1, final Object value) throws EvaluationException { if (type1.isFlagSet(Type.NUMERIC_TYPE) || type1.isFlagSet(Type.ANY_TYPE)) { if (type1.isFlagSet(Type.DATE_TYPE) || type1.isFlagSet(Type.DATETIME_TYPE) || type1.isFlagSet(Type.TIME_TYPE) || type1.isFlagSet(Type.ANY_TYPE)) { if (value instanceof Date) { return DateUtil.normalizeDate((Date) value, type1); } } } final Number serial = convertToNumber(type1, value); final BigDecimal bd = NumberUtil.getAsBigDecimal(serial); return HSSFDateUtil.getJavaDate(bd); } protected NumberFormat getDefaultNumberFormat() { final Locale locale = context.getLocalizationContext().getLocale(); return new DecimalFormat("#0.#########", new DecimalFormatSymbols(locale)); } public ArrayCallback convertToArray(final Type type, final Object value) throws EvaluationException { if (value instanceof ArrayCallback) { return (ArrayCallback) value; } if (value == null) { return new DefaultDataTable().getAsArray(); } final Class valueType = value.getClass(); if (valueType.isArray() == false) { if (value instanceof Collection) { final Collection colVal = (Collection) value; final DefaultDataTable table = new DefaultDataTable(); final Iterator iterator = colVal.iterator(); int i = 0; while (iterator.hasNext()) { table.setObject(i, 0, new StaticValue(iterator.next())); i += 1; } return table.getAsArray(); } return new ArrayConverterCallback(value, type); } final Class componentType = valueType.getComponentType(); if (componentType.isArray()) { final DefaultDataTable table = new DefaultDataTable(); final int length = Array.getLength(value); for (int row = 0; row < length; row++) { final Object innerArray = Array.get(value, row); final int innerLength = Array.getLength(innerArray); for (int col = 0; col < innerLength; col++) { table.setObject(row, col, new StaticValue(Array.get(innerArray, col))); } } return table.getAsArray(); } final DefaultDataTable table = new DefaultDataTable(); final int length = Array.getLength(value); for (int i = 0; i < length; i++) { table.setObject(i, 0, new StaticValue(Array.get(value, i))); } return table.getAsArray(); } /** * A internal method that converts the given value-pair into a sequence. * * @param targetType * @param valuePair * @return * @throws TypeConversionException if there was a error while converting types. */ private TypeValuePair convertToSequence(final Type targetType, final TypeValuePair valuePair) throws EvaluationException { if (targetType.isFlagSet(Type.NUMERIC_SEQUENCE_TYPE)) { return new TypeValuePair (targetType, convertToNumberSequence(valuePair.getType(), valuePair.getValue(), true)); } return new TypeValuePair(targetType, convertToSequence(valuePair.getType(), valuePair.getValue())); } public Sequence convertToSequence(final Type type, final Object value) throws EvaluationException { // sclar if (type.isFlagSet(Type.SCALAR_TYPE)) { return new AnySequence(new StaticValue(value, type), context); } // else already a sequence else if (type.isFlagSet(Type.SEQUENCE_TYPE)) { if (value instanceof Sequence) { return (Sequence) value; } else { logger.warn("Assertation failure: Type declared to be a sequence, but no sequence found inside."); throw TypeConversionException.getInstance(); } } // else an array source else if (type.isFlagSet(Type.ARRAY_TYPE)) { if (value instanceof ArrayCallback) { return new AnySequence((ArrayCallback) value, context); } else { logger.warn("Assertation failure: Type declared to be array, but no array callback found inside."); throw TypeConversionException.getInstance(); } } throw TypeConversionException.getInstance(); } public NumberSequence convertToNumberSequence(final Type type, final Object value, final boolean strict) throws EvaluationException { // sequence array if (type.isFlagSet(Type.NUMERIC_SEQUENCE_TYPE)) { if (value instanceof DefaultNumberSequence) { return (NumberSequence) value; } else { // a empty sequence ... return new DefaultNumberSequence(context); } } // array else if (type.isFlagSet(Type.ARRAY_TYPE)) { if (value instanceof ArrayCallback) { if (strict) { return new DefaultNumberSequence((ArrayCallback) value, context); } else { return new AnyNumberSequence((ArrayCallback) value, context); } } else { logger.warn("Assertation failure: Type declared to be array, but no array callback found inside."); throw TypeConversionException.getInstance(); } } // else scalar if (type.isFlagSet(Type.SCALAR_TYPE) || type.isFlagSet(Type.NUMERIC_TYPE)) { return new DefaultNumberSequence (new StaticValue(convertToNumber(type, value), NumberType.GENERIC_NUMBER), context); } else { return new DefaultNumberSequence(context); } } /** * Checks whether the target type would accept the specified value object and value type.
This method is called * for auto conversion of fonction parameters using the conversion type declared by the function metadata. * * @param targetType * @param valuePair * @noinspection ObjectEquality is tested at the end of the method for performance reasons only. We just want to * detect whether a new object has been created or not. */ public TypeValuePair convertTo(final Type targetType, final TypeValuePair valuePair) throws EvaluationException { if (targetType.isFlagSet(Type.ARRAY_TYPE)) { if (valuePair.getType().isFlagSet(Type.ARRAY_TYPE)) { return valuePair; } else if (targetType.isFlagSet(Type.SEQUENCE_TYPE)) { return convertTo(targetType, valuePair); } else { final Object o = valuePair.getValue(); if (o != null && o.getClass().isArray()) { return new TypeValuePair(targetType, convertToArray(valuePair.getType(), o)); } else { final Object retval = convertPlainToPlain(targetType, valuePair.getType(), valuePair.getValue()); return new TypeValuePair(targetType, new ArrayConverterCallback(retval, targetType)); } } } else if (targetType.isFlagSet(Type.SEQUENCE_TYPE)) { if (valuePair.getType().isFlagSet(Type.ARRAY_TYPE)) { return convertToSequence(targetType, valuePair); } else if (targetType.isFlagSet(Type.SEQUENCE_TYPE)) { return valuePair; } else { final Object retval = convertPlainToPlain(targetType, valuePair.getType(), valuePair.getValue()); final ArrayConverterCallback converterCallback = new ArrayConverterCallback(retval, targetType); return convertToSequence(targetType, new TypeValuePair(AnyType.ANY_ARRAY, converterCallback)); } } // else scalar final Object value = valuePair.getValue(); final Object o = convertPlainToPlain(targetType, valuePair.getType(), value); if (value == o) { return valuePair; } return new TypeValuePair(targetType, o); } private Object convertPlainToPlain(final Type targetType, final Type sourceType, final Object value) throws EvaluationException { if (targetType.isFlagSet(Type.NUMERIC_TYPE)) { if (targetType.isFlagSet(Type.LOGICAL_TYPE)) { if (sourceType.isFlagSet(Type.LOGICAL_TYPE)) { return value; } return convertToLogical(sourceType, value); } if (value instanceof Date) { if (targetType.isFlagSet(Type.DATE_TYPE) || targetType.isFlagSet(Type.DATETIME_TYPE) || targetType.isFlagSet(Type.TIME_TYPE)) { final Date toJavaDate = (Date) value; return DateUtil.normalizeDate(toJavaDate, targetType, false); } } final Number serial = convertToNumber(sourceType, value); if (targetType.isFlagSet(Type.DATE_TYPE) || targetType.isFlagSet(Type.DATETIME_TYPE) || targetType.isFlagSet(Type.TIME_TYPE)) { final BigDecimal fromAsBigDecimal = NumberUtil.getAsBigDecimal(serial); final BigDecimal normalizedSerial = DateUtil.normalizeDate(fromAsBigDecimal, targetType); final Date toJavaDate = HSSFDateUtil.getJavaDate(normalizedSerial); return DateUtil.normalizeDate(toJavaDate, targetType, false); } return serial; } else if (targetType.isFlagSet(Type.TEXT_TYPE)) { return convertToText(sourceType, value); } // Unknown type - ignore it, crash later :) return value; } public Type guessTypeOfObject(final Object o) { if (o instanceof Number) { return NumberType.GENERIC_NUMBER; } else if (o instanceof Time) { return DateTimeType.TIME_TYPE; } else if (o instanceof java.sql.Date) { return DateTimeType.DATE_TYPE; } else if (o instanceof Date) { return DateTimeType.DATETIME_TYPE; } else if (o instanceof Boolean) { return LogicalType.TYPE; } else if (o instanceof String) { return TextType.TYPE; } return AnyType.TYPE; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/0000755000175000017500000000000011401240106026606 5ustar renerene././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/AnyNumberSequence.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/AnyNumberSequence.ja0000644000175000017500000000566511401240106032527 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.sequence; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.NumberSequence; /** * A sequence that treats text-values as valid numbers that always evaluate to zero. Logical values * are treated as numbers as well and always evaluate to 0 for false and 1 for true. * * @author Cedric Pronzato */ public class AnyNumberSequence extends AnySequence implements NumberSequence { private static final Number ZERO = new BigDecimal("0"); /** * Empty number sequence. */ public AnyNumberSequence(final FormulaContext context) { super(context); } /** * Number sequence bounded to only one number item. * * @param n A number */ public AnyNumberSequence(final LValue n, final FormulaContext context) { super(n, context); } /** * Number sequence bounded to an array. * * @param array */ public AnyNumberSequence(final ArrayCallback array, final FormulaContext context) { super(array, context); } public AnyNumberSequence(final AnySequence anySequence) { super(anySequence); } protected boolean isValidNext(final LValue o) throws EvaluationException { if (o == null) { return false; } final Type type = o.getValueType(); if (type.isFlagSet(Type.NUMERIC_TYPE)) { return true; } if (type.isFlagSet(Type.LOGICAL_TYPE)) { return true; } if (type.isFlagSet(Type.TEXT_TYPE)) { return true; } if (type.isFlagSet(Type.ANY_TYPE)) { return true; } return false; } public Number nextNumber() throws EvaluationException { final Object value = super.next(); if (value instanceof Number) { return (Number) value; } return ZERO; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/DefaultNumberSequence.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/DefaultNumberSequenc0000644000175000017500000000505111401240106032613 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.sequence; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.NumberSequence; /** * @author Cedric Pronzato */ public class DefaultNumberSequence extends AnySequence implements NumberSequence { /** * Empty number sequence. */ public DefaultNumberSequence(final FormulaContext context) { super(context); } /** * Number sequence bounded to only one number item. * * @param n A number */ public DefaultNumberSequence(final LValue n, final FormulaContext context) { super(n, context); } /** * Number sequence bounded to an array. * * @param array */ public DefaultNumberSequence(final ArrayCallback array, final FormulaContext context) { super(array, context); } public DefaultNumberSequence(final AnySequence anySequence) { super(anySequence); } protected boolean isValidNext(final LValue o) throws EvaluationException { if (o == null) { return false; } final Type type = o.getValueType(); if (type == null) { throw new IllegalStateException(); } if (type.isFlagSet(Type.NUMERIC_TYPE)) { return true; } return false; } public Number nextNumber() throws EvaluationException { final Object value = super.next(); if (value instanceof Number) { return (Number) value; } return null; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/sequence/AnySequence.java0000644000175000017500000001173111401240106031674 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.sequence; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Sequence; /** * @author Cedric Pronzato */ public class AnySequence implements Sequence { private int rowCursor; private int columnCursor; private LValue single; private ArrayCallback array; private FormulaContext context; public AnySequence(final FormulaContext context) { if (context == null) { throw new NullPointerException(); } this.context = context; } public AnySequence(final ArrayCallback array, final FormulaContext context) { if (context == null) { throw new NullPointerException(); } if (array == null) { throw new NullPointerException(); } this.array = array; this.context = context; } public AnySequence(final LValue single, final FormulaContext context) { if (context == null) { throw new NullPointerException(); } if (single == null) { throw new NullPointerException(); } this.single = single; this.context = context; } protected AnySequence(final AnySequence anySequence) { this.single = anySequence.single; this.context = anySequence.context; this.array = anySequence.array; this.rowCursor = anySequence.rowCursor; this.columnCursor = anySequence.columnCursor; } public boolean hasNext() throws EvaluationException { // empty sequence if (single == null && array == null) { return false; } // sequence of one object if (single != null && rowCursor == 0) { return isValidNext(single); } // else array if (array == null) { return false; } final int rowCount = array.getRowCount(); final int columnCount = array.getColumnCount(); if (rowCursor >= rowCount) { return false; } if (columnCursor >= columnCount) { columnCursor = 0; } for (; rowCursor < rowCount; rowCursor++) { for (; columnCursor < columnCount; columnCursor++) { final LValue value = array.getRaw(rowCursor, columnCursor); if (isValidNext(value)) { return true; } } columnCursor = 0; // go to start of the next row } return false; } protected boolean isValidNext(final LValue o) throws EvaluationException { if (o == null) { return false; } return true; } public Object next() throws EvaluationException { if (single != null && rowCursor == 0) { rowCursor++; final TypeValuePair pair = single.evaluate(); return pair.getValue(); } if (array != null) { final Object value = array.getValue(rowCursor, columnCursor); // advance if (columnCursor == array.getColumnCount() - 1) { rowCursor++; columnCursor = 0; } else { columnCursor++; } return value; } return null; } public LValue nextRawValue() throws EvaluationException { if (single != null && rowCursor == 0) { rowCursor++; return new StaticValue(single); } else if (array != null) { final LValue raw = array.getRaw(rowCursor, columnCursor); // advance if (columnCursor == array.getColumnCount() - 1) { rowCursor++; columnCursor = 0; } else { columnCursor++; } return raw; } return null; } protected int getRowCursor() { return rowCursor; } protected int getColumnCursor() { return columnCursor; } protected LValue getSingle() { return single; } protected ArrayCallback getArray() { return array; } protected FormulaContext getContext() { return context; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/0000755000175000017500000000000011401240106027013 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/AnyType.java0000644000175000017500000000327011401240106031251 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ public final class AnyType extends DefaultType { public static final AnyType TYPE; public static final AnyType ANY_ARRAY; public static final AnyType ANY_SEQUENCE; private static final long serialVersionUID = 5871721530497016577L; static { TYPE = new AnyType(); TYPE.addFlag(Type.SCALAR_TYPE); TYPE.lock(); ANY_ARRAY = new AnyType(); ANY_ARRAY.addFlag(Type.ARRAY_TYPE); ANY_ARRAY.lock(); ANY_SEQUENCE = new AnyType(); ANY_SEQUENCE.addFlag(Type.SEQUENCE_TYPE); ANY_SEQUENCE.lock(); } private AnyType() { addFlag(Type.ANY_TYPE); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/LogicalType.java0000644000175000017500000000270311401240106032074 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ //TODO: add scalar type? public final class LogicalType extends DefaultType { public static final LogicalType TYPE = new LogicalType(); private static final long serialVersionUID = -5308030940856879227L; private LogicalType() { addFlag(Type.LOGICAL_TYPE); addFlag(Type.NUMERIC_TYPE); addFlag(Type.SCALAR_TYPE); lock(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/TextType.java0000644000175000017500000000257211401240106031452 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ public final class TextType extends DefaultType { public static final TextType TYPE = new TextType(); private static final long serialVersionUID = 6512540465045391761L; private TextType() { addFlag(Type.TEXT_TYPE); addFlag(Type.SCALAR_TYPE); lock(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/DateTimeType.java0000644000175000017500000000431011401240106032212 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * This class regroups all related Types to date and time values. * * @author Cedric Pronzato */ public class DateTimeType extends DefaultType { /** * This Type represents an instant in time described by a date and a time of * day. */ public static final DateTimeType DATETIME_TYPE; /** * This Type represents an instant in time described by a date only. */ public static final DateTimeType DATE_TYPE; /** * This Type represents an instant in time described by a time of day only. */ public static final DateTimeType TIME_TYPE; private static final long serialVersionUID = -9003249643428553897L; static { DATE_TYPE = new DateTimeType(); DATE_TYPE.addFlag(Type.DATE_TYPE); DATE_TYPE.addFlag(Type.NUMERIC_TYPE); DATE_TYPE.lock(); TIME_TYPE = new DateTimeType(); TIME_TYPE.addFlag(Type.TIME_TYPE); TIME_TYPE.addFlag(Type.NUMERIC_TYPE); TIME_TYPE.lock(); DATETIME_TYPE = new DateTimeType(); DATETIME_TYPE.addFlag(Type.DATETIME_TYPE); DATETIME_TYPE.addFlag(Type.NUMERIC_TYPE); DATETIME_TYPE.lock(); } protected DateTimeType() { addFlag(Type.NUMERIC_TYPE); addFlag(Type.SCALAR_TYPE); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/NumberType.java0000644000175000017500000000354411401240106031756 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ public class NumberType extends DefaultType { public static final NumberType GENERIC_NUMBER; public static final NumberType GENERIC_NUMBER_ARRAY; public static final NumberType NUMBER_SEQUENCE; private static final long serialVersionUID = 2070930250111567639L; static { GENERIC_NUMBER = new NumberType(); GENERIC_NUMBER.addFlag(Type.SCALAR_TYPE); GENERIC_NUMBER.lock(); GENERIC_NUMBER_ARRAY = new NumberType(); GENERIC_NUMBER_ARRAY.addFlag(Type.ARRAY_TYPE); GENERIC_NUMBER_ARRAY.lock(); NUMBER_SEQUENCE = new NumberType(); NUMBER_SEQUENCE.addFlag(Type.SEQUENCE_TYPE); NUMBER_SEQUENCE.addFlag(Type.NUMERIC_SEQUENCE_TYPE); NUMBER_SEQUENCE.lock(); } public NumberType() { addFlag(Type.NUMERIC_TYPE); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/coretypes/ErrorType.java0000644000175000017500000000261611401240106031616 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing.coretypes; import org.pentaho.reporting.libraries.formula.typing.DefaultType; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ //add scalar flag? public final class ErrorType extends DefaultType { public static final Type TYPE = new ErrorType(); private static final long serialVersionUID = -5893173280337804811L; private ErrorType() { addFlag(Type.ERROR_TYPE); addFlag(Type.SCALAR_TYPE); lock(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/Type.java0000644000175000017500000000357511401240106026574 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.io.Serializable; /** * Creation-Date: 02.11.2006, 09:32:21 * * @author Thomas Morgner */ public interface Type extends Serializable { public static final String NUMERIC_UNIT = "unit.numeric"; public static final String NUMERIC_TYPE = "type.numeric"; public static final String TEXT_TYPE = "type.text"; public static final String LOGICAL_TYPE = "type.logical"; public static final String SCALAR_TYPE = "type.scalar"; public static final String ANY_TYPE = "type.any"; public static final String ERROR_TYPE = "type.error"; public static final String DATE_TYPE = "type.date"; public static final String TIME_TYPE = "type.time"; public static final String DATETIME_TYPE = "type.datetime"; public static final String ARRAY_TYPE = "type.array"; public static final String SEQUENCE_TYPE = "type.sequence"; public static final String NUMERIC_SEQUENCE_TYPE = "type.numeric.sequence"; public boolean isFlagSet (String name); public Object getProperty (String name); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/ExtendedComparator.java0000644000175000017500000000331511401240106031433 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * A comparator, that offers type support. Unlike the plain Java-Comparator, * this class is able to compare * * @author Thomas Morgner */ public interface ExtendedComparator { public boolean isEqual(final Type type1, final Object value1, final Type type2, final Object value2); /** * Returns null, if the types are not comparable and are not convertible at * all. * * @param type1 * @param value1 * @param type2 * @param value2 * @return */ public int compare(final Type type1, final Object value1, final Type type2, final Object value2) throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/TypeRegistry.java0000644000175000017500000000745511401240106030326 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.util.Date; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.NumberSequence; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * The type registry manages the known value types. * * @author Thomas Morgner */ public interface TypeRegistry { /** * Returns an comparator for the given types. * * @param type1 * @param type2 * @return */ public ExtendedComparator getComparator(Type type1, Type type2); /** * Converts the object of the given type into a number. If the object is not convertible, a NumberFormatException is * thrown. (This conversion is used by the operator implementations.) * * @param type1 * @param value * @return the value as number or ZERO if the value is unconvertible. * @throws TypeConversionException if the type cannot be represented as number. */ public Number convertToNumber(Type type1, Object value) throws EvaluationException; /** * (This conversion is used by the operator implementations.) * * @param type1 * @param value * @return the value as string or an empty string, if the value given is null. * @throws TypeConversionException */ public String convertToText(Type type1, Object value) throws EvaluationException; /** * Converts the object of the given type into a boolean. * * @param type1 * @param value * @return The value as Boolean or null. */ public Boolean convertToLogical(Type type1, Object value) throws EvaluationException; /** * Converts the object of the given type into a date. * * @param type1 * @param value * @return The value as Date or null. */ public Date convertToDate(Type type1, Object value) throws EvaluationException; /** * Converts the given (type,value) pair into a numeric sequence. If the flag "strictTypeChecks" is set to true, the * value sequence will only evaluate numeric values. A non-strict sequence will treat text as zero and logical values * as 0 or 1. * * @param type * @param value * @param strictTypeChecks * @return * @throws TypeConversionException */ public NumberSequence convertToNumberSequence(final Type type, final Object value, final boolean strictTypeChecks) throws EvaluationException; public Sequence convertToSequence(final Type type, final Object value) throws EvaluationException; public ArrayCallback convertToArray(final Type type, final Object value) throws EvaluationException; /** * Checks whether the target type would accept the specified value object and value type. (This conversion is used by * the functions.) * * @param targetType * @param valuePair */ public TypeValuePair convertTo(final Type targetType, final TypeValuePair valuePair) throws EvaluationException; public Type guessTypeOfObject(Object o); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/DefaultType.java0000644000175000017500000000430111401240106030065 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.util.HashMap; import java.util.HashSet; /** * Creation-Date: 02.11.2006, 09:37:54 * * @author Thomas Morgner */ public abstract class DefaultType implements Type { private HashSet flags; private HashMap properties; private boolean locked; private static final long serialVersionUID = -8206983276033867416L; protected DefaultType() { } public boolean isLocked() { return locked; } public void lock() { this.locked = true; } public void addFlag(final String name) { if (locked) { throw new IllegalStateException(); } if (flags == null) { flags = new HashSet(); } flags.add(name); } public boolean isFlagSet(final String name) { if (flags == null) { return false; } return flags.contains(name); } public void setProperty(final String name, final Object value) { if (locked) { throw new IllegalStateException(); } if (properties == null) { properties = new HashMap(); } properties.put(name, value); } public Object getProperty(final String name) { // The type system has no properties yet. This is done later, when we // deal with real meta-data if (properties == null) { return null; } return properties.get(name); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/NumberConverter.java0000644000175000017500000000211611401240106030761 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; /** * A class that converts arbitary data into a numeric representation. * * @author Thomas Morgner */ public interface NumberConverter { public Number toNumber (Type t1, Object o1); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/NumberSequence.java0000644000175000017500000000223511401240106030564 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * Todo: Document Me * * @author Thomas Morgner */ public interface NumberSequence extends Sequence { Number nextNumber() throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/typing/DefaultComparator.java0000644000175000017500000001553611401240106031267 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.math.BigDecimal; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Creation-Date: 03.11.2006, 16:15:28 * * @author Thomas Morgner */ public class DefaultComparator implements ExtendedComparator { private FormulaContext context; private static final int LESS = -1; private static final int EQUAL = 0; private static final int MORE = 1; public DefaultComparator() { } public void inititalize(final FormulaContext context) { if (context == null) { throw new NullPointerException(); } this.context = context; } public boolean isEqual(final Type type1, final Object value1, final Type type2, final Object value2) { // this is rather easy. If at least one of the types is a numeric, // try to compare them as numbers. (And here it gets messy.) if (ObjectUtilities.equal(value1, value2)) { return true; } final TypeRegistry typeRegistry = context.getTypeRegistry(); if (type1.isFlagSet(Type.NUMERIC_TYPE) || type2.isFlagSet(Type.NUMERIC_TYPE)) { try { final Number number1 = typeRegistry.convertToNumber(type1, value1); final Number number2 = typeRegistry.convertToNumber(type2, value2); final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); if (bd1.signum() != bd2.signum()) { return false; } return bd1.compareTo(bd2) == 0; } catch (EvaluationException nfe) { // ignore .. } } if (type1.isFlagSet(Type.TEXT_TYPE) || type2.isFlagSet(Type.TEXT_TYPE)) { String text1 = null; String text2 = null; try { // Convert both values to text .. text1 = typeRegistry.convertToText(type1, value1); text2 = typeRegistry.convertToText(type2, value2); } catch (EvaluationException nfe) { // ignore .. } if (text1 == null && text2 == null) { return true; } if (text1 == null || text2 == null) { return false; } return ObjectUtilities.equal(text1, text2); } // Fall back to Java's equals method and hope the best .. return (ObjectUtilities.equal(value1, value2)); } /** * Returns null, if the types are not comparable and are not convertible at * all. * * @param type1 * @param value1 * @param type2 * @param value2 * @return */ public int compare(final Type type1, final Object value1, final Type type2, final Object value2) { // this is rather easy. If at least one of the types is a numeric, // try to compare them as numbers. (And here it gets messy.) if (value1 == null && value2 == null) { return DefaultComparator.EQUAL; } if (value1 == null) { return DefaultComparator.LESS; } if (value2 == null) { return DefaultComparator.MORE; } // First, we try to compare both types directly. This is the least-expensive // solution, as it does // not include any conversion operations .. if (type1.isFlagSet(Type.SCALAR_TYPE) && type2.isFlagSet(Type.SCALAR_TYPE)) { // this is something else if (value1 instanceof Comparable && value2 instanceof Comparable) { final Comparable c1 = (Comparable) value1; try { final int result = c1.compareTo(value2); if (result == 0) { return DefaultComparator.EQUAL; } else if (result > 0) { return DefaultComparator.MORE; } else { return DefaultComparator.LESS; } } catch (Exception e) { // ignore any exception .. } } } // Next, we check the types on a numeric level. final TypeRegistry typeRegistry = context.getTypeRegistry(); if (type1.isFlagSet(Type.NUMERIC_TYPE) || type2.isFlagSet(Type.NUMERIC_TYPE)) { try { final Number number1 = typeRegistry.convertToNumber(type1, value1); final Number number2 = typeRegistry.convertToNumber(type2, value2); final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); if (bd1.signum() != bd2.signum()) { if (bd1.signum() < 0) { return DefaultComparator.LESS; } else if (bd1.signum() > 0) { return DefaultComparator.MORE; } } final int result = bd1.compareTo(bd2); if (result == 0) { return DefaultComparator.EQUAL; } if (result > 0) { return DefaultComparator.MORE; } return DefaultComparator.LESS; } catch (EvaluationException nfe) { // Ignore .. } } // And finally convert them to text and compare the text values .. // Convert both values to text .. String text1 = null; String text2 = null; try { text1 = typeRegistry.convertToText(type1, value1); text2 = typeRegistry.convertToText(type2, value2); } catch (EvaluationException e) { // failure here can be ignored. } if (text1 == null && text2 == null) { return DefaultComparator.EQUAL; } if (text1 == null) { return DefaultComparator.LESS; } if (text2 == null) { return DefaultComparator.MORE; } final int result = text1.compareTo(text2); if (result == 0) { return DefaultComparator.EQUAL; } else if (result > 0) { return DefaultComparator.MORE; } else { return DefaultComparator.LESS; } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/0000755000175000017500000000000011401240110024434 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/DateUtil.java0000644000175000017500000001356311401240110027022 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.util; import java.math.BigDecimal; import java.sql.Time; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.typing.Type; /** * @author Cedric Pronzato */ public class DateUtil { private static final Date ISO8001_TIME = new GregorianCalendar().getTime(); private DateUtil() { } /** * Converts a Date value according to the requested Type to the proper Date * subclasses (java.sql.Time, java.sql.Date) if needed. If the requested type is unknown, no * conversion takes place and the input date is returned. * * @param fromDate The date to convert. * @param toType The requested type of date. * @return The converted date. */ public static Date normalizeDate(final Date fromDate, final Type toType) { return normalizeDate(fromDate, toType, true); } public static Date normalizeDate(Date fromDate, final Type toType, final boolean convertSerial) { if (fromDate == null) { throw new IllegalArgumentException(); } if (toType == null) { throw new IllegalArgumentException(); } if (convertSerial) { BigDecimal serial = HSSFDateUtil.getExcelDate(fromDate); serial = normalizeDate(serial, toType); fromDate = HSSFDateUtil.getJavaDate(serial); } // final GregorianCalendar gc = new GregorianCalendar(); // gc.setTime(fromDate); // gc.set(GregorianCalendar.MILLISECOND, 0); // fromDate = gc.getTime(); if (toType.isFlagSet(Type.TIME_TYPE)) { return new Time(fromDate.getTime()); } else if (toType.isFlagSet(Type.DATE_TYPE)) { return new java.sql.Date(fromDate.getTime()); } else if (toType.isFlagSet(Type.DATETIME_TYPE)) { return new Date(fromDate.getTime()); } return fromDate; } public static BigDecimal normalizeDate(final BigDecimal fromSerialDate, final Type toType) { if (fromSerialDate == null) { throw new IllegalArgumentException(); } if (toType == null) { throw new IllegalArgumentException(); } if (toType.isFlagSet(Type.TIME_TYPE)) { final BigDecimal o = fromSerialDate.setScale(LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_UP); return o.subtract(new BigDecimal(o.intValue())); // only return the decimal part // final Double d = new Double(fromSerialDate.doubleValue() // - fromSerialDate.intValue()); // return d; } else if (toType.isFlagSet(Type.DATE_TYPE)) { return NumberUtil.performIntRounding(fromSerialDate); } else { // else it must be date-time, so return it unchanged .. return fromSerialDate; } } public static Date now(final LocalizationContext context) { final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(), context.getLocale()); gc.set(Calendar.MILLISECOND, 0); return gc.getTime(); } public static Date createDateTime(final int year, final int month, final int day, final int hour, final int minute, final int second, final LocalizationContext context) { final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(), context.getLocale()); gc.set(Calendar.DAY_OF_MONTH, day); gc.set(Calendar.MONTH, month); gc.set(Calendar.YEAR, year); gc.set(Calendar.MILLISECOND, 0); gc.set(Calendar.HOUR_OF_DAY, hour); gc.set(Calendar.MINUTE, minute); gc.set(Calendar.SECOND, second); return gc.getTime(); } public static Time createTime(final int hour, final int minute, final int second, final LocalizationContext context) { final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(), context.getLocale()); gc.setTime(ISO8001_TIME); gc.set(Calendar.MILLISECOND, 0); gc.set(Calendar.HOUR_OF_DAY, hour); gc.set(Calendar.MINUTE, minute); gc.set(Calendar.SECOND, second); return new Time(gc.getTime().getTime()); } public static java.sql.Date createDate(final int year, final int month, final int day, final LocalizationContext context) { final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(), context.getLocale()); gc.set(Calendar.DAY_OF_MONTH, day); gc.set(Calendar.MONTH, month - 1); gc.set(Calendar.YEAR, year); gc.set(Calendar.MILLISECOND, 0); gc.set(Calendar.HOUR_OF_DAY, 0); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); return new java.sql.Date(gc.getTime().getTime()); } public static Calendar createCalendar(final Date date, final LocalizationContext context) { final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(), context.getLocale()); gc.setTime(date); return gc; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/URLEncoder.java0000644000175000017500000001446011401240110027246 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.util; import java.io.UnsupportedEncodingException; /** * Creation-Date: Jan 22, 2007, 4:36:38 PM * * @author Thomas Morgner */ public class URLEncoder { private URLEncoder() { } private static final String[] hex = { "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27", "%28", "%29", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F", "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37", "%38", "%39", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F", "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47", "%48", "%49", "%4A", "%4B", "%4C", "%4D", "%4E", "%4F", "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57", "%58", "%59", "%5A", "%5B", "%5C", "%5D", "%5E", "%5F", "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67", "%68", "%69", "%6A", "%6B", "%6C", "%6D", "%6E", "%6F", "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77", "%78", "%79", "%7A", "%7B", "%7C", "%7D", "%7E", "%7F", "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F", "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F", "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7", "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF", "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7", "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF", "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7", "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF", "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7", "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF", "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7", "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF", "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7", "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF" }; /** * Encode a string according to RFC 1738. *

* "...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not * including the quotes - ed], and reserved characters used for their reserved purposes * may be used unencoded within a URL." *

*

  • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through * '9' remain the same. *

    *

  • The unreserved characters - _ . ! ~ * ' ( ) remain the same. *

    *

  • All other ASCII characters are converted into the 3-character string "%xy", * where xy is the two-digit hexadecimal representation of the character code *

    *

  • All non-ASCII characters are encoded in two steps: first to a sequence of 2 or * 3 bytes, using the UTF-8 algorithm; secondly each of these bytes is encoded as "%xx". *

* * @param s The string to be encoded * @return The encoded string */ public static String encodeUTF8 (final String s) { final StringBuffer sbuf = new StringBuffer(s.length()); final char[] sChars = s.toCharArray(); final int len = sChars.length; for (int i = 0; i < len; i++) { final int ch = sChars[i]; if ('A' <= ch && ch <= 'Z') { // 'A'..'Z' sbuf.append((char) ch); } else if ('a' <= ch && ch <= 'z') { // 'a'..'z' sbuf.append((char) ch); } else if ('0' <= ch && ch <= '9') { // '0'..'9' sbuf.append((char) ch); } else if (ch == '-' || ch == '_' // unreserved || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')') { sbuf.append((char) ch); } else if (ch <= 0x007f) { // other ASCII sbuf.append(hex[ch]); } else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF sbuf.append(hex[0xc0 | (ch >> 6)]); sbuf.append(hex[0x80 | (ch & 0x3F)]); } else { // 0x7FF < ch <= 0xFFFF sbuf.append(hex[0xe0 | (ch >> 12)]); sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]); sbuf.append(hex[0x80 | (ch & 0x3F)]); } } return sbuf.toString(); } private static String encodeBytes (final byte[] s) { final StringBuffer sbuf = new StringBuffer(s.length); final int len = s.length; for (int i = 0; i < len; i++) { final int ch = (s[i] & 0xff); if ('A' <= ch && ch <= 'Z') { // 'A'..'Z' sbuf.append((char) ch); } else if ('a' <= ch && ch <= 'z') { // 'a'..'z' sbuf.append((char) ch); } else if ('0' <= ch && ch <= '9') { // '0'..'9' sbuf.append((char) ch); } else if (ch == '-' || ch == '_' // unreserved || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')') { sbuf.append((char) ch); } else { // other ASCII sbuf.append(hex[ch]); } } return sbuf.toString(); } public static String encode (final String s, final String encoding) throws UnsupportedEncodingException { if ("utf-8".equalsIgnoreCase(encoding)) { return encodeUTF8(s); } return encodeBytes(s.getBytes(encoding)); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/FormulaUtil.java0000644000175000017500000000574711401240110027557 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.util; import org.pentaho.reporting.libraries.formula.Formula; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.Term; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.parser.ParseException; import org.pentaho.reporting.libraries.base.util.LinkedMap; /** * Todo: Document me! *

* Date: 15.04.2009 * Time: 16:23:02 * * @author Thomas Morgner. */ public class FormulaUtil { private FormulaUtil() { } public static Object[] getReferences(final String formula) throws ParseException { final String formulaExpression; if (formula.length() > 0 && formula.charAt(0) == '=') { // formulaNamespace = "report"; formulaExpression = formula.substring(1); } else { final int separator = formula.indexOf(':'); if (separator <= 0 || ((separator + 1) == formula.length())) { // error: invalid formula. // formulaNamespace = null; formulaExpression = null; } else { // formulaNamespace = formula.substring(0, separator); formulaExpression = formula.substring(separator + 1); } } if (formulaExpression == null) { throw new ParseException("Formula is invalid"); } return getReferences(new Formula(formulaExpression)); } public static Object[] getReferences(final Formula formula) { final LinkedMap map = new LinkedMap(); final LValue lValue = formula.getRootReference(); collectReferences(lValue, map); return map.keys(); } private static void collectReferences(final LValue lval, final LinkedMap map) { if (lval instanceof Term) { final Term t = (Term) lval; final LValue[] childValues = t.getChildValues(); for (int i = 0; i < childValues.length; i++) { final LValue childValue = childValues[i]; collectReferences(childValue, map); } } else if (lval instanceof ContextLookup) { final ContextLookup cl = (ContextLookup) lval; map.put(cl.getName(), Boolean.TRUE); } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/NumberUtil.java0000644000175000017500000001001411401240110027361 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.util; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; public class NumberUtil { public static final BigDecimal DELTA = new BigDecimal("0.000000000000000000000000000000000000005"); public static final BigDecimal INT_TEST_DELTA = new BigDecimal("0.00000000000000000000000000000000005"); private static final int ROUND_SCALE = LibFormulaBoot.GLOBAL_SCALE - 6; private NumberUtil() { } public static BigDecimal getAsBigDecimal(final Number number) { if (number == null) { throw new NullPointerException(); } if(number instanceof BigDecimal) { return (BigDecimal)number; } else { return new BigDecimal(number.toString()); } } /** * Performs a rounding to get a more reliable (int) cast. This makes sure that nearly exact values like * 0.9999999..9999 are correctly interpreted as 1 while exact values like 0.99 are interpreted as 0. * * @param n * @return */ public static BigDecimal performIntRounding(BigDecimal n) { try { // no need to go further if the value is already an integer return n.setScale(0); } catch(ArithmeticException e) { //ignore and continue } final BigDecimal round; if(n.signum()<0) { n = n.subtract(DELTA); round = n.setScale(0, BigDecimal.ROUND_UP); } else { n = n.add(DELTA); round = n.setScale(1, BigDecimal.ROUND_DOWN); } return new BigDecimal(round.intValue()); } public static BigDecimal performTuneRounding(BigDecimal n) { try { // no need to go further if the value is already an integer n.setScale(ROUND_SCALE); return n; } catch(ArithmeticException e) { //ignore and continue } final BigDecimal round; if(n.signum()<0) { n = n.subtract(INT_TEST_DELTA); round = n.setScale(ROUND_SCALE, BigDecimal.ROUND_UP); } else { n = n.add(INT_TEST_DELTA); round = n.setScale(ROUND_SCALE, BigDecimal.ROUND_DOWN); } if (n.compareTo(round) == 0) { return n; } return NumberUtil.removeTrailingZeros(round); } public static BigDecimal removeTrailingZeros(final BigDecimal bd) { if(bd.signum() == 0) { return bd.setScale(0); } final String text = bd.toString(); int scale = bd.scale(); for (int i = text.length() - 1; i >= 0; i--) { final char c = text.charAt(i); if (c != '0') { break; } scale -= 1; } return bd.setScale(scale); } public static BigDecimal divide(final BigDecimal bd1, final BigDecimal bd2) throws EvaluationException { if (bd2.signum() == 0) { // prevent a division by zero .. throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE); } final BigDecimal divide = bd1.divide(bd2, LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_HALF_UP); return NumberUtil.removeTrailingZeros(divide); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/util/HSSFDateUtil.java0000644000175000017500000001525311401240110027504 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.util; import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; /** * Contains methods for dealing with Excel dates.
Modified by Cedric Pronzato * * @author Michael Harhen * @author Glen Stampoultzis (glens at apache.org) * @author Dan Sherman (dsherman at isisph.com) * @author Hack Kampbjorn (hak at 2mba.dk) */ public class HSSFDateUtil { private static final BigDecimal DAY_MILLISECONDS = new BigDecimal(24 * 60 * 60 * 1000); private static final int DAYS_TO_1900 = daysInPriorYears(1900 - 1) + 1; private HSSFDateUtil() { } public static int computeZeroDate(final String config, final boolean excelBugCompatible) { if ("1899".equals(config)) { return 2; } if ("1900".equals(config)) { return 0; } if (excelBugCompatible) { // 1900 is a leap year for excel return -(4 * 365 + 1); } else { // 1900 is no leap year for everyone else. return -(4 * 365); } } public static BigDecimal getExcelDate(final Date date) { final String dateSystem = LibFormulaBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.libraries.formula.ZeroDate", "1900"); final boolean excelBugCompatible = "true".equals(LibFormulaBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.libraries.formula.ExcelDateBugAware", "false")); return getExcelDate(date, excelBugCompatible, computeZeroDate(dateSystem, excelBugCompatible)); } public static BigDecimal getExcelDate(final Date date, final boolean excelBugCompatible, final int zeroDate) { final Calendar calStart = new GregorianCalendar(); calStart.setTime(date); // Because of daylight time saving we cannot use // date.getTime() - calStart.getTimeInMillis() // as the difference in milliseconds between 00:00 and 04:00 // can be 3, 4 or 5 hours but Excel expects it to always // be 4 hours. // E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours // and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours long time = calStart.get(Calendar.HOUR_OF_DAY); time = (time * 60) + calStart.get(Calendar.MINUTE); time = (time * 60) + calStart.get(Calendar.SECOND); time = (time * 1000) + calStart.get(Calendar.MILLISECOND); // scale of 15 should be enough to cover a millisecond final BigDecimal fraction = new BigDecimal(time).divide (DAY_MILLISECONDS, LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_HALF_UP); final int year = calStart.get(Calendar.YEAR); int daysInYear = calStart.get(Calendar.DAY_OF_YEAR); if (excelBugCompatible) { if (zeroDate > 59) { // if we handle dates which are before the 1.3.1900, we have to take the invalid // leap-year computation into account. if (year < 1900 || (year == 1900 && daysInYear > 59)) { daysInYear += 1; } } else if (year > 1900 || (year == 1900 && daysInYear > 59)) { // excel firmly believes that the 29th February 1900 exists. daysInYear += 1; } } final int daysStart = daysInPriorYears(year - 1) - DAYS_TO_1900; final int daysSinceYear = daysInYear + daysStart; return fraction.add(new BigDecimal(daysSinceYear + zeroDate)); } /** * Return the number of days in the years from 0 AD to December 31th of the given year. * * @param y a year * @return days number of days in years prior to yr. * @throws IllegalArgumentException if year is outside of range. */ private static int daysInPriorYears(final int y) { return 365 * y // days in prior years + y / 4 // plus julian leap days in prior years - y / 100 // minus prior century years + y / 400; } /** * Given a excel date, converts it into a Date. Assumes 1900 date windowing. * * @param date the Excel Date * @return Java representation of a date (null if error) */ public static Date getJavaDate(final BigDecimal date) { final String dateSystem = LibFormulaBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.libraries.formula.ZeroDate", "1900"); final boolean excelBugCompatible = "true".equals(LibFormulaBoot.getInstance().getGlobalConfig().getConfigProperty ("org.pentaho.reporting.libraries.formula.ExcelDateBugAware", "false")); return getJavaDate(date, excelBugCompatible, computeZeroDate(dateSystem, excelBugCompatible)); } public static Date getJavaDate(final BigDecimal date, final boolean excelBugCompatible, final int zeroDate) { int correction = 1; final BigDecimal wholeDays = NumberUtil.performIntRounding(date); final int wholeDaysInt = wholeDays.intValue() - zeroDate; if (excelBugCompatible) { // if we deal with a date that is after the 28th februar, adjust the date by one to handle the fact // that excel thinks the 29th February 1900 exists. // by tuning this variable, we map the int-value for the 29th to the next day. if (wholeDaysInt > 59) { correction = 0; } } final BigDecimal fractionNum = date.subtract(wholeDays); final BigDecimal fraction = fractionNum.multiply(DAY_MILLISECONDS); // the use of the calendar could be probably removed, as there is no magic in converting // a running number into a date. final GregorianCalendar calendar = new GregorianCalendar(1900, 0, wholeDaysInt + correction); calendar.set(Calendar.MILLISECOND, fraction.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); return calendar.getTime(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/DefaultLocalizationContext.java0000644000175000017500000001500211401240110031622 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.text.SimpleDateFormat; import java.text.DateFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.TimeZone; import java.util.StringTokenizer; import java.util.Collections; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.base.config.Configuration; /** * Creation-Date: 03.11.2006, 14:28:12 * * @author Thomas Morgner */ public class DefaultLocalizationContext implements LocalizationContext, Serializable { private static final String CONFIG_TIMEZONE_KEY = "org.pentaho.reporting.libraries.formula.timezone"; private static final String CONFIG_LOCALE_KEY = "org.pentaho.reporting.libraries.formula.locale"; private static final String CONFIG_DATEFORMAT_KEY = "org.pentaho.reporting.libraries.formula.dateformat."; private ArrayList dateFormats; private ArrayList datetimeFormats; private ArrayList timeFormats; private Locale locale; private TimeZone timeZone; public DefaultLocalizationContext() { dateFormats = new ArrayList(); datetimeFormats = new ArrayList(); timeFormats = new ArrayList(); } public Locale getLocale() { return locale; } public ResourceBundle getBundle(final String id) { return ResourceBundle.getBundle(id, getLocale()); } public TimeZone getTimeZone() { return timeZone; } public List getDateFormats(final Type type) { if (type.isFlagSet(Type.DATE_TYPE)) { return (List) dateFormats.clone(); } else if (type.isFlagSet(Type.DATETIME_TYPE)) { return (List) datetimeFormats.clone(); } else if (type.isFlagSet(Type.TIME_TYPE)) { return (List) timeFormats.clone(); } return Collections.EMPTY_LIST; } private String[] createLocale(final String locale) { final StringTokenizer strtok = new StringTokenizer(locale, "_"); final String[] retval = new String[3]; if (strtok.hasMoreElements()) { retval[0] = strtok.nextToken(); } else { retval[0] = ""; } if (strtok.hasMoreElements()) { retval[1] = strtok.nextToken(); } else { retval[1] = ""; } if (strtok.hasMoreElements()) { retval[2] = strtok.nextToken(); } else { retval[2] = ""; } return retval; } public void initialize(final Configuration config) { initialize(config, null, null); } public void initialize(final Configuration config, final Locale locale, final TimeZone timeZone) { if (config == null) { throw new NullPointerException(); } if (locale == null) { // setting locale final String declaredLocale = config.getConfigProperty(CONFIG_LOCALE_KEY, Locale.getDefault().toString()); final String[] declaredLocaleParts = createLocale(declaredLocale); this.locale = new Locale(declaredLocaleParts[0], declaredLocaleParts[1], declaredLocaleParts[2]); } else { this.locale = locale; } //setting timezone if (timeZone == null) { final String timeZoneId = config.getConfigProperty(CONFIG_TIMEZONE_KEY, TimeZone.getDefault().getID()); this.timeZone = TimeZone.getTimeZone(timeZoneId); } else { this.timeZone = TimeZone.getDefault(); } final Locale activeLocale = getLocale(); datetimeFormats.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, activeLocale)); dateFormats.add(DateFormat.getDateInstance(DateFormat.FULL, activeLocale)); timeFormats.add(DateFormat.getTimeInstance(DateFormat.FULL, activeLocale)); datetimeFormats.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, activeLocale)); dateFormats.add(DateFormat.getDateInstance(DateFormat.LONG, activeLocale)); timeFormats.add(DateFormat.getTimeInstance(DateFormat.LONG, activeLocale)); datetimeFormats.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, activeLocale)); dateFormats.add(DateFormat.getDateInstance(DateFormat.MEDIUM, activeLocale)); timeFormats.add(DateFormat.getTimeInstance(DateFormat.MEDIUM, activeLocale)); datetimeFormats.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, activeLocale)); dateFormats.add(DateFormat.getDateInstance(DateFormat.SHORT, activeLocale)); timeFormats.add(DateFormat.getTimeInstance(DateFormat.SHORT, activeLocale)); // adding default dateformats using current local datetimeFormats.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, activeLocale)); dateFormats.add(DateFormat.getDateInstance(DateFormat.SHORT, activeLocale)); timeFormats.add(DateFormat.getTimeInstance(DateFormat.SHORT, activeLocale)); // adding default ISO8 dateformats datetimeFormats.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)); datetimeFormats.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US)); dateFormats.add(new SimpleDateFormat("yyyy-MM-dd", Locale.US)); timeFormats.add(new SimpleDateFormat("HH:mm:ss", Locale.US)); timeFormats.add(new SimpleDateFormat("HH:mm", Locale.US)); for (int i = 0; i < dateFormats.size(); i++) { final DateFormat dateFormat = (DateFormat) dateFormats.get(i); dateFormat.setLenient(false); } for (int i = 0; i < datetimeFormats.size(); i++) { final DateFormat dateFormat = (DateFormat) datetimeFormats.get(i); dateFormat.setLenient(false); } for (int i = 0; i < timeFormats.size(); i++) { final DateFormat dateFormat = (DateFormat) timeFormats.get(i); dateFormat.setLenient(false); } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/0000755000175000017500000000000011401240110025475 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/PrefixOperator.java0000644000175000017500000000262511401240110031316 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * Creation-Date: 02.11.2006, 10:17:03 * * @author Thomas Morgner */ public interface PrefixOperator extends Serializable { public TypeValuePair evaluate(final FormulaContext context, TypeValuePair value1) throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/ConcatOperator.java0000644000175000017500000000635611401240110031275 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Concats two strings operator. * * @author Thomas Morgner */ public class ConcatOperator implements InfixOperator { private static final long serialVersionUID = 6579968694761281257L; public ConcatOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1, final TypeValuePair value2) throws EvaluationException { final TypeRegistry typeRegistry = context.getTypeRegistry(); // Error or empty string, that's the question .. final Object raw1 = value1.getValue(); final Object raw2 = value2.getValue(); if (raw1 == null || raw2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final String text1 = typeRegistry.convertToText(value1.getType(), raw1); final String text2 = typeRegistry.convertToText(value2.getType(), raw2); if (text1 == null && text2 == null) { throw EvaluationException.getInstance (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (text1 == null) { return new TypeValuePair(TextType.TYPE, text2); } if (text2 == null) { return new TypeValuePair(TextType.TYPE, text1); } return new TypeValuePair(TextType.TYPE, text1 + text2); } public int getLevel() { return 300; } public String toString() { return "&"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/PercentageOperator.java0000644000175000017500000000534611401240110032141 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import java.math.BigDecimal; /** * Creation-Date: 02.11.2006, 10:27:03 * * @author Thomas Morgner */ public class PercentageOperator implements PostfixOperator { private static final BigDecimal HUNDRED = new BigDecimal(100.0); private static final long serialVersionUID = -5578115447971169716L; public PercentageOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1) throws EvaluationException { final Object rawValue = value1.getValue(); if (rawValue == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final Type type = value1.getType(); final TypeRegistry typeRegistry = context.getTypeRegistry(); if (type.isFlagSet(Type.NUMERIC_TYPE) == false && type.isFlagSet(Type.ANY_TYPE) == false) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // return the same as zero minus value. final Number number = typeRegistry.convertToNumber(type, rawValue); final BigDecimal value = NumberUtil.getAsBigDecimal(number); final BigDecimal percentage = NumberUtil.divide(value, HUNDRED); return new TypeValuePair(NumberType.GENERIC_NUMBER, percentage); } public String toString() { return "%"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/SubtractOperator.java0000644000175000017500000000462111401240110031646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class SubtractOperator extends AbstractNumericOperator { private static final long serialVersionUID = -3455847702508382227L; public SubtractOperator() { } protected Number evaluate(final Number number1, final Number number2) throws EvaluationException { if ((number1 instanceof Integer || number1 instanceof Short) && (number2 instanceof Integer || number2 instanceof Short)) { return new BigDecimal (number1.longValue() - number2.longValue()); } final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); return bd1.subtract(bd2); } public int getLevel() { return 200; } public String toString() { return "-"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/MultiplyOperator.java0000644000175000017500000000465511401240110031705 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class MultiplyOperator extends AbstractNumericOperator { private static final long serialVersionUID = 4121666193537297373L; public MultiplyOperator() { } protected Number evaluate(final Number number1, final Number number2) throws EvaluationException { if ((number1 instanceof Integer || number1 instanceof Short) && (number2 instanceof Integer || number2 instanceof Short)) { // this is still safe .. return new BigDecimal(number1.longValue() * number2.longValue()); } final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); return bd1.multiply(bd2); } public int getLevel() { return 100; } public String toString() { return "*"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/EqualOperator.java0000644000175000017500000000653711401240110031136 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.typing.ExtendedComparator; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class EqualOperator implements InfixOperator { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 2865411431720931171L; public EqualOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1, final TypeValuePair value2) throws EvaluationException { final TypeRegistry typeRegistry = context.getTypeRegistry(); final Object value1Raw = value1.getValue(); final Object value2Raw = value2.getValue(); if (value1Raw == null || value2Raw == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final Type type1 = value1.getType(); final Type type2 = value2.getType(); final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2); final boolean result = comparator.isEqual (type1, value1Raw, type2, value2Raw); if (result) { return RETURN_TRUE; } else { return RETURN_FALSE; } } public int getLevel() { return 400; } public String toString() { return "="; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/DivideOperator.java0000644000175000017500000000433011401240110031260 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * A division operation. This operation expects two valid numbers. * * * @author Thomas Morgner */ public class DivideOperator extends AbstractNumericOperator { private static final long serialVersionUID = 3298154333839229191L; public DivideOperator() { } public Number evaluate(final Number number1, final Number number2) throws EvaluationException { final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); return NumberUtil.divide(bd1, bd2); } public int getLevel() { return 100; } public String toString() { return "/"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/AbstractNumericOperator.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/AbstractNumericOperator.ja0000644000175000017500000000640711401240110032622 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Creation-Date: 10.04.2007, 15:02:39 * * @author Thomas Morgner */ public abstract class AbstractNumericOperator implements InfixOperator { protected static final Number ZERO = new BigDecimal(0.0); private static final long serialVersionUID = -1087959445157130705L; protected AbstractNumericOperator() { } public final TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1, final TypeValuePair value2) throws EvaluationException { final TypeRegistry typeRegistry = context.getTypeRegistry(); if (value1 == null || value2 == null) { // If this happens, then one of the implementations has messed up. throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } final Object raw1 = value1.getValue(); final Object raw2 = value2.getValue(); if (raw1 == null || raw2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final Number number1 = convertToNumber(typeRegistry, value1.getType(), raw1, ZERO); final Number number2 = convertToNumber(typeRegistry, value2.getType(), raw2, ZERO); return new TypeValuePair(NumberType.GENERIC_NUMBER, evaluate(number1, number2)); } protected abstract Number evaluate (final Number number1, final Number number2) throws EvaluationException; private static Number convertToNumber (final TypeRegistry registry, final Type type, final Object value, final Number defaultValue) { if (value == null) { return defaultValue; } try { return registry.convertToNumber(type, value); } catch (EvaluationException e) { return defaultValue; } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/LesserEqualOperator.java0000644000175000017500000000355511401240110032311 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class LesserEqualOperator extends AbstractCompareOperator { private static final long serialVersionUID = -2894251597527836706L; public LesserEqualOperator() { } protected boolean evaluate(final int compareResult) { return compareResult <= 0; } public int getLevel() { return 400; } public String toString() { return "<="; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/DefaultOperatorFactory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/DefaultOperatorFactory.jav0000644000175000017500000001402211401240110032626 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.util.HashMap; import java.util.Iterator; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * Creation-Date: 02.11.2006, 12:29:27 * * @author Thomas Morgner */ public class DefaultOperatorFactory implements OperatorFactory { private static final String INFIX_PREFIX = "org.pentaho.reporting.libraries.formula.operators.infix."; private static final String PREFIX_PREFIX = "org.pentaho.reporting.libraries.formula.operators.prefix."; private static final String POSTFIX_PREFIX = "org.pentaho.reporting.libraries.formula.operators.postfix."; private HashMap infixOperators; private HashMap prefixOperators; private HashMap postfixOperators; public DefaultOperatorFactory() { infixOperators = new HashMap(); prefixOperators = new HashMap(); postfixOperators = new HashMap(); } public void initalize(final Configuration configuration) { loadInfixOperators(configuration); loadPrefixOperators(configuration); loadPostfixOperators(configuration); } private void loadInfixOperators(final Configuration configuration) { final Iterator infixKeys = configuration.findPropertyKeys(INFIX_PREFIX); while (infixKeys.hasNext()) { final String configKey = (String) infixKeys.next(); if (configKey.endsWith(".class") == false) { continue; } final String operatorClass = configuration.getConfigProperty(configKey); if (operatorClass == null) { continue; } if (operatorClass.length() == 0) { continue; } final String tokenKey = configKey.substring (0, configKey.length() - ".class".length()) + ".token"; final String token = configuration.getConfigProperty(tokenKey); if (token == null) { continue; } final String tokenTrimmed = token.trim(); // this assumption was breaking >=, <=, and <> // if (tokenTrimmed.length() != 1) // { // continue; // } final Object operator = ObjectUtilities.loadAndInstantiate (operatorClass, DefaultOperatorFactory.class, InfixOperator.class); if (operator instanceof InfixOperator) { infixOperators.put (tokenTrimmed, operator); } } } private void loadPrefixOperators(final Configuration configuration) { final Iterator infixKeys = configuration.findPropertyKeys(PREFIX_PREFIX); while (infixKeys.hasNext()) { final String configKey = (String) infixKeys.next(); if (configKey.endsWith(".class") == false) { continue; } final String operatorClass = configuration.getConfigProperty(configKey); if (operatorClass == null) { continue; } if (operatorClass.length() == 0) { continue; } final String tokenKey = configKey.substring (0, configKey.length() - ".class".length()) + ".token"; final String token = configuration.getConfigProperty(tokenKey); if (token == null) { continue; } final String tokenTrimmed = token.trim(); // this is an invalid assumption // if (tokenTrimmed.length() != 1) // { // continue; // } final Object operator = ObjectUtilities.loadAndInstantiate (operatorClass, DefaultOperatorFactory.class, PrefixOperator.class); if (operator instanceof PrefixOperator) { prefixOperators.put (tokenTrimmed, operator); } } } private void loadPostfixOperators(final Configuration configuration) { final Iterator infixKeys = configuration.findPropertyKeys(POSTFIX_PREFIX); while (infixKeys.hasNext()) { final String configKey = (String) infixKeys.next(); if (configKey.endsWith(".class") == false) { continue; } final String operatorClass = configuration.getConfigProperty(configKey); if (operatorClass == null) { continue; } if (operatorClass.length() == 0) { continue; } final String tokenKey = configKey.substring (0, configKey.length() - ".class".length()) + ".token"; final String token = configuration.getConfigProperty(tokenKey); if (token == null) { continue; } final String tokenTrimmed = token.trim(); // this is an invalid assumption // if (tokenTrimmed.length() != 1) // { // continue; // } final Object operator = ObjectUtilities.loadAndInstantiate (operatorClass, DefaultOperatorFactory.class, PostfixOperator.class); if (operator instanceof PostfixOperator) { postfixOperators.put (tokenTrimmed, operator); } } } public InfixOperator createInfixOperator(final String operator) { return (InfixOperator) infixOperators.get(operator); } public PostfixOperator createPostfixOperator(final String operator) { return (PostfixOperator) postfixOperators.get(operator); } public PrefixOperator createPrefixOperator(final String operator) { return (PrefixOperator) prefixOperators.get(operator); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/InfixOperator.java0000644000175000017500000000465411401240110031142 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * An operator. An operator always takes two arguments. Prefix and postfix * operators are implemented differently. * * @author Thomas Morgner */ public interface InfixOperator extends Serializable { /** * Evaluates the comptuation for both parameters. This method must never return null. * * @param context * @param value1 * @param value2 * @return * @throws EvaluationException */ public TypeValuePair evaluate(FormulaContext context, TypeValuePair value1, TypeValuePair value2) throws EvaluationException; public int getLevel(); /** * Defines the bind-direction of the operator. That direction defines, in * which direction a sequence of equal operators is resolved. * * @return true, if the operation is left-binding, false if right-binding */ public boolean isLeftOperation(); /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them * a lot better than non-associative operations (ie. merge constant parts * and precompute them once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative(); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/LesserOperator.java0000644000175000017500000000367511401240110031324 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class LesserOperator extends AbstractCompareOperator { private static final long serialVersionUID = 4305611883854102139L; public LesserOperator() { } protected boolean evaluate(final int compareResult) { return compareResult < 0; } public int getLevel() { return 400; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } /** * returns the string representation of this operator. * * @return string */ public String toString() { return "<"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/GreaterOperator.java0000644000175000017500000000354311401240110031452 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class GreaterOperator extends AbstractCompareOperator { private static final long serialVersionUID = -1053475494377977161L; public GreaterOperator() { } protected boolean evaluate(final int compareResult) { return compareResult > 0; } public int getLevel() { return 400; } public String toString() { return ">"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/PlusSignOperator.java0000644000175000017500000000347611401240110031632 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * This is a no-op-operator which is equal to "zero plus x". * * @author Thomas Morgner */ public class PlusSignOperator implements PrefixOperator { private static final long serialVersionUID = 8127033177252320339L; public PlusSignOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1) throws EvaluationException { if (value1 == null) { // This is fatal, but should never happen. throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } return value1; } public String toString() { return "+"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/AddOperator.java0000644000175000017500000000444011401240110030546 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * Null-Values are converted into ZERO * * @author Thomas Morgner */ public class AddOperator extends AbstractNumericOperator { private static final long serialVersionUID = -6676636760348655167L; public AddOperator() { } public Number evaluate(final Number number1, final Number number2) { if ((number1 instanceof Integer || number1 instanceof Short) && (number2 instanceof Integer || number2 instanceof Short)) { return new BigDecimal (number1.longValue() + number2.longValue()); } final BigDecimal bd1 = NumberUtil.getAsBigDecimal(number1); final BigDecimal bd2 = NumberUtil.getAsBigDecimal(number2); return bd1.add(bd2); } public int getLevel() { return 200; } public String toString() { return "+"; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return true; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/AbstractCompareOperator.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/AbstractCompareOperator.ja0000644000175000017500000000547511401240110032612 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.ExtendedComparator; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 06.06.2007, 18:52:25 * * @author Thomas Morgner */ public abstract class AbstractCompareOperator implements InfixOperator { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 1375799912336916036L; protected AbstractCompareOperator() { } public final TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1, final TypeValuePair value2) throws EvaluationException { final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type1 = value1.getType(); final Type type2 = value2.getType(); final Object value1Raw = value1.getValue(); final Object value2Raw = value2.getValue(); if (value1Raw == null || value2Raw == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2); final int result = comparator.compare (type1, value1Raw, type2, value2Raw); if (evaluate(result)) { return RETURN_TRUE; } return RETURN_FALSE; } protected abstract boolean evaluate(int compareResult); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/GreaterEqualOperator.java0000644000175000017500000000355611401240110032446 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class GreaterEqualOperator extends AbstractCompareOperator { private static final long serialVersionUID = 6478407408504176639L; public GreaterEqualOperator() { } protected boolean evaluate(final int compareResult) { return compareResult >= 0; } public int getLevel() { return 400; } public String toString() { return ">="; } public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/PowerOperator.java0000644000175000017500000000430111401240110031146 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * This has to be implemented manually if we want to support arbitary precision. * Damn, do I have to implement the logarithm computation as well? For now: * Ignore that and use doubles! * * @author Thomas Morgner */ public class PowerOperator extends AbstractNumericOperator { private static final long serialVersionUID = -2788666171805222287L; public PowerOperator() { } protected Number evaluate(final Number number1, final Number number2) throws EvaluationException { final double result = StrictMath.pow(number1.doubleValue(), number2.doubleValue()); return new Double(result); } public int getLevel() { return 0; } public String toString() { return "POW"; } public boolean isLeftOperation() { return false; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/MinusSignOperator.java0000644000175000017500000000615111401240110031773 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Creation-Date: 02.11.2006, 10:27:03 * * @author Thomas Morgner */ public class MinusSignOperator implements PrefixOperator { private static final BigDecimal ZERO = new BigDecimal(0.0); private static final long serialVersionUID = 7453766552980074751L; public MinusSignOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1) throws EvaluationException { final Type type = value1.getType(); final Object val = value1.getValue(); if (val == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } if (type.isFlagSet(Type.NUMERIC_TYPE)) { final TypeRegistry typeRegistry = context.getTypeRegistry(); // return the same as zero minus value. final Number number = typeRegistry.convertToNumber(type, val); if (number == null) { throw EvaluationException.getInstance (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal value = NumberUtil.getAsBigDecimal(number); return new TypeValuePair(NumberType.GENERIC_NUMBER, ZERO.subtract(value)); } if(val instanceof Number) { final BigDecimal value = NumberUtil.getAsBigDecimal((Number)val); if (value == null) { throw EvaluationException.getInstance (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(type, ZERO.subtract(value)); } throw EvaluationException.getInstance (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } public String toString() { return "-"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/OperatorFactory.java0000644000175000017500000000247211401240110031470 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.base.config.Configuration; /** * Creation-Date: 02.11.2006, 12:27:52 * * @author Thomas Morgner */ public interface OperatorFactory { public InfixOperator createInfixOperator(String operator); public PostfixOperator createPostfixOperator(String operator); public PrefixOperator createPrefixOperator(String operator); public void initalize(Configuration configuration); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/NotEqualOperator.java0000644000175000017500000000632011401240110031605 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.ExtendedComparator; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 31.10.2006, 16:34:11 * * @author Thomas Morgner */ public class NotEqualOperator implements InfixOperator { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -3928772250539654675L; public NotEqualOperator() { } public TypeValuePair evaluate(final FormulaContext context, final TypeValuePair value1, final TypeValuePair value2) throws EvaluationException { final TypeRegistry typeRegistry = context.getTypeRegistry(); final ExtendedComparator comparator = typeRegistry.getComparator(value1.getType(), value2.getType()); final boolean result = comparator.isEqual (value1.getType(), value1.getValue(), value2.getType(), value2.getValue()); if (result == false) { return RETURN_TRUE; } else { return RETURN_FALSE; } } public int getLevel() { return 400; } public String toString() { return "<>"; } /** * Defines the bind-direction of the operator. That direction defines, in * which direction a sequence of equal operators is resolved. * * @return true, if the operation is left-binding, false if right-binding */ public boolean isLeftOperation() { return true; } /** * Defines, whether the operation is associative. For associative operations, * the evaluation order does not matter, if the operation appears more than * once in an expression, and therefore we can optimize them a lot better than * non-associative operations (ie. merge constant parts and precompute them * once). * * @return true, if the operation is associative, false otherwise */ public boolean isAssociative() { return false; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/operators/PostfixOperator.java0000644000175000017500000000256111401240110031514 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * Creation-Date: 02.11.2006, 10:17:03 * * @author Thomas Morgner */ public interface PostfixOperator extends Serializable { public TypeValuePair evaluate (FormulaContext context, TypeValuePair value1) throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/EvaluationException.java0000644000175000017500000000451511401240110030315 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import org.pentaho.reporting.libraries.base.util.StackableException; /** * Creation-Date: 31.10.2006, 14:15:29 * * @author Thomas Morgner */ public class EvaluationException extends StackableException { private static ThreadLocal localInstance = new ThreadLocal(); private ErrorValue errorValue; private static final long serialVersionUID = 5627076786508932648L; /** * Returns the detail message string of this throwable. * * @return the detail message string of this Throwable instance * (which may be null). */ public String getMessage() { return String.valueOf(errorValue); } /** * Creates a StackableRuntimeException with no message and no parent. * @param errorValue the error value that caused this exception. */ public EvaluationException(final ErrorValue errorValue) { this.errorValue = errorValue; } protected void updateErrorValue(final ErrorValue errorValue) { this.errorValue = errorValue; } public ErrorValue getErrorValue() { return errorValue; } public static EvaluationException getInstance(final ErrorValue errorValue) { final EvaluationException o = (EvaluationException) localInstance.get(); if (o == null) { final EvaluationException retval = new EvaluationException(errorValue); localInstance.set(retval); return retval; } o.fillInStackTrace(); o.updateErrorValue(errorValue); return o; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/0000755000175000017500000000000011401240110025132 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/ContextLookup.java0000644000175000017500000000464611401240110030625 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * A reference that queries the datarow. * * @author Thomas Morgner */ public class ContextLookup extends AbstractLValue { private String name; private static final long serialVersionUID = 2882834743999159722L; public ContextLookup(final String name) { this(name, null); } public ContextLookup(final String name, final ParsePosition parsePosition) { this.name = name; setParsePosition(parsePosition); } public TypeValuePair evaluate() throws EvaluationException { final FormulaContext context = getContext(); final Type type = context.resolveReferenceType(name); final Object value = context.resolveReference(name); return new TypeValuePair(type, value); } public Type getValueType() { try { final FormulaContext context = getContext(); return context.resolveReferenceType(name); } catch (final EvaluationException evalex) { // exception ignored. return ErrorType.TYPE; } } public String toString() { return '[' + name + ']'; } /** * Checks whether the LValue is constant. Constant lvalues always return the * same value. * * @return */ public boolean isConstant() { return false; } public String getName() { return name; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/AbstractLValue.java0000644000175000017500000000451411401240110030655 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 01.11.2006, 18:19:00 * * @author Thomas Morgner */ public abstract class AbstractLValue implements LValue { private static final LValue[] EMPTY_CHILDS = new LValue[0]; private transient FormulaContext context; private static final long serialVersionUID = -8929559303303911502L; private ParsePosition parsePosition; protected AbstractLValue() { } public ParsePosition getParsePosition() { return parsePosition; } public void setParsePosition(final ParsePosition parsePosition) { this.parsePosition = parsePosition; } public void initialize(final FormulaContext context) throws EvaluationException { this.context = context; } public FormulaContext getContext() { if (context == null) { throw new NullPointerException(); } return context; } public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { return EMPTY_CHILDS; } /** * Querying the value type is only valid *after* the value has been * evaluated. * * @return */ public Type getValueType() { return null; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/DataTable.java0000644000175000017500000000327011401240110027620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; /** * A database is a two dimensional collection of data, arranged in a table. * Although we do not assume that the whole database is held in memory, we * allow random access of the data. * * Columns may have names, but there is no enforced requirement for that. * * As a database is not just a collection of raw data, this interface returns * LValues instead of plain objects. Columns may be computed values using * formulas (the exact semantics of adressing database cells in a formula is * beyond the scope of this specification and is implementation specific). * * @author Thomas Morgner */ public interface DataTable extends LValue { public int getRowCount(); public int getColumnCount(); public String getColumnName (int column); public LValue getValueAt (int row, int column); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/LValue.java0000644000175000017500000000401311401240110027163 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.typing.Type; /** * A reference is an indirection to hide the details of where the actual * value came from. * * The reference is responsible to report dependencies. * * @author Thomas Morgner */ public interface LValue extends Serializable, Cloneable { public void initialize(FormulaContext context) throws EvaluationException; public TypeValuePair evaluate() throws EvaluationException; public Object clone() throws CloneNotSupportedException; /** * Querying the value type is only valid *after* the value has been evaluated. * @return */ public Type getValueType(); /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues(); /** * Checks whether the LValue is constant. Constant lvalues always return * the same value. * * @return */ public boolean isConstant(); public ParsePosition getParsePosition(); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/Term.java0000644000175000017500000002316011401240110026706 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import java.util.ArrayList; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.operators.InfixOperator; /** * An term is a list of LValues connected by operators. For the sake of efficiency, this is not stored as tree. We store * the term as a list in the following format: (headValue)(OP value)* ... * * @author Thomas Morgner */ public class Term extends AbstractLValue { private static final LValue[] EMPTY_L_VALUE = new LValue[0]; private static final InfixOperator[] EMPTY_OPERATOR = new InfixOperator[0]; private static final long serialVersionUID = -1854082494425470979L; private LValue optimizedHeadValue; private LValue headValue; private ArrayList operators; private ArrayList operands; private InfixOperator[] operatorArray; private LValue[] operandsArray; private boolean initialized; public Term(final LValue headValue) { if (headValue == null) { throw new NullPointerException(); } this.headValue = headValue; } public TypeValuePair evaluate() throws EvaluationException { TypeValuePair result = optimizedHeadValue.evaluate(); for (int i = 0; i < operandsArray.length; i++) { final LValue value = operandsArray[i]; final InfixOperator op = operatorArray[i]; result = op.evaluate(getContext(), result, value.evaluate()); } return result; } public void add(final InfixOperator operator, final LValue operand) { if (operator == null) { throw new NullPointerException(); } if (operand == null) { throw new NullPointerException(); } if (operands == null || operators == null) { this.operands = new ArrayList(); this.operators = new ArrayList(); } operands.add(operand); operators.add(operator); initialized = false; } public void initialize(final FormulaContext context) throws EvaluationException { super.initialize(context); if (operands == null || operators == null) { this.optimizedHeadValue = headValue; this.optimizedHeadValue.initialize(context); this.operandsArray = EMPTY_L_VALUE; this.operatorArray = EMPTY_OPERATOR; return; } if (initialized) { optimizedHeadValue.initialize(context); for (int i = 0; i < operandsArray.length; i++) { final LValue lValue = operandsArray[i]; lValue.initialize(context); } return; } optimize(); this.optimizedHeadValue.initialize(context); for (int i = 0; i < operandsArray.length; i++) { final LValue value = operandsArray[i]; value.initialize(context); } initialized = true; } private void optimize() { if (operands == null || operators == null) { this.optimizedHeadValue = headValue; this.operandsArray = EMPTY_L_VALUE; this.operatorArray = EMPTY_OPERATOR; return; } final ArrayList operators = (ArrayList) this.operators.clone(); final ArrayList operands = (ArrayList) this.operands.clone(); this.optimizedHeadValue = headValue; while (true) { // now start to optimize everything. // first, search the operator with the highest priority.. final InfixOperator op = (InfixOperator) operators.get(0); int level = op.getLevel(); boolean moreThanOne = false; for (int i = 1; i < operators.size(); i++) { final InfixOperator operator = (InfixOperator) operators.get(i); final int opLevel = operator.getLevel(); if (opLevel != level) { moreThanOne = true; level = Math.min(opLevel, level); } } if (moreThanOne == false) { // No need to optimize the operators .. break; } // There are at least two op-levels in this term. Term subTerm = null; for (int i = 0; i < operators.size(); i++) { final InfixOperator operator = (InfixOperator) operators.get(i); if (operator.getLevel() != level) { subTerm = null; continue; } if (subTerm == null) { if (i == 0) { subTerm = new Term(optimizedHeadValue); optimizedHeadValue = subTerm; } else { final LValue lval = (LValue) operands.get(i - 1); subTerm = new Term(lval); operands.set(i - 1, subTerm); } } // OK, now a term exists, and we should join it. final LValue operand = (LValue) operands.get(i); subTerm.add(operator, operand); operands.remove(i); operators.remove(i); // Rollback the current index .. //noinspection AssignmentToForLoopParameter i -= 1; } } this.operatorArray = (InfixOperator[]) operators.toArray(new InfixOperator[operators.size()]); this.operandsArray = (LValue[]) operands.toArray(new LValue[operands.size()]); } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { if (operandsArray == null) { optimize(); } final LValue[] values = new LValue[operandsArray.length + 1]; values[0] = headValue; System.arraycopy(operandsArray, 0, values, 1, operandsArray.length); return values; } public String toString() { final StringBuffer b = new StringBuffer(100); b.append('('); b.append(headValue); if (operands != null && operators != null) { for (int i = 0; i < operands.size(); i++) { final InfixOperator op = (InfixOperator) operators.get(i); final LValue value = (LValue) operands.get(i); b.append(op); b.append(value); } } b.append(')'); // // b.append(";OPTIMIZED("); // b.append(optimizedHeadValue); // if (operandsArray != null && operatorArray != null) // { // for (int i = 0; i < operandsArray.length; i++) // { // final InfixOperator op = operatorArray[i]; // final LValue value = operandsArray[i]; // b.append(op); // b.append(value); // } // } // b.append(")"); return b.toString(); } /** * Checks whether the LValue is constant. Constant lvalues always return the same value. * * @return */ public boolean isConstant() { if (headValue.isConstant() == false) { return false; } for (int i = 0; i < operands.size(); i++) { final LValue value = (LValue) operands.get(i); if (value.isConstant() == false) { return false; } } return true; } public Object clone() throws CloneNotSupportedException { final Term o = (Term) super.clone(); if (operands != null) { o.operands = (ArrayList) operands.clone(); } if (operators != null) { o.operators = (ArrayList) operators.clone(); } o.headValue = (LValue) headValue.clone(); o.optimizedHeadValue = null; o.operandsArray = null; o.operatorArray = null; o.initialized = false; return o; } public LValue[] getOperands() { return (LValue[]) operands.toArray(new LValue[operands.size()]); } public InfixOperator[] getOperators() { return (InfixOperator[]) operators.toArray(new InfixOperator[operators.size()]); } public LValue getHeadValue() { return headValue; } /** * Allows access to the post optimized head value note that without the optimization, it's difficult to traverse * libformula's object model. * * @return optimized head value */ public LValue getOptimizedHeadValue() { return optimizedHeadValue; } // // /** // * Allows access to the post optimized operator array // * // * @return optimized operator array // */ // public InfixOperator[] getOptimizedOperators() // { // return operatorArray; // } // // /** // * Allows access to the post optimized operand array // * // * @return optimized operand array // */ // public LValue[] getOptimizedOperands() // { // return operandsArray; // } public ParsePosition getParsePosition() { final ParsePosition parsePosition = super.getParsePosition(); if (parsePosition == null) { final int startColumn = headValue.getParsePosition().getStartColumn(); final int startLine = headValue.getParsePosition().getStartLine(); final ParsePosition lastParsePos = operandsArray[operandsArray.length - 1].getParsePosition(); final int endColumn = lastParsePos.getEndColumn(); final int endLine = lastParsePos.getEndLine(); setParsePosition(new ParsePosition(startLine, startColumn, endLine, endColumn)); } return super.getParsePosition(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/DataCube.java0000644000175000017500000000242611401240110027451 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; /** * A multi-dimensional data collection. It should return LValues, but for now, * this remains totally undefined until I have a clue about what I'm doing here. * * @author Thomas Morgner */ // I guess we are talking about a range functionality as in this example: // SUM([Sheet1.B4:Sheet2.C5]) : Simple 3D range, naturally with explicit sheet // names public interface DataCube { } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/DefaultDataTable.java0000644000175000017500000001604411401240110031130 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.base.util.ObjectTable; /** * Creation-Date: 05.11.2006, 13:34:01 * * @author Thomas Morgner * @author Cedric Pronzato */ public class DefaultDataTable extends ObjectTable implements DataTable { private static class DefaultArrayCallback implements ArrayCallback { private DefaultDataTable table; private TypeValuePair[][] backend; private DefaultArrayCallback(final DefaultDataTable table) { this.table = table; this.backend = new TypeValuePair[table.getRowCount()][table.getColumnCount()]; } public LValue getRaw(final int row, final int column) { return table.getValueAt(row, column); } public Object getValue(final int row, final int column) throws EvaluationException { final TypeValuePair value = get(row, column); return value.getValue(); } private TypeValuePair get(final int row, final int column) throws EvaluationException { TypeValuePair value = backend[row][column]; if(value == null) { value = getRaw(row, column).evaluate(); backend[row][column] = value; } return value; } public Type getType(final int row, final int column) throws EvaluationException { return get(row, column).getType(); } public int getColumnCount() { return table.getColumnCount(); } public int getRowCount() { return table.getRowCount(); } } private transient Boolean constant; private static final LValue[] EMPTY_LVALUES = new LValue[0]; private static final long serialVersionUID = 4942690291611203409L; private ParsePosition parsePosition; /** * Creates a new table. */ public DefaultDataTable() { } public DefaultDataTable(final LValue[][] array) { if(array != null && array.length > 0) { final int colCount = array[0].length; setData(array, colCount); } } public ParsePosition getParsePosition() { return parsePosition; } public void setParsePosition(final ParsePosition parsePosition) { this.parsePosition = parsePosition; } public String getColumnName(int column) { final StringBuffer result = new StringBuffer(10); for (; column >= 0; column = column / 26 - 1) { final int colChar = (char) (column % 26) + 'A'; result.append(colChar); } return result.toString(); } /** * Sets the object for a cell in the table. The table is expanded if * necessary. * * @param row the row index (zero-based). * @param column the column index (zero-based). * @param object the object. */ public void setObject(final int row, final int column, final LValue object) { super.setObject(row, column, object); } public LValue getValueAt(final int row, final int column) { return (LValue) getObject(row, column); } public void initialize(final FormulaContext context) throws EvaluationException { final int rows = getRowCount(); final int cols = getColumnCount(); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { final LValue value = getValueAt(row, col); if(value != null) { value.initialize(context); } } } } public TypeValuePair evaluate() throws EvaluationException { int colCount = -1; final LValue[][] array = (LValue[][])getData(); for(int i=0; i 0 && row.length != colCount) { // error, different column count is not allowed throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE); } else { colCount = row.length; } } return new TypeValuePair(AnyType.ANY_ARRAY, new DefaultArrayCallback(this)); } public ArrayCallback getAsArray() { return new DefaultArrayCallback(this); } public Object clone() throws CloneNotSupportedException { final DefaultDataTable table = (DefaultDataTable) super.clone(); final Object[][] data = getData(); final Object[][] targetData = (Object[][]) data.clone(); for (int i = 0; i < targetData.length; i++) { final Object[] objects = targetData[i]; if (objects == null) { continue; } targetData[i] = (Object[]) objects.clone(); for (int j = 0; j < objects.length; j++) { final LValue object = (LValue) objects[j]; if (object == null) { continue; } objects[j] = object.clone(); } } table.setData(targetData, getColumnCount()); return table; } /** * Querying the value type is only valid *after* the value has been * evaluated. * * @return */ public Type getValueType() { return AnyType.ANY_ARRAY; } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { // too expensive ... return EMPTY_LVALUES; } /** * Checks whether the LValue is constant. Constant lvalues always return the * same value. * * @return */ public boolean isConstant() { if (constant == null) { if (computeConstantValue()) { constant = Boolean.TRUE; } else { constant = Boolean.FALSE; } } return Boolean.TRUE.equals(constant); } private boolean computeConstantValue() { final int rows = getRowCount(); final int cols = getColumnCount(); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { final LValue value = getValueAt(row, col); if (value.isConstant() == false) { return false; } } } return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/StaticValue.java0000644000175000017500000000536711401240110030234 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import java.util.Date; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: 08.10.2006, 11:34:40 * * @author Thomas Morgner */ public class StaticValue extends AbstractLValue { private Object value; private Type type; private static final long serialVersionUID = 7255803922294601237L; public StaticValue(final Object value) { this(value, AnyType.TYPE); } public StaticValue(final Object value, final Type type) { this.value = value; this.type = type; } public StaticValue(final Object value, final ParsePosition parsePosition) { this(value, AnyType.TYPE, parsePosition); } public StaticValue(final Object value, final Type type, final ParsePosition parsePosition) { this.value = value; this.type = type; setParsePosition(parsePosition); } public void initialize(final FormulaContext context) throws EvaluationException { } public TypeValuePair evaluate() { return new TypeValuePair(type, value); } public String toString() { if (value instanceof Number || value instanceof Date) { return String.valueOf(value); } return "\"" + String.valueOf(value) + "\""; } /** * Checks whether the LValue is constant. Constant lvalues always return the * same value. * * @return */ public boolean isConstant() { return true; } public Object getValue() { return value; } /** * This function allows a program traversing the LibFormula object model * to know what type this static value is. * * @return the type of the static value * */ public Type getValueType() { return type; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/ParsePosition.java0000644000175000017500000000357211401240110030603 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import java.io.Serializable; /** * Todo: Document me! * * @author : Thomas Morgner */ public class ParsePosition implements Serializable { private int startColumn; private int startLine; private int endColumn; private int endLine; public ParsePosition(final int startLine, final int startColumn, final int endLine, final int endColumn) { this.startLine = startLine; this.startColumn = startColumn; this.endLine = endLine; this.endColumn = endColumn; } public int getEndColumn() { return endColumn; } public int getEndLine() { return endLine; } public int getStartColumn() { return startColumn; } public int getStartLine() { return startLine; } public String toString () { return "ParsePosition={startLine=" + startLine + "; startColumn=" + startColumn + "; endLine=" + endLine + "; endColumn=" + endColumn + "}"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/PostfixTerm.java0000644000175000017500000000466311401240110030272 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.operators.PostfixOperator; /** * Creation-Date: 02.11.2006, 10:20:27 * * @author Thomas Morgner */ public class PostfixTerm extends AbstractLValue { private PostfixOperator operator; private LValue value; private static final long serialVersionUID = -3652663226326546952L; public PostfixTerm(final LValue value, final PostfixOperator operator) { if (operator == null) { throw new NullPointerException(); } if (value == null) { throw new NullPointerException(); } this.operator = operator; this.value = value; } public PostfixOperator getOperator() { return operator; } public LValue getValue() { return value; } public TypeValuePair evaluate() throws EvaluationException { return operator.evaluate(getContext(), value.evaluate()); } public String toString() { return "(" + value + operator + ')'; } /** * Checks whether the LValue is constant. Constant lvalues always return the * same value. * * @return */ public boolean isConstant() { return value.isConstant(); } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { return new LValue[]{ value }; } public Object clone() throws CloneNotSupportedException { final PostfixTerm o = (PostfixTerm) super.clone(); o.value = (LValue) value.clone(); return o; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/PrefixTerm.java0000644000175000017500000000465411401240110030073 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.pentaho.reporting.libraries.formula.operators.PrefixOperator; import org.pentaho.reporting.libraries.formula.EvaluationException; /** * Creation-Date: 02.11.2006, 10:20:27 * * @author Thomas Morgner */ public class PrefixTerm extends AbstractLValue { private PrefixOperator operator; private LValue value; private static final long serialVersionUID = 6986873199027878219L; public PrefixTerm(final PrefixOperator operator, final LValue value) { if (operator == null) { throw new NullPointerException(); } if (value == null) { throw new NullPointerException(); } this.operator = operator; this.value = value; } public PrefixOperator getOperator() { return operator; } public LValue getValue() { return value; } public TypeValuePair evaluate() throws EvaluationException { return operator.evaluate(getContext(), value.evaluate()); } public String toString() { return "(" + operator + value + ')'; } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { return new LValue[]{ value }; } /** * Checks whether the LValue is constant. Constant lvalues always return the * same value. * * @return */ public boolean isConstant() { return value.isConstant(); } public Object clone() throws CloneNotSupportedException { final PrefixTerm o = (PrefixTerm) super.clone(); o.value = (LValue) value.clone(); return o; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/TypeValuePair.java0000644000175000017500000000324011401240110030526 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.typing.Type; /** * Creation-Date: 02.11.2006, 10:02:54 * * @author Thomas Morgner */ public class TypeValuePair implements Serializable { private Type type; private Object value; private static final long serialVersionUID = 6531903280852042078L; public TypeValuePair(final Type type, final Object value) { if (type == null) { throw new NullPointerException("Type must be given."); } this.type = type; this.value = value; } public Type getType() { return type; } public Object getValue() { return value; } public String toString() { return "TypeValuePair{" + "type=" + type + ", value=" + value + '}'; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/lvalues/FormulaFunction.java0000644000175000017500000002117311401240110031114 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.lvalues; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.FunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionRegistry; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; /** * A function. Formulas consist of functions, references or static values, which are connected by operators. *

* Functions always have a cannonical name, which must be unique and which identifies the function. Functions can have a * list of parameters. The number of parameters can vary, and not all parameters need to be filled. *

* Functions can have required and optional parameters. Mixing required and optional parameters is not allowed. Optional * parameters cannot be ommited, unless they are the last parameter in the list. *

* This class provides the necessary wrapper functionality to fill in the parameters. * * @author Thomas Morgner */ public class FormulaFunction extends AbstractLValue { private static final Log logger = LogFactory.getLog(FormulaFunction.class); private static class FormulaParameterCallback implements ParameterCallback { private TypeValuePair[] backend; private FormulaFunction function; private FormulaParameterCallback(final FormulaFunction function) { this.function = function; this.backend = new TypeValuePair[function.parameters.length]; } private TypeValuePair get(final int pos) throws EvaluationException { final LValue parameter = function.parameters[pos]; final Type paramType = function.metaData.getParameterType(pos); if (parameter != null) { final TypeValuePair result = parameter.evaluate(); if (result.getValue() == null) { return result; } // lets do some type checking, right? final TypeRegistry typeRegistry = function.getContext().getTypeRegistry(); final TypeValuePair converted = typeRegistry.convertTo(paramType, result); if (converted == null) { if (logger.isDebugEnabled()) { logger.debug("Failed to evaluate parameter " + pos + " on function " + function); } throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_AUTO_ARGUMENT_VALUE); } return converted; } else { return new TypeValuePair(paramType, function.metaData.getDefaultValue(pos)); } } public LValue getRaw(final int position) { return function.parameters[position]; } public Object getValue(final int position) throws EvaluationException { final TypeValuePair retval = backend[position]; if (retval != null) { return retval.getValue(); } final TypeValuePair pair = get(position); backend[position] = pair; return pair.getValue(); } public Type getType(final int position) throws EvaluationException { final TypeValuePair retval = backend[position]; if (retval != null) { return retval.getType(); } final TypeValuePair pair = get(position); backend[position] = pair; return pair.getType(); } public int getParameterCount() { return backend.length; } } private String functionName; private LValue[] parameters; private Function function; private FunctionDescription metaData; private static final long serialVersionUID = 8023588016882997962L; public FormulaFunction(final String functionName, final LValue[] parameters, final ParsePosition parsePosition) { this.functionName = functionName; setParsePosition(parsePosition); this.parameters = (LValue[]) parameters.clone(); } public FormulaFunction(final String functionName, final LValue[] parameters) { this(functionName, parameters, null); } public void initialize(final FormulaContext context) throws EvaluationException { super.initialize(context); final FunctionRegistry registry = context.getFunctionRegistry(); if (function == null) { function = registry.createFunction(functionName); } if (metaData == null) { metaData = registry.getMetaData(functionName); } for (int i = 0; i < parameters.length; i++) { parameters[i].initialize(context); } } /** * Returns the function's name. This is the normalized name and may not be suitable for the user. Query the function's * metadata to retrieve a display-name. * * @return the function's name. */ public String getFunctionName() { return functionName; } /** * Returns the initialized function. Be aware that this method will return null if this LValue instance has not yet * been initialized. * * @return the function instance or null, if the FormulaFunction instance has not yet been initialized. */ public Function getFunction() { return function; } /** * Returns the function's meta-data. Be aware that this method will return null if this LValue instance has not yet * been initialized. * * @return the function description instance or null, if the FormulaFunction instance has not yet been initialized. */ public FunctionDescription getMetaData() { return metaData; } public Object clone() throws CloneNotSupportedException { final FormulaFunction fn = (FormulaFunction) super.clone(); fn.parameters = (LValue[]) parameters.clone(); for (int i = 0; i < parameters.length; i++) { final LValue parameter = parameters[i]; fn.parameters[i] = (LValue) parameter.clone(); } return fn; } public TypeValuePair evaluate() throws EvaluationException { // First, grab the parameters and their types. final FormulaContext context = getContext(); // And if everything is ok, compute the stuff .. if (function == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_FUNCTION_VALUE); } try { return function.evaluate(context, new FormulaParameterCallback(this)); } catch (EvaluationException e) { throw e; } catch (Exception e) { logger.error("Unexpected exception while evaluating", e); throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } } /** * Returns any dependent lvalues (parameters and operands, mostly). * * @return */ public LValue[] getChildValues() { return (LValue[]) parameters.clone(); } public String toString() { final StringBuffer b = new StringBuffer(100); b.append(functionName); b.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { b.append(';'); } final LValue parameter = parameters[i]; b.append(parameter); } b.append(')'); return b.toString(); } /** * Checks whether the LValue is constant. Constant lvalues always return the same value. * * @return true, if the function will always return the same value. */ public boolean isConstant() { if (metaData.isVolatile()) { return false; } for (int i = 0; i < parameters.length; i++) { final LValue value = parameters[i]; if (value.isConstant() == false) { return false; } } return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/0000755000175000017500000000000011401240106024760 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/GeneratedFormulaParser.java0000644000175000017500000003755111401240106032237 0ustar renerene/* Generated By:JavaCC: Do not edit this line. GeneratedFormulaParser.java */ package org.pentaho.reporting.libraries.formula.parser; import java.math.BigDecimal; import java.util.ArrayList; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.FormulaFunction; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.PostfixTerm; import org.pentaho.reporting.libraries.formula.lvalues.PrefixTerm; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; import org.pentaho.reporting.libraries.formula.lvalues.Term; import org.pentaho.reporting.libraries.formula.lvalues.DefaultDataTable; import org.pentaho.reporting.libraries.formula.operators.InfixOperator; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; import org.pentaho.reporting.libraries.formula.operators.PostfixOperator; import org.pentaho.reporting.libraries.formula.operators.PrefixOperator; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; import org.pentaho.reporting.libraries.formula.lvalues.ParsePosition; public abstract class GeneratedFormulaParser implements GeneratedFormulaParserConstants { protected GeneratedFormulaParser () { } protected abstract OperatorFactory getOperatorFactory(); protected ParsePosition createPosition(Token token) { return new ParsePosition (token.beginLine, token.beginColumn, token.endLine, token.endColumn); } final public LValue getExpression() throws ParseException { LValue retval = null; Term term = null; retval = getLValue(); switch (jj_nt.kind) { case PLUS: case MINUS: case MULT: case DIV: case POW: case EQUALS: case NOT_EQUALS: case LT_EQUALS: case GT_EQUALS: case LT: case GT: case CONCAT: term = startTail(new Term(retval)); label_1: while (true) { switch (jj_nt.kind) { case PLUS: case MINUS: case MULT: case DIV: case POW: case EQUALS: case NOT_EQUALS: case LT_EQUALS: case GT_EQUALS: case LT: case GT: case CONCAT: ; break; default: jj_la1[0] = jj_gen; break label_1; } term = startTail(term); } break; default: jj_la1[1] = jj_gen; ; } if (term != null) { {if (true) return term;} } {if (true) return retval;} throw new Error("Missing return statement in function"); } final public Term startTail(LValue retval) throws ParseException { LValue val = null; InfixOperator op = null; Term ex = null; op = getInfixOperator(); val = getLValue(); if (retval instanceof Term) { ex = (Term) retval; } else { ex = new Term (retval); } ex.add (op, val); {if (true) return ex;} throw new Error("Missing return statement in function"); } final public LValue getLValue() throws ParseException { Token value = null; LValue retval = null; PrefixOperator prefixOp = null; PostfixOperator postfixOp = null; switch (jj_nt.kind) { case PLUS: case MINUS: prefixOp = getPrefixOperator(); break; default: jj_la1[2] = jj_gen; ; } switch (jj_nt.kind) { case COLUMN_LOOKUP: value = jj_consume_token(COLUMN_LOOKUP); retval = new ContextLookup (ParserTools.stripReferenceQuote(value.image), createPosition(value)); break; case STRING_LITERAL: value = jj_consume_token(STRING_LITERAL); retval = new StaticValue (ParserTools.stripQuote(value.image), TextType.TYPE, createPosition(value)); break; case UNSIGNED_NUMERIC_LITERAL: value = jj_consume_token(UNSIGNED_NUMERIC_LITERAL); retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER, createPosition(value)); break; case UNSIGNED_INTEGER: value = jj_consume_token(UNSIGNED_INTEGER); retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER, createPosition(value)); break; case NULL: jj_consume_token(NULL); retval = new StaticValue (null, createPosition(value)); break; case L_BRACE: jj_consume_token(L_BRACE); retval = parseArray(); jj_consume_token(R_BRACE); break; case IDENTIFIER: value = jj_consume_token(IDENTIFIER); jj_consume_token(L_PAREN); retval = parseFunction(value.image, createPosition(value)); jj_consume_token(R_PAREN); break; case L_PAREN: jj_consume_token(L_PAREN); retval = getExpression (); jj_consume_token(R_PAREN); if (retval instanceof Term == false) { retval = new Term (retval); } break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } switch (jj_nt.kind) { case PERCENT: postfixOp = getPostfixOperator(); break; default: jj_la1[4] = jj_gen; ; } if (postfixOp != null) { retval = new PostfixTerm(retval, postfixOp); } if (prefixOp != null) { retval = new PrefixTerm(prefixOp, retval); } {if (true) return retval;} throw new Error("Missing return statement in function"); } final public LValue parseArray() throws ParseException { ArrayList rows = new ArrayList(); LValue[] row = null; row = parseRow(); rows.add(row); label_2: while (true) { switch (jj_nt.kind) { case PIPE: ; break; default: jj_la1[5] = jj_gen; break label_2; } jj_consume_token(PIPE); row = parseRow(); // should we check here for column count equality to the first row column count? // or do we give this responsability to a DefaultDataTable constructor? rows.add(row); } LValue[][] table = (LValue[][])rows.toArray(new LValue[rows.size()][]); {if (true) return new DefaultDataTable(table);} throw new Error("Missing return statement in function"); } final public LValue[] parseRow() throws ParseException { ArrayList cols = new ArrayList();; LValue column = null; column = getExpression(); cols.add(column); label_3: while (true) { switch (jj_nt.kind) { case SEMICOLON: ; break; default: jj_la1[6] = jj_gen; break label_3; } jj_consume_token(SEMICOLON); column = getExpression(); cols.add(column); } {if (true) return (LValue[]) cols.toArray(new LValue[cols.size()]);} throw new Error("Missing return statement in function"); } final public LValue parseFunction(String name, ParsePosition parsePosition) throws ParseException { ArrayList params = new ArrayList(); LValue parameter = null; Token value = null; boolean parameterExpected = false; switch (jj_nt.kind) { case UNSIGNED_INTEGER: case SEMICOLON: case L_PAREN: case L_BRACE: case PLUS: case MINUS: case IDENTIFIER: case COLUMN_LOOKUP: case STRING_LITERAL: case UNSIGNED_NUMERIC_LITERAL: case NULL: switch (jj_nt.kind) { case SEMICOLON: value = jj_consume_token(SEMICOLON); parameterExpected = false; params.add(new StaticValue(null, createPosition(value))); break; case UNSIGNED_INTEGER: case L_PAREN: case L_BRACE: case PLUS: case MINUS: case IDENTIFIER: case COLUMN_LOOKUP: case STRING_LITERAL: case UNSIGNED_NUMERIC_LITERAL: case NULL: parameter = getExpression(); parameterExpected = false; params.add(parameter); break; default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); } label_4: while (true) { switch (jj_nt.kind) { case SEMICOLON: ; break; default: jj_la1[8] = jj_gen; break label_4; } value = jj_consume_token(SEMICOLON); if (parameterExpected == true) { params.add(new StaticValue(null, createPosition(value))); } parameterExpected = true; switch (jj_nt.kind) { case UNSIGNED_INTEGER: case L_PAREN: case L_BRACE: case PLUS: case MINUS: case IDENTIFIER: case COLUMN_LOOKUP: case STRING_LITERAL: case UNSIGNED_NUMERIC_LITERAL: case NULL: parameter = getExpression(); params.add(parameter); parameterExpected = false; break; default: jj_la1[9] = jj_gen; ; } } break; default: jj_la1[10] = jj_gen; ; } if (parameterExpected == true) { params.add(new StaticValue(null, createPosition(value))); } if (params == null) { {if (true) return new FormulaFunction(name, new LValue[0], parsePosition);} } LValue[] paramVals = (LValue[]) params.toArray(new LValue[params.size()]); {if (true) return new FormulaFunction(name, paramVals, parsePosition);} throw new Error("Missing return statement in function"); } final public PrefixOperator getPrefixOperator() throws ParseException { Token value = null; switch (jj_nt.kind) { case PLUS: value = jj_consume_token(PLUS); break; case MINUS: value = jj_consume_token(MINUS); break; default: jj_la1[11] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return getOperatorFactory().createPrefixOperator(value.image);} throw new Error("Missing return statement in function"); } final public PostfixOperator getPostfixOperator() throws ParseException { Token value = null; value = jj_consume_token(PERCENT); {if (true) return getOperatorFactory().createPostfixOperator(value.image);} throw new Error("Missing return statement in function"); } final public InfixOperator getInfixOperator() throws ParseException { InfixOperator op = null; Token value = null; switch (jj_nt.kind) { case PLUS: value = jj_consume_token(PLUS); break; case MINUS: value = jj_consume_token(MINUS); break; case MULT: value = jj_consume_token(MULT); break; case DIV: value = jj_consume_token(DIV); break; case POW: value = jj_consume_token(POW); break; case EQUALS: value = jj_consume_token(EQUALS); break; case NOT_EQUALS: value = jj_consume_token(NOT_EQUALS); break; case LT_EQUALS: value = jj_consume_token(LT_EQUALS); break; case GT_EQUALS: value = jj_consume_token(GT_EQUALS); break; case LT: value = jj_consume_token(LT); break; case GT: value = jj_consume_token(GT); break; case CONCAT: value = jj_consume_token(CONCAT); break; default: jj_la1[12] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return getOperatorFactory().createInfixOperator(value.image);} throw new Error("Missing return statement in function"); } public GeneratedFormulaParserTokenManager token_source; JavaCharStream jj_input_stream; public Token token, jj_nt; private int jj_gen; final private int[] jj_la1 = new int[13]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { jj_la1_0(); jj_la1_1(); } private static void jj_la1_0() { jj_la1_0 = new int[] {0xf8000000,0xf8000000,0x18000000,0x1080100,0x0,0x4000000,0x40000,0x190c0100,0x40000,0x19080100,0x190c0100,0x18000000,0xf8000000,}; } private static void jj_la1_1() { jj_la1_1 = new int[] {0x7f,0x7f,0x0,0x10f00,0x80,0x0,0x0,0x10f00,0x0,0x10f00,0x10f00,0x0,0x7f,}; } public GeneratedFormulaParser(java.io.InputStream stream) { jj_input_stream = new JavaCharStream(stream, 1, 1); token_source = new GeneratedFormulaParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public void ReInit(java.io.InputStream stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public GeneratedFormulaParser(java.io.Reader stream) { jj_input_stream = new JavaCharStream(stream, 1, 1); token_source = new GeneratedFormulaParserTokenManager(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public GeneratedFormulaParser(GeneratedFormulaParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public void ReInit(GeneratedFormulaParserTokenManager tm) { token_source = tm; token = new Token(); token.next = jj_nt = token_source.getNextToken(); jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } final private Token jj_consume_token(int kind) throws ParseException { Token oldToken = token; if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); if (token.kind == kind) { jj_gen++; return token; } jj_nt = token; token = oldToken; jj_kind = kind; throw generateParseException(); } final public Token getNextToken() { if ((token = jj_nt).next != null) jj_nt = jj_nt.next; else jj_nt = jj_nt.next = token_source.getNextToken(); jj_gen++; return token; } final public Token getToken(int index) { Token t = token; for (int i = 0; i < index; i++) { if (t.next != null) t = t.next; else t = t.next = token_source.getNextToken(); } return t; } private java.util.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[49]; for (int i = 0; i < 49; i++) { la1tokens[i] = false; } if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 13; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1< 1) kind = 1; } else if ((0x3ff000000000000L & l) != 0L) { if (kind > 8) kind = 8; jjCheckNAddStates(0, 5); } else if (curChar == 46) jjCheckNAddTwoStates(17, 21); else if (curChar == 34) jjCheckNAddStates(6, 8); else if (curChar == 36) { if (kind > 40) kind = 40; jjCheckNAddTwoStates(8, 9); } else if (curChar == 45) jjstateSet[jjnewStateCnt++] = 1; break; case 1: if (curChar == 45) jjCheckNAddStates(9, 11); break; case 2: if ((0xffffffffffffdbffL & l) != 0L) jjCheckNAddStates(9, 11); break; case 3: if ((0x2400L & l) != 0L && kind > 2) kind = 2; break; case 4: if (curChar == 10 && kind > 2) kind = 2; break; case 5: if (curChar == 13) jjstateSet[jjnewStateCnt++] = 4; break; case 6: if (curChar == 45) jjstateSet[jjnewStateCnt++] = 1; break; case 7: if (curChar != 36) break; if (kind > 40) kind = 40; jjCheckNAddTwoStates(8, 9); break; case 8: if ((0x3ff001000000000L & l) == 0L) break; if (kind > 40) kind = 40; jjCheckNAddTwoStates(8, 9); break; case 9: if (curChar != 46) break; if (kind > 40) kind = 40; jjCheckNAdd(10); break; case 10: if ((0x3ff001000000000L & l) == 0L) break; if (kind > 40) kind = 40; jjCheckNAdd(10); break; case 11: case 12: if (curChar == 34) jjCheckNAddStates(6, 8); break; case 13: if (curChar == 34) jjstateSet[jjnewStateCnt++] = 12; break; case 14: if ((0xfffffffbffffffffL & l) != 0L) jjCheckNAddStates(6, 8); break; case 15: if (curChar == 34 && kind > 42) kind = 42; break; case 16: if (curChar == 46) jjCheckNAddTwoStates(17, 21); break; case 17: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(17, 18); break; case 19: if ((0x280000000000L & l) != 0L) jjCheckNAdd(20); break; case 20: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 43) kind = 43; jjCheckNAdd(20); break; case 21: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 43) kind = 43; jjCheckNAdd(21); break; case 23: jjCheckNAddTwoStates(23, 24); break; case 25: case 26: if (curChar == 34) jjCheckNAddStates(12, 14); break; case 27: if (curChar == 34) jjstateSet[jjnewStateCnt++] = 26; break; case 28: if ((0xfffffffbffffffffL & l) != 0L) jjCheckNAddStates(12, 14); break; case 29: if (curChar == 34) jjCheckNAdd(24); break; case 30: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 8) kind = 8; jjCheckNAddStates(0, 5); break; case 31: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 8) kind = 8; jjCheckNAdd(31); break; case 32: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddStates(15, 17); break; case 33: if (curChar == 46) jjCheckNAdd(34); break; case 34: if ((0x3ff000000000000L & l) != 0L) jjCheckNAddTwoStates(34, 18); break; case 35: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 43) kind = 43; jjCheckNAddTwoStates(35, 36); break; case 36: if (curChar == 46) jjCheckNAdd(37); break; case 37: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 43) kind = 43; jjCheckNAdd(37); break; default : break; } } while(i != startsAt); } else if (curChar < 128) { long l = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 0: if ((0x7fffffe87fffffeL & l) != 0L) { if (kind > 40) kind = 40; jjCheckNAddTwoStates(8, 9); } else if (curChar == 91) jjCheckNAddStates(18, 20); break; case 2: jjAddStates(9, 11); break; case 7: case 8: if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 40) kind = 40; jjCheckNAddTwoStates(8, 9); break; case 10: if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 40) kind = 40; jjstateSet[jjnewStateCnt++] = 10; break; case 14: jjAddStates(6, 8); break; case 18: if ((0x2000000020L & l) != 0L) jjAddStates(21, 22); break; case 22: if (curChar == 91) jjCheckNAddStates(18, 20); break; case 23: if ((0xffffffffdfffffffL & l) != 0L) jjCheckNAddTwoStates(23, 24); break; case 24: if (curChar == 93 && kind > 41) kind = 41; break; case 28: jjAddStates(12, 14); break; default : break; } } while(i != startsAt); } else { int hiByte = (int)(curChar >> 8); int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do { switch(jjstateSet[--i]) { case 2: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(9, 11); break; case 14: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(6, 8); break; case 23: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(23, 24); break; case 28: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(12, 14); break; default : break; } } while(i != startsAt); } if (kind != 0x7fffffff) { jjmatchedKind = kind; jjmatchedPos = curPos; kind = 0x7fffffff; } ++curPos; if ((i = jjnewStateCnt) == (startsAt = 38 - (jjnewStateCnt = startsAt))) break; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { break; } } if (jjmatchedPos > strPos) return curPos; int toRet = Math.max(curPos, seenUpto); if (curPos < toRet) for (i = toRet - Math.min(curPos, seenUpto); i-- > 0; ) try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { throw new Error("Internal Error : Please send a bug report."); } if (jjmatchedPos < strPos) { jjmatchedKind = strKind; jjmatchedPos = strPos; } else if (jjmatchedPos == strPos && jjmatchedKind > strKind) jjmatchedKind = strKind; return toRet; } static final int[] jjnextStates = { 31, 32, 33, 18, 35, 36, 13, 14, 15, 2, 3, 5, 27, 28, 29, 32, 33, 18, 23, 24, 25, 19, 20, 23, 24, }; private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) { switch(hiByte) { case 0: return ((jjbitVec2[i2] & l2) != 0L); default : if ((jjbitVec0[i1] & l1) != 0L) return true; return false; } } public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, null, null, null, null, null, null, "\54", null, null, null, null, "\73", "\50", "\51", "\133", "\135", "\77", "\173", "\175", "\174", "\53", "\55", "\52", "\57", "\136", "\75", "\74\76", "\74\75", "\76\75", "\74", "\76", "\46", "\45", null, null, null, null, null, null, null, null, null, }; public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { 0x10ffffffc2101L, }; static final long[] jjtoSkip = { 0x6L, }; protected JavaCharStream input_stream; private final int[] jjrounds = new int[38]; private final int[] jjstateSet = new int[76]; protected char curChar; public GeneratedFormulaParserTokenManager(JavaCharStream stream) { if (JavaCharStream.staticFlag) throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); input_stream = stream; } public GeneratedFormulaParserTokenManager(JavaCharStream stream, int lexState) { this(stream); SwitchTo(lexState); } public void ReInit(JavaCharStream stream) { jjmatchedPos = jjnewStateCnt = 0; curLexState = defaultLexState; input_stream = stream; ReInitRounds(); } private final void ReInitRounds() { int i; jjround = 0x80000001; for (i = 38; i-- > 0;) jjrounds[i] = 0x80000000; } public void ReInit(JavaCharStream stream, int lexState) { ReInit(stream); SwitchTo(lexState); } public void SwitchTo(int lexState) { if (lexState >= 1 || lexState < 0) throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); else curLexState = lexState; } protected Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); t.kind = jjmatchedKind; String im = jjstrLiteralImages[jjmatchedKind]; t.image = (im == null) ? input_stream.GetImage() : im; t.beginLine = input_stream.getBeginLine(); t.beginColumn = input_stream.getBeginColumn(); t.endLine = input_stream.getEndLine(); t.endColumn = input_stream.getEndColumn(); return t; } int curLexState = 0; int defaultLexState = 0; int jjnewStateCnt; int jjround; int jjmatchedPos; int jjmatchedKind; public Token getNextToken() { int kind; Token specialToken = null; Token matchedToken; int curPos = 0; EOFLoop : for (;;) { try { curChar = input_stream.BeginToken(); } catch(java.io.IOException e) { jjmatchedKind = 0; matchedToken = jjFillToken(); return matchedToken; } jjmatchedKind = 0x7fffffff; jjmatchedPos = 0; curPos = jjMoveStringLiteralDfa0_0(); if (jjmatchedKind != 0x7fffffff) { if (jjmatchedPos + 1 < curPos) input_stream.backup(curPos - jjmatchedPos - 1); if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) { matchedToken = jjFillToken(); return matchedToken; } else { continue EOFLoop; } } int error_line = input_stream.getEndLine(); int error_column = input_stream.getEndColumn(); String error_after = null; boolean EOFSeen = false; try { input_stream.readChar(); input_stream.backup(1); } catch (java.io.IOException e1) { EOFSeen = true; error_after = curPos <= 1 ? "" : input_stream.GetImage(); if (curChar == '\n' || curChar == '\r') { error_line++; error_column = 0; } else error_column++; } if (!EOFSeen) { input_stream.backup(1); error_after = curPos <= 1 ? "" : input_stream.GetImage(); } throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/JavaCharStream.java0000644000175000017500000003347311401240106030470 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; /** * An implementation of interface CharStream, where the stream is assumed to * contain only ASCII characters (with java-like unicode escape processing). */ public class JavaCharStream { public static final boolean staticFlag = false; static int hexval(final char c) throws java.io.IOException { switch(c) { case '0' : return 0; case '1' : return 1; case '2' : return 2; case '3' : return 3; case '4' : return 4; case '5' : return 5; case '6' : return 6; case '7' : return 7; case '8' : return 8; case '9' : return 9; case 'a' : case 'A' : return 10; case 'b' : case 'B' : return 11; case 'c' : case 'C' : return 12; case 'd' : case 'D' : return 13; case 'e' : case 'E' : return 14; case 'f' : case 'F' : return 15; } throw new java.io.IOException(); // Should never come here } public int bufpos = -1; int bufsize; int available; int tokenBegin; protected int[] bufline; protected int[] bufcolumn; protected int column = 0; protected int line = 1; protected boolean prevCharIsCR = false; protected boolean prevCharIsLF = false; protected java.io.Reader inputStream; protected char[] nextCharBuf; protected char[] buffer; protected int maxNextCharInd = 0; protected int nextCharInd = -1; protected int inBuf = 0; protected void ExpandBuff(final boolean wrapAround) { final char[] newbuffer = new char[bufsize + 2048]; final int[] newbufline = new int[bufsize + 2048]; final int[] newbufcolumn = new int[bufsize + 2048]; try { if (wrapAround) { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); buffer = newbuffer; System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); bufline = newbufline; System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); bufcolumn = newbufcolumn; bufpos += (bufsize - tokenBegin); } else { System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); buffer = newbuffer; System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); bufline = newbufline; System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); bufcolumn = newbufcolumn; bufpos -= tokenBegin; } } catch (Throwable t) { throw new Error(t.getMessage()); } available = (bufsize += 2048); tokenBegin = 0; } protected void FillBuff() throws java.io.IOException { if (maxNextCharInd == 4096) { maxNextCharInd = nextCharInd = 0; } try { final int i; if ((i = inputStream.read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) == -1) { inputStream.close(); throw new java.io.IOException(); } maxNextCharInd += i; return; } catch(java.io.IOException e) { if (bufpos != 0) { --bufpos; backup(0); } else { bufline[bufpos] = line; bufcolumn[bufpos] = column; } throw e; } } protected char ReadByte() throws java.io.IOException { if (++nextCharInd >= maxNextCharInd) { FillBuff(); } return nextCharBuf[nextCharInd]; } public char BeginToken() throws java.io.IOException { if (inBuf > 0) { --inBuf; if (++bufpos == bufsize) { bufpos = 0; } tokenBegin = bufpos; return buffer[bufpos]; } tokenBegin = 0; bufpos = -1; return readChar(); } protected void AdjustBuffSize() { if (available == bufsize) { if (tokenBegin > 2048) { bufpos = 0; available = tokenBegin; } else { ExpandBuff(false); } } else if (available > tokenBegin) { available = bufsize; } else if ((tokenBegin - available) < 2048) { ExpandBuff(true); } else { available = tokenBegin; } } protected void UpdateLineColumn(final char c) { column++; if (prevCharIsLF) { prevCharIsLF = false; line += (column = 1); } else if (prevCharIsCR) { prevCharIsCR = false; if (c == '\n') { prevCharIsLF = true; } else { line += (column = 1); } } switch (c) { case '\r' : prevCharIsCR = true; break; case '\n' : prevCharIsLF = true; break; case '\t' : column--; column += (8 - (column & 07)); break; default : break; } bufline[bufpos] = line; bufcolumn[bufpos] = column; } public char readChar() throws java.io.IOException { if (inBuf > 0) { --inBuf; if (++bufpos == bufsize) { bufpos = 0; } return buffer[bufpos]; } if (++bufpos == available) { AdjustBuffSize(); } char c; if ((buffer[bufpos] = c = ReadByte()) == '\\') { UpdateLineColumn(c); int backSlashCnt = 1; for (;;) // Read all the backslashes { if (++bufpos == available) { AdjustBuffSize(); } try { if ((buffer[bufpos] = c = ReadByte()) != '\\') { UpdateLineColumn(c); // found a non-backslash char. if ((c == 'u') && ((backSlashCnt & 1) == 1)) { if (--bufpos < 0) { bufpos = bufsize - 1; } break; } backup(backSlashCnt); return '\\'; } } catch(java.io.IOException e) { if (backSlashCnt > 1) { backup(backSlashCnt); } return '\\'; } UpdateLineColumn(c); backSlashCnt++; } // Here, we have seen an odd number of backslash's followed by a 'u' try { while ((c = ReadByte()) == 'u') { ++column; } buffer[bufpos] = c = (char)(hexval(c) << 12 | hexval(ReadByte()) << 8 | hexval(ReadByte()) << 4 | hexval(ReadByte())); column += 4; } catch(java.io.IOException e) { throw new Error("Invalid escape character at line " + line + " column " + column + '.'); } if (backSlashCnt == 1) { return c; } else { backup(backSlashCnt - 1); return '\\'; } } else { UpdateLineColumn(c); return (c); } } /** * @deprecated * @see #getEndColumn */ public int getColumn() { return bufcolumn[bufpos]; } /** * @deprecated * @see #getEndLine */ public int getLine() { return bufline[bufpos]; } public int getEndColumn() { return bufcolumn[bufpos]; } public int getEndLine() { return bufline[bufpos]; } public int getBeginColumn() { return bufcolumn[tokenBegin]; } public int getBeginLine() { return bufline[tokenBegin]; } public void backup(final int amount) { inBuf += amount; if ((bufpos -= amount) < 0) { bufpos += bufsize; } } public JavaCharStream(final java.io.Reader dstream, final int startline, final int startcolumn, final int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; available = bufsize = buffersize; buffer = new char[buffersize]; bufline = new int[buffersize]; bufcolumn = new int[buffersize]; nextCharBuf = new char[4096]; } public JavaCharStream(final java.io.Reader dstream, final int startline, final int startcolumn) { this(dstream, startline, startcolumn, 4096); } public JavaCharStream(final java.io.Reader dstream) { this(dstream, 1, 1, 4096); } public void ReInit(final java.io.Reader dstream, final int startline, final int startcolumn, final int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; if (buffer == null || buffersize != buffer.length) { available = bufsize = buffersize; buffer = new char[buffersize]; bufline = new int[buffersize]; bufcolumn = new int[buffersize]; nextCharBuf = new char[4096]; } prevCharIsLF = prevCharIsCR = false; tokenBegin = inBuf = maxNextCharInd = 0; nextCharInd = bufpos = -1; } public void ReInit(final java.io.Reader dstream, final int startline, final int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public void ReInit(final java.io.Reader dstream) { ReInit(dstream, 1, 1, 4096); } public JavaCharStream(final java.io.InputStream dstream, final int startline, final int startcolumn, final int buffersize) { this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public JavaCharStream(final java.io.InputStream dstream, final int startline, final int startcolumn) { this(dstream, startline, startcolumn, 4096); } public JavaCharStream(final java.io.InputStream dstream) { this(dstream, 1, 1, 4096); } public void ReInit(final java.io.InputStream dstream, final int startline, final int startcolumn, final int buffersize) { ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public void ReInit(final java.io.InputStream dstream, final int startline, final int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public void ReInit(final java.io.InputStream dstream) { ReInit(dstream, 1, 1, 4096); } public String GetImage() { if (bufpos >= tokenBegin) { return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); } else { return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1); } } public char[] GetSuffix(final int len) { final char[] ret = new char[len]; if ((bufpos + 1) >= len) { System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); } else { System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1); System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); } return ret; } public void Done() { nextCharBuf = null; buffer = null; bufline = null; bufcolumn = null; } /** * Method to adjust line and column numbers for the start of a token. */ public void adjustBeginLineColumn(int newLine, final int newCol) { int start = tokenBegin; final int len; if (bufpos >= tokenBegin) { len = bufpos - tokenBegin + inBuf + 1; } else { len = bufsize - tokenBegin + bufpos + 1 + inBuf; } int i = 0; int j = 0; int k; int nextColDiff; int columnDiff = 0; while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) { bufline[j] = newLine; nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; bufcolumn[j] = newCol + columnDiff; columnDiff = nextColDiff; i++; } if (i < len) { bufline[j] = newLine++; bufcolumn[j] = newCol + columnDiff; while (i++ < len) { if (bufline[j = start % bufsize] != bufline[++start % bufsize]) { bufline[j] = newLine++; } else { bufline[j] = newLine; } } } line = bufline[j]; column = bufcolumn[j]; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/Token.java0000644000175000017500000000672311401240106026713 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; /** * Describes the input token stream. */ public class Token { /** * An integer that describes the kind of this token. This numbering * system is determined by JavaCCParser, and a table of these numbers is * stored in the file ...Constants.java. */ public int kind; /** * beginLine and beginColumn describe the position of the first character * of this token; endLine and endColumn describe the position of the * last character of this token. */ public int beginLine; public int beginColumn; public int endLine; public int endColumn; /** * The string image of the token. */ public String image; /** * A reference to the next regular (non-special) token from the input * stream. If this is the last token from the input stream, or if the * token manager has not read tokens beyond this one, this field is * set to null. This is true only if this token is also a regular * token. Otherwise, see below for a description of the contents of * this field. */ public Token next; /** * This field is used to access special tokens that occur prior to this * token, but after the immediately preceding regular (non-special) token. * If there are no such special tokens, this field is set to null. * When there are more than one such special token, this field refers * to the last of these special tokens, which in turn refers to the next * previous special token through its specialToken field, and so on * until the first special token (whose specialToken field is null). * The next fields of special tokens refer to other special tokens that * immediately follow it (without an intervening regular token). If there * is no such token, this field is null. */ public Token specialToken; public Token() { } /** * Returns the image. */ public String toString() { return image; } /** * Returns a new Token object, by default. However, if you want, you * can create and return subclass objects based on the value of ofKind. * Simply add the cases to the switch for all those special cases. * For example, if you have a subclass of Token called IDToken that * you want to create if ofKind is ID, simlpy add something like : * * case MyParserConstants.ID : return new IDToken(); * * to the following switch statement. Then you can cast matchedToken * variable to the appropriate type and use it in your lexical actions. */ public static Token newToken(final int ofKind) { switch(ofKind) { default : return new Token(); } } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/FormulaParser.java0000644000175000017500000000627311401240106030415 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; import java.io.StringReader; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.operators.DefaultOperatorFactory; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; public class FormulaParser extends GeneratedFormulaParser { // This is my parser class private OperatorFactory operatorFactory; public FormulaParser() { super(new StringReader("")); operatorFactory = new DefaultOperatorFactory(); operatorFactory.initalize(LibFormulaBoot.getInstance().getGlobalConfig()); } protected OperatorFactory getOperatorFactory() { return operatorFactory; } /** @noinspection ThrowableInstanceNeverThrown,ThrowableResultOfMethodCallIgnored */ public ParseException generateParseException() { final ParseException parent = super.generateParseException(); return new FormulaParseException (parent.currentToken, parent.expectedTokenSequences, parent.tokenImage); } public LValue parse(final String formula) throws ParseException { if (formula == null) { throw new NullPointerException("Formula-text given must not be null."); } try { ReInit(new StringReader(formula)); final LValue expression = getExpression(); if (token.next != null && token.next.image.length() > 0) { throw new FormulaParseException("Extra content: '" + token.next.image + "'"); } return expression; } catch (ParseException pe) { if (pe instanceof FormulaParseException) { throw pe; } throw new FormulaParseException(pe); } } public static void main(final String[] args) throws ParseException { LibFormulaBoot.getInstance().start(); final FormulaParser formulaParser = new FormulaParser(); formulaParser.enable_tracing(); System.out.println ("LValue: " + formulaParser.parse("[\\n]")); System.out.println ("LValue: " + formulaParser.parse("[\"\"]")); final String s = "[\\\\]"; System.out.println(s); System.out.println ("LValue: " + formulaParser.parse(s)); System.out.println ("LValue: " + formulaParser.parse("T(\"a\\\\\") = \"a\"")); System.out.println ("LValue: " + formulaParser.parse("[\"[OK]\"]")); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/ParserTools.java0000644000175000017500000000433411401240106030104 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; /** * Creation-Date: 03.11.2006, 18:57:23 * * @author Thomas Morgner */ public class ParserTools { private ParserTools() { } public static String stripReferenceQuote(String s) { if (s.length() < 2) { return s; } final String strippedBraces = s.substring(1, s.length() - 1); if (strippedBraces.length() <= 2) { return strippedBraces; } if (strippedBraces.startsWith("\"") && strippedBraces.endsWith("\"")) { return stripQuote(strippedBraces); } return strippedBraces; } /** * Unconditionally removes the first and last character of the given string and also unquotes the quoted double-quotes. * * @param s the string to be stripped. * @return the stripped string. */ public static String stripQuote(final String s) { boolean encounteredQuote = false; final StringBuffer b = new StringBuffer(s.length() - 2); final int size = s.length() - 1; for (int i = 1; i < size; i++) { final char c = s.charAt(i); if (encounteredQuote) { if (c == '"') { encounteredQuote = false; continue; } } if (c == '"') { encounteredQuote = true; } else { encounteredQuote = false; } b.append(c); } return b.toString(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/ParseException.java0000644000175000017500000001620311401240106030556 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; /** * This exception is thrown when parse errors are encountered. * You can explicitly create objects of this exception type by * calling the method generateParseException in the generated * parser. * * You can modify this class to customize your error reporting * mechanisms so long as you retain the public fields. */ public class ParseException extends Exception { private static final long serialVersionUID = -6267349574816712060L; /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", * "expectedTokenSequences", and "tokenImage" set. The boolean * flag "specialConstructor" is also set to true to indicate that * this constructor was used to create this object. * This constructor calls its super class with the empty string * to force the "toString" method of parent class "Throwable" to * print the error message in the form: * ParseException: */ public ParseException(final Token currentTokenVal, final int[][] expectedTokenSequencesVal, final String[] tokenImageVal ) { super(""); specialConstructor = true; currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; } /** * The following constructors are for use by you for whatever * purpose you can think of. Constructing the exception in this * manner makes the exception behave in the normal way - i.e., as * documented in the class "Throwable". The fields "errorToken", * "expectedTokenSequences", and "tokenImage" do not contain * relevant information. The JavaCC generated code does not use * these constructors. */ public ParseException() { super(); specialConstructor = false; } public ParseException(final String message) { super(message); specialConstructor = false; } /** * This variable determines which constructor was used to create * this object and thereby affects the semantics of the * "getMessage" method (see below). */ protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If * this object has been created due to a parse error, the token * followng this token will (therefore) be the first error token. */ public Token currentToken; /** * Each entry in this array is an array of integers. Each array * of integers represents a sequence of tokens (by their ordinal * values) that is expected at this point of the parse. */ public int[][] expectedTokenSequences; /** * This is a reference to the "tokenImage" array of the generated * parser within which the parse error occurred. This array is * defined in the generated ...Constants interface. */ public String[] tokenImage; /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses * "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown * from the parser), then this method is called during the printing * of the final stack trace, and hence the correct error message * gets displayed. */ public String getMessage() { if (!specialConstructor) { return super.getMessage(); } String expected = ""; int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { expected += tokenImage[expectedTokenSequences[i][j]] + ' '; } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected += "..."; } expected += eol + " "; } String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) { retval += " "; } if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += add_escapes(tok.image); tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += '.' + eol; if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected; return retval; } /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ protected String add_escapes(final String str) { final StringBuffer retval = new StringBuffer(); for (int i = 0; i < str.length(); i++) { final char ch; switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { final String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/TokenMgrError.java0000644000175000017500000001364711401240106030376 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; /** * Although this class was autogenerated, we modified it to provide better * error reporting. Do not delete this file or let the auto-generator replace it, * or you will suffer compile errors later. */ public class TokenMgrError extends Error { /* * Ordinals for various reasons why an Error of this type can be thrown. */ /** * Lexical error occured. */ public static final int LEXICAL_ERROR = 0; /** * An attempt wass made to create a second instance of a static token manager. */ public static final int STATIC_LEXER_ERROR = 1; /** * Tried to change to an invalid lexical state. */ public static final int INVALID_LEXICAL_STATE = 2; /** * Detected (and bailed out of) an infinite loop in the token manager. */ public static final int LOOP_DETECTED = 3; private static final long serialVersionUID = -4952285962531386774L; /** * Indicates the reason why the exception is thrown. It will have one of the above 4 values. */ private int errorCode; private boolean EOFSeen; private int lexState; private int errorLine; private int errorColumn; private String errorAfter; private char curChar; private int reason; /** * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string */ protected static String addEscapes(final String str) { final StringBuffer retval = new StringBuffer(); for (int i = 0; i < str.length(); i++) { final char ch; switch (str.charAt(i)) { case 0: continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { final String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } /** * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error. * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this * error occured errorLine : line number when the error occured errorColumn : column number when the error occured * errorAfter : prefix that was seen before this error occured curchar : the offending character Note: You can * customize the lexical error message by modifying this method. */ protected static String LexicalError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final char curChar) { return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + (EOFSeen ? " " : ('\"' + addEscapes(String.valueOf(curChar)) + '\"') + " (" + (int) curChar + "), ") + "after : \"" + addEscapes(errorAfter) + '\"'); } /** * You can also modify the body of this method to customize your error messages. For example, cases like * LOOP_DETECTED and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like : *

* "Internal Error : Please file a bug report .... " *

* from this method for such cases in the release version of your parser. */ public String getMessage() { return super.getMessage(); } /* * Constructors of various flavors follow. */ public TokenMgrError() { } public TokenMgrError(final String message, final int reason) { super(message); errorCode = reason; } public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final char curChar, final int reason) { this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); this.EOFSeen = EOFSeen; this.lexState = lexState; this.errorLine = errorLine; this.errorColumn = errorColumn; this.errorAfter = errorAfter; this.curChar = curChar; this.reason = reason; } public int getErrorCode() { return errorCode; } public boolean isEOFSeen() { return EOFSeen; } public int getLexState() { return lexState; } public int getErrorLine() { return errorLine; } public int getErrorColumn() { return errorColumn; } public String getErrorAfter() { return errorAfter; } public char getCurChar() { return curChar; } public int getReason() { return reason; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/GeneratedFormulaParserConstants.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/GeneratedFormulaParserConstan0000644000175000017500000000412211401240106032631 0ustar renerene/* Generated By:JavaCC: Do not edit this line. GeneratedFormulaParserConstants.java */ package org.pentaho.reporting.libraries.formula.parser; public interface GeneratedFormulaParserConstants { int EOF = 0; int WHITESPACE = 1; int LETTER = 3; int NON_ZERO_DIGIT = 4; int DIGIT = 5; int HEX_DIGIT = 6; int BINARY_DIGIT = 7; int UNSIGNED_INTEGER = 8; int EXPONENT_PART = 9; int NEWLINE = 10; int NONQUOTE_CHARACTER = 11; int NONQUOTE_LOOKUP = 12; int COMMA = 13; int PERIOD = 14; int COLON = 15; int QUOTE = 16; int DQUOTE = 17; int SEMICOLON = 18; int L_PAREN = 19; int R_PAREN = 20; int L_BRACKET = 21; int R_BRACKET = 22; int QUEST = 23; int L_BRACE = 24; int R_BRACE = 25; int PIPE = 26; int PLUS = 27; int MINUS = 28; int MULT = 29; int DIV = 30; int POW = 31; int EQUALS = 32; int NOT_EQUALS = 33; int LT_EQUALS = 34; int GT_EQUALS = 35; int LT = 36; int GT = 37; int CONCAT = 38; int PERCENT = 39; int IDENTIFIER = 40; int COLUMN_LOOKUP = 41; int STRING_LITERAL = 42; int UNSIGNED_NUMERIC_LITERAL = 43; int EXACT_NUMERIC_LITERAL = 44; int APPROXIMATE_NUMERIC_LITERAL = 45; int MANTISSA = 46; int SIGN = 47; int NULL = 48; int DEFAULT = 0; String[] tokenImage = { "", "", "", "", "", "", "", "", "", "", "", "", "", "\",\"", "\".\"", "\":\"", "\"\\\'\"", "\"\\\"\"", "\";\"", "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"?\"", "\"{\"", "\"}\"", "\"|\"", "\"+\"", "\"-\"", "\"*\"", "\"/\"", "\"^\"", "\"=\"", "\"<>\"", "\"<=\"", "\">=\"", "\"<\"", "\">\"", "\"&\"", "\"%\"", "", "", "", "", "", "", "", "", "\"null\"", }; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/Parser.jj0000644000175000017500000002170011401240106026541 0ustar renereneoptions { LOOKAHEAD=1; UNICODE_INPUT=true; //IGNORE_CASE=true; FORCE_LA_CHECK=true; CACHE_TOKENS=true; STATIC=false; JAVA_UNICODE_ESCAPE=true; } PARSER_BEGIN(GeneratedFormulaParser) package org.pentaho.reporting.libraries.formula.parser; import java.math.BigDecimal; import java.util.ArrayList; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.FormulaFunction; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.PostfixTerm; import org.pentaho.reporting.libraries.formula.lvalues.PrefixTerm; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; import org.pentaho.reporting.libraries.formula.lvalues.Term; import org.pentaho.reporting.libraries.formula.lvalues.DefaultDataTable; import org.pentaho.reporting.libraries.formula.operators.InfixOperator; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; import org.pentaho.reporting.libraries.formula.operators.PostfixOperator; import org.pentaho.reporting.libraries.formula.operators.PrefixOperator; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; import org.pentaho.reporting.libraries.formula.lvalues.ParsePosition; public abstract class GeneratedFormulaParser { protected GeneratedFormulaParser () { } protected abstract OperatorFactory getOperatorFactory(); protected ParsePosition createPosition(Token token) { return new ParsePosition (token.beginLine, token.beginColumn, token.endLine, token.endColumn); } } PARSER_END(GeneratedFormulaParser) SKIP : { | <"--" (~["\n","\r"])* ("\n" | "\r" | "\r\n")> } TOKEN: { <#LETTER: (["a" - "z"]|["A" - "Z"]|["_"]|["$"])> | <#NON_ZERO_DIGIT: ["1"-"9"]> | <#DIGIT: ["0"-"9"]> | <#HEX_DIGIT: ( | ["A" - "F"] | ["a" - "f"])> | <#BINARY_DIGIT: ["0", "1"] > | )+)> | <#EXPONENT_PART: ( ("e" | "E") (("+" | "-")?) ()+ ) > | <#NEWLINE: (["\n","\r"] | "\n\r" | "\r\n")> | <#NONQUOTE_CHARACTER: ("\"\"" | ~[ "\""] )> | <#NONQUOTE_LOOKUP: ( ~["]"] )> | | <#PERIOD: "." > | <#COLON: ":" > | <#QUOTE: "'" > | <#DQUOTE: "\"" > | | | | | | | | | // | <#COMMENT_INTRODUCER: "--"> } TOKEN [IGNORE_CASE]: { // Operators for expressions: First the Infix-Operators. | | | | | "> | ="> | | "> | // Postfix operators: Only one for now. | // Prefix operators: Two defined at the moment, PLUS and MINUS (already covered). /// /// | ( | )* ( ( | )*)?)> | ()* ) | ( ()* ))> | ()* )> /// Defining numeric values. /// | | )> | <#EXACT_NUMERIC_LITERAL: ( ( )? | ( ))> | <#APPROXIMATE_NUMERIC_LITERAL: ( ["E","e"] ( ()? ))> | <#MANTISSA: > | <#SIGN: ["+","-"]> | } LValue getExpression () : { LValue retval = null; Term term = null; } { retval = getLValue () ( term = startTail (new Term(retval)) ( term = startTail (term) )* )? { if (term != null) { return term; } return retval; } } Term startTail (LValue retval) : { LValue val = null; InfixOperator op = null; Term ex = null; } { op = getInfixOperator() val = getLValue () { if (retval instanceof Term) { ex = (Term) retval; } else { ex = new Term (retval); } ex.add (op, val); return ex; } } LValue getLValue (): { Token value = null; LValue retval = null; PrefixOperator prefixOp = null; PostfixOperator postfixOp = null; } { ( prefixOp = getPrefixOperator() )? ( value = { retval = new ContextLookup (ParserTools.stripReferenceQuote(value.image), createPosition(value)); } | value = { retval = new StaticValue (ParserTools.stripQuote(value.image), TextType.TYPE, createPosition(value)); } | value = { retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER, createPosition(value)); } | value = { retval = new StaticValue (new BigDecimal (value.image), NumberType.GENERIC_NUMBER, createPosition(value)); } | { retval = new StaticValue (null, createPosition(value)); } | retval = parseArray() | value = { retval = parseFunction(value.image, createPosition(value)); } | { retval = getExpression (); } { if (retval instanceof Term == false) { retval = new Term (retval); } } ) ( postfixOp = getPostfixOperator() )? { if (postfixOp != null) { retval = new PostfixTerm(retval, postfixOp); } if (prefixOp != null) { retval = new PrefixTerm(prefixOp, retval); } return retval; } } LValue parseArray() : { ArrayList rows = new ArrayList(); LValue[] row = null; } { ( row = parseRow() { rows.add(row); } ) ( row = parseRow() { // should we check here for column count equality to the first row column count? // or do we give this responsability to a DefaultDataTable constructor? rows.add(row); } )* { LValue[][] table = (LValue[][])rows.toArray(new LValue[rows.size()][]); return new DefaultDataTable(table); } } LValue[] parseRow(): { ArrayList cols = new ArrayList();; LValue column = null; } { ( column = getExpression() { cols.add(column); } ) ( column = getExpression() { cols.add(column); } )* { return (LValue[]) cols.toArray(new LValue[cols.size()]); } } LValue parseFunction (String name, ParsePosition parsePosition) : { ArrayList params = new ArrayList(); LValue parameter = null; Token value = null; boolean parameterExpected = false; } { ( ( ( value = { parameterExpected = false; params.add(new StaticValue(null, createPosition(value))); } ) | ( parameter = getExpression() { parameterExpected = false; params.add(parameter); } ) ) ( ( value = { if (parameterExpected == true) { params.add(new StaticValue(null, createPosition(value))); } parameterExpected = true; } ) ( parameter = getExpression() { params.add(parameter); parameterExpected = false; } )? )* )? { if (parameterExpected == true) { params.add(new StaticValue(null, createPosition(value))); } if (params == null) { return new FormulaFunction(name, new LValue[0], parsePosition); } LValue[] paramVals = (LValue[]) params.toArray(new LValue[params.size()]); return new FormulaFunction(name, paramVals, parsePosition); } } PrefixOperator getPrefixOperator () : { Token value = null; } { ( value = | value = ) { return getOperatorFactory().createPrefixOperator(value.image); } } PostfixOperator getPostfixOperator () : { Token value = null; } { ( value = ) { return getOperatorFactory().createPostfixOperator(value.image); } } InfixOperator getInfixOperator () : { InfixOperator op = null; Token value = null; } { ( value = | value = | value = | value =

| value = | value = | value = | value = | value = | value = | value = | value = ) { return getOperatorFactory().createInfixOperator(value.image); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/parser/FormulaParseException.java0000644000175000017500000000472611401240106032113 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.parser; import org.pentaho.reporting.libraries.formula.lvalues.ParsePosition; /** * Todo: Document me! * * @author : Thomas Morgner */ public class FormulaParseException extends ParseException { private ParsePosition parsePosition; private TokenMgrError error; private Token currentTokenVal; private Throwable parent; public FormulaParseException(final String message) { super(message); } public FormulaParseException(final ParseException pe) { this(pe.currentToken, pe.expectedTokenSequences, pe.tokenImage); this.parent = pe; } public FormulaParseException(final Token currentTokenVal, final int[][] expectedTokenSequencesVal, final String[] tokenImageVal) { super(currentTokenVal, expectedTokenSequencesVal, tokenImageVal); this.currentTokenVal = currentTokenVal; parsePosition = new ParsePosition (currentTokenVal.beginLine, currentTokenVal.beginColumn, currentTokenVal.endLine, currentTokenVal.endColumn); } public Token getCurrentTokenVal() { return currentTokenVal; } public Throwable getParent() { return parent; } public FormulaParseException(final TokenMgrError error) { super(error.getMessage()); this.error = error; this.parent = error; this.parsePosition = new ParsePosition (error.getErrorLine(), error.getErrorColumn(), error.getErrorLine(), error.getErrorColumn()); } public TokenMgrError getError() { return error; } public ParsePosition getParsePosition() { return parsePosition; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/ContextEvaluationException.java0000644000175000017500000000230611401240110031656 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; /** * Creation-Date: Dec 5, 2006, 4:19:26 PM * * @author Thomas Morgner */ public class ContextEvaluationException extends EvaluationException { private static final long serialVersionUID = -2989428049599498476L; public ContextEvaluationException(final ErrorValue errorValue) { super(errorValue); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/LibFormulaInfo.java0000644000175000017500000000332211401240110027172 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import org.pentaho.reporting.libraries.base.LibBaseInfo; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; /** * Creation-Date: 31.10.2006, 12:31:15 * * @author Thomas Morgner */ public class LibFormulaInfo extends ProjectInformation { private static LibFormulaInfo instance; public static synchronized LibFormulaInfo getInstance() { if (instance == null) { instance = new LibFormulaInfo(); } return instance; } public LibFormulaInfo() { super("libformula", "LibFormula"); setLicenseName("LGPL"); setInfo("http://reporting.pentaho.org/libformula/"); setCopyright ("(C)opyright 2007-2010, by Pentaho Corporation and Contributors"); setBootClass("org.pentaho.reporting.libraries.formula.LibFormulaBoot"); addLibrary(LibBaseInfo.getInstance()); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/FormulaContext.java0000644000175000017500000000741111401240110027277 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import org.pentaho.reporting.libraries.formula.function.FunctionRegistry; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.base.config.Configuration; /** * The formula-context connects the formula functions with the outside world. The context can be used to resolve * external references, to query the configuration or to retrieve information about the formula-evaluation system. * * @author Thomas Morgner */ public interface FormulaContext { /** * Checks whether the external object referenced by name has changed. * * @param name the name that identifies the reference. * @return true, if the reference has changed, false otherwise. * @throws ContextEvaluationException if an error occurs. */ public boolean isReferenceDirty(Object name) throws ContextEvaluationException; /** * Resolves the given reference. How the name is interpreted by the outside system is an implementation detail. * * @param name the name that identifies the reference. * @return the resolved object. * @throws ContextEvaluationException if an error occurs. */ public Object resolveReference(Object name) throws ContextEvaluationException; /** * Queries the type of the given reference. How the name is interpreted by the outside system is an implementation * detail. This return a LibFormula type object matching the type of the object that would be returned by * resolveReference. * * @param name the name that identifies the reference. * @return the type of the resolved object. * @throws ContextEvaluationException if an error occurs. */ public Type resolveReferenceType(Object name) throws ContextEvaluationException; /** * Returns the localization context of this formula. The localization context can be used to query locale specific * configuration settings. * * @return the localization context. */ public LocalizationContext getLocalizationContext(); /** * Returns the local configuration of the formula. * * @return the local configuration. */ public Configuration getConfiguration(); /** * Returns the function registry. The function registry grants access to all formula-function implementations. * * @return the function registry. */ public FunctionRegistry getFunctionRegistry(); /** * Returns the type registry. The type registry contains all type information and allows to convert values between * different types. * * @return the function registry. */ public TypeRegistry getTypeRegistry(); /** * Returns the operator registry. The Operator-registry contains all operator-implementations. * * @return the operator registry. */ public OperatorFactory getOperatorFactory(); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/LibFormulaErrorValue.java0000644000175000017500000001112211401240110030362 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.util.Locale; import java.util.MissingResourceException; /** * Creation-Date: 31.10.2006, 13:07:37 * * @author Thomas Morgner */ public class LibFormulaErrorValue implements ErrorValue { public static final int ERROR_REFERENCE_NOT_RESOLVABLE = 499; /** A parse error */ public static final int ERROR_INVALID_CHARACTER = 501; /** Function name is invalid error code */ public static final int ERROR_INVALID_FUNCTION = 505; /** Function name is invalid error */ public static final LibFormulaErrorValue ERROR_INVALID_FUNCTION_VALUE = new LibFormulaErrorValue(ERROR_INVALID_FUNCTION); /** Parameter types are invalid error code */ public static final int ERROR_INVALID_ARGUMENT = 502; /** Parameter types are invalid error */ public static final LibFormulaErrorValue ERROR_INVALID_ARGUMENT_VALUE = new LibFormulaErrorValue(ERROR_INVALID_ARGUMENT); /** Parameter types are invalid error code */ public static final int ERROR_INVALID_AUTO_ARGUMENT = 666; /** Parameter types are invalid error */ public static final LibFormulaErrorValue ERROR_INVALID_AUTO_ARGUMENT_VALUE = new LibFormulaErrorValue(ERROR_INVALID_AUTO_ARGUMENT); public static final int ERROR_ILLEGAL_ARRAY = 667; public static final LibFormulaErrorValue ERROR_ILLEGAL_ARRAY_VALUE = new LibFormulaErrorValue(ERROR_ILLEGAL_ARRAY); /** Number arithmetic error code */ public static final int ERROR_ARITHMETIC = 503; /** Number arithmetic error */ public static final LibFormulaErrorValue ERROR_ARITHMETIC_VALUE = new LibFormulaErrorValue(ERROR_ARITHMETIC); /** Invalid number of arguments error code*/ public static final int ERROR_ARGUMENTS = 1; /** Invalid number of arguments error */ public static final LibFormulaErrorValue ERROR_ARGUMENTS_VALUE = new LibFormulaErrorValue(ERROR_ARGUMENTS); /** Occurence not found error code */ public static final int ERROR_NOT_FOUND = 504; /** Occurence not found error */ public static final LibFormulaErrorValue ERROR_NOT_FOUND_VALUE = new LibFormulaErrorValue(ERROR_NOT_FOUND); /** NA error code*/ public static final int ERROR_NA = 522; /** NA error*/ public static final LibFormulaErrorValue ERROR_NA_VALUE = new LibFormulaErrorValue(ERROR_NA); /** Unexpected error code */ public static final int ERROR_UNEXPECTED = 0; /** Unexpected error */ public static final LibFormulaErrorValue ERROR_UNEXPECTED_VALUE = new LibFormulaErrorValue(ERROR_UNEXPECTED); public static final int ERROR_MISSING_VARIABLE = 511; public static final ErrorValue ERROR_MISSING_ARGUMENT_VALUE = new LibFormulaErrorValue(ERROR_MISSING_VARIABLE); private int errorCode; private static final long serialVersionUID = 5945536244711597636L; public LibFormulaErrorValue(final int errorCode) { this.errorCode = errorCode; } public String getNamespace() { return "http://jfreereport.sourceforge.net/libformula"; } public int getErrorCode() { return errorCode; } public String getErrorMessage(final Locale locale) { try { return new Messages(locale).strictString("ErrorValue." + errorCode); } catch (MissingResourceException mre) { return new Messages(locale).formatMessage("ErrorValue.Generic", new Integer(errorCode)); } } public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof LibFormulaErrorValue)) { return false; } final LibFormulaErrorValue that = (LibFormulaErrorValue) o; if (errorCode != that.errorCode) { return false; } return true; } public int hashCode() { return errorCode; } public String toString() { return "LibFormulaErrorValue{" + "errorCode=" + errorCode + '}'; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/LibFormulaBoot.java0000644000175000017500000000357511401240110027214 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import org.pentaho.reporting.libraries.base.boot.AbstractBoot; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; /** * Creation-Date: 31.10.2006, 12:30:43 * * @author Thomas Morgner */ public class LibFormulaBoot extends AbstractBoot { public static final int GLOBAL_SCALE = 40; private static LibFormulaBoot instance; public static synchronized LibFormulaBoot getInstance() { if (instance == null) { instance = new LibFormulaBoot(); } return instance; } private LibFormulaBoot() { } protected Configuration loadConfiguration() { return createDefaultHierarchicalConfiguration ("/org/pentaho/reporting/libraries/formula/libformula.properties", "/libformula.properties", true, LibFormulaBoot.class); } protected void performBoot() { } protected ProjectInformation getProjectInfo() { return LibFormulaInfo.getInstance(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/0000755000175000017500000000000011401240106025311 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/0000755000175000017500000000000011401240106026242 5ustar renerene././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxAFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxAFunctionDescriptio0000644000175000017500000000402111401240106032544 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes MaxFunction function. * @see MaxFunction * * @author Cedric Pronzato * */ public class MaxAFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 495894247676188783L; public MaxAFunctionDescription() { super("MAXA", "org.pentaho.reporting.libraries.formula.function.math.MaxA-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/category.properties0000644000175000017500000000025611401240106032200 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Mathematical description=Contains functions that provide general mathematical functionality.libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageFunction.java0000644000175000017500000000526111401240106032171 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the average of the number sequence. * * @author Cedric Pronzato */ public class AverageFunction implements Function { private static final long serialVersionUID = -5057715506050635450L; private SumFunction sumFunction; public AverageFunction() { sumFunction = new SumFunction(); } protected AverageFunction(final SumFunction sumFunction) { this.sumFunction = sumFunction; } public String getCanonicalName() { return "AVERAGE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final TypeValuePair sum = sumFunction.evaluate(context, parameters); final Number n = context.getTypeRegistry().convertToNumber(sum.getType(), sum.getValue()); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal divident = NumberUtil.getAsBigDecimal(n); final BigDecimal divisor = new BigDecimal(parameters.getParameterCount()); final BigDecimal avg = NumberUtil.divide(divident, divisor); return new TypeValuePair(NumberType.GENERIC_NUMBER, avg); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sqrt-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sqrt-Function.properti0000644000175000017500000000027311401240106032546 0ustar renerenedisplay-name=SQRT description=Returns the square root of a number. parameter.0.display-name=number parameter.0.description=A positive value for which the square root is to be calculated. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/CosFunction.java0000644000175000017500000000477511401240106031354 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class CosFunction implements Function { public String getCanonicalName() { return "COS"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.cos(d))); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ExpFunction.java0000644000175000017500000000467511401240106031363 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * */ public class ExpFunction implements Function { public String getCanonicalName() { return "EXP"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.exp(d))); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/VarFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/VarFunctionDescription0000644000175000017500000000367411401240106032641 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes VarFunction function. * @see VarFunction * * @author ocke * */ public class VarFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public VarFunctionDescription() { super("VAR", "org.pentaho.reporting.libraries.formula.function.math.Var-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AsinFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AsinFunctionDescriptio0000644000175000017500000000370211401240106032615 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AsinFunction function. * @see AsinFunction * * @author ocke * */ public class AsinFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public AsinFunctionDescription() { super("ASIN", "org.pentaho.reporting.libraries.formula.function.math.Asin-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SinFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SinFunctionDescription0000644000175000017500000000367411401240106032642 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes SinFunction function. * @see SinFunction * * @author ocke * */ public class SinFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public SinFunctionDescription() { super("SIN", "org.pentaho.reporting.libraries.formula.function.math.Sin-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageAFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageAFunctionDescri0000644000175000017500000000436611401240106032511 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AverageFunction function. * @see AverageFunction * * @author Cedric Pronzato * */ public class AverageAFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 1190836694344833890L; public AverageAFunctionDescription() { super("AVERAGEA", "org.pentaho.reporting.libraries.formula.function.math.AverageA-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Acos-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Acos-Function.properti0000644000175000017500000000027511401240106032504 0ustar renerenedisplay-name=ACOS description=Returns the arccosine of a number. parameter.0.display-name=Number parameter.0.description=A value between -1 and 1 for which the arccosine is to be returned. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxFunctionDescription0000644000175000017500000000410311401240106032622 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes MaxFunction function. * @see org.pentaho.reporting.libraries.formula.function.math.MaxFunction * * @author Cedric Pronzato * */ public class MaxFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 495894247676188783L; public MaxFunctionDescription() { super("MAX", "org.pentaho.reporting.libraries.formula.function.math.Max-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PowerFunction.java0000644000175000017500000000543211401240106031713 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the value of one number raised to the power of another number. * * @author Cedric Pronzato */ public class PowerFunction implements Function { public PowerFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Type type2 = parameters.getType(1); final Object value2 = parameters.getValue(1); final Number result1 = context.getTypeRegistry().convertToNumber(type1, value1); final Number result2 = context.getTypeRegistry().convertToNumber(type2, value2); if (result1 == null || result2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double power = Math.pow(result1.doubleValue(), result2.doubleValue()); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(power)); } public String getCanonicalName() { return "POWER"; } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Even-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Even-Function.properti0000644000175000017500000000041111401240106032504 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=EVEN description=Rounds a positive number up and negative number down to the nearest even integer. parameter.0.display-name=Number parameter.0.description=The number to be rounded up. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AbsFunction.java0000644000175000017500000000513211401240106031321 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the absolute (nonnegative) of the value. * * @author Cedric Pronzato * */ public class AbsFunction implements Function { private static final long serialVersionUID = 5203290270060842214L; public AbsFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal num = NumberUtil.getAsBigDecimal(result); return new TypeValuePair(NumberType.GENERIC_NUMBER, num.abs()); } public String getCanonicalName() { return "ABS"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sum-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sum-Function.propertie0000644000175000017500000000041311401240106032522 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=SUM description=Returns the sum of all arguments. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 arguments whose total is to be calculated. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AbsFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AbsFunctionDescription0000644000175000017500000000370711401240106032613 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AbsFunction function. * @see AbsFunction * * @author Cedric Pronzato * */ public class AbsFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public AbsFunctionDescription() { super("ABS", "org.pentaho.reporting.libraries.formula.function.math.Abs-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumFunctionDescription0000644000175000017500000000431011401240106032641 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Creation-Date: 31.10.2006, 17:41:12 * * @author Thomas Morgner */ public class SumFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5844556222254305990L; public SumFunctionDescription() { super("SUM", "org.pentaho.reporting.libraries.formula.function.math.Sum-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MathFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MathFunctionCategory.j0000644000175000017500000000262111401240106032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class MathFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new MathFunctionCategory(); private MathFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.math.category"); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinAFunction.java0000644000175000017500000000232211401240106031436 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; /** * This function returns the minimum from a set of numbers. * * @author Cedric Pronzato */ public class MinAFunction extends MinFunction { public MinAFunction() { } protected boolean isStrictSequenceNeeded() { return false; } public String getCanonicalName() { return "MINA"; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinFunctionDescription0000644000175000017500000000402011401240106032616 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes MinFunction function. * @see MinFunction * * @author Cedric Pronzato * */ public class MinFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -2974454751189094698L; public MinFunctionDescription() { super("MIN", "org.pentaho.reporting.libraries.formula.function.math.Min-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumAFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumAFunctionDescriptio0000644000175000017500000000431311401240106032567 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Creation-Date: 31.10.2006, 17:41:12 * * @author Thomas Morgner */ public class SumAFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5844556222254305990L; public SumAFunctionDescription() { super("SUMA", "org.pentaho.reporting.libraries.formula.function.math.SumA-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ModFunction.java0000644000175000017500000000716211401240106031340 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import java.math.BigDecimal; /** * This function returns the remainder when one number is divided by another number. * * @author Cedric Pronzato */ public class ModFunction implements Function { private static final long serialVersionUID = -2492279311353854670L; public ModFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number number1 = typeRegistry.convertToNumber(type1, value1); if (number1 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal divided = NumberUtil.getAsBigDecimal(number1); final Type type2 = parameters.getType(1); final Object value2 = parameters.getValue(1); final Number number2 = typeRegistry.convertToNumber(type2, value2); if (number2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal divisor = NumberUtil.getAsBigDecimal(number2); if(divisor.signum() == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE); } final BigDecimal divide = new BigDecimal(divided.divide(divisor, 0, BigDecimal.ROUND_FLOOR).toString()); BigDecimal reminder = divided.subtract(divisor.multiply(divide)); if(divide.signum() == 0) { if((divided.signum() == -1 && divisor.signum() != -1) || (divisor.signum() == -1 && divided.signum() != -1)) { reminder = divided.add(divisor); } } return new TypeValuePair(NumberType.GENERIC_NUMBER, reminder); } public String getCanonicalName() { return "MOD"; } }././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log10FunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log10FunctionDescripti0000644000175000017500000000372311401240106032431 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes Log10Function function. * @see Log10Function * * @author Cedric Pronzato * */ public class Log10FunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public Log10FunctionDescription() { super("LOG10", "org.pentaho.reporting.libraries.formula.function.math.Log10-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SqrtFunction.java0000644000175000017500000000470411401240106031551 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the sqrt of the value. * * @author ocke * */ public class SqrtFunction implements Function { public String getCanonicalName() { return "SQRT"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.sqrt(d))); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcosFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcosFunctionDescriptio0000644000175000017500000000371611401240106032615 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AcosFunction function. * @see AcosFunction *a * @author Cedric Pronzato * */ public class AcosFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public AcosFunctionDescription() { super("ACOS", "org.pentaho.reporting.libraries.formula.function.math.Acos-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumAFunction.java0000644000175000017500000000227211401240106031463 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; /** * Creation-Date: 31.10.2006, 17:39:19 * * @author Thomas Morgner */ public class SumAFunction extends SumFunction { public SumAFunction() { } public String getCanonicalName() { return "SUMA"; } protected boolean isStrictSequenceNeeded() { return false; } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan-Function.properti0000644000175000017500000000026011401240106032474 0ustar renerenedisplay-name=ATAN description=Returns the arctangent of a number. parameter.0.display-name=Number parameter.0.description=The value for which the arctangent is to be returned. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/EvenFunction.java0000644000175000017500000000647511401240106031524 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the rounding of a number up to the nearest even * integer. * * @author Cedric Pronzato * */ public class EvenFunction implements Function { private static final long serialVersionUID = 2587673708222713810L; public EvenFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); final BigDecimal ret = compute(result); return new TypeValuePair(NumberType.GENERIC_NUMBER, ret); } private static BigDecimal compute(final Number result) { final int intValue; if (result.doubleValue() < 0) { intValue = (int) Math.floor(result.doubleValue()); } else { intValue = (int) Math.ceil(result.doubleValue()); } final BigDecimal ret; if (intValue % 2 == 0) // even { if (intValue == 0) { if (result.doubleValue() < 0) { ret = new BigDecimal(-2); } else if (result.doubleValue() > 0) { ret = new BigDecimal(2); } else { ret = new BigDecimal(0); } } else { ret = new BigDecimal(intValue); } } else // odd { if (result.doubleValue() < 0) { ret = new BigDecimal(intValue - 1); } else { ret = new BigDecimal(intValue + 1); } } return ret; } public String getCanonicalName() { return "EVEN"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Mod-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Mod-Function.propertie0000644000175000017500000000050311401240106032475 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MOD description=Calculates the remainder of a division. parameter.0.display-name=Dividend parameter.0.description=The number to be divided. parameter.1.display-name=Divisor parameter.1.description=The number by which the dividend is divided. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Average-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Average-Function.prope0000644000175000017500000000042411401240106032446 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=AVERAGE description=Returns the average of a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2;...are 1 to 30 numeric arguments representing a population sample. ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumA-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumA-Function.properti0000644000175000017500000000052211401240106032457 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=SUMA description=Returns the sum of all arguments. Numbers, text and logical values are included in the calculation too. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 arguments whose total is to be calculated. ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan2FunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan2FunctionDescripti0000644000175000017500000000371011401240106032510 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes Atan2Function function. * @see Atan2Function * * @author ocke * */ public class Atan2FunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public Atan2FunctionDescription() { super("ATAN2", "org.pentaho.reporting.libraries.formula.function.math.Atan2-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AsinFunction.java0000644000175000017500000000522511401240106031511 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class AsinFunction implements Function { public String getCanonicalName() { return "ASIN"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); if ( d < -1.0 || d > 1.0 ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.asin(d))); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AtanFunction.java0000644000175000017500000000500011401240106031471 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class AtanFunction implements Function { public String getCanonicalName() { return "ATAN"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.atan(d))); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log10Function.java0000644000175000017500000000552511401240106031504 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * @noinspection UnpredictableBigDecimalConstructorCall */ public class Log10Function implements Function { private static final BigDecimal LOG10BASE = new BigDecimal(StrictMath.log(10)); public String getCanonicalName() { return "LOG10"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = StrictMath.log(result.doubleValue()); final BigDecimal divide = new BigDecimal(d).divide(LOG10BASE, LibFormulaBoot.GLOBAL_SCALE, BigDecimal.ROUND_HALF_UP); return new TypeValuePair(NumberType.GENERIC_NUMBER, NumberUtil.removeTrailingZeros(divide)); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Power-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Power-Function.propert0000644000175000017500000000045311401240106032540 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=POWER description=Computes a number raised to the power by another number. parameter.0.display-name=Number parameter.0.description=The number. parameter.1.display-name=Power parameter.1.description=The power. ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Abs-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Abs-Function.propertie0000644000175000017500000000035011401240106032463 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ABS description=Absolute value of a number. parameter.0.display-name=Number parameter.0.description=The number whose absolute value is to be returned. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ExpFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ExpFunctionDescription0000644000175000017500000000367511401240106032646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes ExpFunction function. * @see expFunction *a * @author ocke * */ public class ExpFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public ExpFunctionDescription() { super("EXP", "org.pentaho.reporting.libraries.formula.function.math.Exp-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PiFunction.java0000644000175000017500000000406111401240106031164 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * */ public class PiFunction implements Function { private static final BigDecimal PI_VALUE = new BigDecimal(Math.PI); public String getCanonicalName() { return "PI"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount > 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, PI_VALUE); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxFunction.java0000644000175000017500000000733311401240106031346 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the maximum from a set of numbers. * * @author Cedric Pronzato */ public class MaxFunction implements Function { private static final BigDecimal ZERO = new BigDecimal(0.0); private static final long serialVersionUID = -836670420852371100L; public MaxFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount == 0) { return new TypeValuePair(NumberType.GENERIC_NUMBER, ZERO); } final TypeRegistry typeRegistry = context.getTypeRegistry(); BigDecimal last = null; for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++) { final Type type = parameters.getType(paramIdx); final Object value = parameters.getValue(paramIdx); final Sequence sequence = typeRegistry.convertToNumberSequence(type, value, isStrictSequenceNeeded()); while (sequence.hasNext()) { final LValue rawValue = sequence.nextRawValue(); if (rawValue == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final TypeValuePair nextValue = rawValue.evaluate(); final Number number = typeRegistry.convertToNumber(nextValue.getType(), nextValue.getValue()); final BigDecimal next = NumberUtil.getAsBigDecimal(number); if (last == null) { last = next; } else { if (last.compareTo(next) == -1) { last = next; } } } } if (last == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, last); } protected boolean isStrictSequenceNeeded() { return true; } public String getCanonicalName() { return "MAX"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SumFunction.java0000644000175000017500000000644011401240106031363 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.NumberSequence; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import java.math.BigDecimal; /** * Creation-Date: 31.10.2006, 17:39:19 * * @author Thomas Morgner */ public class SumFunction implements Function { public static final BigDecimal ZERO = new BigDecimal(0.0); private static final long serialVersionUID = -8604838130517819412L; public SumFunction() { } public String getCanonicalName() { return "SUM"; } protected boolean isStrictSequenceNeeded() { return true; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { BigDecimal computedResult = ZERO; final int parameterCount = parameters.getParameterCount(); if (parameterCount == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++) { final Type type = parameters.getType(paramIdx); final Object value = parameters.getValue(paramIdx); final NumberSequence sequence = typeRegistry.convertToNumberSequence(type, value, isStrictSequenceNeeded()); while (sequence.hasNext()) { computedResult = compute(sequence.nextNumber(), computedResult); } } return new TypeValuePair(NumberType.GENERIC_NUMBER, computedResult); } private BigDecimal compute(final Number value, final BigDecimal computedResult) { if (value == null) { // no-op .. return computedResult; } return computedResult.add(NumberUtil.getAsBigDecimal(value)); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcoshFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcoshFunctionDescripti0000644000175000017500000000371011401240106032600 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AcoshFunction function. * @see AcoshFunction * * @author ocke * */ public class AcoshFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public AcoshFunctionDescription() { super("ACOSH", "org.pentaho.reporting.libraries.formula.function.math.Acosh-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/OddFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/OddFunctionDescription0000644000175000017500000000371011401240106032606 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes OddFunction function. * @see OddFunction * * @author Cedric Pronzato * */ public class OddFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 3193808485135180085L; public OddFunctionDescription() { super("ODD", "org.pentaho.reporting.libraries.formula.function.math.Odd-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Acosh-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Acosh-Function.propert0000644000175000017500000000034011401240106032474 0ustar renerenedisplay-name=ACOSH description=Returns the inverse hyperbolic cosine of a number. parameter.0.display-name=Number parameter.0.description=A value greater than or equal to 1 for which the hyperbolic cosine is to be returned. ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Odd-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Odd-Function.propertie0000644000175000017500000000041011401240106032461 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ODD description=Rounds a positive number up and negative number down to the nearest odd integer. parameter.0.display-name=Number parameter.0.description=The number to be rounded up. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageA-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageA-Function.prop0000644000175000017500000000050611401240106032403 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=AVERAGEA description=Returns the average value for a sample. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;.. .are 1 to 30 arguments representing a sample taken from a basic total population. ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Asin-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Asin-Function.properti0000644000175000017500000000027111401240106032505 0ustar renerenedisplay-name=ASIN description=Returns the arcsine of a number. parameter.0.display-name=Number parameter.0.description=A value between -1 and 1 for which the arcsine is to be returned. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageAFunction.java0000644000175000017500000000227011401240106032267 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; /** * This function returns the average of the number sequence. * * @author Cedric Pronzato */ public class AverageAFunction extends AverageFunction { public AverageAFunction() { super(new SumAFunction()); } public String getCanonicalName() { return "AVERAGEA"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Pi-Function.properties0000644000175000017500000000010011401240106032502 0ustar renerenedisplay-name=PI description=Returns the value of the number Pi. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PiFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PiFunctionDescription.0000644000175000017500000000354011401240106032527 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes PiFunction function. * @see PiFunction * * @author ocke * */ public class PiFunctionDescription extends AbstractFunctionDescription { public PiFunctionDescription() { super("PI", "org.pentaho.reporting.libraries.formula.function.math.Pi-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return null; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return false; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Max-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Max-Function.propertie0000644000175000017500000000046611401240106032513 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MAX description=Returns the maximum value in a list of arguments. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments for which the largest number is to be determined. ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxA-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxA-Function.properti0000644000175000017500000000052211401240106032440 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MAXA description=Returns the maximum value in a list of arguments. Text is evaluated as zero. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments for which the largest number is to be determined. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/EvenFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/EvenFunctionDescriptio0000644000175000017500000000371611401240106032625 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes EvenFunction function. * @see EvenFunction * * @author Cedric Pronzato * */ public class EvenFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7912737754606057685L; public EvenFunctionDescription() { super("EVEN", "org.pentaho.reporting.libraries.formula.function.math.Even-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/VarFunction.java0000644000175000017500000000577311401240106031357 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import java.util.List; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class VarFunction implements Function { public String getCanonicalName() { return "VAR"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } double fSum = 0.0; double vSum = 0.0; double vMean = 0.0; double nValCount = 0.0; double[] values = new double[parameterCount]; for (int i = 0; i < parameterCount; i++) { final Type type1 = parameters.getType(i); final Object value1 = parameters.getValue(i); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); fSum += d; values[i] = d; nValCount++; } vMean = fSum / nValCount; for (int i = 0; i < nValCount; i++) vSum += (values[i] - vMean) * (values[i] - vMean); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(vSum / (nValCount - 1.0))); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinA-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinA-Function.properti0000644000175000017500000000050411401240106032436 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MINA description=Returns the smallest value in a list of arguments. Text is evaluated as zero. parameter.0.display-name=value parameter.0.description=Value 1; value 2;... are 1 to 30 arguments whose smallest number is to be determined. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcoshFunction.java0000644000175000017500000000500211401240106031645 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class AcoshFunction implements Function { public String getCanonicalName() { return "ACOSH"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.acos(d))); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AverageFunctionDescrip0000644000175000017500000000436311401240106032565 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AverageFunction function. * @see AverageFunction * * @author Cedric Pronzato * */ public class AverageFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 1190836694344833890L; public AverageFunctionDescription() { super("AVERAGE", "org.pentaho.reporting.libraries.formula.function.math.Average-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Ln-Function.properties0000644000175000017500000000031611401240106032514 0ustar renerenedisplay-name=LN description=Calculates the natural logarithm of a number. parameter.0.display-name=Number parameter.0.description=A value greater than 0 for which the natural logarithm is to be calculated. ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Cos-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Cos-Function.propertie0000644000175000017500000000026611401240106032510 0ustar renerenedisplay-name=COS description=Returns the cosine of a number. parameter.0.display-name=Number parameter.0.description=The angle in the radians for which the cosine is to be returned. ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log10-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log10-Function.propert0000644000175000017500000000031111401240106032317 0ustar renerenedisplay-name=LOG10 description=Calculates the base-10 logarithm of a number. parameter.0.display-name=Number parameter.0.description=A value greater than 0 for which the logarithm is to be calculated. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LnFunction.java0000644000175000017500000000467311401240106031176 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * */ public class LnFunction implements Function { public String getCanonicalName() { return "LN"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.log(d))); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan2-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan2-Function.propert0000644000175000017500000000041111401240106032403 0ustar renerenedisplay-name=ATAN2 description=Returns the arctangent for the specified coordinates. parameter.0.display-name=number_x parameter.0.description=The value for the x coordinate. parameter.1.display-name=number_y parameter.1.description=The value for the y coordinate. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ModFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/ModFunctionDescription0000644000175000017500000000377611401240106032633 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes ModFunction function. * @see org.pentaho.reporting.libraries.formula.function.math.ModFunction * * @author Cedric Pronzato * */ public class ModFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -7372799362385391577L; public ModFunctionDescription() { super("MOD", "org.pentaho.reporting.libraries.formula.function.math.Mod-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/OddFunction.java0000644000175000017500000000620311401240106031322 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the rounding a number up to the nearest odd integer, * where "up" means "away from 0". * * @author Cedric Pronzato * */ public class OddFunction implements Function { private static final long serialVersionUID = -7438242687193650125L; public OddFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); return new TypeValuePair(NumberType.GENERIC_NUMBER, compute(result)); } private static BigDecimal compute(final Number result) { final int intValue; final double v = result.doubleValue(); if (v < 0) { intValue = (int) Math.floor(v); } else { intValue = (int) Math.ceil(v); } final BigDecimal ret; if (intValue == 0) { if (v < 0) { ret = new BigDecimal(-1); } else { ret = new BigDecimal(1); } } else if (intValue % 2 != 0) // already odd { ret = new BigDecimal(intValue); } else // number is even { if (v < 0) { ret = new BigDecimal(intValue - 1); } else { ret = new BigDecimal(intValue + 1); } } return ret; } public String getCanonicalName() { return "ODD"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sin-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Sin-Function.propertie0000644000175000017500000000026011401240106032507 0ustar renerenedisplay-name=SIN description=Returns the sine of a number. parameter.0.display-name=number parameter.0.description=The angle in radians for which the sine is to be calculated. ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Min-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Min-Function.propertie0000644000175000017500000000047511401240106032511 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MIN description=Returns the minimum value in a list of arguments. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments for which the smallest number is to be determined. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinFunction.java0000644000175000017500000000722411401240106031343 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the minimum from a set of numbers. * * @author Cedric Pronzato * */ public class MinFunction implements Function { private static final long serialVersionUID = 255618510939561419L; public MinFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if(parameterCount == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); BigDecimal last = null; for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++) { final Type type = parameters.getType(paramIdx); final Object value = parameters.getValue(paramIdx); final Sequence sequence = typeRegistry.convertToNumberSequence(type, value, isStrictSequenceNeeded()); while (sequence.hasNext()) { final LValue rawValue = sequence.nextRawValue(); if (rawValue == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final TypeValuePair nextValue = rawValue.evaluate(); final Number number = typeRegistry.convertToNumber(nextValue.getType(), nextValue.getValue()); final BigDecimal next = NumberUtil.getAsBigDecimal(number); if(last == null) { last = next; } else { if(last.compareTo(next) == 1) { last = next; } } } } if(last == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, last); } protected boolean isStrictSequenceNeeded() { return true; } public String getCanonicalName() { return "MIN"; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/CosFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/CosFunctionDescription0000644000175000017500000000367411401240106032635 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes CosFunction function. * @see CosFunction * * @author ocke * */ public class CosFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public CosFunctionDescription() { super("COS", "org.pentaho.reporting.libraries.formula.function.math.Cos-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AcosFunction.java0000644000175000017500000000512511401240106031503 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * */ public class AcosFunction implements Function { public String getCanonicalName() { return "ACOS"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); if ( d < -1.0 || d > 1.0 ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.acos(d))); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LogFunction.java0000644000175000017500000000610311401240106031334 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the acos of the value. * * @author ocke * */ public class LogFunction implements Function { public String getCanonicalName() { return "LOG"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1 || parameterCount > 3 ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); if ( d <= 0 ) throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); double n = 10; if ( parameterCount == 2 ) { final Type type2 = parameters.getType(1); final Object value2 = parameters.getValue(1); final Number result2 = context.getTypeRegistry().convertToNumber(type2, value2); if (result2 == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } n = result2.doubleValue(); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.log(d)/Math.log(n))); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AtanFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/AtanFunctionDescriptio0000644000175000017500000000370211401240106032606 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AtanFunction function. * @see AtanFunction * * @author ocke * */ public class AtanFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public AtanFunctionDescription() { super("ATAN", "org.pentaho.reporting.libraries.formula.function.math.Atan-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PowerFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/PowerFunctionDescripti0000644000175000017500000000370511401240106032643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes PowerFunction function. * @see org.pentaho.reporting.libraries.formula.function.math.PowerFunction * * @author Cedric Pronzato * */ public class PowerFunctionDescription extends AbstractFunctionDescription { public PowerFunctionDescription() { super("POWER", "org.pentaho.reporting.libraries.formula.function.math.Power-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Exp-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Exp-Function.propertie0000644000175000017500000000023211401240106032511 0ustar renerenedisplay-name=EXP description=Calculates the exponent for basis e. parameter.0.display-name=Number parameter.0.description=The exponent applied to base e. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinAFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MinAFunctionDescriptio0000644000175000017500000000402411401240106032545 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes MinFunction function. * @see MinFunction * * @author Cedric Pronzato * */ public class MinAFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -2974454751189094698L; public MinAFunctionDescription() { super("MINA", "org.pentaho.reporting.libraries.formula.function.math.MinA-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LnFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LnFunctionDescription.0000644000175000017500000000366611401240106032541 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes LnFunction function. * @see LnFunction * * @author ocke * */ public class LnFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public LnFunctionDescription() { super("LN", "org.pentaho.reporting.libraries.formula.function.math.Ln-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Var-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Var-Function.propertie0000644000175000017500000000034111401240106032506 0ustar renerenedisplay-name=VAR description=Calculates the variance based on a sample. parameter.0.display-name=number parameter.0.description=Number 1, number 2, ... are 1 to 30 numerical arguments which portray a sample of a population. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SqrtFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SqrtFunctionDescriptio0000644000175000017500000000370211401240106032654 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes SqrtFunction function. * @see SqrtFunction * * @author ocke * */ public class SqrtFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public SqrtFunctionDescription() { super("SQRT", "org.pentaho.reporting.libraries.formula.function.math.Sqrt-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Log-Function.propertie0000644000175000017500000000043211401240106032500 0ustar renerenedisplay-name=LOG description=Calculates the logarithm to any specified base. parameter.0.display-name=Number parameter.0.description=A value greater than 0 for which the logarithm is to be calculated. parameter.1.display-name=Base parameter.1.description=The base of the logarithm. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/SinFunction.java0000644000175000017500000000500611401240106031345 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class SinFunction implements Function { public String getCanonicalName() { return "SIN"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d = result.doubleValue(); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.sin(d))); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/MaxAFunction.java0000644000175000017500000000232211401240106031440 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; /** * This function returns the maximum from a set of numbers. * * @author Cedric Pronzato */ public class MaxAFunction extends MaxFunction { public MaxAFunction() { } protected boolean isStrictSequenceNeeded() { return false; } public String getCanonicalName() { return "MAXA"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/Atan2Function.java0000644000175000017500000000602211401240106031560 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns the acos of the value. * * @author ocke * */ public class Atan2Function implements Function { public String getCanonicalName() { return "ATAN2"; } public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Type type2 = parameters.getType(0); final Object value2 = parameters.getValue(0); final Number result2 = context.getTypeRegistry().convertToNumber(type2, value2); if (result2 == null ) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final double d1 = result.doubleValue(); final double d2 = result2.doubleValue(); if ( d1 == 0 || d2 == 0 ) throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(Math.atan2(d1,d2))); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LogFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/math/LogFunctionDescription0000644000175000017500000000367611401240106032634 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes AtanFunction function. * @see AtanFunction * * @author ocke * */ public class LogFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public LogFunctionDescription() { super("LOG", "org.pentaho.reporting.libraries.formula.function.math.Log-Function"); } public FunctionCategory getCategory() { return MathFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/AbstractFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/AbstractFunctionDescription0000644000175000017500000000617311401240106032720 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.Locale; import java.util.ResourceBundle; import java.util.MissingResourceException; /** * Creation-Date: 04.11.2006, 18:30:33 * * @author Thomas Morgner */ public abstract class AbstractFunctionDescription implements FunctionDescription { private String bundleName; private String cannonicalName; private static final long serialVersionUID = 6174633076234746415L; protected AbstractFunctionDescription(final String cannonicalName, final String bundleName) { if (bundleName == null) { throw new NullPointerException(); } if (cannonicalName == null) { throw new NullPointerException(); } this.bundleName = bundleName; this.cannonicalName = cannonicalName; } public String getCanonicalName() { return cannonicalName; } public boolean isVolatile() { return false; } /** * Returns the default value for an optional parameter. If the value returned * here is null, then this either means, that the parameter is mandatory or * that the default value is computed by the expression itself. * * @param position * @return null. */ public Object getDefaultValue(final int position) { return null; } public boolean isInfiniteParameterCount() { return false; } protected ResourceBundle getBundle(final Locale locale) { try { return ResourceBundle.getBundle(bundleName, locale); } catch (final MissingResourceException mre) { // ignore the exception, fall back to explicit english locales. Fail, if that fails too. return ResourceBundle.getBundle(bundleName, Locale.ENGLISH); } } public String getDisplayName(final Locale locale) { return getBundle(locale).getString("display-name"); } public String getDescription(final Locale locale) { return getBundle(locale).getString("description"); } public String getParameterDisplayName(final int position, final Locale locale) { return getBundle(locale).getString("parameter." + position + ".display-name"); } public String getParameterDescription(final int position, final Locale locale) { return getBundle(locale).getString("parameter." + position + ".description"); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/0000755000175000017500000000000011401240106026275 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/category.properties0000644000175000017500000000024111401240106032225 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Text description=Contains functions that provide text processing functionality.././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReplaceFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReplaceFunctionDescrip0000644000175000017500000000415611401240106032621 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes ReplaceFunction function. * @see ReplaceFunction * * @author Cedric Pronzato * */ public class ReplaceFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -7429162918022452367L; public ReplaceFunctionDescription() { super("REPLACE", "org.pentaho.reporting.libraries.formula.function.text.Replace-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 4; } public Type getParameterType(final int position) { if(position == 0 || position == 3) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Upper-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Upper-Function.propert0000644000175000017500000000037311401240106032573 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=UPPER description=Converts text to uppercase. parameter.0.display-name=text parameter.0.description=The text in which lower case letters are to be converted to capitals. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/FindFunction.java0000644000175000017500000000730511401240106031533 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the starting position of a given text in the given text. * * @author Cedric Pronzato */ public class FindFunction implements Function { private static final long serialVersionUID = -6581390286475368968L; public FindFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 2 || parameterCount > 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type searchType = parameters.getType(0); final Object searchValue = parameters.getValue(0); final Type textType = parameters.getType(1); final Object textValue = parameters.getValue(1); Type indexType = null; Object indexValue = null; if (parameterCount == 3) { indexType = parameters.getType(2); indexValue = parameters.getValue(2); if (indexType == null || indexValue == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_MISSING_ARGUMENT_VALUE); } } final String search = typeRegistry.convertToText(searchType, searchValue); final String text = typeRegistry.convertToText(textType, textValue); if (search == null || text == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } int indexFrom = 0; if (indexType != null) { final Number n = typeRegistry.convertToNumber(indexType, indexValue); if (n.intValue() >= 1) { indexFrom = n.intValue() - 1; } else { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } } final int index = text.indexOf(search, indexFrom); if (index < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NOT_FOUND_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(index + 1)); } public String getCanonicalName() { return "FIND"; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LeftFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LeftFunctionDescriptio0000644000175000017500000000420111401240106032643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes LeftFunction function. * @see LeftFunction * * @author Cedric Pronzato * */ public class LeftFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6885086567123440746L; public LeftFunctionDescription() { super("LEFT", "org.pentaho.reporting.libraries.formula.function.text.Left-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { if(position == 0) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { if(position == 2) { return false; } return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TrimFunction.java0000644000175000017500000000667411401240106031576 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given text free of leading spaces. * Removes all leading and trailing spaces and all extra spaces inside the text. * * @author Cedric Pronzato * @link http://mercury.ccil.org/%7Ecowan/OF/textfuncs.html */ public class TrimFunction implements Function { private static final long serialVersionUID = 7379670108270974597L; public TrimFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String result = context.getTypeRegistry().convertToText(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // remove all unnecessary spaces .. // we dont use regexps, because they are JDK 1.4, but this library is aimed // for JDK 1.2.2 final char[] chars = result.toCharArray(); final StringBuffer b = new StringBuffer(chars.length); boolean removeNextWs = true; for (int i = 0; i < chars.length; i++) { final char c = chars[i]; if (Character.isWhitespace(c)) { if (removeNextWs) { continue; } b.append(c); removeNextWs = true; continue; } b.append(c); removeNextWs = false; } // now check whether the last char is a whitespace and remove that one // if neccessary final String trimmedResult; if (removeNextWs && b.length() > 0) { trimmedResult = b.substring(0, b.length() - 1); } else { trimmedResult = b.toString(); } return new TypeValuePair(TextType.TYPE, trimmedResult); } public String getCanonicalName() { return "TRIM"; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LowerFunction.java0000644000175000017500000000474111401240106031744 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given text in lower case. * * @author Cedric Pronzato * */ public class LowerFunction implements Function { private static final long serialVersionUID = -7121097352643128092L; public LowerFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String result = context.getTypeRegistry().convertToText(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(TextType.TYPE, result.toLowerCase(context.getLocalizationContext().getLocale())); } public String getCanonicalName() { return "LOWER"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Len-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Len-Function.propertie0000644000175000017500000000035511401240106032534 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=LEN description=Calculates length of a text string. parameter.0.display-name=text parameter.0.description=The text in which the length is to be determined. ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/RightFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/RightFunctionDescripti0000644000175000017500000000421011401240106032647 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes RightFunction function. * @see RightFunction * * @author Cedric Pronzato * */ public class RightFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -1227750116961019328L; public RightFunctionDescription() { super("RIGHT", "org.pentaho.reporting.libraries.formula.function.text.Right-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { if(position == 0) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { if(position == 2) { return false; } return true; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Text-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Text-Function.properti0000644000175000017500000000052011401240106032567 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=TEXT description=Converts a number to text according to a given format. parameter.0.display-name=number parameter.0.description=The numeric value to be converted. parameter.1.display-name=Format parameter.1.description=The text that describes the format. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ExactFunction.java0000644000175000017500000000754711401240106031727 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.TypeConversionException; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function reports if two given text values are exactly equal using a case-sensitive comparison. * * @author Cedric Pronzato * */ public class ExactFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = -6303315343568906710L; public ExactFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type textType1 = parameters.getType(0); final Object textValue1 = parameters.getValue(0); final Type textType2 = parameters.getType(1); final Object textValue2 = parameters.getValue(1); // Numerical comparisons ignore "trivial" differences that // depend only on numeric precision of finite numbers. // This fixes the common rounding errors, that are encountered when computing "((1/3) * 3)", which results // in 0.99999 and not 1, as expected. try { final Number number1 = typeRegistry.convertToNumber(textType1, textValue1); final Number number2 = typeRegistry.convertToNumber(textType2, textValue2); final double delta = Math.abs(Math.abs(number1.doubleValue()) - Math.abs(number2.doubleValue())); if(delta < 0.00005) { return RETURN_TRUE; } return RETURN_FALSE; } catch(TypeConversionException tce) { // Ignore, try to compare them as strings .. } final String text1 = typeRegistry.convertToText(textType1, textValue1); final String text2 = typeRegistry.convertToText(textType2, textValue2); if(text1 == null || text2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (text1.equals(text2)) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "EXACT"; } }././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ExactFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ExactFunctionDescripti0000644000175000017500000000401211401240106032636 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes ExactFunction function. * @see ExactFunction * * @author Cedric Pronzato * */ public class ExactFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6387173839128572562L; public ExactFunctionDescription() { super("EXACT", "org.pentaho.reporting.libraries.formula.function.text.Exact-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return TextType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Unicode-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Unicode-Function.prope0000644000175000017500000000035511401240106032520 0ustar renerenedisplay-name=UNICODE description=Returns the numeric code for the first Unicode character in a text string. parameter.0.display-name=text parameter.0.description=This is the text for which the code of the first character is to be found. ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UpperFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UpperFunctionDescripti0000644000175000017500000000400211401240106032664 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes UpperFunction function. * @see UpperFunction * * @author Cedric Pronzato * */ public class UpperFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 2096398786776380395L; public UpperFunctionDescription() { super("UPPER", "org.pentaho.reporting.libraries.formula.function.text.Upper-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Mid-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Mid-Function.propertie0000644000175000017500000000071011401240106032522 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MID description=Returns a partial text string of a text. parameter.0.display-name=text parameter.0.description=The text in which partial words are to be determined. parameter.1.display-name=start parameter.1.description=The position from which the part word is to be determined. parameter.2.display-name=number parameter.2.description=The number of characters for the text. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LenFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LenFunctionDescription0000644000175000017500000000400411401240106032646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes LenFunction function. * @see LenFunction * * @author Cedric Pronzato * */ public class LenFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 2266930971663214932L; public LenFunctionDescription() { super("LEN", "org.pentaho.reporting.libraries.formula.function.text.Len-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LenFunction.java0000644000175000017500000000476211401240106031375 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the lengh in characters of the given value. * * @author Cedric Pronzato * */ public class LenFunction implements Function { private static final long serialVersionUID = 9051363583066740780L; public LenFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String result = context.getTypeRegistry().convertToText(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(result.length())); } public String getCanonicalName() { return "LEN"; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunction.jav0000644000175000017500000001110011401240106032651 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns text where an old text is substituted with a new text. * * @author Cedric Pronzato */ public class SubstituteFunction implements Function { private static final long serialVersionUID = -1557813953499941337L; public SubstituteFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 3 || parameterCount > 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final Type oldTextType = parameters.getType(1); final Object oldTextValue = parameters.getValue(1); final String text = typeRegistry.convertToText(textType, textValue); final String oldText = typeRegistry.convertToText(oldTextType, oldTextValue); if (oldText.length() == 0) { return new TypeValuePair(TextType.TYPE, text); } final Type newTextType = parameters.getType(2); final Object newTextValue = parameters.getValue(2); final String newText = typeRegistry.convertToText(newTextType, newTextValue); if (parameterCount == 3) { int oldIndex = 0; int index = text.indexOf(oldText); if (index == -1) { return new TypeValuePair(TextType.TYPE, text); } final StringBuffer result = new StringBuffer(text.length()); while (index >= 0) { result.append(text.substring(oldIndex, index)); result.append(newText); oldIndex = index + oldText.length(); index = text.indexOf(oldText, oldIndex); } result.append(text.substring(oldIndex)); return new TypeValuePair(TextType.TYPE, result.toString()); } // Instead of replacing all occurences, the user only requested to replace // a specific one. final Type whichType = parameters.getType(3); final Object whichValue = parameters.getValue(3); final Number n = typeRegistry.convertToNumber(whichType, whichValue); if (n.doubleValue() < 1) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final int nthOccurence = n.intValue(); int index = text.indexOf(oldText); if (index == -1) { return new TypeValuePair(TextType.TYPE, text); } String result = text; int counter = 1; while (index >= 0) { if (counter == nthOccurence) { final StringBuffer buffer = new StringBuffer(result); buffer.replace(index, index + oldText.length(), newText); result = buffer.toString(); return new TypeValuePair(TextType.TYPE, result); } index = result.indexOf(oldText, index + 1); counter += 1; } return new TypeValuePair(TextType.TYPE, result); } public String getCanonicalName() { return "SUBSTITUTE"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/URLEncodeFunction.java0000644000175000017500000000662011401240106032432 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.io.UnsupportedEncodingException; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; import org.pentaho.reporting.libraries.formula.util.URLEncoder; /** * This function encodes a given text using the URL-Encoding schema. An optional * second parameter can be given to specify the character encoding that should * be used when converting text to bytes. * * @author Cedric Pronzato */ public class URLEncodeFunction implements Function { private static final long serialVersionUID = 646428113862238221L; public URLEncodeFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final String textResult = context.getTypeRegistry().convertToText(textType, textValue); if(textResult == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final String encodingResult; if(parameterCount == 2) { final Type encodingType = parameters.getType(1); final Object encodingValue = parameters.getValue(1); encodingResult = context.getTypeRegistry().convertToText(encodingType, encodingValue); if(encodingResult == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } } else { encodingResult = "ISO-8859-1"; } try { return new TypeValuePair (TextType.TYPE, URLEncoder.encode(textResult, encodingResult)); } catch(UnsupportedEncodingException use) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } } public String getCanonicalName() { return "URLENCODE"; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Find-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Find-Function.properti0000644000175000017500000000070011401240106032523 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=FIND description=Looks for a string of text within another (case sensitive) parameter.0.display-name=find_text parameter.0.description=The text to be found. parameter.1.display-name=text parameter.1.description=The text in which a search is to be made. parameter.2.display-name=position parameter.2.description=The position in the text from which the search starts. ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TextFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TextFunctionCategory.j0000644000175000017500000000262111401240106032601 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class TextFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new TextFunctionCategory(); private TextFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.text.category"); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MidFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MidFunctionDescription0000644000175000017500000000410511401240106032643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes MidFunction function. * @see MidFunction * * @author Cedric Pronzato * */ public class MidFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 2207257367525146799L; public MidFunctionDescription() { super("MID", "org.pentaho.reporting.libraries.formula.function.text.Mid-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { if(position == 0) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TFunctionDescription.j0000644000175000017500000000375211401240106032574 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes TFunction function. * @see TFunction * * @author Cedric Pronzato * */ public class TFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7982024479324130664L; public TFunctionDescription() { super("T", "org.pentaho.reporting.libraries.formula.function.text.T-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Substitute-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Substitute-Function.pr0000644000175000017500000000110511401240106032573 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=SUBSTITUTE description=Substitutes new text for old text in a string. parameter.0.display-name=text parameter.0.description=The text in which partial words are to be replaced. parameter.1.display-name=search_text parameter.1.description=The partial string to be (repeatedly) replaced. parameter.2.display-name=new text parameter.2.description=The text which is to replace the text string. parameter.3.display-name=occurrence parameter.3.description=Which occurence of the old text is to be replaced. ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicodeFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicodeFunctionDescrip0000644000175000017500000000366511401240106032640 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; public class UnicodeFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6842849033225519941L; public UnicodeFunctionDescription() { super("UNICODE", "org.pentaho.reporting.libraries.formula.function.text.Unicode-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return TextType.TYPE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TFunction.java0000644000175000017500000000467311401240106031063 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given text value or a zero lenght string for non text type. * * @author Cedric Pronzato * */ public class TFunction implements Function { private static final TypeValuePair EMPTY_STRING = new TypeValuePair(TextType.TYPE, ""); private static final long serialVersionUID = 5792821944649583654L; public TFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); if(type1 instanceof TextType || value1 instanceof String) { return new TypeValuePair(TextType.TYPE, value1); } else { return EMPTY_STRING; } } public String getCanonicalName() { return "T"; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/URLEncode-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/URLEncode-Function.pro0000644000175000017500000000067511401240106032372 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=URLENCODE description=Applies URL-Encoding to a text given in the first parameter \ using the encoding specified in the second parameter. If no encoding is \ given, ISO-8859-1 is assumed. parameter.0.description=The text that should be encoded. parameter.0.display-name=Text parameter.1.description=The Encoding to be used. parameter.1.display-name=Encoding libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/T-Function.properties0000644000175000017500000000021111401240106032373 0ustar renerenedisplay-name=T description=Converts a value into text. parameter.0.display-name=value parameter.0.description=The value to be converted. ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Right-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Right-Function.propert0000644000175000017500000000055611401240106032560 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=RIGHT description=Returns the last character or characters of a text. parameter.0.display-name=text parameter.0.description=The text in which the end partial words are to be determined. parameter.1.display-name=number parameter.1.description=The number of characters for the end text. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Message-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Message-Function.prope0000644000175000017500000000051211401240106032511 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MESSAGE description=Formats the values using the given message-format. parameter.0.display-name=Format parameter.0.description=The text that describes the format. parameter.1.display-name=Parameter parameter.1.description=The value to be formatted. ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Left-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Left-Function.properti0000644000175000017500000000056111401240106032542 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=LEFT description=Returns the first character or characters of a text. parameter.0.display-name=text parameter.0.description=The text where the initial partial words are to be determined. parameter.1.display-name=number parameter.1.description=The number of characters for the start text. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReplaceFunction.java0000644000175000017500000000726511401240106032233 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns text where an old text is substituted with a new text. * * @author Cedric Pronzato */ public class ReplaceFunction implements Function { private static final long serialVersionUID = -7678830657739807780L; public ReplaceFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type newTextType = parameters.getType(3); final Object newTextValue = parameters.getValue(3); final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final Type startType = parameters.getType(1); final Object startValue = parameters.getValue(1); final Type lengthType = parameters.getType(2); final Object lengthValue = parameters.getValue(2); final String newText = typeRegistry.convertToText(newTextType, newTextValue); final String text = typeRegistry.convertToText(textType, textValue); final Number start = typeRegistry.convertToNumber(startType, startValue); if (start.intValue() <= 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Number length = typeRegistry.convertToNumber(lengthType, lengthValue); if (length.intValue() < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final String result1 = MidFunction.process(text, 1, (start.intValue() - 1)); final String result2 = MidFunction.process(text, (start.intValue() + length.intValue()), (text.length())); final StringBuffer buffer = new StringBuffer(result1.length() + newText.length() + result2.length()); buffer.append(result1); buffer.append(newText); buffer.append(result2); return new TypeValuePair(TextType.TYPE, buffer.toString()); } public String getCanonicalName() { return "REPLACE"; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TextFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TextFunctionDescriptio0000644000175000017500000000364311401240106032706 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; public class TextFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6842849033225519941L; public TextFunctionDescription() { super("TEXT", "org.pentaho.reporting.libraries.formula.function.text.Text-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return position == 0; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/RightFunction.java0000644000175000017500000000631411401240106031727 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns a selected number of text characters from the right.
* This function depends on MidFunction. * * @see MidFunction * * @author Cedric Pronzato * */ public class RightFunction implements Function { private static final long serialVersionUID = 1637903638146059530L; public RightFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1 || parameterCount > 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final String text = typeRegistry.convertToText(textType, textValue); final int length; if(parameterCount == 2) { final Number lengthVal = typeRegistry.convertToNumber(parameters.getType(1), parameters.getValue(1)); if (lengthVal.doubleValue() < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } length = lengthVal.intValue(); } else { length = 1; } if(text == null || length < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } int s = text.length()-length +1; if(s < 1) { s = 1; } return new TypeValuePair(TextType.TYPE, MidFunction.process(text, s, length)); } public String getCanonicalName() { return "RIGHT"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MessageFunction.java0000644000175000017500000000325411401240106032236 0ustar renerenepackage org.pentaho.reporting.libraries.formula.function.text; import java.text.MessageFormat; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 11.11.2009 * Time: 13:02:29 * * @author Thomas Morgner. */ public class MessageFunction implements Function { public String getCanonicalName() { return "MESSAGE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String message = context.getTypeRegistry().convertToText(type1, value1); final MessageFormat format = new MessageFormat(message, context.getLocalizationContext().getLocale()); final Object[] args = new Object[parameterCount - 1]; for (int i = 1; i < parameterCount; i += 1) { args[i - 1] = parameters.getValue(i); } return new TypeValuePair(TextType.TYPE, format.format(args)); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReptFunction.java0000644000175000017500000000577411401240106031575 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns text repeated Count times. * * @author Cedric Pronzato * */ public class ReptFunction implements Function { private static final long serialVersionUID = -6832781189129832501L; public ReptFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type countType = parameters.getType(1); final Object countValue = parameters.getValue(1); final int count = typeRegistry.convertToNumber(countType, countValue).intValue(); if (count < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Type textType1 = parameters.getType(0); final Object textValue1 = parameters.getValue(0); final String rawText = typeRegistry.convertToText(textType1, textValue1); if(rawText == null) { return new TypeValuePair(TextType.TYPE, ""); } final StringBuffer buffer = new StringBuffer(rawText.length() * count); for(int i=0; i * This function depends on MidFunction. * * @see MidFunction * * @author Cedric Pronzato * */ public class LeftFunction implements Function { private static final long serialVersionUID = 7929942586373275084L; public LeftFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1 || parameterCount > 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final String text = typeRegistry.convertToText(textType, textValue); final int length; if (parameterCount == 2) { final Type lengthType = parameters.getType(1); final Object lengthValue = parameters.getValue(1); final Number lengthConv = typeRegistry.convertToNumber(lengthType, lengthValue); if (lengthConv.doubleValue() < 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } length = lengthConv.intValue(); } else { length = 1; } if (text == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // Note that MID(T;1;Length) produces the same results as LEFT(T;Length). return new TypeValuePair(TextType.TYPE, MidFunction.process(text, 1, length)); } public String getCanonicalName() { return "LEFT"; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UpperFunction.java0000644000175000017500000000474011401240106031746 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given text in upper case. * * @author Cedric Pronzato * */ public class UpperFunction implements Function { private static final long serialVersionUID = 2415465663289752026L; public UpperFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String result = context.getTypeRegistry().convertToText(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(TextType.TYPE, result.toUpperCase(context.getLocalizationContext().getLocale())); } public String getCanonicalName() { return "UPPER"; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicharFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicharFunctionDescrip0000644000175000017500000000366511401240106032643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; public class UnicharFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6842849033225519941L; public UnicharFunctionDescription() { super("UNICHAR", "org.pentaho.reporting.libraries.formula.function.text.Unichar-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MessageFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MessageFunctionDescrip0000644000175000017500000000376411401240106032636 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; public class MessageFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 6842849033225519941L; public MessageFunctionDescription() { super("MESSAGE", "org.pentaho.reporting.libraries.formula.function.text.Message-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return position == 0; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Replace-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Replace-Function.prope0000644000175000017500000000110011401240106032472 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=REPLACE description=Replaces characters within a text string with a different text string. parameter.0.display-name=Text parameter.0.description=The text in which some characters are to be replaced. parameter.1.display-name=position parameter.1.description=The character position from which text is to be replaced. parameter.2.display-name=length parameter.2.description=The number of characters to be replaced. parameter.3.display-name=new text parameter.3.description=The text to be inserted. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicharFunction.java0000644000175000017500000000471311401240106032244 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given value as text. * * @author Cedric Pronzato * */ public class UnicharFunction implements Function { private static final long serialVersionUID = 3505313019941429911L; public UnicharFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(TextType.TYPE, String.valueOf(((char) result.intValue()))); } public String getCanonicalName() { return "UNICHAR"; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Unichar-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Unichar-Function.prope0000644000175000017500000000026611401240106032524 0ustar renerenedisplay-name=UNICHAR description=Converts a code number into a Unicode character or letter. parameter.0.display-name=number parameter.0.description=The code value for the character. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReptFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/ReptFunctionDescriptio0000644000175000017500000000411311401240106032665 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes ReptFunction function. * @see ReptFunction * * @author Cedric Pronzato * */ public class ReptFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -1973101420318862666L; public ReptFunctionDescription() { super("REPT", "org.pentaho.reporting.libraries.formula.function.text.Rept-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { if(position == 0) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Rept-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Rept-Function.properti0000644000175000017500000000047711401240106032570 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=REPT description=Repeats text a given number of times. parameter.0.display-name=text parameter.0.description=The text to be repeated. parameter.1.display-name=number parameter.1.description=The number of times the text is to be repeated. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/MidFunction.java0000644000175000017500000000715711401240106031371 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns extracted text, given an original text, starting position, and length. * * @author Cedric Pronzato * */ public class MidFunction implements Function { private static final long serialVersionUID = 4190365695032245709L; public MidFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type textType = parameters.getType(0); final Object textValue = parameters.getValue(0); final Type startType = parameters.getType(1); final Object startValue = parameters.getValue(1); final Type lengthType = parameters.getType(2); final Object lengthValue = parameters.getValue(2); final String text = typeRegistry.convertToText(textType, textValue); final Number start = typeRegistry.convertToNumber(startType, startValue); final Number length = typeRegistry.convertToNumber(lengthType, lengthValue); if(length.doubleValue() < 0 || start.doubleValue() < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(TextType.TYPE, process(text, start.intValue(), length.intValue())); } /** * Computes the substring for the given text, using the 1-based start index and the given length. * * @param text * @param start * @param lengthValue * @return */ public static String process(final String text, final int start, int lengthValue) { final int startValue = start -1; if(startValue >= text.length() || startValue < 0) { return ""; } if((lengthValue +startValue) > text.length()) { lengthValue = text.length()-startValue; } return text.substring(startValue, startValue +lengthValue); } public String getCanonicalName() { return "MID"; } }././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LowerFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/LowerFunctionDescripti0000644000175000017500000000400311401240106032662 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes LowerFunction function. * @see LowerFunction * * @author Cedric Pronzato * */ public class LowerFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -1445500850790274405L; public LowerFunctionDescription() { super("LOWER", "org.pentaho.reporting.libraries.formula.function.text.Lower-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Trim-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Trim-Function.properti0000644000175000017500000000037011401240106032561 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=TRIM description=Removes extra spaces from text. parameter.0.display-name=text parameter.0.description=The text in which extra spaces between words are to be deleted. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TextFunction.java0000644000175000017500000001105311401240106031572 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.util.Date; import java.util.Locale; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.text.DateFormatSymbols; import java.text.NumberFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * This function returns the given value as text. * * @author Cedric Pronzato * */ public class TextFunction implements Function { private static final long serialVersionUID = 3505313019941429911L; public TextFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final TypeRegistry typeRegistry = context.getTypeRegistry(); if (parameterCount == 1) { final String result = typeRegistry.convertToText(type1, value1); if(result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(TextType.TYPE, result); } try { final Type type2 = parameters.getType(1); final Object value2 = parameters.getValue(1); final String formatString = typeRegistry.convertToText(type2, value2); final Locale locale = context.getLocalizationContext().getLocale(); if (value1 instanceof Date) { final DateFormat dateFormat = new SimpleDateFormat (formatString, new DateFormatSymbols(locale)); return new TypeValuePair(TextType.TYPE, dateFormat.format(value1)); } if (value1 instanceof Number) { final NumberFormat dateFormat = new DecimalFormat (formatString, new DecimalFormatSymbols(locale)); return new TypeValuePair(TextType.TYPE, dateFormat.format(value1)); } try { final Date date = typeRegistry.convertToDate(type2, value2); final DateFormat dateFormat = new SimpleDateFormat (formatString, new DateFormatSymbols(locale)); return new TypeValuePair(TextType.TYPE, dateFormat.format(date)); } catch (EvaluationException ev) { // ignore } try { final Number date = typeRegistry.convertToNumber(type2, value2); final NumberFormat dateFormat = new DecimalFormat (formatString, new DecimalFormatSymbols(locale)); return new TypeValuePair(TextType.TYPE, dateFormat.format(date)); } catch (EvaluationException ev) { // ignore } } catch (EvaluationException ev) { throw ev; } catch (Exception ex) { throw new EvaluationException(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } public String getCanonicalName() { return "TEXT"; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TrimFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/TrimFunctionDescriptio0000644000175000017500000000377511401240106032703 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes TrimFunction function. * @see TrimFunction * * @author Cedric Pronzato * */ public class TrimFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -7658361544754433688L; public TrimFunctionDescription() { super("TRIM", "org.pentaho.reporting.libraries.formula.function.text.Trim-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/FindFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/FindFunctionDescriptio0000644000175000017500000000437211401240106032642 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes FindFunction function. * @see FindFunction * * @author Cedric Pronzato * */ public class FindFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 3300046053895569309L; public FindFunctionDescription() { super("FIND", "org.pentaho.reporting.libraries.formula.function.text.Find-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { if(position == 0 || position == 1) { return TextType.TYPE; } if(position == 2) { return NumberType.GENERIC_NUMBER; } return null; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { if(position == 0 || position == 1) { return true; } else { return false; } } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Exact-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Exact-Function.propert0000644000175000017500000000052211401240106032540 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=EXACT description=Specifies whether two texts are identical. parameter.0.display-name=text_1 parameter.0.description=The first text to be used for comparing texts. parameter.1.display-name=text_2 parameter.1.description=The second text for comparing texts. ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/URLEncodeFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/URLEncodeFunctionDescr0000644000175000017500000000406711401240106032476 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes LowerFunction function. * @see org.pentaho.reporting.libraries.formula.function.text.LowerFunction * * @author Cedric Pronzato * */ public class URLEncodeFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7241603575392886827L; public URLEncodeFunctionDescription() { super("URLENCODE", "org.pentaho.reporting.libraries.formula.function.text.URLEncode-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return TextType.TYPE; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { if (position == 1) { return false; } return true; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Lower-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/Lower-Function.propert0000644000175000017500000000036511401240106032571 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=LOWER description=Converts text to lowercase. parameter.0.display-name=text parameter.0.description=The text in which capitals are converted to lower case letters. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/UnicodeFunction.java0000644000175000017500000000504111401240106032234 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the given value as text. * * @author Cedric Pronzato */ public class UnicodeFunction implements Function { private static final long serialVersionUID = 3505313019941429911L; public UnicodeFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final String result = context.getTypeRegistry().convertToText(type1, value1); if (result == null || result.length() == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(result.charAt(0))); } public String getCanonicalName() { return "UNICODE"; } }././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunctionDesc0000644000175000017500000000424511401240106032705 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes SubstituteFunction function. * @see SubstituteFunction * * @author Cedric Pronzato * */ public class SubstituteFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -6053755288623137282L; public SubstituteFunctionDescription() { super("SUBSTITUTE", "org.pentaho.reporting.libraries.formula.function.text.Substitute-Function"); } public FunctionCategory getCategory() { return TextFunctionCategory.CATEGORY; } public int getParameterCount() { return 4; } public Type getParameterType(final int position) { if(position != 3) { return TextType.TYPE; } return NumberType.GENERIC_NUMBER; } public Type getValueType() { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { if(position == 3) { return false; } return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/0000755000175000017500000000000011401240106026723 5ustar renerenelibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/category.properties0000644000175000017500000000024211401240106032654 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Logical description=Contains functions that deal with or produce logical values.././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/FalseFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/FalseFunctionDescri0000644000175000017500000000420311401240106032537 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class FalseFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -1846971196399484893L; public FalseFunctionDescription() { super("FALSE", "org.pentaho.reporting.libraries.formula.function.logical.False-Function"); } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/NotFunction.java0000644000175000017500000000526011401240106032037 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class NotFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = -5011404461198906096L; public NotFunction() { } public String getCanonicalName() { return "NOT"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount()!= 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type conditionType = parameters.getType(0); final Object conditionValue = parameters.getValue(0); final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue); if(condition == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (!Boolean.TRUE.equals(condition)) { return RETURN_TRUE; } return RETURN_FALSE; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/OrFunction.java0000644000175000017500000000545311401240106031663 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class OrFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = -5584112968514776342L; public OrFunction() { } public String getCanonicalName() { return "OR"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final int length = parameters.getParameterCount(); for (int i = 0; i < length; i++) { final Type conditionType = parameters.getType(i); final Object conditionValue = parameters.getValue(i); final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue); if(condition == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (Boolean.TRUE.equals(condition)) { return RETURN_TRUE; } } return RETURN_FALSE; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/FalseFunction.java0000644000175000017500000000415111401240106032327 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class FalseFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -4103284451660191648L; public FalseFunction() { } public String getCanonicalName() { return "FALSE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() != 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } return RETURN_FALSE; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfNaFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfNaFunctionDescrip0000644000175000017500000000431711401240106032510 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class IfNaFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5553370162761578407L; public IfNaFunctionDescription() { super("IFNA", "org.pentaho.reporting.libraries.formula.function.logical.IfNa-Function"); } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return AnyType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 1 || position == 2) { return true; } else { return false; } } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/If-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/If-Function.propert0000644000175000017500000000076611401240106032472 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=IF description=Specifies a logical test to be performed. parameter.0.display-name=Test parameter.0.description=Any value or expression which can be either TRUE or FALSE. parameter.1.display-name=Then_value parameter.1.description=The result of the function if the logical test returns a TRUE. parameter.2.display-name=Otherwise_value parameter.2.description=The result of the function if the logical test returns FALSE. ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/TrueFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/TrueFunctionDescrip0000644000175000017500000000417711401240106032616 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class TrueFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -1604554594665374925L; public TrueFunctionDescription() { super("TRUE", "org.pentaho.reporting.libraries.formula.function.logical.True-Function"); } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/OrFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/OrFunctionDescripti0000644000175000017500000000427411401240106032612 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class OrFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 2578285607828670991L; public OrFunctionDescription() { super("OR", "org.pentaho.reporting.libraries.formula.function.logical.Or-Function"); } public int getParameterCount() { return 1; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/And-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/And-Function.proper0000644000175000017500000000046711401240106032450 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=AND description=Returns TRUE if all arguments are TRUE. parameter.0.display-name=Logical value parameter.0.description=Logical value 1, logical value 2;...are 1 to 30 conditions to be tested and each returns either TRUE or FALSE. ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/False-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/False-Function.prop0000644000175000017500000000021011401240106032433 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=FALSE description=Defines the logical value as FALSE. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/XorFunction.java0000644000175000017500000000563711401240106032057 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class XorFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = 1593151240024848931L; public XorFunction() { } public String getCanonicalName() { return "XOR"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } int count = 0; final int parameterCount = parameters.getParameterCount(); for (int i = 0; i < parameterCount; i++) { final Type conditionType = parameters.getType(i); final Object conditionValue = parameters.getValue(i); final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue); if(condition == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (Boolean.TRUE.equals(condition)) { count += 1; } } if (count % 2 == 1) { return RETURN_TRUE; } else { return RETURN_FALSE; } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/AndFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/AndFunctionDescript0000644000175000017500000000427711401240106032566 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class AndFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -796481383341381910L; public AndFunctionDescription() { super("AND", "org.pentaho.reporting.libraries.formula.function.logical.And-Function"); } public int getParameterCount() { return 1; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/AndFunction.java0000644000175000017500000000536411401240106032006 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class AndFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -3737884974501253814L; public AndFunction() { } public String getCanonicalName() { return "AND"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int length = parameters.getParameterCount(); if(length < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } for (int i = 0; i < length; i++) { final Object value = parameters.getValue(i); final Type type1 = parameters.getType(i); final Boolean condition = context.getTypeRegistry().convertToLogical(type1, value); if(condition == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (Boolean.FALSE.equals(condition)) { return RETURN_FALSE; } } return RETURN_TRUE; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/True-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/True-Function.prope0000644000175000017500000000020211401240106032466 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=TRUE description=Returns the logical value TRUE. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Not-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Not-Function.proper0000644000175000017500000000036511401240106032503 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=NOT description=Reverses the value of the argument. parameter.0.display-name=Logical value parameter.0.description=An expression that can be either TRUE or FALSE. ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/NotFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/NotFunctionDescript0000644000175000017500000000417111401240106032615 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class NotFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 4556811604638050337L; public NotFunctionDescription() { super("NOT", "org.pentaho.reporting.libraries.formula.function.logical.Not-Function"); } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfNa-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfNa-Function.prope0000644000175000017500000000060011401240106032366 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=IFNA description=Return X unless it is an NA, in which case return an alternative value. parameter.0.display-name=Field or Value parameter.0.description=Any value or expression. parameter.1.display-name=Alternative Value parameter.1.description=The result of the function if the Field or Value was NA. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfNaFunction.java0000644000175000017500000000700311401240106032111 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.formula.ErrorValue; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class IfNaFunction implements Function { private static final Log logger = LogFactory.getLog(IfNaFunction.class); private static final long serialVersionUID = -7517668261071087411L; public IfNaFunction() { } public String getCanonicalName() { return "IFNA"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } Object value = null; Type type = null; boolean nafound = false; try { type = parameters.getType(0); value = parameters.getValue(0); if (ErrorType.TYPE.equals(type) && value instanceof ErrorValue) { logger.warn("Passing errors around is deprecated. Throw exceptions instead."); final ErrorValue na = (ErrorValue) value; if (na.getErrorCode() == LibFormulaErrorValue.ERROR_NA) { nafound = true; } } else { if (value == null) { nafound = true; } } } catch (EvaluationException e) { if (e.getErrorValue().getErrorCode() == LibFormulaErrorValue.ERROR_NA) { nafound = true; } else { // here the error propagates, as IFNA([x],"v") is defined to behave like IF(ISNA([x]); "v"; [x]) // and the second evaluation of [X] may yield the error that was swallowed by ISNA. throw e; } } if (nafound == false) { return new TypeValuePair(type, value); } return new TypeValuePair(parameters.getType(1), parameters.getValue(1)); } }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Or-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Or-Function.propert0000644000175000017500000000046411401240106032507 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=OR description=Returns TRUE if an argument is TRUE. parameter.0.display-name=Logical value parameter.0.description=Logical value 1, logical value 2,... are 1 to 30 conditions to be tested and which return either TRUE or FALSE. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Xor-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/Xor-Function.proper0000644000175000017500000000050311401240106032505 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=XOR description=Returns TRUE if a odd number of arguments are TRUE. parameter.0.display-name=Logical value parameter.0.description=Logical value 1, logical value 2;...are 1 to 30 conditions to be tested and each returns either TRUE or FALSE. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfFunction.java0000644000175000017500000000604611401240106031640 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class IfFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -7517668261071087411L; public IfFunction() { } public String getCanonicalName() { return "IF"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type conditionType = parameters.getType(0); final Object conditionValue = parameters.getValue(0); final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue); if(condition == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (Boolean.TRUE.equals(condition)) { final Object value = parameters.getValue(1); final Type type = parameters.getType(1); return new TypeValuePair(type, value); } // if condition is false and no third parameter, return false if(parameterCount == 2 || parameters.getValue(2) == null) { return RETURN_FALSE; } // else return third parameter final Object value = parameters.getValue(2); final Type type = parameters.getType(2); return new TypeValuePair(type, value); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/XorFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/XorFunctionDescript0000644000175000017500000000430111401240106032620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class XorFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -5225706771499777084L; public XorFunctionDescription() { super("XOR", "org.pentaho.reporting.libraries.formula.function.logical.Xor-Function"); } public int getParameterCount() { return 1; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return LogicalType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/TrueFunction.java0000644000175000017500000000413211401240106032213 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 04.11.2006, 18:28:15 * * @author Thomas Morgner */ public class TrueFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = 3103588076262714854L; public TrueFunction() { } public String getCanonicalName() { return "TRUE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() != 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } return RETURN_TRUE; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/IfFunctionDescripti0000644000175000017500000000456011401240106032566 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class IfFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5553370162761578407L; public IfFunctionDescription() { super("IF", "org.pentaho.reporting.libraries.formula.function.logical.If-Function"); } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { if (position == 0) { return LogicalType.TYPE; } else { return AnyType.TYPE; } } public Type getValueType() { return AnyType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 1 || position == 2) { return true; } else { return false; } } public FunctionCategory getCategory() { return LogicalFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/LogicalFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/logical/LogicalFunctionCate0000644000175000017500000000264011401240106032525 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class LogicalFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new LogicalFunctionCategory(); private LogicalFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.logical.category"); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/AbstractFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/AbstractFunctionCategory.ja0000644000175000017500000000344611401240106032603 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.ResourceBundle; import java.util.Locale; /** * Creation-Date: 05.11.2006, 14:31:22 * * @author Thomas Morgner */ public class AbstractFunctionCategory implements FunctionCategory { private String bundleName; protected AbstractFunctionCategory(final String bundleName) { this.bundleName = bundleName; } protected ResourceBundle getBundle(final Locale locale) { return ResourceBundle.getBundle(bundleName, locale); } public String getDisplayName(final Locale locale) { return getBundle(locale).getString("display-name"); } public String getDescription(final Locale locale) { return getBundle(locale).getString("description"); } public boolean equals(final Object o) { if (this == o) { return true; } return !(o == null || getClass() != o.getClass()); } public int hashCode() { return getClass().hashCode(); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/0000755000175000017500000000000011401240106027606 5ustar renerene././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/category.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/category.proper0000644000175000017500000000021211401240106032647 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=User-Defined description=Contains unclassified functions././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/Null-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/Null-Function.p0000644000175000017500000000017111401240106032463 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=NULL description=Returns a NULL-Value ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/UserDefinedFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/UserDefinedFunc0000644000175000017500000000265611401240106032553 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 15:05:38 * * @author Thomas Morgner */ public class UserDefinedFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new UserDefinedFunctionCategory(); private UserDefinedFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.userdefined.category"); } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArrayFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArrayF0000644000175000017500000000340511401240106032600 0ustar renerenepackage org.pentaho.reporting.libraries.formula.function.userdefined; import java.util.ArrayList; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Todo: Document me! *

* Date: 23.10.2009 * Time: 11:43:28 * * @author Thomas Morgner. */ public class NormalizeArrayFunction implements Function { public NormalizeArrayFunction() { } public String getCanonicalName() { return "NORMALIZEARRAY"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Sequence sequence = context.getTypeRegistry().convertToSequence(parameters.getType(0), parameters.getValue(0)); if (sequence == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final ArrayList retval = new ArrayList(); while (sequence.hasNext()) { final Object o = sequence.next(); if (o != null) { retval.add(o); } } return new TypeValuePair(AnyType.ANY_ARRAY, retval.toArray()); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArrayFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArrayFunctio0000644000175000017500000000507311401240106032620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:21:23 * * @author Thomas Morgner. */ public class CsvArrayFunctionDescription extends AbstractFunctionDescription { public CsvArrayFunctionDescription() { super("CSVARRAY", "org.pentaho.reporting.libraries.formula.function.userdefined.CsvArray-Function"); } public Type getValueType() { return AnyType.TYPE; } public FunctionCategory getCategory() { return UserDefinedFunctionCategory.CATEGORY; } public int getParameterCount() { return 4; } /** * Returns the parameter type at the given position using the function * metadata. The first parameter is at the position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { if (position == 1) { return LogicalType.TYPE; } return TextType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need * not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 0) { return true; } return false; } }././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NullFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NullFunctionDes0000644000175000017500000000417611401240106032615 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: 04.11.2006, 18:28:55 * * @author Thomas Morgner */ public class NullFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5710880620780379157L; public NullFunctionDescription() { super("NULL", "org.pentaho.reporting.libraries.formula.function.userdefined.Null-Function"); } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return AnyType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public FunctionCategory getCategory() { return UserDefinedFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDateFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDateFuncti0000644000175000017500000000676711401240106032572 0ustar renerenepackage org.pentaho.reporting.libraries.formula.function.userdefined; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.StringTokenizer; import java.util.TimeZone; import org.pentaho.reporting.libraries.base.util.StringUtils; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; /** * Todo: Document me! *

* Date: 04.01.2010 * Time: 18:12:07 * * @author Thomas Morgner. */ public class ParseDateFunction implements Function { public ParseDateFunction() { } public String getCanonicalName() { return "PARSEDATE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() < 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } if (parameters.getParameterCount() > 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final String dateString = typeRegistry.convertToText(parameters.getType(0), parameters.getValue(0)); final String pattern = typeRegistry.convertToText(parameters.getType(1), parameters.getValue(1)); final Locale locale; if (parameters.getParameterCount() > 2) { final String localeText = typeRegistry.convertToText(parameters.getType(2), parameters.getValue(2)); if (StringUtils.isEmpty(localeText)) { locale = context.getLocalizationContext().getLocale(); } else { locale = parseLocale(localeText); } } else { locale = context.getLocalizationContext().getLocale(); } final TimeZone timeZone; if (parameters.getParameterCount() > 3) { final String timeZoneText = typeRegistry.convertToText(parameters.getType(3), parameters.getValue(3)); timeZone = TimeZone.getTimeZone(timeZoneText); } else { timeZone = context.getLocalizationContext().getTimeZone(); } try { final SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setTimeZone(timeZone); sdf.setLenient(false); return new TypeValuePair(DateTimeType.DATETIME_TYPE, sdf.parse(dateString)); } catch (Exception e) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } } private Locale parseLocale(final String s) throws EvaluationException { final StringTokenizer strtok = new StringTokenizer(s.trim(), "_"); if (strtok.hasMoreElements() == false) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } final String language = strtok.nextToken(); String country = ""; if (strtok.hasMoreTokens()) { country = strtok.nextToken(); } String variant = ""; if (strtok.hasMoreTokens()) { variant = strtok.nextToken(); } return new Locale(language, country, variant); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArrayFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArrayF0000644000175000017500000000501711401240106032601 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:21:23 * * @author Thomas Morgner. */ public class NormalizeArrayFunctionDescription extends AbstractFunctionDescription { public NormalizeArrayFunctionDescription() { super("NORMALIZEARRAY", "org.pentaho.reporting.libraries.formula.function.userdefined.NormalizeArray-Function"); } public Type getValueType() { return AnyType.ANY_ARRAY; } public FunctionCategory getCategory() { return UserDefinedFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } /** * Returns the parameter type at the given position using the function * metadata. The first parameter is at the position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { if (position == 0) { return AnyType.ANY_SEQUENCE; } return TextType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need * not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 0) { return true; } return false; } }././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvText-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvText-Functio0000644000175000017500000000065611401240106032545 0ustar renerenedisplay-name=CSVTEXT description=Converts a Array into a CSV-Text. parameter.0.display-name=Array parameter.0.description=The DataSource, used as a sequence. parameter.1.display-name=Apply Quoting parameter.1.description=Flag indicating whether values should be quoted. parameter.2.display-name=Separator parameter.2.description=The Separator Character. parameter.3.display-name=Quote parameter.3.description=The Quote Character. ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArray-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NormalizeArray-0000644000175000017500000000027511401240106032551 0ustar renerenedisplay-name=NORMALIZEARRAY description=Converts a Array, Database or sequence into a flat array. parameter.0.display-name=Array parameter.0.description=The DataSource, used as a sequence. ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArray-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArray-Functi0000644000175000017500000000063311401240106032513 0ustar renerenedisplay-name=CSVARRAY description=Converts a CSV-text into an array. parameter.0.display-name=String parameter.0.description=The CSV text. parameter.1.display-name=Apply Quoting parameter.1.description=Flag indicating whether values should be quoted. parameter.2.display-name=Separator parameter.2.description=The Separator Character. parameter.3.display-name=Quote parameter.3.description=The Quote Character. ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDateFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDateFuncti0000644000175000017500000000301011401240106032544 0ustar renerenepackage org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 04.01.2010 * Time: 18:12:23 * * @author Thomas Morgner. */ public class ParseDateFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5710880620780379157L; public ParseDateFunctionDescription() { super("PARSEDATE", "org.pentaho.reporting.libraries.formula.function.userdefined.ParseDate-Function"); } public int getParameterCount() { return 4; } public Type getParameterType(final int position) { return TextType.TYPE; } public Type getValueType() { return DateTimeType.DATETIME_TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return position < 2; } public FunctionCategory getCategory() { return UserDefinedFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NullFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/NullFunction.ja0000644000175000017500000000342211401240106032543 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: Dec 18, 2006, 12:54:55 PM * * @author Thomas Morgner */ public class NullFunction implements Function { private static final TypeValuePair NULL = new TypeValuePair(AnyType.TYPE, null); private static final long serialVersionUID = -2213352007005452516L; public NullFunction() { } public String getCanonicalName() { return "NULL"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) { return NULL; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvTextFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvTextFunction0000644000175000017500000001011211401240106032632 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.base.util.CSVQuoter; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:20:37 * * @author Thomas Morgner. */ public class CsvTextFunction implements Function { public CsvTextFunction() { } public String getCanonicalName() { return "CSVTEXT"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1 || parameterCount > 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Sequence sequence = context.getTypeRegistry().convertToSequence(parameters.getType(0), parameters.getValue(0)); if (sequence == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } String quote = "\""; String separator = ","; boolean doQuoting = false; if (parameterCount > 1) { final Type indexType = parameters.getType(1); final Object indexValue = parameters.getValue(1); final Boolean indexNumber = context.getTypeRegistry().convertToLogical(indexType, indexValue); doQuoting = Boolean.TRUE.equals(indexNumber); } if (parameterCount > 2) { final Type indexType = parameters.getType(2); final Object indexValue = parameters.getValue(2); separator = context.getTypeRegistry().convertToText(indexType, indexValue); } if (parameterCount > 3) { final Type indexType = parameters.getType(3); final Object indexValue = parameters.getValue(3); quote = context.getTypeRegistry().convertToText(indexType, indexValue); } if (doQuoting == false) { StringBuffer b = new StringBuffer(); while (sequence.hasNext()) { final Object o = sequence.next(); if (o != null) { b.append(o); } if (sequence.hasNext()) { b.append(separator); } } return new TypeValuePair(TextType.TYPE, b.toString()); } else { final CSVQuoter quoter = new CSVQuoter(quote.charAt(0), quote.charAt(0)); StringBuffer b = new StringBuffer(); while (sequence.hasNext()) { final Object o = sequence.next(); if (o != null) { b.append(quoter.doQuoting(String.valueOf(o))); } if (sequence.hasNext()) { b.append(separator); } } return new TypeValuePair(TextType.TYPE, b.toString()); } } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDate-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/ParseDate-Funct0000644000175000017500000000067011401240106032461 0ustar renerenedisplay-name=PARSEDATE description=Converts Text into a Date using a SimpleDateFormat. parameter.0.display-name=Text parameter.0.description=The text that should be parsed. parameter.1.display-name=Pattern parameter.1.description=The SimpleDateFormat pattern. parameter.2.display-name=Locale parameter.2.description=The Locale that should be used. parameter.3.display-name=TimeZone parameter.3.description=The TimeZone that should be used. ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvTextFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvTextFunction0000644000175000017500000000517411401240106032646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:21:23 * * @author Thomas Morgner. */ public class CsvTextFunctionDescription extends AbstractFunctionDescription { public CsvTextFunctionDescription() { super("CSVTEXT", "org.pentaho.reporting.libraries.formula.function.userdefined.CsvText-Function"); } public Type getValueType() { return TextType.TYPE; } public FunctionCategory getCategory() { return UserDefinedFunctionCategory.CATEGORY; } public int getParameterCount() { return 4; } /** * Returns the parameter type at the given position using the function * metadata. The first parameter is at the position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { if (position == 0) { return AnyType.ANY_ARRAY; } if (position == 1) { return LogicalType.TYPE; } return TextType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need * not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 0) { return true; } return false; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArrayFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/userdefined/CsvArrayFunctio0000644000175000017500000000775011401240106032624 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.userdefined; import java.util.ArrayList; import java.util.Enumeration; import java.util.StringTokenizer; import org.pentaho.reporting.libraries.base.util.CSVTokenizer; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:20:37 * * @author Thomas Morgner. */ public class CsvArrayFunction implements Function { public CsvArrayFunction() { } public String getCanonicalName() { return "CSVARRAY"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1 || parameterCount > 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final String sequence = context.getTypeRegistry().convertToText(parameters.getType(0), parameters.getValue(0)); if (sequence == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } String quote = "\""; String separator = ","; boolean doQuoting = false; if (parameterCount > 1) { final Type indexType = parameters.getType(1); final Object indexValue = parameters.getValue(1); final Boolean indexNumber = context.getTypeRegistry().convertToLogical(indexType, indexValue); doQuoting = Boolean.TRUE.equals(indexNumber); } if (parameterCount > 2) { final Type indexType = parameters.getType(2); final Object indexValue = parameters.getValue(2); separator = context.getTypeRegistry().convertToText(indexType, indexValue); } if (parameterCount > 3) { final Type indexType = parameters.getType(1); final Object indexValue = parameters.getValue(1); quote = context.getTypeRegistry().convertToText(indexType, indexValue); } final ArrayList resultList; final Enumeration strtok; if (doQuoting == false) { final StringTokenizer strtokenizer = new StringTokenizer(sequence, separator); resultList = new ArrayList(strtokenizer.countTokens()); strtok = strtokenizer; } else { final CSVTokenizer strtokenizer = new CSVTokenizer(sequence, separator, quote, false); resultList = new ArrayList(strtokenizer.countTokens()); strtok = strtokenizer; } while (strtok.hasMoreElements()) { final Object o = strtok.nextElement(); if (o != null) { resultList.add(o); } } return new TypeValuePair(AnyType.TYPE, resultList.toArray(new String[resultList.size()])); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/0000755000175000017500000000000011401240106027105 5ustar renerene././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/category.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/category.propertie0000644000175000017500000000023511401240106032655 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Date/Time description=Contains functions that compute time and date values.././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunctionDes0000644000175000017500000000427311401240106032500 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes DateDifFunction function. * @see DateDifFunction * * @author Cedric Pronzato */ public class DateDifFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 2428452931728654158L; public DateDifFunctionDescription() { super("DATEDIF", "org.pentaho.reporting.libraries.formula.function.datetime.DateDif-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { if(position == 2) { return TextType.TYPE; } return DateTimeType.DATE_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TodayFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TodayFunctionDescr0000644000175000017500000000426711401240106032610 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; /** * Creation-Date: 04.11.2006, 18:59:11 * * @author Thomas Morgner */ public class TodayFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7674329573702445275L; public TodayFunctionDescription() { super("TODAY", "org.pentaho.reporting.libraries.formula.function.datetime.Today-Function"); } public Type getValueType() { return DateTimeType.DATE_TYPE; } public boolean isVolatile() { return true; } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return null; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/YearFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/YearFunctionDescri0000644000175000017500000000404611401240106032574 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes YearFunction function. * * @see YearFunction * * @author Cedric Pronzato */ public class YearFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 1152202788652836026L; public YearFunctionDescription() { super("YEAR", "org.pentaho.reporting.libraries.formula.function.datetime.Year-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.DATE_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunctionDesc0000644000175000017500000000375211401240106032557 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes SecondFunction function. * * @see MinuteFunction * * @author Cedric Pronzato */ public class SecondFunctionDescription extends AbstractFunctionDescription { public SecondFunctionDescription() { super("SECOND", "org.pentaho.reporting.libraries.formula.function.datetime.Second-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.TIME_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Date-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Date-Function.prop0000644000175000017500000000100511401240106032443 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=DATE description=Provides an internal number for the date given. parameter.0.display-name=year parameter.0.description=An integer between 1583 and 9956 or 0 and 99 (19xx or 20xx depending on the defined option). parameter.1.display-name=month parameter.1.description=An integer between 1 and 12 representing the month. parameter.2.display-name=day parameter.2.description=An integer between 1 and 31 representing the day of the month. ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/NowFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/NowFunctionDescrip0000644000175000017500000000426411401240106032621 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; /** * Creation-Date: 04.11.2006, 18:59:11 * * @author Thomas Morgner */ public class NowFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -4785660363309520356L; public NowFunctionDescription() { super("NOW", "org.pentaho.reporting.libraries.formula.function.datetime.Now-Function"); } public Type getValueType() { return DateTimeType.DATETIME_TYPE; } public boolean isVolatile() { return true; } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return null; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Days-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Days-Function.prop0000644000175000017500000000045311401240106032474 0ustar renerenedisplay-name=DAYS description=Calculates the number of days between two dates. parameter.0.display-name=Date_2 parameter.0.description=The end date for calculating the difference in days. parameter.1.display-name=Date_1 parameter.1.description=The start date for calculating the difference in days. ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DayFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DayFunctionDescrip0000644000175000017500000000404011401240106032563 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes DayFunction function. * * @see DayFunction * * @author Cedric Pronzato */ public class DayFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 8306010409074007316L; public DayFunctionDescription() { super("DAY", "org.pentaho.reporting.libraries.formula.function.datetime.Day-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.DATE_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValueFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValueFunctionD0000644000175000017500000000436111401240106032541 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes the TimeFunction function * * @author Cedric Pronzato * @see TimeFunction */ public class TimeValueFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5414013076902907910L; public TimeValueFunctionDescription() { super("TIMEVALUE", "org.pentaho.reporting.libraries.formula.function.datetime.TimeValue-Function"); } public Type getValueType() { return DateTimeType.TIME_TYPE; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return TextType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A mandatory parameter must be filled in, while * optional parameters need not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/NowFunction.java0000644000175000017500000000457711401240106032236 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Date; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * Return the serial number of the current date and time. This returns the current day and time serial number, using the * current locale. If you want only the serial number of the current day, use TODAY. * * @author Thomas Morgner * @since 23.03.2007 */ public class NowFunction implements Function { private static final long serialVersionUID = 4108282053598696841L; public NowFunction() { } public String getCanonicalName() { return "NOW"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final LocalizationContext localizationContext = context.getLocalizationContext(); final Date now = DateUtil.now(localizationContext); final Date date = DateUtil.normalizeDate(now, DateTimeType.DATETIME_TYPE); return new TypeValuePair(DateTimeType.DATETIME_TYPE, date); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Time-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Time-Function.prop0000644000175000017500000000064111401240106032471 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=TIME description=Determines a time value from the details for hour, minute and second. parameter.0.display-name=hour parameter.0.description=The integer for the hour. parameter.1.display-name=minute parameter.1.description=The integer for the minute. parameter.2.display-name=second parameter.2.description=The integer for the second. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TodayFunction.java0000644000175000017500000000430511401240106032540 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Date; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * Todo: Document me! * * @author Thomas Morgner * @since 23.03.2007 */ public class TodayFunction implements Function { private static final long serialVersionUID = -456922288664083206L; public TodayFunction() { } public String getCanonicalName() { return "TODAY"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final LocalizationContext localizationContext = context.getLocalizationContext(); final Date now = DateUtil.now(localizationContext); final Date date = DateUtil.normalizeDate(now, DateTimeType.DATE_TYPE); return new TypeValuePair(DateTimeType.DATE_TYPE, date); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunction.ja0000644000175000017500000001101611401240106032457 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Calendar; import java.util.Date; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This function extracts the day of week from a date.

The returned value * depends of the Type passed as second argument using the following table:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Day of WeekType=1 ResultType=2 ResultType=3 Result
Sunday 1 7 6
Monday 2 1 0
Tuesday 3 2 1
Wednesday 4 3 2
Thursday 5 4 3
Friday 6 5 4
Saturday 7 6 5
* * @author Cedric Pronzato */ public class WeekDayFunction implements Function { private static final long serialVersionUID = -825027235225096201L; public WeekDayFunction() { } public String getCanonicalName() { return "WEEKDAY"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() > 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters.getValue(0)); int type = 1; // default is Type 1 if (parameters.getParameterCount() == 2) { final Number n = typeRegistry.convertToNumber(parameters.getType(1), parameters.getValue(1)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } type = n.intValue(); if (type < 1 || type > 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } } if (d == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Calendar gc = DateUtil.createCalendar(d, context.getLocalizationContext()); final int dayOfWeek = gc.get(Calendar.DAY_OF_WEEK); // in java Sunday = 1 (= Type 1 of openformula) final int result = convertType(dayOfWeek, type); //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal((double)result)); } public int convertType(final int currentDayOfWeek, final int type) { if (type == 1) { return currentDayOfWeek; } else if (type == 2) { final int i = ((currentDayOfWeek + 6) % 8); if(i == 7) { return i; } else { return i + 1; } } else { return (currentDayOfWeek + 5) % 7; } } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValueFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValueFunction.0000644000175000017500000000511511401240106032511 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Date; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This fonction constructs a time from hours, minutes, and seconds. * * @author Cedric Pronzato */ public class TimeValueFunction implements Function { private static final long serialVersionUID = -9175775325047486483L; public TimeValueFunction() { } public String getCanonicalName() { return "TIMEVALUE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type = parameters.getType(0); final Object value = parameters.getValue(0); final Date date1 = typeRegistry.convertToDate(type, value); final Date time = DateUtil.normalizeDate(date1, DateTimeType.TIME_TYPE); return new TypeValuePair(DateTimeType.TIME_TYPE, time); } }././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunctionDes0000644000175000017500000000432211401240106032524 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes WeekDayFunction function. * * @see WeekDayFunction * * @author Cedric Pronzato */ public class WeekDayFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -2974907368693600555L; public WeekDayFunctionDescription() { super("WEEKDAY", "org.pentaho.reporting.libraries.formula.function.datetime.WeekDay-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { if (position == 0) { return DateTimeType.DATE_TYPE; } return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { if (position == 0) { return true; } else { return false; } } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValue-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeValue-Function0000644000175000017500000000037611401240106032514 0ustar renerenedisplay-name=TIMEVALUE description=Returns a sequential number for a text shown in a possible time entry format. parameter.0.display-name=text parameter.0.description=A text enclosed in quotation marks which returns a time in a %PRODUCTNAME time format. ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Minute-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Minute-Function.pr0000644000175000017500000000041111401240106032470 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MINUTE description=Determines the sequential number for the minute of the hour (0-59) for the time value. parameter.0.display-name=Number parameter.0.description=Internal time value. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/YearFunction.java0000644000175000017500000000534011401240106032360 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Calendar; import java.util.Date; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This function extracts the year from a date. * * @author Cedric Pronzato */ public class YearFunction implements Function { private static final long serialVersionUID = 2486417585939551783L; public YearFunction() { } public String getCanonicalName() { return "YEAR"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters.getValue(0)); if (d == null) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Calendar gc = DateUtil.createCalendar(d, context.getLocalizationContext()); final int year = gc.get(Calendar.YEAR); //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal((double)year)); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DayFunction.java0000644000175000017500000000534511401240106032202 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Calendar; import java.util.Date; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This function extracts the day from a date. * * @author Cedric Pronzato */ public class DayFunction implements Function { private static final long serialVersionUID = 1909656887085891862L; public DayFunction() { } public String getCanonicalName() { return "DAY"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters.getValue(0)); if (d == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Calendar gc = DateUtil.createCalendar(d, context.getLocalizationContext()); final int dayOfMonth = gc.get(Calendar.DAY_OF_MONTH); //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal((double)dayOfMonth)); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Day-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Day-Function.prope0000644000175000017500000000043011401240106032451 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=DAY description=Returns the sequential date of the month as an integer (1-31) in relation to the date value. parameter.0.display-name=Number parameter.0.description=The internal number for the date. ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunctionD0000644000175000017500000000406011401240106032514 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes DateValueFunction function. * @see DateValueFunction * * @author Cedric Pronzato */ public class DateValueFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 3110217290825835653L; public DateValueFunctionDescription() { super("DATEVALUE", "org.pentaho.reporting.libraries.formula.function.datetime.DateValue-Function"); } public Type getValueType() { return DateTimeType.DATE_TYPE; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return TextType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DaysFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DaysFunctionDescri0000644000175000017500000000404111401240106032567 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes DayFunction function. * * @see DayFunction * * @author Cedric Pronzato */ public class DaysFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 8306010409074007316L; public DaysFunctionDescription() { super("DAYS", "org.pentaho.reporting.libraries.formula.function.datetime.Days-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 2; } public Type getParameterType(final int position) { return DateTimeType.DATE_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } }././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateTimeFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateTimeFunctionCa0000644000175000017500000000264511401240106032505 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class DateTimeFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new DateTimeFunctionCategory(); private DateTimeFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.datetime.category"); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateFunction.java0000644000175000017500000000567311401240106032346 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * Creation-Date: 04.11.2006, 18:59:11 * * @author Thomas Morgner */ public class DateFunction implements Function { private static final long serialVersionUID = 4956151361696995668L; public DateFunction() { } public String getCanonicalName() { return "DATE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n1 = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); final Number n2 = typeRegistry.convertToNumber(parameters.getType(1), parameters.getValue(1)); final Number n3 = typeRegistry.convertToNumber(parameters.getType(2), parameters.getValue(2)); if (n1 == null || n2 == null || n3 == null) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final LocalizationContext localizationContext = context .getLocalizationContext(); final java.sql.Date date = DateUtil.createDate(n1.intValue(), n2.intValue(), n3.intValue(), localizationContext); return new TypeValuePair(DateTimeType.DATE_TYPE, date); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunction.jav0000644000175000017500000000623111401240106032532 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function extracts the minute (0 through 59) from a time. * * @author Cedric Pronzato */ public class SecondFunction implements Function { private static final BigDecimal MINUTES_PER_DAY = new BigDecimal(24 * 60.0); private static final BigDecimal SECONDS = new BigDecimal(60.0); public SecondFunction() { } public String getCanonicalName() { return "SECOND"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // calculation is as follows // time * 24 so that we get the full hours (which we remove later) final BigDecimal bd = NumberUtil.getAsBigDecimal(n); final BigDecimal hours = bd.multiply(MINUTES_PER_DAY); final BigDecimal dayAndHoursAsInt = NumberUtil.performIntRounding(hours); final BigDecimal minutesFraction = hours.subtract(dayAndHoursAsInt); // Multiply the minutes with 60 to get the minutes as ints final BigDecimal seconds = minutesFraction.multiply(SECONDS); final BigDecimal secondsAsInt = NumberUtil.performIntRounding(seconds); return new TypeValuePair(NumberType.GENERIC_NUMBER, secondsAsInt); } }././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Hour-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Hour-Function.prop0000644000175000017500000000040211401240106032503 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=HOUR description=Determines the sequential number of the hour of the day (0-23) for the time value. parameter.0.display-name=Number parameter.0.description=Internal time value ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MonthFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MonthFunctionDescr0000644000175000017500000000405411401240106032607 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes MonthFunction function. * * @see MonthFunction * * @author Cedric Pronzato */ public class MonthFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7315838970574323742L; public MonthFunctionDescription() { super("MONTH", "org.pentaho.reporting.libraries.formula.function.datetime.Month-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.DATE_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MonthFunction.java0000644000175000017500000000525111401240106032546 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Calendar; import java.util.Date; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This function extracts the month from a date. * * @author Cedric Pronzato */ public class MonthFunction implements Function { private static final long serialVersionUID = 4577299588034323045L; public MonthFunction() { } public String getCanonicalName() { return "MONTH"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date d = typeRegistry.convertToDate(parameters.getType(0), parameters.getValue(0)); if (d == null) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Calendar gc = DateUtil.createCalendar(d, context.getLocalizationContext()); final int month = gc.get(Calendar.MONTH) + 1; return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(month)); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Year-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Year-Function.prop0000644000175000017500000000035011401240106032470 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=YEAR description=Returns the year of a date value as an integer. parameter.0.display-name=Number parameter.0.description=Internal number of the date. ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunction.jav0000644000175000017500000000636711401240106032572 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function extracts the minute (0 through 59) from a time. * * @author Cedric Pronzato */ public class MinuteFunction implements Function { private static final BigDecimal MINUTES_PER_DAY = new BigDecimal(24.0 * 60); private static final BigDecimal MINUTES = new BigDecimal(60.0); private static final BigDecimal HOURS = new BigDecimal(24.0); public MinuteFunction() { } public String getCanonicalName() { return "MINUTE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } // calculation is as follows // time * 24 so that we get the full hours (which we remove later) final BigDecimal bd = NumberUtil.getAsBigDecimal(n); final BigDecimal hours = bd.multiply(HOURS); final BigDecimal dayAndHoursAsInt = new BigDecimal(NumberUtil.performIntRounding(hours).intValue()); final BigDecimal minutesFraction = hours.subtract(dayAndHoursAsInt); // Multiply the minutes with 60 to get the minutes as ints final BigDecimal minutes = minutesFraction.multiply(MINUTES); final BigDecimal minutesAsInt = minutes.setScale(0, BigDecimal.ROUND_HALF_UP); return new TypeValuePair(NumberType.GENERIC_NUMBER, minutesAsInt); } }././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValue-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValue-Function0000644000175000017500000000047111401240106032467 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=DATEVALUE description=Returns an internal number for a text having a possible date format. parameter.0.display-name=text parameter.0.description=A text enclosed in quotation marks which returns a date in a %PRODUCTNAME date format. ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunctionDesc0000644000175000017500000000404411401240106032600 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes SecondFunction function. * * @see org.pentaho.reporting.libraries.formula.function.datetime.MinuteFunction * * @author Cedric Pronzato */ public class MinuteFunctionDescription extends AbstractFunctionDescription { public MinuteFunctionDescription() { super("MINUTE", "org.pentaho.reporting.libraries.formula.function.datetime.Minute-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.TIME_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } }././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunction.0000644000175000017500000000460311401240106032471 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Date; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; /** * This function returns * * * @author Cedric Pronzato */ public class DateValueFunction implements Function { private static final long serialVersionUID = -906531902889630172L; public DateValueFunction() { } public String getCanonicalName() { return "DATEVALUE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Type type = parameters.getType(0); final Object value = parameters.getValue(0); final Date date1 = typeRegistry.convertToDate(type, value); return new TypeValuePair(DateTimeType.DATE_TYPE, date1); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Second-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Second-Function.pr0000644000175000017500000000030711401240106032446 0ustar renerenedisplay-name=SECOND description=Determines the sequential number of the second of a minute (0-59) for the time value. parameter.0.display-name=Number parameter.0.description=The internal time value. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DaysFunction.java0000644000175000017500000000764111401240106032366 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Date; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; import java.util.Locale; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This is the same as DATEDIFF(date_1, date_2, "d"); * * @author Thomas Morgner */ public class DaysFunction implements Function { public DaysFunction() { } public String getCanonicalName() { return "DAYS"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Date date1 = typeRegistry.convertToDate (parameters.getType(0), parameters.getValue(0)); final Date date2 = typeRegistry.convertToDate (parameters.getType(1), parameters.getValue(1)); if (date1 == null || date2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final LocalizationContext localizationContext = context.getLocalizationContext(); final TimeZone timeZone = localizationContext.getTimeZone(); final Locale locale = localizationContext.getLocale(); final GregorianCalendar calandar1 = new GregorianCalendar(timeZone, locale); calandar1.setTime(date1); final GregorianCalendar calandar2 = new GregorianCalendar(timeZone, locale); calandar2.setTime(date2); final int dayOfYear1 = calandar1.get(Calendar.DAY_OF_YEAR); final int dayOfYear2 = calandar2.get(Calendar.DAY_OF_YEAR); final int year1 = calandar1.get(Calendar.YEAR); final int year2 = calandar2.get(Calendar.YEAR); final GregorianCalendar workingCalandar = new GregorianCalendar(timeZone, locale); int res = dayOfYear2 - dayOfYear1; // run through the inner years, without counting the border years // Always run from the lower to the higher, so that we prevent infinite // loops .. final int targetYear = Math.max(year1, year2); for (int i = Math.min(year1, year2); i < targetYear; i++) { workingCalandar.set(Calendar.YEAR, i); res += workingCalandar.getActualMaximum(Calendar.DAY_OF_YEAR); } //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal((double)res)); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeFunction.java0000644000175000017500000000635111401240106032361 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.sql.Time; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.util.DateUtil; /** * This fonction constructs a time from hours, minutes, and seconds. * * @author Cedric Pronzato */ public class TimeFunction implements Function { private static final long serialVersionUID = -9175775325047486483L; public TimeFunction() { } public String getCanonicalName() { return "TIME"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Number n1; final Number n2; final Number n3; try { final TypeRegistry typeRegistry = context.getTypeRegistry(); n1 = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); n2 = typeRegistry.convertToNumber(parameters.getType(1), parameters.getValue(1)); n3 = typeRegistry.convertToNumber(parameters.getType(2), parameters.getValue(2)); } catch (NumberFormatException e) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (n1 == null || n2 == null || n3 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final int hours = n1.intValue(); final int minutes = n2.intValue(); final int seconds = n3.intValue(); final LocalizationContext localizationContext = context.getLocalizationContext(); final Time time = DateUtil.createTime(hours, minutes, seconds, localizationContext); return new TypeValuePair(DateTimeType.TIME_TYPE, time); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateFunctionDescri0000644000175000017500000000440311401240106032546 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Creation-Date: 04.11.2006, 18:59:11 * * @author Thomas Morgner */ public class DateFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -7355472670804158123L; public DateFunctionDescription() { super("DATE", "org.pentaho.reporting.libraries.formula.function.datetime.Date-Function"); } public Type getValueType() { return DateTimeType.DATE_TYPE; } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return true, as all parameters are mandatory. */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/HourFunction.java0000644000175000017500000000560511401240106032401 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function extracts the hour (0 through 23) from a time. * * @author Cedric Pronzato */ public class HourFunction implements Function { private static final BigDecimal HOUR_24 = new BigDecimal(24.0); private static final long serialVersionUID = 1877256236005061937L; public HourFunction() { } public String getCanonicalName() { return "HOUR"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0)); if (n == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal bd = NumberUtil.getAsBigDecimal(n); final BigDecimal day = new BigDecimal(NumberUtil.performIntRounding(bd).intValue()); final BigDecimal dayFraction = bd.subtract(day); final BigDecimal hourAndMinutesVal = dayFraction.multiply(HOUR_24); final BigDecimal hours = NumberUtil.performIntRounding(hourAndMinutesVal); return new TypeValuePair(NumberType.GENERIC_NUMBER, hours); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDif-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDif-Function.p0000644000175000017500000000057011401240106032353 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=DATEDIF description=Returns the number of years, months, or days between two dates. parameter.0.display-name=StartDate parameter.0.description=First date. parameter.1.display-name=EndDate parameter.1.description=Second date. parameter.2.display-name=Format parameter.2.description=Format code. ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDay-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/WeekDay-Function.p0000644000175000017500000000116311401240106032403 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=WEEKDAY description=Returns the day of the week for the date value as an integer (1-7). parameter.0.display-name=Number parameter.0.description=The internal number for the date. parameter.1.display-name=Type parameter.1.description=Fixes the beginning of the week and the type of calculation to be used.\ (1 = Sunday is the first day of the week, with value 1; Saturday has value 7, \ 2 = Monday is the first day of the week, with value 1; Sunday has value 7, \ 3 = Monday is the first day of the week, with value 0; Sunday has value 6) ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/HourFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/HourFunctionDescri0000644000175000017500000000404611401240106032611 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes HourFunction function. * * @see HourFunction * * @author Cedric Pronzato */ public class HourFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7083009440959512989L; public HourFunctionDescription() { super("HOUR", "org.pentaho.reporting.libraries.formula.function.datetime.Hour-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return DateTimeType.TIME_TYPE; } public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Month-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Month-Function.pro0000644000175000017500000000042011401240106032473 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=MONTH description=Determines the sequential number of a month of the year (1-12) for the date value. parameter.0.display-name=Number parameter.0.description=The internal number of the date. ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunction.ja0000644000175000017500000001637411401240106032442 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the number of years, months, or days between two date * numbers.
*

* The Format is a code from the following table, entered as text, that * specifies the format you want: * * *
format Returns the * number of
y Years
mMonths. If there is not a complete month between the dates, 0 will be * returned.
d Days
mdDays, ignoring months and years
ym Months, * ignoring years
yd Days, ignoring years
* * @author Cedric Pronzato */ public class DateDifFunction implements Function { public static final String YEARS_CODE = "y"; public static final String MONTHS_CODE = "m"; public static final String DAYS_CODE = "d"; public static final String DAYS_IGNORING_YEARS = "yd"; public static final String MONTHS_IGNORING_YEARS = "ym"; public static final String DAYS_IGNORING_MONTHS_YEARS = "md"; private static final long serialVersionUID = 81013707499607068L; public DateDifFunction() { } public String getCanonicalName() { return "DATEDIF"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 3) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final TypeRegistry typeRegistry = context.getTypeRegistry(); final String formatCode = typeRegistry.convertToText (parameters.getType(2), parameters.getValue(2)); if (formatCode == null || "".equals(formatCode)) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (DateDifFunction.DAYS_CODE.equals(formatCode)) { final Number date1 = typeRegistry.convertToNumber (parameters.getType(0), parameters.getValue(0)); final Number date2 = typeRegistry.convertToNumber (parameters.getType(1), parameters.getValue(1)); final BigDecimal dn1 = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(date1)); final BigDecimal dn2 = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(date2)); //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(dn2.longValue() - dn1.longValue())); } final Date date1 = typeRegistry.convertToDate (parameters.getType(0), parameters.getValue(0)); final Date date2 = typeRegistry.convertToDate (parameters.getType(1), parameters.getValue(1)); if (date1 == null || date2 == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final LocalizationContext localizationContext = context.getLocalizationContext(); final TimeZone timeZone = localizationContext.getTimeZone(); final Locale locale = localizationContext.getLocale(); final GregorianCalendar calandar1 = new GregorianCalendar(timeZone, locale); calandar1.setTime(date1); final GregorianCalendar calandar2 = new GregorianCalendar(timeZone, locale); calandar2.setTime(date2); final int res; if (DateDifFunction.YEARS_CODE.equals(formatCode)) { res = Math.abs(calandar2.get(Calendar.YEAR) - calandar1.get(Calendar.YEAR)); } else if (DateDifFunction.MONTHS_CODE.equals(formatCode)) { final int month1 = calandar1.get(Calendar.MONTH); final int month2 = calandar2.get(Calendar.MONTH); final int year1 = calandar1.get(Calendar.YEAR); final int year2 = calandar2.get(Calendar.YEAR); res = Math.abs(year2 - year1) * 12 + Math.abs(month2 - month1); } else if (DateDifFunction.DAYS_IGNORING_MONTHS_YEARS.equals(formatCode)) { // The number of days between Date1 and Date2, as if Date1 and // Date2 were in the same month and the same year. // Not sure what happens to leap years, so this solution may be invalid. calandar1.set(Calendar.YEAR, calandar2.get(Calendar.YEAR)); calandar1.set(Calendar.MONTH, calandar2.get(Calendar.MONTH)); res = Math.abs(calandar2.get(Calendar.DAY_OF_MONTH) - calandar1.get(Calendar.DAY_OF_MONTH)); } else if (DateDifFunction.MONTHS_IGNORING_YEARS.equals(formatCode)) { final int month1 = calandar1.get(Calendar.MONTH); final int month2 = calandar2.get(Calendar.MONTH); res = Math.abs(month2 - month1); } else if (DateDifFunction.DAYS_IGNORING_YEARS.equals(formatCode)) { //Isn't that a stupid case? How could we count the days while ignoring //how much days there are in each months without using the year? // The number of days between Date1 and Date2, as if Date1 and Date2 // were in the same year. // Not sure what happens to leap years, so this solution may be invalid. calandar1.set(Calendar.YEAR, calandar2.get(Calendar.YEAR)); final int dayOne = calandar1.get(Calendar.DAY_OF_YEAR); final int dayTwo = calandar2.get(Calendar.DAY_OF_YEAR); res = Math.abs(dayOne - dayTwo); } else { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } //noinspection UnpredictableBigDecimalConstructorCall return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal((double) res)); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/TimeFunctionDescri0000644000175000017500000000436111401240106032572 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes the TimeFunction function * * @see TimeFunction * @author Cedric Pronzato */ public class TimeFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5414013076902907910L; public TimeFunctionDescription() { super("TIME","org.pentaho.reporting.libraries.formula.function.datetime.Time-Function"); } public Type getValueType() { return DateTimeType.TIME_TYPE; } public int getParameterCount() { return 3; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return DateTimeFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Now-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Now-Function.prope0000644000175000017500000000021711401240106032502 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=NOW description=Determines the current time of the computer. ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Today-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/datetime/Today-Function.pro0000644000175000017500000000022111401240106032465 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=TODAY description=Determines the current date of the computer. libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/FunctionDescription.java0000644000175000017500000000557611401240106032162 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.Locale; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.typing.Type; /** * A static definition of the function's parameters, return values etc. * This is a support class with emphasis on GUI tools. * * However, the parameter declarations are also used when filling in the * parameter values. * * Functions have a defined set of known parameters and can have a unlimited * number of optional parameters. If a function declares at least one parameter * and declares that its parameter list is infinite, then the last parameter * type is used on all remaining parameters. * * @author Thomas Morgner */ public interface FunctionDescription extends Serializable { public String getCanonicalName(); public String getDisplayName (Locale locale); public String getDescription (Locale locale); public boolean isVolatile(); public Type getValueType(); public FunctionCategory getCategory(); public int getParameterCount (); public boolean isInfiniteParameterCount(); /** * Returns the parameter type at the given position using the function * metadata. The first parameter is at the position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(int position); public String getParameterDisplayName(int position, Locale locale); public String getParameterDescription(int position, Locale locale); /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need * not to be filled in. * * @return */ public boolean isParameterMandatory(int position); /** * Returns the default value for an optional parameter. If the value returned * here is null, then this either means, that the parameter is mandatory or * that the default value is computed by the expression itself. * * @param position * @return */ public Object getDefaultValue (int position); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/FunctionCategory.java0000644000175000017500000000217511401240106031444 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.Locale; /** * Creation-Date: 05.11.2006, 14:24:20 * * @author Thomas Morgner */ public interface FunctionCategory { public String getDisplayName (Locale locale); public String getDescription (Locale locale); } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/InvalidFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/InvalidFunctionCategory.jav0000644000175000017500000000321011401240106032601 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.function.userdefined.UserDefinedFunctionCategory; /** * This category is used when a problem occured while loading a function metadata category. It usualy points a * problem in the configuration file or a missing function metadata class. * * @author Cedric Pronzato */ public class InvalidFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new InvalidFunctionCategory(); private InvalidFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.invalid.category"); } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/ParameterCallback.java0000644000175000017500000000262211401240106031513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.LValue; /** * Creation-Date: 13.11.2006, 13:52:21 * * @author Thomas Morgner */ public interface ParameterCallback { public LValue getRaw (int position); public Object getValue (int position) throws EvaluationException; public Type getType (int position) throws EvaluationException; public int getParameterCount(); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/FunctionRegistry.java0000644000175000017500000000310011401240106031464 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; /** * The function registry contains all information about all function available. * It is also the central point from where to get function meta-data or where * to instantiate functions. * * All functions are queried by their cannonical name. * * @author Thomas Morgner */ public interface FunctionRegistry { public FunctionCategory[] getCategories(); public Function[] getFunctions(); public Function[] getFunctionsByCategory(FunctionCategory category); public String[] getFunctionNames(); public String[] getFunctionNamesByCategory(FunctionCategory category); public Function createFunction(String name); public FunctionDescription getMetaData (String name); } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/financial/0000755000175000017500000000000011401240104027233 5ustar renerene././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/financial/category.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/financial/category.properti0000644000175000017500000000020511401240104032633 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Financial description=Contains financial functions.././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/financial/FinancialFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/financial/FinancialFunction0000644000175000017500000000265211401240104032555 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.financial; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class FinancialFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new FinancialFunctionCategory(); private FinancialFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.financial.category"); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/DefaultFunctionRegistry.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/DefaultFunctionRegistry.jav0000644000175000017500000001463411401240106032646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import org.pentaho.reporting.libraries.base.util.HashNMap; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; import org.pentaho.reporting.libraries.base.config.Configuration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Creation-Date: 02.11.2006, 12:48:32 * * @author Thomas Morgner */ public class DefaultFunctionRegistry implements FunctionRegistry { private static final Log logger = LogFactory.getLog(DefaultFunctionRegistry.class); private static final String FUNCTIONS_PREFIX = "org.pentaho.reporting.libraries.formula.functions."; private static final String[] EMPTY_ARRAY = new String[0]; private static final FunctionCategory[] EMPTY_CATEGORIES = new FunctionCategory[0]; private FunctionCategory[] categories; private HashNMap categoryFunctions; private HashMap functions; private HashMap functionMetaData; private HashMap cachedFunctions; public DefaultFunctionRegistry() { cachedFunctions = new HashMap(); categoryFunctions = new HashNMap(); functionMetaData = new HashMap(); functions = new HashMap(); categories = EMPTY_CATEGORIES; } public FunctionCategory[] getCategories() { return (FunctionCategory[]) categories.clone(); } public Function[] getFunctions() { final String[] fnNames = getFunctionNames(); final ArrayList functions = new ArrayList(fnNames.length); for (int i = 0; i < fnNames.length; i++) { final String aName = fnNames[i]; final Function function = createFunction(aName); if (function == null) { logger.debug ("There is no such function: " + aName); } else { functions.add(function); } } return (Function[]) functions.toArray(new Function[functions.size()]); } public String[] getFunctionNames() { return (String[]) functions.keySet().toArray(new String[functions.size()]); } public String[] getFunctionNamesByCategory(final FunctionCategory category) { return (String[]) categoryFunctions.toArray(category, EMPTY_ARRAY); } public Function[] getFunctionsByCategory(final FunctionCategory category) { final String[] fnNames = (String[]) categoryFunctions.toArray(category, EMPTY_ARRAY); final ArrayList functions = new ArrayList(fnNames.length); for (int i = 0; i < fnNames.length; i++) { final String aName = fnNames[i]; final Function function = createFunction(aName); if (function != null) { functions.add(function); } } return (Function[]) functions.toArray(new Function[functions.size()]); } public Function createFunction(final String name) { if (name == null) { throw new NullPointerException(); } final String functionClass = (String) functions.get(name.toUpperCase()); final Class cachedClass = (Class) cachedFunctions.get(functionClass); if (cachedClass != null) { try { return (Function) cachedClass.newInstance(); } catch (Exception e) { return null; } } final Function function = (Function) ObjectUtilities.loadAndInstantiate (functionClass, DefaultFunctionRegistry.class, Function.class); if (function == null) { logger.debug ("There is no such function: " + name); } else { cachedFunctions.put(functionClass, function.getClass()); } return function; } public FunctionDescription getMetaData(final String name) { if (name == null) { throw new NullPointerException(); } return (FunctionDescription) functionMetaData.get(name.toUpperCase()); } public void initialize(final Configuration configuration) { final Iterator functionKeys = configuration.findPropertyKeys(FUNCTIONS_PREFIX); final HashSet categories = new HashSet(); while (functionKeys.hasNext()) { final String classKey = (String) functionKeys.next(); if (classKey.endsWith(".class") == false) { continue; } final String className = configuration.getConfigProperty(classKey); if (className.length() == 0) { continue; } final Object fn = ObjectUtilities.loadAndInstantiate (className, DefaultFunctionRegistry.class, Function.class); if (fn instanceof Function == false) { continue; } final Function function = (Function) fn; final int endIndex = classKey.length() - 6; // 6 = ".class".length(); final String descrKey = classKey.substring(0, endIndex) + ".description"; final String descrClassName = configuration.getConfigProperty(descrKey); final Object descr = ObjectUtilities.loadAndInstantiate (descrClassName, DefaultFunctionRegistry.class, FunctionDescription.class); final FunctionDescription description; if (descr instanceof FunctionDescription == false) { description = new DefaultFunctionDescription(function.getCanonicalName()); } else { description = (FunctionDescription) descr; } final FunctionCategory cat = description.getCategory(); categoryFunctions.add(cat, function.getCanonicalName()); functionMetaData.put (function.getCanonicalName(), description); functions.put(function.getCanonicalName(), className); categories.add(cat); } this.categories = (FunctionCategory[]) categories.toArray(new FunctionCategory[categories.size()]); } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/0000755000175000017500000000000011401240106027636 5ustar renerene././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/category.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/category.proper0000644000175000017500000000022511401240106032703 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Information description=Contains functions which provide meta-data.././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFuncti0000644000175000017500000000506111401240106032602 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function checks whatever the given value is of Logical type. * * @author Cedric Pronzato * */ public class IsLogicalFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair( LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair( LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 7918371444174838208L; public IsLogicalFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); if(value1 instanceof Boolean || type1.isFlagSet(Type.LOGICAL_TYPE)) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISLOGICAL"; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOddFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOddFunctionDe0000644000175000017500000000405611401240106032547 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes IsOddFunction function. * @see IsOddFunction * * @author Cedric Pronzato * */ public class IsOddFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -5127816920222970031L; public IsOddFunctionDescription() { super("ISODD", "org.pentaho.reporting.libraries.formula.function.information.IsOdd-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ValueFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ValueFunctionDe0000644000175000017500000000413211401240106032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Describes ValueFunction function. * @see org.pentaho.reporting.libraries.formula.function.information.ValueFunction * * @author Kurits * */ public class ValueFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 743117553650008440L; public ValueFunctionDescription() { super("VALUE", "org.pentaho.reporting.libraries.formula.function.information.Value-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return TextType.TYPE; } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsTextFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsTextFunctionD0000644000175000017500000000404311401240106032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsTextFunction function. * @see IsTextFunction * * @author Cedric Pronzato * */ public class IsTextFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7656355697192122385L; public IsTextFunctionDescription() { super("ISTEXT", "org.pentaho.reporting.libraries.formula.function.information.IsText-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountFunction.j0000644000175000017500000000575611401240106032624 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function counts the numbers in the list of NumberSequences provided. Only numbers in references are counted; all * other types are ignored. Errors are not propagated. * * @author Cedric Pronzato */ public class CountFunction implements Function { public CountFunction() { } public String getCanonicalName() { return "COUNT"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } int count = 0; for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++) { try { final Type type = parameters.getType(paramIdx); final Object value = parameters.getValue(paramIdx); final Sequence sequence = context.getTypeRegistry().convertToNumberSequence(type, value, true); while (sequence.hasNext()) { sequence.next(); count++; } } catch (EvaluationException e) { // This is in case of an error value in a scalar argument, we must ignore this error in number sequences // todo: maybe it has to be done for other type of excetions. } } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(count)); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRef-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRef-Function.0000644000175000017500000000033011401240106032426 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISREF description=Returns TRUE if value is a reference. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsError-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsError-Functio0000644000175000017500000000034111401240106032551 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISERROR description=Returns TRUE if the value is an error value. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunction0000644000175000017500000000434111401240106032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 31.10.2006, 17:41:12 * * @author Thomas Morgner */ public class IsBlankFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 3439147216891768842L; public IsBlankFunctionDescription() { super("ISBLANK", "org.pentaho.reporting.libraries.formula.function.information.IsBlank-Function"); } public Type getValueType() { return LogicalType.TYPE; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return false */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChangedFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChangedFunct0000644000175000017500000000463711401240106032560 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Creation-Date: 24.11.2006, 13:02:41 * * @author Thomas Morgner */ public class HasChangedFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = 5952911264465883971L; public HasChangedFunction() { } public String getCanonicalName() { return "HASCHANGED"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { // we expect strings and will check, whether the reference for theses // strings is dirty. final int parCount = parameters.getParameterCount(); for (int i = 0; i < parCount; i++) { final Object value = parameters.getValue(i); if (value == null) { continue; } if (context.isReferenceDirty(value)) { return RETURN_TRUE; } } return RETURN_FALSE; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunctio0000644000175000017500000000470111401240106032637 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns true if the given value is of type Number. * * @author Cedric Pronzato * */ public class IsNumberFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 3298090211745552284L; public IsNumberFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); if(type1.isFlagSet(Type.NUMERIC_TYPE)) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISNUMBER"; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChangedFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChangedFunct0000644000175000017500000000455411401240106032556 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * Creation-Date: 31.10.2006, 17:41:12 * * @author Thomas Morgner */ public class HasChangedFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 1739366268594059040L; public HasChangedFunctionDescription() { super("HASCHANGED", "org.pentaho.reporting.libraries.formula.function.information.HasChanged-Function"); } public Type getValueType() { return LogicalType.TYPE; } public int getParameterCount() { return 1; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { return TextType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return false */ public boolean isParameterMandatory(final int position) { return false; } public boolean isVolatile() { return true; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ValueFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ValueFunction.j0000644000175000017500000000512711401240106032600 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.util.NumberUtil; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function returns the number value of a text string. * * @author Kurtis Cruzada * */ public class ValueFunction implements Function { private static final long serialVersionUID = 5203290270060842213L; public ValueFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final BigDecimal num = NumberUtil.getAsBigDecimal(result); return new TypeValuePair(NumberType.GENERIC_NUMBER, num); } public String getCanonicalName() { return "VALUE"; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Count-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Count-Function.0000644000175000017500000000051111401240106032507 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=COUNT description=Counts how many numbers are in the list of arguments. parameter.0.display-name=value parameter.0.description=Value 1, value 2, ... are 1 to 30 arguments containing different data types but where only numbers are counted. ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEven-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEven-Function0000644000175000017500000000033611401240106032537 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISEVEN description=Returns TRUE if value is an even integer. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOdd-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOdd-Function.0000644000175000017500000000033411401240106032424 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISODD description=Returns TRUE if value is an odd integer. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOddFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsOddFunction.j0000644000175000017500000000565311401240106032532 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns true if the given value is an odd number. * * @author Cedric Pronzato * */ public class IsOddFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair( LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair( LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 4967067216812927973L; public IsOddFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value = parameters.getValue(0); final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number number = typeRegistry.convertToNumber(type1, value); if (number == null) { throw EvaluationException.getInstance( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } int intValue = number.intValue(); if (intValue < 0) { intValue *= -1; } if (intValue % 2 == 1) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISODD"; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunct0000644000175000017500000000475011401240106032627 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Describes the CountBlankFunction function. * * @author Cedric Pronzato * @see org.pentaho.reporting.libraries.formula.function.information.CountBlankFunction */ public class CountBlankFunctionDescription extends AbstractFunctionDescription { public CountBlankFunctionDescription() { super("COUNTBLANK", "org.pentaho.reporting.libraries.formula.function.information.CountBlank-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } /** * Returns the parameter type at the given position using the function metadata. The first parameter is at the * position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { return AnyType.ANY_SEQUENCE; } /** * Defines, whether the parameter at the given position is mandatory. A mandatory parameter must be filled in, while * optional parameters need not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/InformationFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/InformationFunc0000644000175000017500000000266411401240106032672 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * Creation-Date: 05.11.2006, 14:30:36 * * @author Thomas Morgner */ public final class InformationFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new InformationFunctionCategory(); private InformationFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.information.category"); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRefFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRefFunctionDe0000644000175000017500000000403611401240106032553 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsRefFunction function. * @see IsRefFunction * * @author Cedric Pronzato * */ public class IsRefFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -2610558047437179067L; public IsRefFunctionDescription() { super("ISREF", "org.pentaho.reporting.libraries.formula.function.information.IsRef-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNa-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNa-Function.p0000644000175000017500000000032511401240106032434 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISNA description=Returns TRUE if value equals #N/A. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IndexFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IndexFunctionDe0000644000175000017500000000476211401240106032620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:13:36 * * @author Thomas Morgner. */ public class IndexFunctionDescription extends AbstractFunctionDescription { public IndexFunctionDescription() { super("INDEX", "org.pentaho.reporting.libraries.formula.function.information.Index-Function"); } public Type getValueType() { return AnyType.TYPE; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 3; } /** * Returns the parameter type at the given position using the function * metadata. The first parameter is at the position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { if (position == 0) { return AnyType.ANY_ARRAY; } return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need * not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { if (position == 0) { return true; } return false; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Index-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Index-Function.0000644000175000017500000000061411401240106032472 0ustar renerenedisplay-name=INDEX description=Select a value using a row and column index value (and optionally an area index). parameter.0.display-name=Array parameter.0.description=The DataSource. parameter.1.display-name=Row parameter.1.description=The Row-Index. parameter.2.display-name=Column parameter.2.description=The Column-Index. parameter.3.display-name=Area parameter.3.description=The Area Index. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ChooseFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ChooseFunction.0000644000175000017500000000502311401240106032565 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; /** * This function uses an index to return a value from a list of values. * The first value index is 1, 2 for the second and so on. * * @author Cedric Pronzato */ public class ChooseFunction implements Function { private static final long serialVersionUID = 5328221291584681439L; public ChooseFunction() { } public String getCanonicalName() { return "CHOOSE"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() <= 2) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type indexType = parameters.getType(0); final Object indexValue = parameters.getValue(0); final int index= context.getTypeRegistry().convertToNumber(indexType, indexValue).intValue(); if (index < 1 || index >= parameters.getParameterCount()) { // else throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(parameters.getType(index), parameters.getValue(index)); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrFunction.j0000644000175000017500000000651111401240106032546 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.ErrorValue; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * This function returns true if the parameter is of error and not of error type NA. * * @author Cedric Pronzato */ public class IsErrFunction implements Function { private static final Log logger = LogFactory.getLog(IsErrFunction.class); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 6749192734608313367L; public IsErrFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } try { final Type type = parameters.getType(0); final Object value = parameters.getValue(0); if (ErrorType.TYPE.equals(type) && value instanceof ErrorValue) { logger.warn ("Passing errors around is deprecated. Throw exceptions instead."); final ErrorValue na = (ErrorValue) value; if (na.getErrorCode() == LibFormulaErrorValue.ERROR_NA) { return RETURN_FALSE; } else { return RETURN_TRUE; } } } catch (EvaluationException e) { if (e.getErrorValue().getErrorCode() == LibFormulaErrorValue.ERROR_NA) { return RETURN_FALSE; } else { return RETURN_TRUE; } } return RETURN_FALSE; } public String getCanonicalName() { return "ISERR"; } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNaFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNaFunctionDes0000644000175000017500000000411511401240106032556 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsNaFunction function. * @see IsNaFunction * * @author Cedric Pronzato * */ public class IsNaFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -2401043278926889339L; public IsNaFunctionDescription() { super("ISNA", "org.pentaho.reporting.libraries.formula.function.information.IsNa-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { if(position == 0) { return AnyType.TYPE; } return null; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Choose-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Choose-Function0000644000175000017500000000057611401240106032574 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=CHOOSE description=Selects a value from a list of up to 30 value arguments. parameter.0.display-name=Index parameter.0.description=The index of the value (1..30) selected. parameter.1.display-name=value parameter.1.description=Value 1, value 2,... The list of arguments from which a value is chosen. ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunction0000644000175000017500000000507411401240106032620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Document me! * * @author : Thomas Morgner */ public class IsBlankFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair( LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair( LogicalType.TYPE, Boolean.TRUE); private static final long serialVersionUID = 3352413434463488403L; public IsBlankFunction() { } public String getCanonicalName() { return "ISBLANK"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Object value = parameters.getValue(0); final LValue raw = parameters.getRaw(0); if (raw instanceof ContextLookup) { if (value == null) { return RETURN_TRUE; } } return RETURN_FALSE; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrFunctionDe0000644000175000017500000000403511401240106032566 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsErrFunction function. * @see IsErrFunction * * @author Cedric Pronzato * */ public class IsErrFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 8746229705220584237L; public IsErrFunctionDescription() { super("ISERR", "org.pentaho.reporting.libraries.formula.function.information.IsErr-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/NaFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/NaFunctionDescr0000644000175000017500000000353511401240106032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; public class NaFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -7921200887236616400L; public NaFunctionDescription() { super("ISNA", "org.pentaho.reporting.libraries.formula.function.information.Na-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public Type getParameterType(final int position) { return null; } public Type getValueType() { return ErrorType.TYPE; } public boolean isParameterMandatory(final int position) { return false; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlank-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlank-Func0000644000175000017500000000040711401240106032513 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=COUNTBLANK description=Counts the blank cells in a specified range. parameter.0.display-name=range parameter.0.description=The range in which empty cells are to be counted. ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlank-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsBlank-Functio0000644000175000017500000000034411401240106032512 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISBLANK description=Returns TRUE if value refers to an empty cell. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunction.0000644000175000017500000000564411401240106032547 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns true if the given value is an even number. * * @author Cedric Pronzato * */ public class IsEvenFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair( LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair( LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 3298591139016352997L; public IsEvenFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value = parameters.getValue(0); final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number number = typeRegistry.convertToNumber(type1, value); if (number == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } int intValue = number.intValue(); if (intValue < 0) { intValue *= -1; } if (intValue % 2 == 0) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISEVEN"; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountFunctionDe0000644000175000017500000000471711401240106032641 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes the CountFunction function. * * @author Cedric Pronzato * @see org.pentaho.reporting.libraries.formula.function.information.CountFunction */ public class CountFunctionDescription extends AbstractFunctionDescription { public CountFunctionDescription() { super("COUNT", "org.pentaho.reporting.libraries.formula.function.information.Count-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } /** * Returns the parameter type at the given position using the function metadata. The first parameter is at the * position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { return NumberType.NUMBER_SEQUENCE; } /** * Defines, whether the parameter at the given position is mandatory. A mandatory parameter must be filled in, while * optional parameters need not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunctionD0000644000175000017500000000406311401240106032567 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes IsEvenFunction function. * @see IsEvenFunction * * @author Cedric Pronzato * */ public class IsEvenFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7863054657516063105L; public IsEvenFunctionDescription() { super("ISEVEN", "org.pentaho.reporting.libraries.formula.function.information.IsEven-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/NaFunction.java0000644000175000017500000000372511401240106032554 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; /** * This function class represents the constant error NA. * * @author Cedric Pronzato * */ public class NaFunction implements Function { private static final long serialVersionUID = 3433794709691209411L; public NaFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() != 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } public String getCanonicalName() { return "NA"; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErr-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErr-Function.0000644000175000017500000000036111401240106032446 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISERR description=Returns TRUE if the value is an error value not equal to #N/A. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountAFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountAFunction.0000644000175000017500000000555211401240106032545 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * This function counts the number of non-empty values in the list of AnySequences provided. A value is non-blank if it * contains any content of any type, including an error. * * @author Cedric Pronzato */ public class CountAFunction implements Function { public CountAFunction() { } public String getCanonicalName() { return "COUNTA"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount == 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } int count = 0; for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++) { try { final Type type = parameters.getType(paramIdx); final Object value = parameters.getValue(paramIdx); final Sequence sequence = context.getTypeRegistry().convertToSequence(type, value); while (sequence.hasNext()) { final Object o = sequence.next(); if (o != null) { count++; } } } catch (EvaluationException e) { count++; } } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(count)); } }././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonText-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonText-Funct0000644000175000017500000000033511401240106032532 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISNONTEXT description=Returns TRUE if the value is not text. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumber-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumber-Functi0000644000175000017500000000033011401240106032527 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISNUMBER description=Returns TRUE if value is a number. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IndexFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IndexFunction.j0000644000175000017500000000735211401240106032575 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Todo: Document me! *

* Date: 02.07.2009 * Time: 20:11:37 * * @author Thomas Morgner. */ public class IndexFunction implements Function { public IndexFunction() { } public String getCanonicalName() { return "INDEX"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 2 || parameterCount > 4) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final ArrayCallback arrayCallback = context.getTypeRegistry().convertToArray(parameters.getType(0), parameters.getValue(0)); if (arrayCallback == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE); } final Type rowType = parameters.getType(1); final Object rowValue = parameters.getValue(1); Number rowNumber; if (rowValue == null) { rowNumber = null; } else { rowNumber = context.getTypeRegistry().convertToNumber(rowType, rowValue); } if (rowNumber == null) { rowNumber = new BigDecimal(1); } else if (rowNumber.intValue() <= 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } if (parameterCount == 3) { Number columnNumber; final Type columnType = parameters.getType(2); final Object columnValue = parameters.getValue(2); if (columnValue == null) { columnNumber = null; } else { columnNumber = context.getTypeRegistry().convertToNumber(columnType, columnValue); } if (columnNumber == null) { columnNumber = new BigDecimal(1); } else if (columnNumber.intValue() <= 0) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } return new TypeValuePair(AnyType.TYPE, arrayCallback.getValue(rowNumber.intValue() - 1, columnNumber.intValue() - 1)); } else { return new TypeValuePair(AnyType.TYPE, arrayCallback.getValue(rowNumber.intValue() - 1, 0)); } } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountA-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountA-Function0000644000175000017500000000045411401240106032540 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=COUNTA description=Counts how many values are in the list of arguments. parameter.0.display-name=value parameter.0.description=Value 1, value 2, ... are 1 to 30 arguments representing the values to be counted. ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountAFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountAFunctionD0000644000175000017500000000472711401240106032576 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Describes the CountFunction function. * * @author Cedric Pronzato * @see CountFunction */ public class CountAFunctionDescription extends AbstractFunctionDescription { public CountAFunctionDescription() { super("COUNTA", "org.pentaho.reporting.libraries.formula.function.information.CountA-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 0; } public boolean isInfiniteParameterCount() { return true; } /** * Returns the parameter type at the given position using the function metadata. The first parameter is at the * position 0; * * @param position The parameter index. * @return The parameter type. */ public Type getParameterType(final int position) { return AnyType.ANY_SEQUENCE; } /** * Defines, whether the parameter at the given position is mandatory. A mandatory parameter must be filled in, while * optional parameters need not to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } }././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ChooseFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/ChooseFunctionD0000644000175000017500000000434311401240106032617 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes ChooseFunction function. * * @author Cedric Pronzato * @see ChooseFunction */ public class ChooseFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -9029773973577207676L; public ChooseFunctionDescription() { super("CHOOSE", "org.pentaho.reporting.libraries.formula.function.information.Choose-Function"); } public Type getValueType() { return AnyType.TYPE; } public int getParameterCount() { return 2; } public boolean isInfiniteParameterCount() { return true; } public Type getParameterType(final int position) { if (position == 1) { return NumberType.GENERIC_NUMBER; } return AnyType.TYPE; } public boolean isParameterMandatory(final int position) { if (position == 1) { return true; } return false; } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogical-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogical-Funct0000644000175000017500000000036211401240106032505 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISLOGICAL description=Returns TRUE if the value carries a logical number format. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunctio0000644000175000017500000000405711401240106032643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsNumberFunction function. * @see IsNumberFunction * * @author Cedric Pronzato * */ public class IsNumberFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 5013209949963878951L; public IsNumberFunctionDescription() { super("ISNUMBER", "org.pentaho.reporting.libraries.formula.function.information.IsNumber-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunction0000644000175000017500000000527211401240106032662 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.ErrorValue; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function returns true if the parameter is of error. * * @author Cedric Pronzato * */ public class IsErrorFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = 5692502042198617868L; public IsErrorFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if(parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } try { final Type type = parameters.getType(0); final Object value = parameters.getValue(0); if(ErrorType.TYPE.equals(type) && value instanceof ErrorValue) { return RETURN_TRUE; } } catch (EvaluationException e) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISERROR"; } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChanged-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/HasChanged-Func0000644000175000017500000000040211401240106032433 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=HASCHANGED description=Checks whether the columns specified by the given names has changed. parameter.0.description=Column name parameter.0.display-name=A name of the column. ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsText-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsText-Function0000644000175000017500000000032211401240106032561 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=ISTEXT description=Returns TRUE if value is text. parameter.0.display-name=value parameter.0.description=The value to be tested. ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFuncti0000644000175000017500000000406511401240106032632 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsNonTextFunction function. * @see IsNonTextFunction * * @author Cedric Pronzato * */ public class IsNonTextFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 3006040859953929468L; public IsNonTextFunctionDescription() { super("ISNONTEXT", "org.pentaho.reporting.libraries.formula.function.information.IsNonText-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFuncti0000644000175000017500000000420211401240106032623 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns false if the given value is of type Text. * * @author Cedric Pronzato * */ public class IsNonTextFunction extends IsTextFunction { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -372702612173903875L; public IsNonTextFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final TypeValuePair typeValuePair = super.evaluate(context, parameters); if(typeValuePair.getValue().equals(Boolean.TRUE)) { return RETURN_FALSE; } else { return RETURN_TRUE; } } public String getCanonicalName() { return "ISNONTEXT"; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Na-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Na-Function.pro0000644000175000017500000000021511401240106032477 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=NA description=Not available. Returns the error value #N/A. ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunction0000644000175000017500000000404511401240106032657 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsErrFunction function. * @see IsErrFunction * * @author Cedric Pronzato * */ public class IsErrorFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = 7082570664684812028L; public IsErrorFunctionDescription() { super("ISERROR", "org.pentaho.reporting.libraries.formula.function.information.IsError-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsTextFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsTextFunction.0000644000175000017500000000500511401240106032565 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns true if the given value is of type Text. * * @author Cedric Pronzato * */ public class IsTextFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -5358713524671627304L; public IsTextFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); if(type1.isFlagSet(Type.TEXT_TYPE) || value1 instanceof String) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISTEXT"; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRefFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsRefFunction.j0000644000175000017500000000516711401240106032540 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * This function retruns true if the given value is reference. * * @author Cedric Pronzato * */ public class IsRefFunction implements Function { private static final TypeValuePair RETURN_TRUE = new TypeValuePair( LogicalType.TYPE, Boolean.TRUE); private static final TypeValuePair RETURN_FALSE = new TypeValuePair( LogicalType.TYPE, Boolean.FALSE); private static final long serialVersionUID = -4662209967036236915L; public IsRefFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount < 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } // we want error values propagated so we need to evaluate the parameter parameters.getValue(0); final LValue raw = parameters.getRaw(0); if (raw instanceof ContextLookup) { return RETURN_TRUE; } return RETURN_FALSE; } public String getCanonicalName() { return "ISREF"; } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFuncti0000644000175000017500000000406611401240106032606 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; /** * Describes IsLogicalFunction function. * @see IsLogicalFunction * * @author Cedric Pronzato * */ public class IsLogicalFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -4814148966968602320L; public IsLogicalFunctionDescription() { super("ISLOGICAL", "org.pentaho.reporting.libraries.formula.function.information.IsLogical-Function"); } public FunctionCategory getCategory() { return InformationFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } public Type getValueType() { return LogicalType.TYPE; } public boolean isParameterMandatory(final int position) { return true; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNaFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/IsNaFunction.ja0000644000175000017500000000644311401240106032521 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.ErrorValue; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.ErrorType; import org.pentaho.reporting.libraries.formula.typing.coretypes.LogicalType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * This function returns true if the parameter is of error type NA. * * @author Cedric Pronzato */ public class IsNaFunction implements Function { private static final TypeValuePair RETURN_FALSE = new TypeValuePair(LogicalType.TYPE, Boolean.FALSE); private static final TypeValuePair RETURN_TRUE = new TypeValuePair(LogicalType.TYPE, Boolean.TRUE); private static final Log logger = LogFactory.getLog(IsNaFunction.class); private static final long serialVersionUID = 1205462839536368718L; public IsNaFunction() { } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } try { final Type type = parameters.getType(0); final Object value = parameters.getValue(0); if (ErrorType.TYPE.equals(type) && value instanceof ErrorValue) { logger.warn ("Passing errors around is deprecated. Throw exceptions instead."); final ErrorValue na = (ErrorValue) value; if (na.getErrorCode() == LibFormulaErrorValue.ERROR_NA) { return RETURN_TRUE; } } else { if (value == null) { return RETURN_TRUE; } } } catch (EvaluationException e) { if (e.getErrorValue().getErrorCode() == LibFormulaErrorValue.ERROR_NA) { return RETURN_TRUE; } } return RETURN_FALSE; } public String getCanonicalName() { return "ISNA"; } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Value-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/Value-Function.0000644000175000017500000000036311401240106032500 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=VALUE description=Returns the number value of a string. parameter.0.display-name=Number parameter.0.description=The string whose numeric value is to be returned. ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunction.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunct0000644000175000017500000000634111401240106032625 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeConversionException; import org.pentaho.reporting.libraries.formula.typing.Sequence; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.sequence.AnySequence; /** * This function counts the number of blank cells in the Reference provided. A cell is blank if it cell is empty. * * @author Cedric Pronzato */ // todo: maybe use something else than sequence (use array instead because sequence allows the use of scalar) public class CountBlankFunction implements Function { public CountBlankFunction() { } public String getCanonicalName() { return "COUNTBLANK"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { final int parameterCount = parameters.getParameterCount(); if (parameterCount != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } int count = 0; final Object value = parameters.getValue(0); final Type type = parameters.getType(0); final LValue raw = parameters.getRaw(0); if (raw instanceof ContextLookup) { if (value != null) { try { final Sequence sequence = context.getTypeRegistry().convertToSequence(type, value); while (sequence.hasNext()) { final Object o = sequence.next(); if (o == null) { count++; } } } catch (EvaluationException e) { } } } return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(count)); } }libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/0000755000175000017500000000000011401240106027136 5ustar renerene././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/category.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/category.propertie0000644000175000017500000000020311401240106032701 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=Rounding description=Contains rounding functions.libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/IntFunction.java0000644000175000017500000000505111401240106032242 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.rounding; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.function.Function; import org.pentaho.reporting.libraries.formula.function.ParameterCallback; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.util.NumberUtil; /** * This function returns a number down to the nearest integer. * * @author Cedric Pronzato */ public class IntFunction implements Function { private static final long serialVersionUID = 5835830031037500816L; public IntFunction() { } public String getCanonicalName() { return "INT"; } public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException { if (parameters.getParameterCount() != 1) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE); } final Type type1 = parameters.getType(0); final Object value1 = parameters.getValue(0); final Number result = context.getTypeRegistry().convertToNumber(type1, value1); if (result == null) { throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE); } final Number ret = NumberUtil.performIntRounding(NumberUtil.getAsBigDecimal(result)); return new TypeValuePair(NumberType.GENERIC_NUMBER, ret); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/IntFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/IntFunctionDescrip0000644000175000017500000000424111401240106032634 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.rounding; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionDescription; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; /** * Describes IntFunction function. * @see IntFunction * * @author Cedric Pronzato * */ public class IntFunctionDescription extends AbstractFunctionDescription { private static final long serialVersionUID = -8009587992546048556L; public IntFunctionDescription() { super("INT", "org.pentaho.reporting.libraries.formula.function.rounding.Int-Function"); } public Type getValueType() { return NumberType.GENERIC_NUMBER; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return NumberType.GENERIC_NUMBER; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return true; } public FunctionCategory getCategory() { return RoundingFunctionCategory.CATEGORY; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/RoundingFunctionCategory.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/RoundingFunctionCa0000644000175000017500000000260011401240106032616 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.rounding; import org.pentaho.reporting.libraries.formula.function.AbstractFunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; /** * * @author Cedric Pronzato */ public final class RoundingFunctionCategory extends AbstractFunctionCategory { public static final FunctionCategory CATEGORY = new RoundingFunctionCategory(); private RoundingFunctionCategory() { super("org.pentaho.reporting.libraries.formula.function.rounding.category"); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/Int-Function.propertieslibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/rounding/Int-Function.prope0000644000175000017500000000034611401240106032525 0ustar renerene# # Copyright (c) 2007, Pentaho Corporation. All Rights Reserved. # display-name=INT description=Rounds a number down to the nearest integer. parameter.0.display-name=Number parameter.0.description=The number to be rounded down. ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/DefaultFunctionDescription.javalibformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/DefaultFunctionDescription.0000644000175000017500000000566011401240106032617 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.util.Locale; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * Creation-Date: 05.11.2006, 15:13:03 * * @author Thomas Morgner */ public class DefaultFunctionDescription implements FunctionDescription { private String name; private static final long serialVersionUID = 8718537288789701618L; public DefaultFunctionDescription(final String name) { this.name = name; } public String getCanonicalName() { return name; } public Type getValueType() { return AnyType.TYPE; } public FunctionCategory getCategory() { return InvalidFunctionCategory.CATEGORY; } public int getParameterCount() { return 1; } public Type getParameterType(final int position) { return AnyType.TYPE; } /** * Defines, whether the parameter at the given position is mandatory. A * mandatory parameter must be filled in, while optional parameters need not * to be filled in. * * @return */ public boolean isParameterMandatory(final int position) { return false; } public String getDisplayName(final Locale locale) { return name; } public String getDescription(final Locale locale) { return ""; } public boolean isVolatile() { // assume the worst .. return true; } public boolean isInfiniteParameterCount() { return true; } public String getParameterDisplayName(final int position, final Locale locale) { // todo this is surely ugly .. return "Parameter " + String.valueOf(position); } public String getParameterDescription(final int position, final Locale locale) { return ""; } /** * Returns the default value for an optional parameter. If the value returned * here is null, then this either means, that the parameter is mandatory or * that the default value is computed by the expression itself. * * @param position * @return */ public Object getDefaultValue(final int position) { return null; } } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/function/Function.java0000644000175000017500000000336411401240106027747 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function; import java.io.Serializable; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.typing.TypeConversionException; /** * A function is an arbitary computation. A return value type is not available * unless the function has been evaluated. * * Functions must be stateless, that means: Calling the same function with * exactly the same parameters must always result in the same computed value. * * @author Thomas Morgner */ public interface Function extends Serializable { public String getCanonicalName(); public TypeValuePair evaluate (FormulaContext context, ParameterCallback parameters) throws EvaluationException; } libformula-1.1.7/source/org/pentaho/reporting/libraries/formula/ErrorValue.java0000644000175000017500000000225711401240110026416 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.util.Locale; import java.io.Serializable; /** * Creation-Date: 31.10.2006, 13:06:05 * * @author Thomas Morgner */ public interface ErrorValue extends Serializable { public String getNamespace(); public int getErrorCode(); public String getErrorMessage(Locale locale); } libformula-1.1.7/README.txt0000644000175000017500000000365411401240110014006 0ustar renereneLibFormula ========== 1. INTRODUCTION --------------- LibFormula provides Excel-Style-Expressions. The implementation provided here is very generic and can be used in any application that needs to compute formulas. The syntax and expressions ar based on the OpenFormula-specifications, but with carefully pruning away all the spreadsheet specific parts (like references to cell-ranges). For the latest news and information about LibFormula, please refer to: http://reporting.pentaho.org/libformula/ 2. SUPPORT ---------- Free support is available via the Pentaho Reporting forum, follow the link from the LibFormula home page. Please note that questions are answered by volunteers, so there is no guaranteed response time or level of service. Please avoid e-mailing the developers directly for support questions. If you post a message in the forum, then everyone can see the question, and everyone can see the answer. 3. REPORTING BUGS ----------------- If you find bugs in LibFormula, we'd like to hear about it so that we can improve future releases of LibFormula. Please post a bug report to the JIRA bug-tracker at Pentaho.org: http://jira.pentaho.org/browse/PRD Please be sure to provide as much information as you can. We need to know the version of LibFormula that you are using, the JDK version, and the steps required to replicate the bug. Include any other information that you think is relevant. 4. ANT ------ We use an open source build tool called Ant to build LibFormula. An Ant script (tested using Ant 1.6) is included in the distribution: /build.xml You can find out more about Ant at: http://ant.apache.org/ Ant is licensed under the terms of the Apache Software License (a popular open source software license). 5. OTHER FEEDBACK ----------------- For other feedback and comments, please post a message on the Pentaho forums. The Forum is available at http://forums.pentaho.org/ libformula-1.1.7/ivy.xml0000644000175000017500000000163211401240110013633 0ustar renerene libformula-1.1.7/test-lib/0000755000175000017500000000000011640447256014054 5ustar renerenelibformula-1.1.7/lib/0000755000175000017500000000000011636174536013102 5ustar renerenelibformula-1.1.7/test/0000755000175000017500000000000011401240104013262 5ustar renerenelibformula-1.1.7/test/org/0000755000175000017500000000000011401240104014051 5ustar renerenelibformula-1.1.7/test/org/pentaho/0000755000175000017500000000000011401240104015507 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/0000755000175000017500000000000011401240104017520 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/0000755000175000017500000000000011401240104021474 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/0000755000175000017500000000000011401240104023141 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/typing/0000755000175000017500000000000011401240104024453 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/typing/ArrayTest.java0000644000175000017500000000736611401240104027250 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.Formula; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.common.TestFormulaContext; import org.pentaho.reporting.libraries.formula.lvalues.TypeValuePair; import org.pentaho.reporting.libraries.formula.parser.ParseException; /** * @author Cedric Pronzato */ public class ArrayTest extends TestCase { private FormulaContext context; public ArrayTest() { } public ArrayTest(final String s) { super(s); } public void setUp() { context = new TestFormulaContext(TestFormulaContext.testCaseDataset); LibFormulaBoot.getInstance().start(); } public void testRowsInlineArrays() throws Exception { final Formula formula = new Formula("{3|2|1}"); formula.initialize(context); final TypeValuePair evaluation = formula.evaluateTyped(); assertNotNull(evaluation); assertTrue(evaluation.getType().isFlagSet(Type.ARRAY_TYPE)); final ArrayCallback table = (ArrayCallback) evaluation.getValue(); assertEquals(table.getColumnCount(), 1); assertEquals(table.getRowCount(), 3); } public void testColumnsInlineArrays() throws Exception { final Formula formula = new Formula("{3;2;1}"); formula.initialize(context); final TypeValuePair evaluation = formula.evaluateTyped(); assertNotNull(evaluation); assertTrue(evaluation.getType().isFlagSet(Type.ARRAY_TYPE)); final ArrayCallback table = (ArrayCallback) evaluation.getValue(); assertEquals(table.getColumnCount(), 3); assertEquals(table.getRowCount(), 1); } public void testInlineArrays() throws Exception { final Formula formula = new Formula("{3;2;1|2;4;6}"); formula.initialize(context); final TypeValuePair evaluation = formula.evaluateTyped(); assertNotNull(evaluation); assertTrue(evaluation.getType().isFlagSet(Type.ARRAY_TYPE)); final ArrayCallback table = (ArrayCallback) evaluation.getValue(); assertEquals(table.getColumnCount(), 3); assertEquals(table.getRowCount(), 2); } public void testInvalidInlineArrays() throws Exception { final Formula formula = new Formula("{3;2;1|2;6}"); formula.initialize(context); final Object evaluate = formula.evaluate(); assertEquals(evaluate, LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE); } public void testInvalidInlineArrays2() throws EvaluationException, ParseException { Formula formula = null; formula = new Formula("{3;1|2;6;5;6}"); formula.initialize(context); final Object evaluate = formula.evaluate(); assertEquals(evaluate, LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/typing/TypeRegisteryTest.java0000644000175000017500000001103111401240104030771 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.common.TestFormulaContext; import org.pentaho.reporting.libraries.formula.typing.coretypes.DateTimeType; import org.pentaho.reporting.libraries.formula.typing.coretypes.NumberType; import org.pentaho.reporting.libraries.formula.typing.coretypes.TextType; /** * @author Cedric Pronzato */ public class TypeRegisteryTest extends TestCase { private FormulaContext context; public TypeRegisteryTest() { } public TypeRegisteryTest(final String s) { super(s); } public void setUp() { context = new TestFormulaContext(TestFormulaContext.testCaseDataset); LibFormulaBoot.getInstance().start(); } public void testZeroDateConvertion() throws EvaluationException { final Calendar cal = new GregorianCalendar (context.getLocalizationContext().getTimeZone(), context.getLocalizationContext().getLocale()); cal.setTimeInMillis(0); final Date d = cal.getTime(); final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(DateTimeType.DATETIME_TYPE, d); assertNotNull("The date has not been converted to a number", n); final Date d1 = typeRegistry.convertToDate(DateTimeType.DATETIME_TYPE, n); assertNotNull("The number has not been converted to a date", d1); assertEquals("dates are different: " + d1 + " vs. " + d, d1.getTime(), d.getTime()); } public void testNowDateConvertion() throws Exception { final Calendar cal = new GregorianCalendar (context.getLocalizationContext().getTimeZone(), context.getLocalizationContext().getLocale()); final Date d = cal.getTime(); final Number n = context.getTypeRegistry().convertToNumber(DateTimeType.DATETIME_TYPE, d); assertNotNull("The date has not been converted to a number", n); final Date d1 = context.getTypeRegistry().convertToDate(NumberType.GENERIC_NUMBER, n); assertNotNull("The number has not been converted to a date", d1); assertEquals("dates are differents", d1.getTime(), d.getTime()); } public void testStringDateConversion() throws EvaluationException { final Date d = TestFormulaContext.createDate1(2004, GregorianCalendar.JANUARY, 1, 0, 0, 0, 0); final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(DateTimeType.DATE_TYPE, d); final Date d1 = typeRegistry.convertToDate(TextType.TYPE, "2004-01-01"); if (d1.getTime() != d.getTime()) { final Number n2 = typeRegistry.convertToNumber(DateTimeType.DATE_TYPE, d); final Date dx = typeRegistry.convertToDate(TextType.TYPE, "2004-01-01"); } assertEquals("dates are different", d1.getTime(), d.getTime()); } public void testStringNumberConversion() throws EvaluationException { final Number d = new Double(2000.5); final TypeRegistry typeRegistry = context.getTypeRegistry(); final Number n = typeRegistry.convertToNumber(NumberType.GENERIC_NUMBER, d); final Number d1 = typeRegistry.convertToNumber(TextType.TYPE, "2000.5"); if (d1.doubleValue() != d.doubleValue()) { final Number n2 = typeRegistry.convertToNumber(DateTimeType.DATE_TYPE, d); final Date dx = typeRegistry.convertToDate(TextType.TYPE, "2004-01-01"); } assertEquals("dates are different", d1.doubleValue(), d.doubleValue(), 0.0); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/typing/AnySequenceTest.java0000644000175000017500000001010511401240104030373 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.typing.sequence.AnySequence; import org.pentaho.reporting.libraries.formula.common.TestFormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.StaticValue; import org.pentaho.reporting.libraries.formula.lvalues.DefaultDataTable; /** * Todo: Document me! *

* Date: 08.07.2009 * Time: 15:41:11 * * @author Thomas Morgner. */ public class AnySequenceTest extends TestCase { public AnySequenceTest() { } public AnySequenceTest(final String s) { super(s); } public void testIterate() throws EvaluationException { final TestFormulaContext formulaContext = new TestFormulaContext(); final AnySequence emptySequence = new AnySequence(formulaContext); assertFalse(emptySequence.hasNext()); final AnySequence singleNullValueSequence = new AnySequence(new StaticValue(null), formulaContext); assertTrue(singleNullValueSequence.hasNext()); assertNull(singleNullValueSequence.next()); assertFalse(singleNullValueSequence.hasNext()); final AnySequence singleValueSequence = new AnySequence(new StaticValue("test"), formulaContext); assertTrue(singleValueSequence.hasNext()); assertEquals("test", singleValueSequence.next()); assertFalse(singleValueSequence.hasNext()); final DefaultDataTable rowTable = new DefaultDataTable(); rowTable.setObject(0, 0, new StaticValue("Test")); rowTable.setObject(1, 0, new StaticValue("Test2")); final AnySequence rowArraySequence = new AnySequence(rowTable.getAsArray(), formulaContext); assertTrue(rowArraySequence.hasNext()); assertEquals("Test", rowArraySequence.next()); assertTrue(rowArraySequence.hasNext()); assertEquals("Test2", rowArraySequence.next()); assertFalse(rowArraySequence.hasNext()); final DefaultDataTable colTable = new DefaultDataTable(); colTable.setObject(0, 0, new StaticValue("Test")); colTable.setObject(0, 1, new StaticValue("Test2")); final AnySequence colArraySequence = new AnySequence(colTable.getAsArray(), formulaContext); assertTrue(colArraySequence.hasNext()); assertEquals("Test", colArraySequence.next()); assertTrue(colArraySequence.hasNext()); assertEquals("Test2", colArraySequence.next()); assertFalse(colArraySequence.hasNext()); final DefaultDataTable colRowTable = new DefaultDataTable(); colRowTable.setObject(0, 0, new StaticValue("Test")); colRowTable.setObject(0, 1, new StaticValue("Test2")); colRowTable.setObject(1, 0, new StaticValue("Test3")); colRowTable.setObject(1, 1, new StaticValue("Test4")); final AnySequence colRowArraySequence = new AnySequence(colRowTable.getAsArray(), formulaContext); assertTrue(colRowArraySequence.hasNext()); assertEquals("Test", colRowArraySequence.next()); assertTrue(colRowArraySequence.hasNext()); assertEquals("Test2", colRowArraySequence.next()); assertTrue(colRowArraySequence.hasNext()); assertEquals("Test3", colRowArraySequence.next()); assertTrue(colRowArraySequence.hasNext()); assertEquals("Test4", colRowArraySequence.next()); assertFalse(colRowArraySequence.hasNext()); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/typing/DateConversionTest.java0000644000175000017500000001561211401240104031106 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula.typing; import java.util.Date; import java.math.BigDecimal; import junit.framework.AssertionFailedError; import org.pentaho.reporting.libraries.formula.util.HSSFDateUtil; import org.pentaho.reporting.libraries.formula.util.DateUtil; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.FormulaContext; /** * Todo: Document Me * * @author Thomas Morgner */ public class DateConversionTest extends FormulaTestBase { private static final Object[][] EMPTY_DATA = new Object[0][]; public DateConversionTest() { } public DateConversionTest(final String s) { super(s); } protected Object[][] createDataTest() { return EMPTY_DATA; } public void testDateConversion1904 () { final FormulaContext context = getContext(); final Date januaryFirst1904 = DateUtil.createDate(1904, 1, 1, context.getLocalizationContext()); final Date januaryFirst1900 = DateUtil.createDate(1900, 1, 1, context.getLocalizationContext()); final Date marchFirst1904 = DateUtil.createDate(1904, 3, 1, context.getLocalizationContext()); final Date marchFirst1900 = DateUtil.createDate(1900, 3, 1, context.getLocalizationContext()); // these numbers must match whatever OpenOffice computes .. assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, false, HSSFDateUtil.computeZeroDate("1904", false)), new BigDecimal(-1460)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, false, HSSFDateUtil.computeZeroDate("1904", false)), new BigDecimal(-1401)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, false, HSSFDateUtil.computeZeroDate("1904", false)), new BigDecimal(0)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, false, HSSFDateUtil.computeZeroDate("1904", false)), new BigDecimal(60)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, true, HSSFDateUtil.computeZeroDate("1904", true)), new BigDecimal(-1461)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, true, HSSFDateUtil.computeZeroDate("1904", true)), new BigDecimal(-1401)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, true, HSSFDateUtil.computeZeroDate("1904", true)), new BigDecimal(0)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, true, HSSFDateUtil.computeZeroDate("1904", true)), new BigDecimal(60)); } public void testDateConversion1900 () { final FormulaContext context = getContext(); final Date januaryFirst1904 = DateUtil.createDate(1904, 1, 1, context.getLocalizationContext()); final Date januaryFirst1900 = DateUtil.createDate(1900, 1, 1, context.getLocalizationContext()); final Date marchFirst1904 = DateUtil.createDate(1904, 3, 1, context.getLocalizationContext()); final Date marchFirst1900 = DateUtil.createDate(1900, 3, 1, context.getLocalizationContext()); // these numbers must match whatever OpenOffice computes .. assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, false, HSSFDateUtil.computeZeroDate("1900", false)), new BigDecimal(0)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, false, HSSFDateUtil.computeZeroDate("1900", false)), new BigDecimal(59)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, false, HSSFDateUtil.computeZeroDate("1900", false)), new BigDecimal(1460)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, false, HSSFDateUtil.computeZeroDate("1900", false)), new BigDecimal(1520)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, true, HSSFDateUtil.computeZeroDate("1900", true)), new BigDecimal(0)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, true, HSSFDateUtil.computeZeroDate("1900", true)), new BigDecimal(60)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, true, HSSFDateUtil.computeZeroDate("1900", true)), new BigDecimal(1461)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, true, HSSFDateUtil.computeZeroDate("1900", true)), new BigDecimal(1521)); } public void testDateConversion1899 () { final FormulaContext context = getContext(); final Date januaryFirst1904 = DateUtil.createDate(1904, 1, 1, context.getLocalizationContext()); final Date januaryFirst1900 = DateUtil.createDate(1900, 1, 1, context.getLocalizationContext()); final Date marchFirst1904 = DateUtil.createDate(1904, 3, 1, context.getLocalizationContext()); final Date marchFirst1900 = DateUtil.createDate(1900, 3, 1, context.getLocalizationContext()); // these numbers must match whatever OpenOffice computes .. assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, false, HSSFDateUtil.computeZeroDate("1899", false)), new BigDecimal(2)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, false, HSSFDateUtil.computeZeroDate("1899", false)), new BigDecimal(61)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, false, HSSFDateUtil.computeZeroDate("1899", false)), new BigDecimal(1462)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, false, HSSFDateUtil.computeZeroDate("1899", false)), new BigDecimal(1522)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1900, true, HSSFDateUtil.computeZeroDate("1899", true)), new BigDecimal(2)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1900, true, HSSFDateUtil.computeZeroDate("1899", true)), new BigDecimal(62)); assertEqual(HSSFDateUtil.getExcelDate(januaryFirst1904, true, HSSFDateUtil.computeZeroDate("1899", true)), new BigDecimal(1463)); assertEqual(HSSFDateUtil.getExcelDate(marchFirst1904, true, HSSFDateUtil.computeZeroDate("1899", true)), new BigDecimal(1523)); } public void assertEqual (final BigDecimal expectedResult, final BigDecimal receivedResult) { if (expectedResult == null && receivedResult == null) { return; } if (expectedResult == null || receivedResult == null) { throw new AssertionFailedError("Assertation failed: Expected " + expectedResult + ", but got " + receivedResult); } if (expectedResult.compareTo(receivedResult) != 0) { throw new AssertionFailedError("Assertation failed: Expected " + expectedResult + ", but got " + receivedResult); } } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/common/0000755000175000017500000000000011401240104024431 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/common/OperatorTest.java0000644000175000017500000000405111401240104027727 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.common; import java.math.BigDecimal; import junit.framework.Assert; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.ContextEvaluationException; public class OperatorTest extends FormulaTestBase { protected Object[][] createDataTest() { return new Object[][] { {"1 + 1", new BigDecimal(2)}, {"1 - 1", new BigDecimal(0)}, {"1 = 1", Boolean.TRUE}, {"1 <> 1", Boolean.FALSE}, {"1 < 1", Boolean.FALSE}, {"1 > 1", Boolean.FALSE}, {"1 >= 1", Boolean.TRUE}, {"1 <= 1", Boolean.TRUE}, {"1 * 1", new BigDecimal(1)}, {"1 ^ 1", new BigDecimal(1.0)}, {"1 / 1", new BigDecimal(1)}, {"1%", new BigDecimal("0.01")}, {"0.1%", new BigDecimal("0.001")}}; } public void testDefault() throws Exception { runDefaultTest(); } public void testRangeOperator() throws ContextEvaluationException { final Object resolveReference = getContext().resolveReference(".B4:.B5"); Assert.assertNotNull("Reference should not be null", resolveReference); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/common/TestFormulaContext.java0000644000175000017500000002561411401240104031116 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.common; import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.formula.ContextEvaluationException; import org.pentaho.reporting.libraries.formula.DefaultFormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.FormulaContext; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; import org.pentaho.reporting.libraries.formula.LocalizationContext; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.function.FunctionRegistry; import org.pentaho.reporting.libraries.formula.lvalues.ContextLookup; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.operators.OperatorFactory; import org.pentaho.reporting.libraries.formula.typing.ArrayCallback; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.TypeRegistry; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * @author Cedric Pronzato */ public class TestFormulaContext implements FormulaContext { private class InlineArrayCallback implements ArrayCallback { private final String firstColumnName; private final int firstRow; private final int firstCol; private final int count; protected InlineArrayCallback(final String firstColumnName, final int firstRow, final int firstCol, final int count) { this.firstColumnName = firstColumnName; this.firstRow = firstRow; this.firstCol = firstCol; this.count = count; } public LValue getRaw(final int row, final int column) throws EvaluationException { if (column == 0) { final ContextLookup lookup = new ContextLookup("." + firstColumnName + (firstRow + row)); lookup.initialize(formulaContext); return lookup; } return null; } public Object getValue(final int row, final int column) throws EvaluationException { // System.out.println((firstRow+row) + " col " + column + " first col " + firstCol); if (column == 0) { return model.getValueAt(firstRow + row, firstCol); } throw new RuntimeException("cannot find symbol"); } public Type getType(final int row, final int column) throws EvaluationException { if (column == 0) { return resolveReferenceType('.' + firstColumnName + (firstRow + row)); } return AnyType.TYPE; } public int getColumnCount() { return 1; } public int getRowCount() { return count; } } public static Date createDate1(final int year, final int month, final int day, final int hour, final int minute, final int sec, final int millisec) { final Calendar cal = GregorianCalendar.getInstance(); cal.set(GregorianCalendar.YEAR, year); cal.set(GregorianCalendar.MONTH, month); cal.set(GregorianCalendar.DAY_OF_MONTH, day); cal.set(GregorianCalendar.HOUR_OF_DAY, hour); cal.set(GregorianCalendar.MINUTE, minute); cal.set(GregorianCalendar.SECOND, sec); cal.set(GregorianCalendar.MILLISECOND, millisec); return cal.getTime(); } /* * id B C 3 ="7" 4 =2 4 5 =3 5 6 =1=1 7 7 ="Hello" 2005-01-31 8 2006-01-31 9 * =1/0 02:00:00 10 =0 23:00:00 11 3 5 12 4 6 13 2005-01-31T01:00:00 8 14 1 * 4 15 2 3 16 3 2 17 4 1 */ public static Date createDate1() { final Calendar cal = GregorianCalendar.getInstance(); cal.set(GregorianCalendar.YEAR, 2005); cal.set(GregorianCalendar.MONTH, GregorianCalendar.JANUARY); cal.set(GregorianCalendar.DAY_OF_MONTH, 31); cal.set(GregorianCalendar.MILLISECOND, 0); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); return cal.getTime(); } public static java.sql.Date createDate(final int year, final int month, final int day) { final Calendar cal = GregorianCalendar.getInstance(); cal.set(GregorianCalendar.YEAR, year); cal.set(GregorianCalendar.MONTH, month); cal.set(GregorianCalendar.DAY_OF_MONTH, day); cal.set(GregorianCalendar.MILLISECOND, 0); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); return new java.sql.Date(cal.getTime().getTime()); } private static class TestCaseTableModel extends AbstractTableModel { private Object[][] data = new Object[][] { // B , C {null, null}, // 0 {null, null}, // 1 {null, null}, // 2 {"7", null}, // 3 {new BigDecimal(2), new BigDecimal(4)}, // 4 {new BigDecimal(3), new BigDecimal(5)}, // 5 {Boolean.TRUE, new BigDecimal(7)}, // 6 {"Hello", createDate(2005, Calendar.JANUARY, 31)}, // 7 {null, createDate1(2006, Calendar.JANUARY, 31, 0, 0, 0, 0)}, // 8 {LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE, createDate1(0, 0, 0, 2, 0, 0, 0)}, // 9 {new BigDecimal(0), createDate1(0, 0, 0, 23, 0, 0, 0)}, // 10 {new BigDecimal(3), new BigDecimal(5)}, // 11 {new BigDecimal(4), new BigDecimal(6)}, // 12 {null, null}, // 13 {new BigDecimal(1), new BigDecimal(4)}, // 14 {new BigDecimal(2), new BigDecimal(3)}, // 15 {new BigDecimal(3), new BigDecimal(2)}, // 16 {new BigDecimal(4), new BigDecimal(1)}, // 17 }; public int getColumnCount() { return 2; } public String getColumnName(final int column) { if (column == 0) { return "B"; } else if (column == 1) { return "C"; } return null; } public int getRowCount() { return 18; } public Object getValueAt(final int rowIndex, final int columnIndex) { return data[rowIndex][columnIndex]; } } private FormulaContext formulaContext; private TableModel model; private boolean useGuessType; public static final TableModel testCaseDataset = new TestCaseTableModel(); /** * Creates an empty formula context. It means that no references will be available. */ public TestFormulaContext() { this(new DefaultTableModel(), true); } /** * Creates a formula context using the given model for references. The references type will always be of type * Any. * * @param model The model. */ public TestFormulaContext(final TableModel model) { this(model, true); } /** * Creates a formula context using the given model for references. * * @param model The table model to use * @param guessType if resolveReferenceType should guess the type of the reference or return a type * Any. */ public TestFormulaContext(final TableModel model, final boolean guessType) { formulaContext = new DefaultFormulaContext (LibFormulaBoot.getInstance().getGlobalConfig(), Locale.US, TimeZone.getDefault()); this.model = model; useGuessType = guessType; } public Configuration getConfiguration() { return formulaContext.getConfiguration(); } public FunctionRegistry getFunctionRegistry() { return formulaContext.getFunctionRegistry(); } public LocalizationContext getLocalizationContext() { return formulaContext.getLocalizationContext(); } public OperatorFactory getOperatorFactory() { return formulaContext.getOperatorFactory(); } public TypeRegistry getTypeRegistry() { return formulaContext.getTypeRegistry(); } public boolean isReferenceDirty(final Object name) throws ContextEvaluationException { return formulaContext.isReferenceDirty(name); } public Object resolveReference(final Object name) throws ContextEvaluationException { if (name instanceof String) { final String ref = (String) name; final String[] split = ref.split(":"); if (split.length == 0) { return null; } // assuming references with the following format: // - starting with a . // - followed by the column name identified by one letter // - followed by digits representing the row number final String firstColumnName = split[0].substring(1, 2); int col = -1; for (int i = 0; i < model.getColumnCount(); i++) { if (firstColumnName.equalsIgnoreCase(model.getColumnName(i))) { col = i; break; } } final int firstCol = col; final int firstRow = Integer.parseInt(split[0].substring(2)); if (split.length == 2) { // array of reference assuming same column name final int secondRow = Integer.parseInt(split[1].substring(2)); final int count = secondRow - firstRow; if (count >= 0) { return new InlineArrayCallback(firstColumnName, firstRow, firstCol, count + 1); } // else error } else { // one reference return model.getValueAt(firstRow, firstCol); } } return null; } public Type resolveReferenceType(final Object name) throws ContextEvaluationException { if (name instanceof String) { final String ref = (String) name; final String[] split = ref.split(":"); if (split.length == 2) { return AnyType.ANY_ARRAY; } } if (useGuessType) { final Object value = resolveReference(name); return getTypeRegistry().guessTypeOfObject(value); } else { return AnyType.TYPE; } } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/operators/0000755000175000017500000000000011401240104025157 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/operators/EqualOperatorTest.java0000644000175000017500000000306311401240104031447 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * Creation-Date: 10.04.2007, 15:31:58 * * @author Thomas Morgner */ public class EqualOperatorTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"1=\"1\"", Boolean.TRUE}, {"2=2.0", Boolean.TRUE}, {"\"2004-01-01\"=DATE(2004; 1; 1)", Boolean.TRUE}, // comparing values of different types should yield 'false' }; } public EqualOperatorTest() { } public EqualOperatorTest(final String s) { super(s); } public void testDefault() throws Exception { runDefaultTest(); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/operators/PercentageOperatorTest.java0000644000175000017500000000265711401240104032465 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * Creation-Date: 11.26.2007, 15:31:58 * * @author David Kincade */ public class PercentageOperatorTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"0.25%", new BigDecimal("0.0025")}, {"25%", new BigDecimal("0.25")}, {"125%", new BigDecimal("1.25")}, }; } public void testDefault() throws Exception { runDefaultTest(); } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/operators/MinusSignOperatorTest.java0000644000175000017500000000265311401240104032320 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * Creation-Date: 11.26.2007, 15:31:58 * * @author David Kincade */ public class MinusSignOperatorTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"-0.5", new BigDecimal("-0.5")}, {"-5", new BigDecimal("-5.0")}, {"-5.0", new BigDecimal("-5.0")}, }; } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/operators/ArithmeticOperatorTest.java0000644000175000017500000000276211401240104032476 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.operators; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * Creation-Date: 10.04.2007, 15:31:58 * * @author Thomas Morgner */ public class ArithmeticOperatorTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"(1/3)*3", new BigDecimal(1)}, {"(5/24)*24", new BigDecimal(5)}, }; } public ArithmeticOperatorTest() { } public ArithmeticOperatorTest(final String s) { super(s); } public void testDefault() throws Exception { runDefaultTest(); } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/OpenFormulaConformance.java0000644000175000017500000001357511401240104030421 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import java.util.ArrayList; import java.util.HashSet; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.common.TestFormulaContext; import org.pentaho.reporting.libraries.base.util.DebugLog; public class OpenFormulaConformance extends TestCase { public static final String SMALL_GROUP = "ABS; ACOS; AND;" + "ASIN; ATAN; ATAN2; AVERAGE; CHOOSE; COLUMNS; COS; COUNT; COUNTA;" + "COUNTBLANK; COUNTIF; DATE; DAVERAGE; DAY; DCOUNT; DCOUNTA; DDB;" + "DEGREES; DGET; DMAX; DMIN; DPRODUCT; DSTDEV; DSTDEVP; DSUM; DVAR;" + "DVARP; EVEN; EXACT; EXP; FACT; FALSE; FIND; FV; HLOOKUP; HOUR; IF; INDEX;" + "INT; IRR; ISBLANK; ISERR; ISERROR; ISLOGICAL; ISNA; ISNONTEXT; ISNUMBER;" + "ISTEXT; LEFT; LEN; LN; LOG; LOG10; LOWER; MATCH; MAX; MID; MIN; MINUTE;" + "MOD; MONTH; N; NA; NOT; NOW; NPER; NPV; ODD; OR; PI; PMT; POWER;" + "PRODUCT; PROPER; PV; RADIANS; RATE; REPLACE; REPT; RIGHT; ROUND;" + "ROWS; SECOND; SIN; SLN; SQRT; STDEV; STDEVP; SUBSTITUTE; SUM; SUMIF;" + "SYD; T; TAN; TIME; TODAY; TRIM; TRUE; TRUNC; UPPER; VALUE; VAR; VARP;" + "VLOOKUP; WEEKDAY; YEAR"; public static final String MEDIUM_GROUP = SMALL_GROUP + "ACCRINT; ACCRINTM; ACOSH; ACOT; ACOTH; ADDRESS; ASINH; ATANH; AVEDEV;" + "BESSELI; BESSELJ; BESSELK; BESSELY; BETADIST; BETAINV; BINOMDIST; CEILING;" + "CHAR; CHIDIST; CHIINV; CHITEST; CLEAN; CODE; COLUMN; COMBIN; CON CATENATE;" + "CONFIDENCE; CONVERT; CORREL; COSH; COT; COTH; COUPDAYBS; COUPDAYS;" + "COUPDAYSNC; COUPNCD; COUPNUM; COUPPCD; COVAR; CRITBINOM; CUMIPMT;" + "CUMPRINC; DATEVALUE; DAYS360; DB; DEVSQ; DISC; DOLLARDE; DOLLARFR;" + "DURATION; EOMONTH; ERF; ERFC; EXPONDIST; FDIST; FINV; FISHER; FISHERINV; FIXED;" + "FLOOR; FORECAST; FTEST; GAMMADIST; GAMMAINV; GAMMALN; GCD; GEOMEAN;" + "HARMEAN; HYPGEOMDIST; INTERCEPT; INTRATE; ISEVEN; ISODD; KURT; LARGE; LCM;" + "LINEST; LOGINV; LOGNORMDIST; LOOKUP; MDURATION; MEDIAN; MINVERSE; MIRR;" + "MMULT; MODE; MROUND; MULTINOMIAL; NEGBINOMDIST; NETWORKDAYS; NOMINAL;" + "NORMDIST; NORMINV; NORMSDIST; NORMSINV; ODDFPRICE; ODDFYIELD; ODDLPRICE;" + "ODDLYIELD; OFFSET; PEARSON; PERCENTILE; PERCENTRANK; PERMUT; POISSON;" + "PRICE; PRICEMAT; PROB; QUARTILE; QUOTIENT; RAND; RANDBETWEEN; RANK;" + "RECEIVED; ROMAN; ROUNDDOWN; ROUNDUP; ROW; RSQ; SERIESSUM; SIGN; SINH;" + "SKEW; SLOPE; SMALL; SQRTPI; STANDARDIZE; STDEVPA; STEYX; SUBTOTAL;" + "SUMPRODUCT; SUMSQ; SUMX2MY2; SUMX2PY2; SUMXMY2; TANH; TBILLEQ; TBILLPRICE;" + "TBILLYIELD; TDIST; TIMEVALUE; TINV; TRANSPOSE; TREND; TRIMMEAN; TTEST; TYPE;" + "VARA; VDB; WEEKNUM; WEIBULL; WORKDAY; XIRR; XNPV; YEARFRAC; YIELD;" + "YIELDDISC; YIELDMAT; ZTEST"; public static final String LARGE_GROUP = MEDIUM_GROUP + "AMORDEGRC; AMORLINC; ARABIC; AREAS; ASC; AVERAGEA; B; BAHTTEXT; BASE;" + "BIN2DEC; BIN2HEX; BIN2OCT; BITAND; BITLSHIFT; BITOR; BITRSHIFT; BITXORCEILING;" + "COMBINA; COMPLEX; CURRENT; DATEDIF; DAYS; DBSC; DDE; DEC2BIN; DEC2HEX;" + "DEC2OCT; DECIMAL; DELTA; EDATE; EFFECT; EFFECTIVE; ERROR.TYPE; FACTDOUBLE;" + "FINDB; FORMULA; FREQUENCY; FVSCHEDULE; GAMMA; GAUSS; GESTEP;" + "GETPIVOTDATA; GROWTH; HEX2BIN; HEX2DEC; HEX2OCT; HYPERLINK; HYPGEOMVERT;" + "IMABS; IMAGINARY; IMARGUMENT; IMCONJUGATE; IMCOS; IMDIV; IMEXP; IMLN;" + "IMLOG10; IMLOG2; IMPOWER; IMPRODUCT; IMREAL; IMSIN; IMSQRT; IMSUB; IMSUM;" + "INDIRECT; INFO; IPMT; ISFORMULA; ISPMT; ISREF; LEFTB; LENB; MAXA; MDETERM;" + "MUNIT; MIDB; MINA; MNORMSINV; NUMBERSTRING; OCT2BIN; OCT2DEC; OCT2HEX;" + "PERMUTATIONA; PHI; PHONETIC; PPMT; PRICEDISC; REPLACEB; RIGHTB; RRI; RTD;" + "SEARCH; SEARCHB; SHEET; SHEETS; TEXT; VARPA; XOR"; private FormulaContext context; private HashSet implementedFunctions; public OpenFormulaConformance() { } public OpenFormulaConformance(final String s) { super(s); } protected void setUp() throws Exception { context = new TestFormulaContext(); LibFormulaBoot.getInstance().start(); implementedFunctions = new HashSet(); final String[] functionNames = context.getFunctionRegistry().getFunctionNames(); for (int i = 0; i < functionNames.length; i++) { implementedFunctions.add(functionNames[i]); } } public void testIsInSmallGroup() { isInGroup("SmallGroup", SMALL_GROUP); } private void isInGroup(final String groupName, final String groupFunctions) { final ArrayList functionsNotInGroup = new ArrayList(); final String[] split = groupFunctions.split(";"); for (int i = 0; i < split.length; i++) { final String func = split[i].trim(); if (!implementedFunctions.contains(func)) { functionsNotInGroup.add(func); } } DebugLog.log ("The following " + functionsNotInGroup.size() + " (out of " + split.length + " requested) functions are not yet implemented for the " + groupName + " conformance: " + functionsNotInGroup.toString()); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/FormulaTestBase.java0000644000175000017500000000543111401240104027047 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.common.TestFormulaContext; /** * Todo: Document Me * * @author Thomas Morgner */ public abstract class FormulaTestBase extends TestCase { private FormulaContext context; protected FormulaTestBase() { } protected FormulaTestBase(final String s) { super(s); } protected void setUp() throws Exception { context = new TestFormulaContext(TestFormulaContext.testCaseDataset); LibFormulaBoot.getInstance().start(); } protected abstract Object[][] createDataTest(); public FormulaContext getContext() { return context; } protected void runDefaultTest() throws Exception { final Object[][] dataTest = createDataTest(); runTest(dataTest); } protected void runTest(final Object[][] dataTest) throws Exception { for (int i = 0; i < dataTest.length; i++) { final Object[] objects = dataTest[i]; performTest((String) objects[0], objects[1]); } } protected void performTest(final String formul, final Object result) throws Exception { performTest(formul, result, this.context); } protected void performTest(final String formul, final Object result, final FormulaContext context) throws Exception { final Formula formula = new Formula(formul); formula.initialize(context); final Object eval = formula.evaluateTyped().getValue(); if (result instanceof Comparable && eval instanceof Comparable) { final Comparable n = (Comparable) result; try { assertTrue("Failure numeric comparison on " + formul + ": " + result + " vs. " + eval, n.compareTo(eval) == 0); } catch (final ClassCastException cce) { cce.printStackTrace(); fail("Failure numeric comparison on " + formul + ": " + result + " vs. " + eval); } } else { assertEquals("Failure on " + formul, result, eval); } } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/FormulaParsingTest.java0000644000175000017500000000674511401240104027611 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.formula; import junit.framework.TestCase; import org.pentaho.reporting.libraries.formula.parser.ParseException; import org.pentaho.reporting.libraries.formula.lvalues.Term; /** * Todo: Document Me * * @author Thomas Morgner */ public class FormulaParsingTest extends TestCase { public FormulaParsingTest() { super(); } public FormulaParsingTest(final String s) { super(s); } protected void setUp() throws Exception { LibFormulaBoot.getInstance().start(); } public void testTermOperands() throws ParseException, EvaluationException { final Formula formula = new Formula("\"a\" & \"b\" & \"c\""); formula.initialize(new DefaultFormulaContext()); Term term = (Term) formula.getRootReference(); term.getOperands(); } public void testParseWithLineBreaks() throws ParseException, EvaluationException { final Formula formula = new Formula("\"aaa\" \n&\n \"bb\" & \"\n\" & \"\""); formula.initialize(new DefaultFormulaContext()); final Object o = formula.evaluate(); assertEquals("Formula value", "aaabb\n", o); } public void testParse() throws ParseException, EvaluationException { final Formula formula = new Formula("MID(UPPER([name] & \n\r" + " \" \" \n\r" + " & [firstname]);5;10)"); final DefaultFormulaContext context = new DefaultFormulaContext(); context.defineReference("name", "name"); context.defineReference("firstname", "firstname"); formula.initialize(context); final Object o = formula.evaluate(); assertEquals("Formula value", " FIRSTNAME", o); } public void testEscapes() throws Exception { final Formula formula = new Formula("T(\"\\\") = \"A\""); final DefaultFormulaContext context = new DefaultFormulaContext(); context.defineReference("path", "x"); formula.initialize(context); final Object o = formula.evaluate(); assertEquals("Formula value", Boolean.FALSE, o); } public void testQuotedReference() throws Exception { final Formula formula = new Formula("T([\"\\\\\"]) = \"A\""); final DefaultFormulaContext context = new DefaultFormulaContext(); context.defineReference("path", "x"); formula.initialize(context); final Object o = formula.evaluate(); assertEquals("Formula value", Boolean.FALSE, o); } public void testQuotedReference2() throws Exception { final Formula formula = new Formula("T([\"[x]\"]) = \"x\""); final DefaultFormulaContext context = new DefaultFormulaContext(); context.defineReference("[x]", "x"); formula.initialize(context); final Object o = formula.evaluate(); assertEquals("Formula value", Boolean.TRUE, o); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/0000755000175000017500000000000011401240104024766 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/0000755000175000017500000000000011401240104025717 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/ModFunctionTest.java0000644000175000017500000000360511401240104031653 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class ModFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"MOD(10;3)", new BigDecimal(1)}, {"MOD(2;8)", new BigDecimal(2)}, {"MOD(5.5;2.5)", new BigDecimal(0.5)}, {"MOD(-2;3)", new BigDecimal(1)}, {"MOD(2;-3)", new BigDecimal(-1)}, {"MOD(-2;-3)", new BigDecimal(-2)}, {"MOD(10;0)", LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE}, // custom tests {"MOD(40;50)", new BigDecimal(40)}, {"MOD(-40;50)", new BigDecimal(10)}, {"MOD(40;-50)", new BigDecimal(-10)}, {"MOD(-40;-50)", new BigDecimal(-40)}, }; } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/MinFunctionTest.java0000644000175000017500000000346611401240104031664 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class MinFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"MIN(2;4;1;-8)", new BigDecimal(-8)}, // {"MIN([.B4:.B5])", new BigDecimal(2)}, // TODO {"MIN([.B3])", new BigDecimal(0)}, I do not understand what is wanted: // What happens when MIN is provided 0 parameters is implementation-defined, but MIN() with no parameters should return 0. // TODO same for MAX() // TODO {"MIN(\"a\")", error}, this case should not yet be handled (inline != reference) // {"MIN([.B3:.B5])", new BigDecimal(2)}, {"MIN(\"5\";\"7\")", new BigDecimal(5)}, }; } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/AverageFunctionTest.java0000644000175000017500000000245611401240104032511 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class AverageFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"AVERAGE(2;4)", new BigDecimal(3)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/OddFunctionTest.java0000644000175000017500000000500211401240104031633 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class OddFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ODD(5)", new BigDecimal(5)}, {"ODD(-5)", new BigDecimal(-5)}, {"ODD(2)", new BigDecimal(3)}, {"ODD(0.3)", new BigDecimal(1)}, {"ODD(-2)", new BigDecimal(-3)}, {"ODD(-0.3)", new BigDecimal(-1)}, {"ODD(0)", new BigDecimal(1)}, {"ODD(0.0)", new BigDecimal(1)}, {"ODD(0.05)", new BigDecimal(1)}, {"ODD(0.95)", new BigDecimal(1)}, {"ODD(1.0)", new BigDecimal(1)}, {"ODD(1.05)", new BigDecimal(3)}, {"ODD(1.9)", new BigDecimal(3)}, {"ODD(2.0)", new BigDecimal(3)}, {"ODD(2.05)", new BigDecimal(3)}, {"ODD(2.95)", new BigDecimal(3)}, {"ODD(3.0)", new BigDecimal(3)}, {"ODD(3.05)", new BigDecimal(5)}, {"ODD(-0.05)", new BigDecimal(-1)}, {"ODD(-0.95)", new BigDecimal(-1)}, {"ODD(-1.0)", new BigDecimal(-1)}, {"ODD(-1.05)", new BigDecimal(-3)}, {"ODD(-1.9)", new BigDecimal(-3)}, {"ODD(-2.0)", new BigDecimal(-3)}, {"ODD(-2.05)", new BigDecimal(-3)}, {"ODD(-2.95)", new BigDecimal(-3)}, {"ODD(-3.0)", new BigDecimal(-3)}, {"ODD(-3.05)", new BigDecimal(-5)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/AbsFunctionTest.java0000644000175000017500000000266211401240104031643 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.FormulaContext; /** * @author Cedric Pronzato */ public class AbsFunctionTest extends FormulaTestBase { private FormulaContext context; public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ABS(4)", new BigDecimal(4)}, {"ABS(-4)", new BigDecimal(4)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/EvenFunctionTest.java0000644000175000017500000000454111401240104032031 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class EvenFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"EVEN(6)", new BigDecimal(6)}, {"EVEN(-4)", new BigDecimal(-4)}, {"EVEN(1)", new BigDecimal(2)}, {"EVEN(0.3)", new BigDecimal(2)}, {"EVEN(-1)", new BigDecimal(-2)}, {"EVEN(-0.3)", new BigDecimal(-2)}, {"EVEN(0)", new BigDecimal(0)}, // test with border cases {"EVEN(0.05)", new BigDecimal(2)}, {"EVEN(2.05)", new BigDecimal(4)}, {"EVEN(3.05)", new BigDecimal(4)}, {"EVEN(4.05)", new BigDecimal(6)}, {"EVEN(5.0)", new BigDecimal(6)}, {"EVEN(6.0)", new BigDecimal(6)}, {"EVEN(7.95)", new BigDecimal(8)}, {"EVEN(8.95)", new BigDecimal(10)}, {"EVEN(-0.05)", new BigDecimal(-2)}, {"EVEN(-2.05)", new BigDecimal(-4)}, {"EVEN(-3.05)", new BigDecimal(-4)}, {"EVEN(-4.05)", new BigDecimal(-6)}, {"EVEN(-5.0)", new BigDecimal(-6)}, {"EVEN(-6.0)", new BigDecimal(-6)}, {"EVEN(-7.95)", new BigDecimal(-8)}, {"EVEN(-8.95)", new BigDecimal(-10)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/PowerFunctionTest.java0000644000175000017500000000267611401240104032237 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.FormulaContext; /** * @author Cedric Pronzato */ public class PowerFunctionTest extends FormulaTestBase { private FormulaContext context; public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"POWER(10;0)", new BigDecimal(1)}, {"POWER(2;8)", new BigDecimal(256)}, }; } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/MaxFunctionTest.java0000644000175000017500000000330611401240104031657 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class MaxFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"MAX(2;4;1;-8)", new BigDecimal(4)}, // {"MAX([.B4:.B5])", new BigDecimal(3)}, {"ISNA(MAX(NA()))", Boolean.TRUE}, // {"MAX([.B3:.B5])", new BigDecimal(3)}, // {"MAX([.B3:.B7])", new BigDecimal(3)}, // //TODO { "MAX([.B3:.B9])", new BigDecimal(4)}, this one sounds fault, there is no '4' // {"MAX([.B3:.B9])", new BigDecimal(3)}, {"MAX(\"5\";\"7\")", new BigDecimal(7)}, }; } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/math/SumFunctionTest.java0000644000175000017500000000274311401240104031702 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.math; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class SumFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"SUM(1;2;3)", new BigDecimal(6)}, {"SUM(TRUE();2;3)", new BigDecimal(6)}, {"SUM({3|2|1})", new BigDecimal(6)}, //TODO operator not yet supported { "SUM([.B4:.B5])", new BigDecimal(5)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/0000755000175000017500000000000011401240104025752 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/LeftFunctionTest.java0000644000175000017500000000331211401240104032054 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class LeftFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"LEFT(\"Hello\";2)", "He"}, {"LEFT(\"Hello\")", "H"}, {"LEFT(\"Hello\";20)", "Hello"}, {"LEFT(\"Hello\";0)", ""}, {"LEFT(\"\";4)", ""}, {"LEN(LEFT(\"xxx\";-0.1))", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"LEN(LEFT(\"xxx\";2^15-1))", new BigDecimal(3)}, {"LEFT(\"Hello\";2.9)", "He"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/TrimFunctionTest.java0000644000175000017500000000267211401240104032105 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class TrimFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"TRIM(\" HI \")", "HI"}, {"LEN(TRIM(\"H\" & \" \" & \" \" & \"I\"))", new BigDecimal(3)}, // custom tests {"TRIM(\" Oh no !\")", "Oh no !"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/RightFunctionTest.java0000644000175000017500000000273111401240104032243 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class RightFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"RIGHT(\"Hello\";2)", "lo"}, {"RIGHT(\"Hello\")", "o"}, {"RIGHT(\"Hello\";20)", "Hello"}, {"RIGHT(\"Hello\";0)", ""}, {"RIGHT(\"Hello\";2^15-1)", "Hello"}, {"RIGHT(\"\";4)", ""}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/LowerFunctionTest.java0000644000175000017500000000241711401240104032257 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class LowerFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"LOWER(\"HELLObc7\")", "hellobc7"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/LenFunctionTest.java0000644000175000017500000000261211401240104031702 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class LenFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"LEN(\"Hi There\")", new BigDecimal(8)}, {"LEN(\"\")", new BigDecimal(0)}, {"LEN(55)", new BigDecimal(2)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/FindFunctionTest.java0000644000175000017500000000356711401240104032056 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class FindFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"FIND(\"b\";\"abcabc\")", new BigDecimal(2)}, {"FIND(\"b\";\"abcabcabc\"; 3)", new BigDecimal(5)}, {"FIND(\"b\";\"ABC\";1)", LibFormulaErrorValue.ERROR_NOT_FOUND_VALUE}, {"FIND(\"b\";\"bbbb\")", new BigDecimal(1)}, {"FIND(\"b\";\"bbbb\";2)", new BigDecimal(2)}, {"FIND(\"b\";\"bbbb\";2.9)", new BigDecimal(2)}, {"FIND(\"b\";\"bbbb\";0)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"FIND(\"b\";\"bbbb\";0.9)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/ReplaceFunctionTest.java0000644000175000017500000000253411401240104032542 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class ReplaceFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"REPLACE(\"123456789\";5;3;\"Q\")", "1234Q89"}, {"REPLACE(\"123456789\";5;0;\"Q\")", "1234Q56789"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/TextFunctionTest.java0000644000175000017500000000314511401240104032112 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import java.util.Locale; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class TextFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { final Locale locale = getContext().getLocalizationContext().getLocale(); final DecimalFormat format = new DecimalFormat("#0.#######", new DecimalFormatSymbols(locale)); return new Object[][] { {"TEXT(\"HI\")", "HI"}, {"TEXT(5)", "5"}, {"TEXT(100.01)", format.format(100.01)} }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/UpperFunctionTest.java0000644000175000017500000000241111401240104032254 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class UpperFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"UPPER(\"Habc7\")", "HABC7"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/TFunctionTest.java0000644000175000017500000000246411401240104031374 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class TFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"T(\"HI\")", "HI"}, {"T([.B3])", "7"}, {"T(5)", ""}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/ExactFunctionTest.java0000644000175000017500000000321411401240104032227 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class ExactFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"EXACT(\"A\";\"A\")", Boolean.TRUE}, {"EXACT(\"A\";\"a\")", Boolean.FALSE}, {"EXACT(1;1)", Boolean.TRUE}, {"EXACT((1/3)*3;1)", Boolean.TRUE}, {"EXACT(TRUE();TRUE())", Boolean.TRUE}, {"EXACT(\"1\";2)", Boolean.FALSE}, {"EXACT(\"h\";1)", Boolean.FALSE}, {"EXACT(\"1\";1)", Boolean.TRUE}, {"EXACT(\" 1\";1)", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/SubstituteFunctionTest.j0000644000175000017500000000304511401240104032650 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class SubstituteFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"SUBSTITUTE(\"121212\";\"2\";\"ab\")", "1ab1ab1ab"}, {"SUBSTITUTE(\"121212\";\"2\";\"ab\";2)", "121ab12"}, {"SUBSTITUTE(\"Hello\";\"x\";\"ab\")", "Hello"}, {"SUBSTITUTE(\"Annna\";\"nn\";\"N\";2)", "AnNa"}, {"SUBSTITUTE(\"1212121\";\"2\";\"ab\")", "1ab1ab1ab1"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/MidFunctionTest.java0000644000175000017500000000350111401240104031673 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class MidFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"MID(\"123456789\";5;3)", "567"}, {"MID(\"123456789\";20;3)", ""}, {"MID(\"123456789\";-1;0)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"MID(\"123456789\";1;0)", ""}, {"MID(\"123456789\";2.9;1)", "2"}, {"MID(\"123456789\";2;2.9)", "23"}, // custom tests {"MID(\"123456789\";5;10)", "56789"}, {"MID(\"123456789\";1;9)", "123456789"}, {"MID(\"text\";2;2)", "ex"}, {"MID(123456789;\"3\";4)", "3456"}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/text/ReptFunctionTest.java0000644000175000017500000000256511401240104032105 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.text; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class ReptFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"REPT(\"X\";3)", "XXX"}, {"REPT(\"XY\";2)", "XYXY"}, {"REPT(\"X\";2.9)", "XX"}, {"REPT(\"X\";0)", ""}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/0000755000175000017500000000000011401240104026400 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/AndFunctionTest.java0000644000175000017500000000326011401240104032314 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class AndFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"AND(FALSE();FALSE())", Boolean.FALSE}, {"AND(FALSE();TRUE())", Boolean.FALSE}, {"AND(TRUE();FALSE())", Boolean.FALSE}, {"AND(TRUE();TRUE())", Boolean.TRUE}, //define NA first {new Formula("AND(TRUE();NA())"), }, {"AND(1;TRUE())", Boolean.TRUE}, {"AND(0;TRUE())", Boolean.FALSE}, {"AND(TRUE();TRUE();TRUE())", Boolean.TRUE}, {"AND(TRUE())", Boolean.TRUE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/NotFunctionTest.java0000644000175000017500000000246711401240104032362 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class NotFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"NOT(FALSE())", Boolean.TRUE}, {"NOT(TRUE())", Boolean.FALSE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/XorFunctionTest.java0000644000175000017500000000320311401240104032357 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class XorFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"XOR(FALSE();FALSE())", Boolean.FALSE}, {"XOR(FALSE();TRUE())", Boolean.TRUE}, {"XOR(TRUE();FALSE())", Boolean.TRUE}, {"XOR(TRUE();TRUE())", Boolean.FALSE}, //TODO { "XOR(FALSE();NA())", Boolean. }, {"XOR(FALSE();FALSE();TRUE())", Boolean.TRUE}, {"XOR(FALSE();TRUE();TRUE())", Boolean.FALSE}, {"XOR(TRUE())", Boolean.TRUE}, }; } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/FalseFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/FalseFunctionTest.jav0000644000175000017500000000264011401240104032504 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class FalseFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"FALSE()", Boolean.FALSE}, //{"IF(ISNUMBER(FALSE());FALSE()=0;FALSE())", Boolean.FALSE}, {"2+FALSE()", new BigDecimal(2)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/IfFunctionTest.java0000644000175000017500000000442611401240104032155 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class IfFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"IF(FALSE();7;8)", new BigDecimal(8)}, {"IF(TRUE();7;8)", new BigDecimal(7)}, {"IF(TRUE();\"HI\";8)", "HI"}, {"IF(1;7;8)", new BigDecimal(7)}, {"IF(5;7;8)", new BigDecimal(7)}, {"IF(0;7;8)", new BigDecimal(8)}, {"IF(TRUE();[.B4];8)", new BigDecimal(2)}, {"IF(TRUE();[.B4]+5;8)", new BigDecimal(7)}, {"IF(\"x\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"IF(\"1\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"IF(\"\";7;8)", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"IF(FALSE();7)", Boolean.FALSE}, {"IF(FALSE();7;)", Boolean.FALSE}, {"IF(FALSE();;7)", new BigDecimal(7)}, //TODO { "IF(FALSE();7;)", new BigDecimal(0) }, we will not allow this syntax {"IF(TRUE();4;1/0)", new BigDecimal(4)}, {"IF(FALSE();1/0;5)", new BigDecimal(5)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/logical/OrFunctionTest.java0000644000175000017500000000306711401240104032177 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.logical; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class OrFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"OR(FALSE();FALSE())", Boolean.FALSE}, {"OR(FALSE();TRUE())", Boolean.TRUE}, {"OR(TRUE();FALSE())", Boolean.TRUE}, {"OR(TRUE();TRUE())", Boolean.TRUE}, //TODO { "OR(FALSE();NA())", }, {"OR(FALSE();FALSE();TRUE())", Boolean.TRUE}, {"OR(TRUE())", Boolean.TRUE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/0000755000175000017500000000000011401240104026562 5ustar renerene././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateFunctionTest.jav0000644000175000017500000000615211401240104032513 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.Formula; /** * @author Cedric Pronzato */ public class DateFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"DATE(2005;1;31)=[.C7]", Boolean.TRUE}, {"DATE(2005;12;31)-DATE(1904;1;1)", new BigDecimal(37255)}, {"DATE(2004;2;29)=DATE(2004;2;28)+1", Boolean.TRUE}, {"DATE(2000;2;29)=DATE(2000;2;28)+1", Boolean.TRUE}, {"DATE(2005;3;1)=DATE(2005;2;28)+1", Boolean.TRUE}, {"DATE(2017.5; 1;2)=DATE(2017; 1; 2)", Boolean.TRUE}, {"DATE(2006; 2.5;3)=DATE(2006; 2; 3)", Boolean.TRUE}, {"DATE(2006; 1;3.5)=DATE(2006; 1; 3)", Boolean.TRUE}, {"DATE(2006; 13; 3)=DATE(2007;1; 3)", Boolean.TRUE}, {"DATE(2006; 1; 32)=DATE(2006;2; 1)", Boolean.TRUE}, {"DATE(2006; 25;34)=DATE(2008;2;3)", Boolean.TRUE}, {"DATE(2006;-1;1)=DATE(2005;11;1)", Boolean.TRUE}, {"DATE(2006;4;-1)=DATE(2006;3;30)", Boolean.TRUE}, {"DATE(2006;-4;-1)=DATE(2005;7;30)", Boolean.TRUE}, {"DATE(2003;2;29)=DATE(2003;3;1)", Boolean.TRUE}, }; } public void testDebugDates() throws Exception { Formula formula = null; formula = new Formula("DATE(2005;1;31)"); formula.initialize(getContext()); Date eval = (Date) formula.evaluate(); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); System.out.println(eval.getClass().getName() + ":" + df.format(eval) + ";" + eval.getTime()); final Date date = (Date) getContext().resolveReference(".C7"); System.out.println(df.format(date) + ";" + date.getTime()); assertEquals(date, eval); } public void testGregorianCalendar() { final Date d1 = new GregorianCalendar(2006, -1, 1).getTime(); final Date d2 = new GregorianCalendar(2005, 11, 1).getTime(); assertEquals(d1, d2); } public void testDefault() throws Exception { runDefaultTest(); } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/NowFunctionTest.java0000644000175000017500000000250711401240104032542 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class NowFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"NOW()>DATE(2006;1;3)", Boolean.TRUE}, {"INT(NOW())=TODAY()", Boolean.TRUE}, }; } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateDifFunctionTest.0000644000175000017500000000462411401240104032437 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class DateDifFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"y\")", new BigDecimal(3)}, {"DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"m\")", new BigDecimal(43)}, //TODO result not found in spec { "DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"d\")", new Integer()}, {"DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"md\")", new BigDecimal(0)}, {"DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"ym\")", new BigDecimal(7)}, //TODO result not found in spec { "DATEDIF(DATE(1990;2;15);DATE(1993;9;15); \"yd\")", new Integer()}, // Additional specs from // http://www.cpearson.com/excel/datedif.htm {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"d\")", new BigDecimal(1626)}, {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"m\")", new BigDecimal(53)}, {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"y\")", new BigDecimal(4)}, {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"ym\")", new BigDecimal(5)}, {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"yd\")", new BigDecimal(165)}, {"DATEDIF(DATE(1995;1;1);DATE(1999;6;15); \"md\")", new BigDecimal(14)}, }; } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/TimeFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/TimeFunctionTest.jav0000644000175000017500000000353311401240104032534 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class TimeFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"0.9999884259259259259259259259259259259*27", new BigDecimal("26.9996875000000000000")}, { "TIME(0;0;0)+0", new BigDecimal(0)}, {"TIME(23;59;59)*60*60*24", new BigDecimal(86399)}, /*{ "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, { "", Boolean.TRUE }, */ }; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DateValueFunctionTes0000644000175000017500000000344511401240104032547 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.util.Locale; import java.util.TimeZone; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.DefaultFormulaContext; /** * @author Cedric Pronzato */ public class DateValueFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"DATEVALUE(\"2004-12-25\")=DATE(2004;12;25)", Boolean.TRUE}, }; } public void testFrenchDateParsing() throws Exception { final DefaultFormulaContext context = new DefaultFormulaContext(LibFormulaBoot.getInstance().getGlobalConfig(), Locale.FRENCH, TimeZone.getDefault()); performTest("DATEVALUE(\"25/12/2004\")=DATE(2004;12;25)", Boolean.TRUE, context); } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/YearFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/YearFunctionTest.jav0000644000175000017500000000247411401240104032541 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class YearFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"YEAR(DATE(1904;1;1))", new BigDecimal(1904)}, }; } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/SecondFunctionTest.j0000644000175000017500000000305211401240104032516 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class SecondFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"SECOND(1/(24*60*60))", new BigDecimal(1)}, //TODO this testcase seems to be wrong as the definition is: round to the nearest integer wich should be 0 // {"SECOND(1/(24*60*60*2))", new BigDecimal(1)}, {"SECOND(1/(24*60*60*4))", new BigDecimal(0)}, }; } public void testDefault() throws Exception { runDefaultTest(); } }././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/WeekDayFunctionTest.0000644000175000017500000000550711401240104032471 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class WeekDayFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"WEEKDAY(DATE(2006;5;21))", new BigDecimal(1)}, {"WEEKDAY(DATE(2005;1;1))", new BigDecimal(7)}, {"WEEKDAY(DATE(2005;1;1);1)", new BigDecimal(7)}, {"WEEKDAY(DATE(2005;1;1);2)", new BigDecimal(6)}, {"WEEKDAY(DATE(2005;1;1);3)", new BigDecimal(5)},}; } private Number[][] createTypeDataTest() { return new Number[][] { {new BigDecimal(1), new BigDecimal(7), new BigDecimal(6)}, {new BigDecimal(2), new BigDecimal(1), new BigDecimal(0)}, {new BigDecimal(3), new BigDecimal(2), new BigDecimal(1)}, {new BigDecimal(4), new BigDecimal(3), new BigDecimal(2)}, {new BigDecimal(5), new BigDecimal(4), new BigDecimal(3)}, {new BigDecimal(6), new BigDecimal(5), new BigDecimal(4)}, {new BigDecimal(7), new BigDecimal(6), new BigDecimal(5)}, }; } public void testAllTypes() { final WeekDayFunction function = new WeekDayFunction(); final Number[][] dataTest = createTypeDataTest(); for (int i = 0; i < dataTest.length; i++) { final Number[] objects = dataTest[i]; final Number type1 = objects[0]; final Number type2 = objects[1]; final Number type3 = objects[2]; assertEquals("Error with Type 1 conversion", function.convertType(type1.intValue(), 1), type1.intValue()); assertEquals("Error with Type 2 conversion", function.convertType(type1.intValue(), 2), type2.intValue()); assertEquals("Error with Type 3 conversion", function.convertType(type1.intValue(), 3), type3.intValue()); } } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/TodayFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/TodayFunctionTest.ja0000644000175000017500000000251511401240104032527 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class TodayFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"TODAY()>DATE(2006;1;3)", Boolean.TRUE}, {"INT(TODAY())=TODAY()", Boolean.TRUE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/DayFunctionTest.java0000644000175000017500000000271511401240104032515 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class DayFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"DAY(DATE(2006;5;21))", new BigDecimal(21)}, // TODO signal this usecase as wrong { "DAY(\"2006-12-15\")", new Integer(12) } {"DAY(\"2006-12-15\")", new BigDecimal(15)}, }; } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/HourFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/HourFunctionTest.jav0000644000175000017500000000264011401240104032551 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class HourFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"HOUR(5/24)", new BigDecimal(5)}, {"HOUR(5/24-1/(24*60*60))", new BigDecimal(4)}, {"HOUR(\"14:00\")", new BigDecimal(14)}, }; } public void testDefault() throws Exception { runDefaultTest(); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/MonthFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/MonthFunctionTest.ja0000644000175000017500000000254311401240104032535 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class MonthFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"MONTH([.C7])", new BigDecimal(1)}, {"MONTH(DATE(2006;5;21))", new BigDecimal(5)},}; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/datetime/MinuteFunctionTest.j0000644000175000017500000000264611401240104032554 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.datetime; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class MinuteFunctionTest extends FormulaTestBase { public Object[][] createDataTest() { return new Object[][] { {"MINUTE(1/(24*60))", new BigDecimal(1)}, {"MINUTE(TODAY()+1/(24*60))", new BigDecimal(1)}, {"MINUTE(1/24)", new BigDecimal(0)}, }; } public void testDefault() throws Exception { runDefaultTest(); } }libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/0000755000175000017500000000000011401240104027313 5ustar renerene././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsErrFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsErrFunctionTest0000644000175000017500000000262511401240104032635 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsErrFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISERR(1/0)", Boolean.TRUE}, {"ISERR(NA())", Boolean.FALSE}, {"ISERR(\"#N/A\")", Boolean.FALSE}, {"ISERR(1)", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsErrorFunctionTe0000644000175000017500000000277511401240104032635 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsErrorFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISERROR(1/0)", Boolean.TRUE}, {"ISERROR(NA())", Boolean.TRUE}, {"ISERROR(\"#N/A\")", Boolean.FALSE}, {"ISERROR(1)", Boolean.FALSE}, //{"ISERROR(CHOOSE(0; \"Apple\";\"Orange\"; \"Grape\";\"Perry\"))", Boolean.TRUE}, }; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsEvenFunctionTes0000644000175000017500000000327511401240104032620 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsEvenFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISEVEN(2)", Boolean.TRUE}, {"ISEVEN(6)", Boolean.TRUE}, {"ISEVEN(2.1)", Boolean.TRUE}, {"ISEVEN(2.5)", Boolean.TRUE}, {"ISEVEN(2.9)", Boolean.TRUE}, {"ISEVEN(3)", Boolean.FALSE}, {"ISEVEN(3.9)", Boolean.FALSE}, {"ISEVEN(-2)", Boolean.TRUE}, {"ISEVEN(-2.1)", Boolean.TRUE}, {"ISEVEN(-2.5)", Boolean.TRUE}, {"ISEVEN(-2.9)", Boolean.TRUE}, }; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IndexFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IndexFunctionTest0000644000175000017500000000271511401240104032660 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class IndexFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"INDEX({1;2;3 | 4;5;6 | 7;8;9}; 2; 2)", new BigDecimal("5")}, {"INDEX({1; 2; 3};;3)", new BigDecimal("3")}, }; } }././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountBlankFunctio0000644000175000017500000000250411401240104032627 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class CountBlankFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"COUNTBLANK([.B3:.B10])", new BigDecimal(1)}, }; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsOddFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsOddFunctionTest0000644000175000017500000000377611401240104032623 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class IsOddFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISODD(3)", Boolean.TRUE}, {"ISODD(5)", Boolean.TRUE}, {"ISODD(3.1)", Boolean.TRUE}, {"ISODD(3.5)", Boolean.TRUE}, {"ISODD(3.9)", Boolean.TRUE}, {"ISODD(4)", Boolean.FALSE}, {"ISODD(4.9)", Boolean.FALSE}, {"ISODD(-3)", Boolean.TRUE}, {"ISODD(-3.1)", Boolean.TRUE}, {"ISODD(-3.5)", Boolean.TRUE}, {"ISODD(-3.9)", Boolean.TRUE}, {"ISODD(-4)", Boolean.FALSE}, {"ISODD(NA())", LibFormulaErrorValue.ERROR_NA_VALUE}, {"ISODD(0)", Boolean.FALSE}, {"ISODD(1)", Boolean.TRUE}, {"ISODD(2)", Boolean.FALSE}, {"ISODD(2.9)", Boolean.FALSE},}; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/ChooseFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/ChooseFunctionTes0000644000175000017500000000334611401240104032646 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class ChooseFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"CHOOSE(3;\"Apple\";\"Orange\";\"Grape\";\"Perry\")", "Grape"}, {"CHOOSE(0;\"Apple\";\"Orange\";\"Grape\";\"Perry\")", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, {"CHOOSE(5;\"Apple\";\"Orange\";\"Grape\";\"Perry\")", LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE}, // {"CHOOSE(2;SUM([.B4:.B5]);SUM([.B5]))", Boolean.FALSE}, // {"SUM(CHOOSE(2;[.B4:.B5];[.B5]))", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/NaFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/NaFunctionTest.ja0000644000175000017500000000300211401240104032526 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class NaFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISERROR(NA())", Boolean.TRUE}, {"ISNA(NA())", Boolean.TRUE}, {"ISNA(5+NA())", Boolean.TRUE}, // custom tests {"NA()", LibFormulaErrorValue.ERROR_NA_VALUE}, }; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsTextFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsTextFunctionTes0000644000175000017500000000247411401240104032647 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsTextFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISTEXT(1)", Boolean.FALSE}, {"ISTEXT(\"1\")", Boolean.TRUE}, }; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountAFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountAFunctionTes0000644000175000017500000000324411401240104032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class CountAFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"COUNTA(\"1\";2;TRUE())", new BigDecimal(3)}, {"COUNTA([.B3:.B5])", new BigDecimal(3)}, {"COUNTA([.B3:.B5];[.B3:.B5])", new BigDecimal(6)}, {"COUNTA([.B3:.B9])", new BigDecimal(6)}, {"COUNTA(\"1\";2;1/0)", new BigDecimal(3)}, {"COUNTA(\"1\";2;SUM([.B3:.B9]))", new BigDecimal(3)}, {"COUNTA(\"1\";2;[.B3:.B9])", new BigDecimal(8)}, }; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsRefFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsRefFunctionTest0000644000175000017500000000303211401240104032612 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; import org.pentaho.reporting.libraries.formula.LibFormulaErrorValue; /** * @author Cedric Pronzato */ public class IsRefFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISREF([.B3])", Boolean.TRUE}, // {"ISREF([.B3]:[.C4])", Boolean.TRUE}, {"ISREF(1)", Boolean.FALSE}, {"ISREF(\"A1\")", Boolean.FALSE}, {"ISREF(NA())", LibFormulaErrorValue.ERROR_NA_VALUE},}; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsBlankFunctionTe0000644000175000017500000000263511401240104032566 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsBlankFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISBLANK(1)", Boolean.FALSE}, {"ISBLANK(\"\")", Boolean.FALSE}, {"ISBLANK([.B8])", Boolean.TRUE}, {"ISBLANK([.B7])", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsLogicalFunction0000644000175000017500000000257711401240104032625 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsLogicalFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISLOGICAL(TRUE())", Boolean.TRUE}, {"ISLOGICAL(FALSE())", Boolean.TRUE}, {"ISLOGICAL(\"TRUE\")", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNaFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNaFunctionTest.0000644000175000017500000000267411401240104032525 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsNaFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISNA(1/0)", Boolean.FALSE}, {"ISNA(NA())", Boolean.TRUE}, //{"ISNA(#N/A)", Boolean.TRUE}, {"ISNA(\"#N/A\")", Boolean.FALSE}, {"ISNA(1)", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNumberFunctionT0000644000175000017500000000250311401240104032614 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsNumberFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISNUMBER(1)", Boolean.TRUE}, {"ISNUMBER(\"1\")", Boolean.FALSE}, }; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/IsNonTextFunction0000644000175000017500000000301011401240104032631 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IsNonTextFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"ISNONTEXT(1)", Boolean.TRUE}, {"ISNONTEXT(TRUE())", Boolean.TRUE}, {"ISNONTEXT(\"1\")", Boolean.FALSE}, {"ISNONTEXT([.B7])", Boolean.FALSE}, {"ISNONTEXT([.B9])", Boolean.TRUE}, {"ISNONTEXT([.B8])", Boolean.TRUE}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/test/0000755000175000017500000000000011401240104030272 5ustar renerene././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountFunctionTest.javalibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/information/CountFunctionTest0000644000175000017500000000312611401240104032676 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors.. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.information; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class CountFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"COUNT(1;2;3)", new BigDecimal(3)}, // {"COUNT([.B4:.B5])", new BigDecimal(2)}, // {"COUNT([.B4:.B5];[.B4:.B5])", new BigDecimal(4)}, // {"COUNT([.B4:.B9])", new BigDecimal(2)}, // {"COUNT([.B4:.B8];1/0)", new BigDecimal(2)}, // {"COUNT([.B3:.B5])", new BigDecimal(2)}, }; } } libformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/rounding/0000755000175000017500000000000011401240104026613 5ustar renerenelibformula-1.1.7/test/org/pentaho/reporting/libraries/formula/function/rounding/IntFunctionTest.java0000644000175000017500000000302011401240104032551 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.function.rounding; import java.math.BigDecimal; import org.pentaho.reporting.libraries.formula.FormulaTestBase; /** * @author Cedric Pronzato */ public class IntFunctionTest extends FormulaTestBase { public void testDefault() throws Exception { runDefaultTest(); } public Object[][] createDataTest() { return new Object[][] { {"INT(2)", new BigDecimal(2)}, {"INT(-3)", new BigDecimal(-3)}, {"INT(1.2)", new BigDecimal(1)}, {"INT(1.7)", new BigDecimal(1)}, {"INT(-1.2)", new BigDecimal(-2)}, {"INT((1/3)*3)", new BigDecimal(1)}, }; } } libformula-1.1.7/.classpath0000644000175000017500000000146611401240110014272 0ustar renerene libformula-1.1.7/libformula.iml0000644000175000017500000001700311401240110015140 0ustar renerene libformula-1.1.7/build.xml0000644000175000017500000000411211401240110014117 0ustar renerene This build file is used to create the libformula project and works with the common_build.xml file. libformula-1.1.7/demo/0000755000175000017500000000000011401240104013227 5ustar renerenelibformula-1.1.7/demo/org/0000755000175000017500000000000011401240104014016 5ustar renerenelibformula-1.1.7/demo/org/pentaho/0000755000175000017500000000000011401240104015454 5ustar renerenelibformula-1.1.7/demo/org/pentaho/reporting/0000755000175000017500000000000011401240104017465 5ustar renerenelibformula-1.1.7/demo/org/pentaho/reporting/libraries/0000755000175000017500000000000011401240104021441 5ustar renerenelibformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/0000755000175000017500000000000011401240104023106 5ustar renerenelibformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/demo/0000755000175000017500000000000011401240104024032 5ustar renerenelibformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/demo/DemoFormulaContext.java0000644000175000017500000000412311401240104030454 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.demo; import java.util.HashMap; import javax.swing.JOptionPane; import org.pentaho.reporting.libraries.formula.DefaultFormulaContext; import org.pentaho.reporting.libraries.formula.typing.Type; import org.pentaho.reporting.libraries.formula.typing.coretypes.AnyType; /** * A formula context that asks the user for input. * * @author Thomas Morgner */ public class DemoFormulaContext extends DefaultFormulaContext { private HashMap values; public DemoFormulaContext() { values = new HashMap(); } public Object resolveReference(Object name) { final Object fromCache = values.get(name); if (fromCache != null) return fromCache; final String input = JOptionPane.showInputDialog ("Please enter a value for '" + name + '\''); if (input != null) { values.put (name, input); } return input; } public Type resolveReferenceType(Object name) { // by returning the correct type of the reference, you can speed up // the formula computation a little bit, as we dont have to guess the // type from scratch. // If you dont know the type, return ANYTYPE. We will start looking at // the referenced object in that case. return AnyType.TYPE; } } libformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/demo/DemoApplication.java0000644000175000017500000000422211401240104027745 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.demo; import javax.swing.JOptionPane; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.Formula; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.parser.ParseException; /** * Creation-Date: Feb 21, 2007, 2:55:48 PM * * @author Thomas Morgner */ public class DemoApplication { private DemoApplication() { } public static void main(final String[] args) throws ParseException, EvaluationException { LibFormulaBoot.getInstance().start(); final String formula = JOptionPane.showInputDialog("Please enter a formula."); if (formula == null) { return; } // first parse the formula. This checks the general syntax, but does not // check whether the used functions or references are actually valid. final Formula f = new Formula(formula); // connects the parsed formula to the context. The context provides the // operator and function implementations and resolves the references. f.initialize(new DemoFormulaContext()); final Object o = f.evaluate(); JOptionPane.showMessageDialog(null, "The result is " + o, "Result", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } libformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/demo/PrintAllFunctions.java0000644000175000017500000000420311401240104030312 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.demo; import java.util.Arrays; import java.util.Locale; import org.pentaho.reporting.libraries.formula.LibFormulaBoot; import org.pentaho.reporting.libraries.formula.function.FunctionCategory; import org.pentaho.reporting.libraries.formula.function.FunctionRegistry; /** * Creation-Date: 02.11.2007, 13:28:42 * * @author Thomas Morgner */ public class PrintAllFunctions { private PrintAllFunctions() { } public static void main(String[] args) { LibFormulaBoot.getInstance().start(); final DemoFormulaContext context = new DemoFormulaContext(); final FunctionRegistry functionRegistry = context.getFunctionRegistry(); final FunctionCategory[] categories = functionRegistry.getCategories(); for (int c = 0; c < categories.length; c++) { final FunctionCategory category = categories[c]; System.out.println(); System.out.println("Category " + category.getDisplayName(Locale.US)); final String[] strings = functionRegistry.getFunctionNamesByCategory(category); Arrays.sort(strings); for (int i = 0; i < strings.length; i++) { if (i != 0) { System.out.print(", "); } final String string = strings[i]; System.out.print(string); } } } } libformula-1.1.7/demo/org/pentaho/reporting/libraries/formula/demo/FormulaParsePosition.java0000644000175000017500000000410611401240104031023 0ustar renerene/* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.formula.demo; import org.pentaho.reporting.libraries.formula.Formula; import org.pentaho.reporting.libraries.formula.DefaultFormulaContext; import org.pentaho.reporting.libraries.formula.EvaluationException; import org.pentaho.reporting.libraries.formula.lvalues.LValue; import org.pentaho.reporting.libraries.formula.parser.ParseException; /** * Todo: Document me! * * @author : Thomas Morgner */ public class FormulaParsePosition { public static void main(String[] args) throws EvaluationException, ParseException { final Formula f = new Formula("IF(NOT(TRUE()));\"Testing\"; \"Other\""); // connects the parsed formula to the context. The context provides the // operator and function implementations and resolves the references. f.initialize(new DefaultFormulaContext()); final LValue rootReference = f.getRootReference(); print(rootReference, 0); } public static void print (LValue lValue, int level) { System.out.println (level + " " + lValue.getClass() + " " + lValue.getParsePosition()); final LValue[] lValues = lValue.getChildValues(); for (int i = 0; i < lValues.length; i++) { LValue value = lValues[i]; print (value, level +1); } } }