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

📄 appexception.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
字号:
/*====================================================================*\AppException.javaApplication exception 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 exception;//----------------------------------------------------------------------// APPLICATION EXCEPTION CLASSpublic class AppException    extends Exception{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    public static final     String  SUBSTITUTION_PLACEHOLDER_PREFIX = "%";    private static final    int MIN_SUBSTITUTION_INDEX  = 1;    private static final    String  NO_ERROR_STR    = "No error";//////////////////////////////////////////////////////////////////////////  Member interfaces////////////////////////////////////////////////////////////////////////    // EXCEPTION IDENTIFIER INTERFACE    public interface Id    {    ////////////////////////////////////////////////////////////////////    //  Methods    ////////////////////////////////////////////////////////////////////        String getMessage( );        //--------------------------------------------------------------    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Member classes : non-inner classes////////////////////////////////////////////////////////////////////////    // ANONYMOUS IDENTIFIER CLASS    protected static class AnonymousId        implements Id    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        protected AnonymousId( String message )        {            this.message = message;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : Id interface    ////////////////////////////////////////////////////////////////////        public String getMessage( )        {            return message;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private String  message;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public AppException( )    {    }    //------------------------------------------------------------------    public AppException( String messageStr )    {        this( new AnonymousId( messageStr ) );    }    //------------------------------------------------------------------    public AppException( String   messageStr,                         String[] substitutionStrs )    {        this( new AnonymousId( messageStr ), substitutionStrs );    }    //------------------------------------------------------------------    public AppException( String    messageStr,                         Throwable cause )    {        this( new AnonymousId( messageStr ), cause );    }    //------------------------------------------------------------------    public AppException( String    messageStr,                         Throwable cause,                         String[]  substitutionStrs )    {        this( new AnonymousId( messageStr ), cause, substitutionStrs );    }    //------------------------------------------------------------------    public AppException( Id id )    {        super( getString( id ) );        this.id = id;    }    //------------------------------------------------------------------    public AppException( Id       id,                         String[] substitutionStrs )    {        this( id );        setSubstitutionStrings( substitutionStrs );    }    //------------------------------------------------------------------    public AppException( Id        id,                         Throwable cause )    {        super( getString( id ), cause );        this.id = id;    }    //------------------------------------------------------------------    public AppException( Id        id,                         Throwable cause,                         String[]  substitutionStrs )    {        this( id, cause );        setSubstitutionStrings( substitutionStrs );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static String getString( Id id )    {        return ( (id == null) ? NO_ERROR_STR : id.getMessage( ) );    }    //------------------------------------------------------------------    protected static String createString( String    message,                                          String[]  substitutionStrs,                                          Throwable cause )    {        // Append the detail message        StringBuilder buffer = new StringBuilder( );        if ( message != null )            buffer.append( message );        // Insert any substitution strings        if ( substitutionStrs != null )        {            int index = 0;            while ( index < buffer.length( ) )            {                index = buffer.indexOf( SUBSTITUTION_PLACEHOLDER_PREFIX, index );                if ( index < 0 )                    index = buffer.length( );                else                    ++index;                int startIndex = index;                while ( index < buffer.length( ) )                {                    char ch = buffer.charAt( index );                    if ( (ch < '0') || (ch > '9') )                        break;                    ++index;                }                if ( index > startIndex )                {                    int substIndex = Integer.parseInt( buffer.substring( startIndex, index ) ) -                                                                                    MIN_SUBSTITUTION_INDEX;                    if ( (substIndex >= 0) && (substIndex < substitutionStrs.length) )                    {                        String substStr = substitutionStrs[substIndex];                        if ( substStr == null )                            substStr = new String( );                        --startIndex;                        buffer.replace( startIndex, index, substStr );                        index = startIndex + substStr.length( );                    }                }            }        }        // Append the detail message of the cause        if ( cause != null )        {            String str = cause.getMessage( );            if ( str == null )                str = cause.toString( );            buffer.append( "\n[" );            buffer.append( str );            buffer.append( ']' );        }        return buffer.toString( );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : overriding methods////////////////////////////////////////////////////////////////////////    public String toString( )    {        return createString( getMessage( ), substitutionStrs, getCause( ) );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods////////////////////////////////////////////////////////////////////////    public Id getId( )    {        return id;    }    //------------------------------------------------------------------    public String[] getSubstitutionStrings( )    {        return substitutionStrs;    }    //------------------------------------------------------------------    public void clearSubstitutionStrings( )    {        substitutionStrs = null;    }    //------------------------------------------------------------------    public void setSubstitutionStrings( String[] strs )    {        substitutionStrs = strs;    }    //------------------------------------------------------------------    public void setSubstitutionString( String str )    {        substitutionStrs = new String[1];        substitutionStrs[0] = str;    }    //------------------------------------------------------------------    public void setSubstitutionDecVal( int value )    {        setSubstitutionString( Integer.toString( value ) );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    private Id          id;    private String[]    substitutionStrs;}//----------------------------------------------------------------------

⌨️ 快捷键说明

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