View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.StringTokenizer;
26  
27  public class MeasureList implements Iterable<Measure> {
28  
29    private List<Measure> list = new ArrayList<>();
30  
31    public MeasureList() {
32    }
33  
34    @Override
35    public Iterator<Measure> iterator() {
36      return list.iterator();
37    }
38  
39    public static MeasureList parse(final String string) {
40      final MeasureList measureList = new MeasureList();
41      final StringTokenizer tokenizer = new StringTokenizer(string, "; ");
42  
43      while (tokenizer.hasMoreTokens()) {
44        final Measure token = Measure.valueOf(tokenizer.nextToken().trim());
45        measureList.list.add(token);
46      }
47      return measureList;
48    }
49  
50    public int getSize() {
51      return list.size();
52    }
53  
54    public Measure get(final int i) {
55      return list.get(i);
56    }
57  
58    public void add(final Measure measure) {
59      list.add(measure);
60    }
61  
62    public String serialize() {
63      final StringBuilder str = new StringBuilder();
64      for (final Measure measure : list) {
65        str.append(measure);
66        str.append(" ");
67      }
68      return str.toString();
69    }
70  
71    public String toString() {
72      return serialize();
73    }
74  }