1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  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,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 package org.apache.openoffice.ooxml.viewer.tokenview;
23 
24 import java.util.Vector;
25 
26 public class RunRange<TokenType>
27 {
RunRange(final Vector<Run<TokenType>> aRuns)28     RunRange (final Vector<Run<TokenType>> aRuns)
29     {
30         maRuns = aRuns;
31     }
32 
33 
34 
35 
FindTokens( @uppressWarningsR) final TokenType ... eTypeList)36     public int FindTokens (
37         @SuppressWarnings("unchecked")
38         final TokenType ... eTypeList)
39     {
40         return FindTokens(0, eTypeList);
41     }
42 
43 
44 
45 
FindTokens( final int nFirstIndex, @SuppressWarnings(R) final TokenType ... eTypeList)46     public int FindTokens (
47         final int nFirstIndex,
48         @SuppressWarnings("unchecked")
49         final TokenType ... eTypeList)
50     {
51         for (int nIndex=nFirstIndex; nIndex<maRuns.size()-eTypeList.length; ++nIndex)
52         {
53             boolean bMatches = true;
54             for (int nInnerIndex=0; nInnerIndex<eTypeList.length && bMatches; ++nInnerIndex)
55                 if (maRuns.get(nIndex+nInnerIndex).GetTokenType()
56                     != eTypeList[nInnerIndex])
57                 {
58                     bMatches = false;
59                 }
60             if (bMatches)
61                 return nIndex;
62         }
63 
64         return -1;
65     }
66 
67 
68 
69 
IsEmpty()70     public boolean IsEmpty ()
71     {
72         return maRuns.isEmpty();
73     }
74 
75 
76 
77 
Get(final int nIndex)78     public Run<TokenType> Get (final int nIndex)
79     {
80         return maRuns.get(nIndex);
81     }
82 
83 
84 
85 
86     private final Vector<Run<TokenType>> maRuns;
87 }
88