⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parameterset.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
字号:
/*====================================================================*\ParameterSet.javaParameter set class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program.  If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage util;//----------------------------------------------------------------------// IMPORTSimport exception.AppException;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.w3c.dom.Document;import org.w3c.dom.Element;import xml.XmlParseException;import xml.XmlUtilities;//----------------------------------------------------------------------// PARAMETER SET CLASSpublic abstract class ParameterSet    implements Cloneable, Comparable<ParameterSet>{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    protected static final  String  ROOT_ELEMENT_NAME   = ElementName.PARAMETER_SET;    private interface ElementName    {        String  PARAMETER_SET   = "parameterSet";    }    private interface AttrName    {        String  NAME    = "name";        String  VALUE   = "value";    }//////////////////////////////////////////////////////////////////////////  Enumeration types////////////////////////////////////////////////////////////////////////    // ERROR IDENTIFIERS    private enum ErrorId        implements AppException.Id    {    ////////////////////////////////////////////////////////////////////    //  Constants    ////////////////////////////////////////////////////////////////////        NO_ATTRIBUTE        ( "The element does not have such an attribute." );    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private ErrorId( String message )        {            this.message = message;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : AppException.Id interface    ////////////////////////////////////////////////////////////////////        public String getMessage( )        {            return message;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private String  message;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public ParameterSet( )    {    }    //------------------------------------------------------------------    public ParameterSet( Element element )        throws XmlParseException    {        // Attribute: name        String elementPath = XmlUtilities.getElementPath( element );        String paramName = elementPath + "." + AttrName.NAME;        String paramValue = XmlUtilities.getAttribute( element, AttrName.NAME );        if ( paramValue == null )            throw new XmlParseException( ErrorId.NO_ATTRIBUTE, paramName );        name = paramValue;    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    protected static Parameter getParam( Element element,                                         String  name )    {        return new Parameter.ParamSetParam( element, name );    }    //------------------------------------------------------------------    protected static Parameter getParam( Element element,                                         String  name,                                         int     index )    {        return new Parameter.ParamSetParam( element, name, index );    }    //------------------------------------------------------------------    public static String getValue( Element element,                                   String  elementPath )    {        return getValue( element, elementPath, -1 );    }    //------------------------------------------------------------------    public static String getValue( Element element,                                   String  elementPath,                                   int     index )    {        element = XmlUtilities.findElement( element.getOwnerDocument( ), element, elementPath, index,                                            false );        return ( (element == null ) ? null : XmlUtilities.getAttribute( element, AttrName.VALUE ) );    }    //------------------------------------------------------------------    public static boolean setValue( Element element,                                    String  elementPath,                                    String  value )    {        return setValue( element, elementPath, -1, value );    }    //------------------------------------------------------------------    public static boolean setValue( Element element,                                    String  elementPath,                                    int     index,                                    String  value )    {        boolean result = false;        if ( value != null )        {            element = XmlUtilities.findElement( element.getOwnerDocument( ), element, elementPath, index,                                                true );            if ( element != null )            {                element.setAttribute( AttrName.VALUE, value );                result = true;            }        }        return result;    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : Comparable interface////////////////////////////////////////////////////////////////////////    public int compareTo( ParameterSet paramSet )    {        return ( (name == null) ? (paramSet.name == null) ? 0 : -1                                : (paramSet.name == null) ? 1 : name.compareTo( paramSet.name ) );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : abstract methods////////////////////////////////////////////////////////////////////////    protected abstract void getParameters( Element element );    //------------------------------------------------------------------    protected abstract void setParameters( Element element );    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : overriding methods////////////////////////////////////////////////////////////////////////    public Object clone( )    {        ParameterSet paramSet = null;        try        {            paramSet = (ParameterSet)super.clone( );            paramSet.name = new String( name );        }        catch ( CloneNotSupportedException e )        {            e.printStackTrace( );        }        return paramSet;    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods////////////////////////////////////////////////////////////////////////    public String getName( )    {        return name;    }    //------------------------------------------------------------------    public void setName( String name )    {        this.name = name;    }    //------------------------------------------------------------------    public void createElement( Element element )    {        element.setAttribute( AttrName.NAME, name );        setParameters( element );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    private String  name;}//----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -