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

w3c.css.values.CssMax Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
//
// @author Yves Lafon 
//
// (c) COPYRIGHT MIT, ERCIM, Keio, Beihang, 2020.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.values;

import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * CSS max().
 *
 * @spec https://www.w3.org/TR/2019/WD-css-values-4-20190131/#funcdef-max
 */
public class CssMax extends CssCheckableValue {

    public static final int type = CssTypes.CSS_MAX;

    public final int getRawType() {
        return type;
    }

    public final int getType() {
        if (computed_type == CssTypes.CSS_MAX) {
            return type;
        }
        return computed_type;
    }

    ApplContext ac;
    int computed_type = CssTypes.CSS_UNKNOWN;
    ArrayList values = null;
    String _toString = null;


    /**
     * Create a new CssCalc
     */
    public CssMax() {
    }

    public CssMax(ApplContext ac) {
        this(ac, null);
    }

    public CssMax(CssValue value) {
        this(null, value);
    }

    public CssMax(ApplContext ac, CssValue value) {
        if (ac != null) {
            this.ac = ac;
        }
        if (value != null) {
            computed_type = value.getType();
            if (values == null) {
                values = new ArrayList<>();
            }
            values.add(value);
            try {
                computed_type = _checkAcceptableType(value.getType());
            } catch (Exception ex) { // todo report error here or wait ?
            }
        }
    }

    public void set(String s, ApplContext ac) throws InvalidParamException {
        // we don't support this way of setting the value
        // as we rely on the parsing to create it incrementally
        throw new InvalidParamException("unrecognize", s, ac);
    }

    public void setValue(BigDecimal d) {
        // we don't support this way of setting the value
        // as we rely on the parsing to create it incrementally
    }

    /**
     * Add one operand, if we already got one we will... Add one operand.
     *
     * @param value
     * @return
     */
    public CssMax addValue(CssValue value)
            throws InvalidParamException {
        boolean first = false;
        if (values == null) {
            values = new ArrayList<>();
            first = true;
        }
        values.add(value);
        _computeResultingType(false);
        return this;
    }

    public void validate() throws InvalidParamException {
        _computeResultingType(true);
    }

    private int _checkAcceptableType(int type)
            throws InvalidParamException {
        //  , , , 




© 2015 - 2025 Weber Informatics LLC | Privacy Policy