Changes from JWS2 branch merged, mostly javadoc
[jabaws.git] / datamodel / compbio / metadata / ChunkHolder.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.metadata;\r
20 \r
21 import javax.xml.bind.annotation.XmlAccessType;\r
22 import javax.xml.bind.annotation.XmlAccessorType;\r
23 \r
24 /**\r
25  * Represents a chunk of a string data together with the position in a file for\r
26  * the next read operation.\r
27  * \r
28  * @author pvtroshin\r
29  * \r
30  * @version 1.0 December 2009\r
31  */\r
32 @XmlAccessorType(XmlAccessType.FIELD)\r
33 public class ChunkHolder {\r
34 \r
35         String chunk;\r
36         long position;\r
37 \r
38         private ChunkHolder() {\r
39                 // JaxB default constructor\r
40                 // should not be used otherwise\r
41         }\r
42 \r
43         public ChunkHolder(String chunk, long position) {\r
44                 if (position < 0) {\r
45                         throw new IndexOutOfBoundsException(\r
46                                         "Position in a file could not be negative! Given value: "\r
47                                                         + position);\r
48                 }\r
49                 if (chunk == null) {\r
50                         throw new NullPointerException("Chunk must not be NULL!");\r
51                 }\r
52                 this.chunk = chunk;\r
53                 this.position = position;\r
54         }\r
55 \r
56         public String getChunk() {\r
57                 return chunk;\r
58         }\r
59 \r
60         public long getNextPosition() {\r
61                 return position;\r
62         }\r
63 \r
64         @Override\r
65         public boolean equals(Object obj) {\r
66                 if (obj == null) {\r
67                         return false;\r
68                 }\r
69                 ChunkHolder ch = null;\r
70                 if (!(obj instanceof ChunkHolder)) {\r
71                         ch = (ChunkHolder) obj;\r
72                 }\r
73                 if (this.position != ch.position) {\r
74                         return false;\r
75                 }\r
76                 if (!this.chunk.equals(ch.chunk)) {\r
77                         return false;\r
78                 }\r
79                 return true;\r
80         }\r
81 \r
82         @Override\r
83         public String toString() {\r
84                 String value = "Position: " + position + "\n";\r
85                 value += "Chunk size: " + chunk.length() + "\n";\r
86                 value += "Chunk: " + chunk + "\n";\r
87                 return value;\r
88         }\r
89 \r
90         @Override\r
91         public int hashCode() {\r
92                 return new Long(position + chunk.hashCode()).intValue();\r
93         }\r
94 }\r