]> _ Git - cubeextranet.git/blob
68761a42eb52611aa90cdc07a71193b28628a8d4
[cubeextranet.git] /
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 /**
23  * 
24  * @author Koch
25  * @version $Revision: $
26  *
27  * @param <T> the type of object to store the revision numbers with
28  */
29 public class Revisions<T>
30 {
31
32     private List<T> objects;
33     private List<Integer> revisionNumbers;
34
35     private List<T> getObjects()
36     {
37         if (this.objects == null)
38         {
39             this.objects = new ArrayList<T>();
40         }
41         return this.objects;
42     }
43
44     private List<Integer> getRevisionNumbers()
45     {
46         if (this.revisionNumbers == null)
47         {
48             this.revisionNumbers = new ArrayList<Integer>();
49         }
50         return this.revisionNumbers;
51     }
52
53
54     /**
55      * 
56      */
57     public Revisions()
58     {
59     }
60
61
62     /**
63      * Returns the object at the specified position.
64      * 
65      * @param index the position
66      * @return the object
67      * @throws IndexOutOfBoundsException if the index is out of range
68      */
69     public T getObject(int index) throws IndexOutOfBoundsException
70     {
71         return this.getObjects().get(index);
72     }
73
74     /**
75      * Returns the revision number at the specified position.
76      * 
77      * @param index the position
78      * @return the revision number
79      * @throws IndexOutOfBoundsException if the index is out of range
80      */
81     public int getRevisionNumber(int index) throws IndexOutOfBoundsException
82     {
83         return this.getRevisionNumbers().get(index);
84     }
85
86     /**
87      * Adds an object with a specified revision number.
88      * 
89      * @param object the object
90      * @param revisionNumber the revision number
91      */
92     public void addObject(T object, int revisionNumber)
93     {
94         this.getObjects().add(object);
95         this.getRevisionNumbers().add(revisionNumber);
96     }
97
98     /**
99      * Sets the revision number of a specified object.
100      * 
101      * @param object the object
102      * @param revisionNumber the revision number
103      */
104     protected void setRevisionNumber(T object, int revisionNumber)
105     {
106         int index = this.getObjects().indexOf(object);
107         if (index > -1)
108         {
109             this.getRevisionNumbers().set(index, revisionNumber);
110         }
111     }
112
113     /**
114      * Returns the size.
115      * 
116      * @return the size
117      */
118     public int size()
119     {
120         return this.getObjects().size();
121     }
122
123     /**
124      * {@inheritDoc}
125      */
126     public String toString()
127     {
128         StringBuilder sb = new StringBuilder();
129         for (int i = 0; i < this.getObjects().size(); i++)
130         {
131             if (i > 0)
132             {
133                 sb.append("; ");
134             }
135             sb.append("object=").append(this.getObjects().get(i))
136                 .append(", revisionNumber=").append(this.getRevisionNumber(i));
137         }
138         return sb.toString();
139     }
140
141 }