Changeset 4417


Ignore:
Timestamp:
10/16/03 23:13:43 (19 years ago)
Author:
piso
Message:

Refactoring: checkBinaryElementType().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/open.java

    r3894 r4417  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: open.java,v 1.5 2003-09-19 14:44:10 piso Exp $
     5 * $Id: open.java,v 1.6 2003-10-16 23:13:43 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    4343            else
    4444                throw new ConditionThrowable(new TypeError(first, "pathname designator"));
    45             boolean binary;
    46             LispObject elementType = second;
    47             if (elementType == Symbol.BASE_CHAR || elementType == Symbol.CHARACTER)
    48                 binary = false;
    49             else if (elementType == Symbol.UNSIGNED_BYTE)
    50                 binary = true;
    51             else
    52                 throw new ConditionThrowable(new LispError(
    53                     String.valueOf(elementType).concat(" is not a valid stream element type")));
     45            boolean binary = checkBinaryElementType(second);
    5446            File file = new File(namestring);
    5547            LispObject ifExists = third;
     
    9284            else
    9385                throw new ConditionThrowable(new TypeError(first, "pathname designator"));
    94             boolean binary;
    95             LispObject elementType = second;
    96             if (elementType == Symbol.BASE_CHAR || elementType == Symbol.CHARACTER)
    97                 binary = false;
    98             else if (elementType == Symbol.UNSIGNED_BYTE)
    99                 binary = true;
    100             else
    101                 throw new ConditionThrowable(new LispError(
    102                     String.valueOf(elementType).concat(" is not a valid stream element type")));
     86            boolean binary = checkBinaryElementType(second);
    10387            try {
    10488                if (binary)
     
    11296        }
    11397    };
     98
     99    private static final boolean checkBinaryElementType(LispObject elementType)
     100        throws ConditionThrowable
     101    {
     102        if (elementType == Symbol.BASE_CHAR || elementType == Symbol.CHARACTER)
     103            return false;
     104        if (elementType == Symbol.UNSIGNED_BYTE)
     105            return true;
     106        if (elementType instanceof Cons) {
     107            if (elementType.car() == Symbol.UNSIGNED_BYTE) {
     108                if (elementType.length() == 2) {
     109                    if (elementType.cadr() instanceof Fixnum) {
     110                        if (((Fixnum)elementType.cadr()).getValue() == 8)
     111                            return true;
     112                    }
     113                }
     114            }
     115        }
     116        throw new ConditionThrowable(new LispError(String.valueOf(elementType) +
     117                                                   " is not a valid stream element type"));
     118    }
    114119}
Note: See TracChangeset for help on using the changeset viewer.