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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
19 import java.util.ArrayList;
20 import java.util.List;
25 * @version $Revision: $
27 * @param <T> the type of object to store the revision numbers with
29 public class Revisions<T>
32 private List<T> objects;
33 private List<Integer> revisionNumbers;
35 private List<T> getObjects()
37 if (this.objects == null)
39 this.objects = new ArrayList<T>();
44 private List<Integer> getRevisionNumbers()
46 if (this.revisionNumbers == null)
48 this.revisionNumbers = new ArrayList<Integer>();
50 return this.revisionNumbers;
63 * Returns the object at the specified position.
65 * @param index the position
67 * @throws IndexOutOfBoundsException if the index is out of range
69 public T getObject(int index) throws IndexOutOfBoundsException
71 return this.getObjects().get(index);
75 * Returns the revision number at the specified position.
77 * @param index the position
78 * @return the revision number
79 * @throws IndexOutOfBoundsException if the index is out of range
81 public int getRevisionNumber(int index) throws IndexOutOfBoundsException
83 return this.getRevisionNumbers().get(index);
87 * Adds an object with a specified revision number.
89 * @param object the object
90 * @param revisionNumber the revision number
92 public void addObject(T object, int revisionNumber)
94 this.getObjects().add(object);
95 this.getRevisionNumbers().add(revisionNumber);
99 * Sets the revision number of a specified object.
101 * @param object the object
102 * @param revisionNumber the revision number
104 protected void setRevisionNumber(T object, int revisionNumber)
106 int index = this.getObjects().indexOf(object);
109 this.getRevisionNumbers().set(index, revisionNumber);
120 return this.getObjects().size();
126 public String toString()
128 StringBuilder sb = new StringBuilder();
129 for (int i = 0; i < this.getObjects().size(); i++)
135 sb.append("object=").append(this.getObjects().get(i))
136 .append(", revisionNumber=").append(this.getRevisionNumber(i));
138 return sb.toString();