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

com.izforge.izpack.installer.debugger.ConditionHistory Maven / Gradle / Ivy

There is a newer version: 5.2.3
Show newest version
/*
 * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Copyright 2007 Dennis Reil
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.izforge.izpack.installer.debugger;

import com.izforge.izpack.api.rules.Condition;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dennis Reil, 
 * @version $Id: $
 */
public class ConditionHistory
{
    private Condition condition;
    private List values;

    private boolean newcondition;
    private boolean changedcondition;


    public ConditionHistory(Condition condition)
    {
        this.condition = condition;
        values = new ArrayList();
        newcondition = true;
        changedcondition = true;
    }

    public void addValue(boolean value, String comment)
    {
        if ((values.size() == 0) || value != getLastValue())
        {
            Object[] valuecomment = new Object[2];
            valuecomment[0] = value;
            valuecomment[1] = comment;
            this.values.add(valuecomment);
            if (values.size() == 1)
            {
                newcondition = true;
                changedcondition = true;
            }
            else
            {
                changedcondition = true;
            }
        }
    }

    public boolean getLastValue()
    {
        if (values.size() > 0)
        {
            return (Boolean) (values.get(values.size() - 1))[0];
        }
        else
        {
            return false;
        }
    }

    public int getValueCount()
    {
        return values.size();
    }

    public void clearState()
    {
        newcondition = false;
        changedcondition = false;
    }

    /**
     * @return the newcondition
     */
    public boolean isNewcondition()
    {
        return this.newcondition;
    }


    /**
     * @return the changedcondition
     */
    public boolean isChangedcondition()
    {
        return this.changedcondition;
    }

    public String toString()
    {
        return Boolean.toString(getLastValue());
    }

    public String getConditionHistoryDetails()
    {
        StringBuffer details = new StringBuffer();
        details.append("");
        details.append("

Details of "); details.append(this.condition.getId()); details.append("

"); for (int i = values.size() - 1; i >= 0; i--) { Object[] condcomment = values.get(i); details.append(i + 1); details.append(". "); details.append(condcomment[0].toString()); details.append(" ("); details.append(condcomment[1]); details.append(")
"); } details.append("

Dependencies

"); details.append(this.condition.getDependenciesDetails()); details.append(""); return details.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy