EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.nio]

COVERAGE SUMMARY FOR SOURCE FILE [UnsignedShortBuffer.java]

nameclass, %method, %block, %line, %
UnsignedShortBuffer.java0%   (0/1)0%   (0/31)0%   (0/216)0%   (0/50)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UnsignedShortBuffer0%   (0/1)0%   (0/31)0%   (0/216)0%   (0/50)
<static initializer> 0%   (0/1)0%   (0/15)0%   (0/1)
UnsignedShortBuffer (ByteBuffer): void 0%   (0/1)0%   (0/6)0%   (0/3)
allocate (int): UnsignedShortBuffer 0%   (0/1)0%   (0/7)0%   (0/1)
capacity (): int 0%   (0/1)0%   (0/5)0%   (0/1)
clear (): BufferMarker 0%   (0/1)0%   (0/6)0%   (0/2)
compareTo (Object): int 0%   (0/1)0%   (0/9)0%   (0/2)
computeNumBytes (int): int 0%   (0/1)0%   (0/4)0%   (0/1)
computeNumEls (int): int 0%   (0/1)0%   (0/14)0%   (0/2)
equals (Object): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
flip (): BufferMarker 0%   (0/1)0%   (0/6)0%   (0/2)
get (): int 0%   (0/1)0%   (0/8)0%   (0/2)
get (int []): void 0%   (0/1)0%   (0/14)0%   (0/3)
get (int): int 0%   (0/1)0%   (0/7)0%   (0/1)
getByteBuffer (): ByteBuffer 0%   (0/1)0%   (0/3)0%   (0/1)
hasRemaining (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
hashCode (): int 0%   (0/1)0%   (0/4)0%   (0/1)
isReadOnly (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
limit (): int 0%   (0/1)0%   (0/5)0%   (0/1)
limit (int): BufferMarker 0%   (0/1)0%   (0/8)0%   (0/2)
makeUnsigned (int): int 0%   (0/1)0%   (0/4)0%   (0/1)
mark (): BufferMarker 0%   (0/1)0%   (0/6)0%   (0/2)
order (ByteOrder): UnsignedShortBuffer 0%   (0/1)0%   (0/7)0%   (0/2)
position (): int 0%   (0/1)0%   (0/5)0%   (0/1)
position (int): BufferMarker 0%   (0/1)0%   (0/8)0%   (0/2)
put (int []): void 0%   (0/1)0%   (0/14)0%   (0/3)
put (int): void 0%   (0/1)0%   (0/7)0%   (0/2)
put (int, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
remaining (): int 0%   (0/1)0%   (0/5)0%   (0/1)
reset (): BufferMarker 0%   (0/1)0%   (0/6)0%   (0/2)
rewind (): BufferMarker 0%   (0/1)0%   (0/6)0%   (0/2)
sizeof (): int 0%   (0/1)0%   (0/2)0%   (0/1)

1/*
2 * $Id: UnsignedShortBuffer.java,v 1.2 2005/12/16 22:32:46 hastings Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12package com.moesol.nio;
13 
14import java.nio.ByteBuffer;
15import java.nio.ByteOrder;
16 
17import com.moesol.bindings.NativeStructure;
18 
19 
20/**
21 * Help getting bytes back as unsigned short (C size 4 bytes).
22 * Same as CharBuffer, but System.out.println does the right thing.
23 * 
24 * @author Hastings
25 */
26public class UnsignedShortBuffer implements BufferMarker, Comparable {
27 
28        private final ByteBuffer m_byte_buffer;
29 
30        public UnsignedShortBuffer(ByteBuffer b) {
31                m_byte_buffer = b;
32        }
33        
34        /**
35         * @param length
36     * @return new byte buffre
37         */
38        public static UnsignedShortBuffer allocate(int length) {
39                return new UnsignedShortBuffer(ByteBuffer.allocate(computeNumBytes(length)));
40        }
41        
42        public int get() {
43                int r = m_byte_buffer.getChar();
44                return makeUnsigned(r);
45        }
46        public int get(int offset) {
47                return makeUnsigned(m_byte_buffer.getChar(offset));
48        }
49        public void put(int v) {
50                m_byte_buffer.putChar((char)v);
51        }
52        public void put(int offset, int v) {
53                m_byte_buffer.putChar(offset, (char)v);
54        }
55 
56        /**
57         * @param result
58         */
59        public void get(int[] result) {
60                for (int i = 0; i < result.length; i++) {
61                        result[i] = get();
62                }
63        }
64 
65        /**
66         * @param values
67         */
68        public void put(int[] values) {
69                for (int i = 0; i < values.length; i++) {
70                        put(values[i]);
71                }
72        }
73        
74        /**
75         * @param r
76     * @return unsigned short
77         */
78        private int makeUnsigned(int r) {
79                return r & 0xFFFF;
80        }
81 
82        /**
83     * @return true if remaining
84         */
85        public boolean hasRemaining() {
86                return m_byte_buffer.hasRemaining();
87        }
88 
89        /**
90     * @return remaining
91         */
92        public int remaining() {
93                return computeNumEls(m_byte_buffer.remaining());
94        }
95 
96        /**
97     * @return limit
98         */
99        public int limit() {
100                return computeNumEls(m_byte_buffer.limit());
101        }
102        
103        /**
104     * @return capacity
105         */
106        public int capacity() {
107                return computeNumEls(m_byte_buffer.capacity());
108        }
109 
110        /**
111     * @return number of elements that fit n bytes.
112         */
113        private static int computeNumEls(int bytes) {
114                assert(bytes % sizeof() == 0);
115                return bytes / sizeof();
116        }
117        private static int computeNumBytes(int els) {
118                return els * sizeof();
119        }
120 
121        /**
122     * @return underlying byte buffer
123         */
124        public ByteBuffer getByteBuffer() {
125                return m_byte_buffer;
126        }
127 
128        public UnsignedShortBuffer order(ByteOrder o) {
129                m_byte_buffer.order(o);
130                return this;
131        }
132 
133        public BufferMarker flip() {
134                m_byte_buffer.flip();
135                return this;
136        }
137 
138        /* (non-Javadoc)
139         * @see java.lang.Comparable#compareTo(java.lang.Object)
140         */
141        public int compareTo(Object o) {
142                UnsignedShortBuffer other = (UnsignedShortBuffer)o;
143                return m_byte_buffer.compareTo(other.getByteBuffer());
144        }
145        
146        private static int sizeof() {
147                return NativeStructure.getUnsignedShortSize();
148        }
149        public int position() {
150                return computeNumEls(m_byte_buffer.position());
151        }
152        public BufferMarker position(int newPosition) {
153                m_byte_buffer.position(computeNumBytes(newPosition));
154                return this;
155        }
156        public BufferMarker limit(int newLimit) {
157                m_byte_buffer.limit(computeNumBytes(newLimit));
158                return this;
159        }
160        public BufferMarker mark() {
161                m_byte_buffer.mark();
162                return this;
163        }
164        public BufferMarker reset() {
165                m_byte_buffer.reset();
166                return this;
167        }
168        public BufferMarker clear() {
169                m_byte_buffer.clear();
170                return this;
171        }
172        public BufferMarker rewind() {
173                m_byte_buffer.rewind();
174                return this;
175        }
176        public boolean isReadOnly() {
177                return m_byte_buffer.isReadOnly();
178        }
179        
180        public boolean equals(Object arg0) {
181                return 0 == compareTo(arg0);
182        }
183 
184        public int hashCode() {
185                return m_byte_buffer.hashCode();
186        }
187 
188}

[all classes][com.moesol.nio]
EMMA 2.0.5312 (C) Vladimir Roubtsov