Source code: com/voytechs/jnetanalyzer/message/MessageSegmentList.java
1 /*
2 * File: MessageSegmentList.java
3 * Auth: Mark Bednarczyk
4 * Date: DATE
5 * Id: $Id: MessageSegmentList.java,v 1.1.1.1 2003/09/22 16:32:06 voytechs Exp $
6 ********************************************
7 Copyright (C) 2003 Mark Bednarczyk
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ********************************************
23 * $Log: MessageSegmentList.java,v $
24 * Revision 1.1.1.1 2003/09/22 16:32:06 voytechs
25 * Initial import.
26 *
27 */
28 package com.voytechs.jnetanalyzer.message;
29
30 import java.lang.*;
31 import java.util.*;
32
33 /**
34 *
35 */
36 public class MessageSegmentList {
37
38 /* Internal attributes */
39 private static final boolean debug = false;
40
41 private ArrayList segmentList = new ArrayList();
42
43 /**
44 * Initialize empty list.
45 */
46 public MessageSegmentList() {
47 }
48
49 /**
50 * add a new element to the end of the list.
51 */
52 public void add(MessageSegment seg) {
53 segmentList.add(seg);
54 }
55
56 /**
57 * Find if segment already exists.
58 */
59 public boolean segmentExists(MessageSegment seg) {
60
61 if(find(seg.getSeq()) != null)
62 return(true);
63 else
64 return(false);
65 }
66
67 /**
68 * Find if segment already exists.
69 */
70 public boolean segmentExists(long seq) {
71
72 if(find(seq) != null)
73 return(true);
74 else
75 return(false);
76 }
77
78 /**
79 * Find first segment in the list with specified byte.
80 * @return MessageSegment if found, otherwise null.
81 */
82 public MessageSegment find(long seq) {
83
84 for(int i = 0; i < segmentList.size(); i ++) {
85 MessageSegment s = (MessageSegment)segmentList.get(i);
86
87 if(s.getSeq() <= seq && (s.getSeq() + s.getLength()) >= seq)
88 return(s);
89 }
90
91 return(null);
92 }
93
94 /**
95 * Test function for MessageSegmentList
96 * @param args command line arguments
97 */
98 public static void main(String [] args) {
99 }
100
101 } /* END OF: MessageSegmentList */