KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > DefaultMOTableModel


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - DefaultMOTableModel.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent.mo;
23
24 import java.util.TreeMap JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.SortedMap JavaDoc;
27 import org.snmp4j.smi.OID;
28 import java.util.Iterator JavaDoc;
29
30 public class DefaultMOTableModel implements MOTableModel {
31
32   protected SortedMap JavaDoc rows = Collections.synchronizedSortedMap(new TreeMap JavaDoc());
33   protected int columnCount = 0;
34
35   public DefaultMOTableModel() {
36   }
37
38   public synchronized MOTableRow addRow(MOTableRow row) {
39     this.columnCount = Math.max(row.size(), columnCount);
40     return (MOTableRow) rows.put(row.getIndex(), row);
41   }
42
43   public int getColumnCount() {
44     return columnCount;
45   }
46
47   public int getRowCount() {
48     return rows.size();
49   }
50
51   public synchronized MOTableRow getRow(OID index) {
52     return (MOTableRow) rows.get(index);
53   }
54
55   public synchronized OID firstIndex() {
56     if (rows.size() > 0) {
57       return (OID) rows.firstKey();
58     }
59     return null;
60   }
61
62   public synchronized Iterator JavaDoc iterator() {
63     return rows.values().iterator();
64   }
65
66   public synchronized MOTableRow firstRow() {
67     OID index = firstIndex();
68     if (index != null) {
69       return (MOTableRow) rows.get(index);
70     }
71     return null;
72   }
73
74   public synchronized OID lastIndex() {
75     if (rows.size() > 0) {
76       return (OID) rows.lastKey();
77     }
78     return null;
79   }
80
81   public synchronized MOTableRow lastRow() {
82     OID index = lastIndex();
83     if (index != null) {
84       return (MOTableRow) rows.get(index);
85     }
86     return null;
87   }
88
89   public boolean containsRow(OID index) {
90     return rows.containsKey(index);
91   }
92
93   public synchronized Iterator JavaDoc tailIterator(OID lowerBound) {
94     if (lowerBound == null) {
95       return iterator();
96     }
97     return rows.tailMap(lowerBound).values().iterator();
98   }
99 }
100
Popular Tags