01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id: MinFunction.java 426576 2006-07-28 15:44:37Z jeremias $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.datatypes.Numeric;
23: import org.apache.fop.fo.properties.Property;
24:
25: /**
26: * Class for managing the "min" Number Function. See Sec. 5.10.1 in the XSL-FO
27: * standard.
28: */
29: public class MinFunction extends FunctionBase {
30:
31: /**
32: * @return 2 (the number of arguments required for the min function)
33: */
34: public int nbArgs() {
35: return 2;
36: }
37:
38: /**
39: * Handle "numerics" if no proportional/percent parts
40: * @param args array of arguments to be processed
41: * @param pInfo PropertyInfo to be processed
42: * @return the minimum of the two args elements passed
43: * @throws PropertyException for invalid operands
44: */
45: public Property eval(Property[] args, PropertyInfo pInfo)
46: throws PropertyException {
47: Numeric n1 = args[0].getNumeric();
48: Numeric n2 = args[1].getNumeric();
49: if (n1 == null || n2 == null) {
50: throw new PropertyException(
51: "Non numeric operands to min function");
52: }
53: return (Property) NumericOp.min(n1, n2);
54: }
55:
56: }
|