View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Charles on 11/16/12
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.refdata;
18  
19  import org.kuali.student.r2.common.helper.EntityMergeHelper;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.TreeMap;
27  
28  /**
29   * One row of data (using key-value pairs where key is header name)
30   *
31   * @author Kuali Student Team
32   */
33  public class SpreadsheetRowData implements Iterable<String> {
34      Map<String, String> fieldNamesToValue = new HashMap<String, String>();
35      List<String> fieldNames = new ArrayList<String>();
36  
37      public boolean addData(String field, String data) {
38          if (fieldNamesToValue.containsKey(field)) {
39              return false;
40          }
41          fieldNamesToValue.put(field, data);
42          fieldNames.add(field);
43          return true;
44      }
45  
46      public String getValue(String fieldName) {
47          return fieldNamesToValue.get(fieldName);
48      }
49  
50      @Override
51      public Iterator<String> iterator() {
52          return new Iterator<String>() {
53              Iterator<String> iter = fieldNames.iterator();
54              String fieldName = null;
55              @Override
56              public boolean hasNext() {
57                  return iter.hasNext();
58              }
59  
60              @Override
61              public String next() {
62                  fieldName = iter.next();
63                  String nextVal = getValue(fieldName);
64                  return nextVal;
65              }
66  
67              @Override
68              public void remove() {
69                  fieldNamesToValue.remove(fieldName);
70              }
71          };
72      }
73  }