| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| Input |
|
| 1.3333333333333333;1.333 |
| 1 | /*---------------------------------------------------------------- |
|
| 2 | * $Id: Input.java,v 1.1.1.1 2004/01/26 20:46:18 pkb Exp $ |
|
| 3 | * |
|
| 4 | * (c)2000 - Paul Blankenbaker |
|
| 5 | * |
|
| 6 | * Revision Log |
|
| 7 | * |
|
| 8 | * 2000-11-16 10:49:15 Paul Blankenbaker |
|
| 9 | * |
|
| 10 | * Created initial version |
|
| 11 | */ |
|
| 12 | //---------------------------------------------------------------- |
|
| 13 | ||
| 14 | package com.ccg.macros; |
|
| 15 | ||
| 16 | import java.io.*; // needed for I/O operations |
|
| 17 | ||
| 18 | //---------------------------------------------------------------- |
|
| 19 | /** Describe... |
|
| 20 | * |
|
| 21 | * <code><pre> |
|
| 22 | * class Example { |
|
| 23 | * public void main(String[] args) { |
|
| 24 | * com.ccg.macros.Input o = new com.ccg.macros.Input(); |
|
| 25 | * System.out.println(o); |
|
| 26 | * } |
|
| 27 | * } |
|
| 28 | * </pre></code> |
|
| 29 | * |
|
| 30 | * @version $Revision: 1.1.1.1 $ |
|
| 31 | * |
|
| 32 | * @since 1.0 |
|
| 33 | * |
|
| 34 | * @author $Author: pkb $ */ |
|
| 35 | //---------------------------------------------------------------- |
|
| 36 | ||
| 37 | public class Input { |
|
| 38 | ||
| 39 | 0 | public Input() { |
| 40 | 0 | _buf = new char[0]; |
| 41 | 0 | } |
| 42 | ||
| 43 | 1032 | public Input(String s) { |
| 44 | 1032 | _buf = (s == null) ? new char[0] : s.toCharArray(); |
| 45 | 1032 | _len = _buf.length; |
| 46 | 1032 | } |
| 47 | ||
| 48 | 52 | public Input(char[] buf, int ofs, int len) { |
| 49 | 52 | _buf = buf; |
| 50 | 52 | _ofs = ofs; |
| 51 | 52 | _len = len; |
| 52 | 52 | } |
| 53 | ||
| 54 | final int getLength() { |
|
| 55 | 4724 | return _len; |
| 56 | } |
|
| 57 | ||
| 58 | final int getOffset() { |
|
| 59 | 5878 | return _ofs; |
| 60 | } |
|
| 61 | ||
| 62 | final char[] getBuffer() { |
|
| 63 | 3026 | return _buf; |
| 64 | } |
|
| 65 | ||
| 66 | //---------------------------------------------------------------- |
|
| 67 | // This method ALWAYS forces the offset back to zero |
|
| 68 | //---------------------------------------------------------------- |
|
| 69 | ||
| 70 | int shiftAndFill(int cur_ofs) throws IOException { |
|
| 71 | // remaining length |
|
| 72 | 1154 | int left = (_len - cur_ofs); |
| 73 | 1154 | if (left <= 0) { // if nothing left, clear buffer |
| 74 | 1154 | _len = 0; |
| 75 | 1154 | } |
| 76 | // if something to shift over |
|
| 77 | 0 | else if ((cur_ofs < _len) && (cur_ofs > 0)) { |
| 78 | 0 | int len = _len = (_len - cur_ofs); |
| 79 | 0 | int j = cur_ofs; |
| 80 | 0 | int i = 0; |
| 81 | 0 | char[] buf = _buf; |
| 82 | 0 | while (i < len) buf[i++] = buf[j++]; |
| 83 | } |
|
| 84 | 1154 | _ofs = 0; // offset always shifted back to 0 |
| 85 | ||
| 86 | 1154 | return _len; |
| 87 | } |
|
| 88 | ||
| 89 | //---------------------------------------------------------------- |
|
| 90 | // private data |
|
| 91 | //---------------------------------------------------------------- |
|
| 92 | ||
| 93 | private char[] _buf; |
|
| 94 | ||
| 95 | 70 | public final void setLength(int len) { _len = len; } |
| 96 | 3640 | public final void setOffset(int ofs) { _ofs = ofs; } |
| 97 | ||
| 98 | private int _len; |
|
| 99 | private int _ofs; |
|
| 100 | ||
| 101 | } |