001 /**
002 * Copyright 2012 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 *
015 * Created by Charles on 11/16/12
016 */
017 package org.kuali.student.enrollment.class2.courseoffering.refdata;
018
019 import org.kuali.student.r2.common.helper.EntityMergeHelper;
020
021 import java.util.ArrayList;
022 import java.util.HashMap;
023 import java.util.Iterator;
024 import java.util.List;
025 import java.util.Map;
026 import java.util.TreeMap;
027
028 /**
029 * One row of data (using key-value pairs where key is header name)
030 *
031 * @author Kuali Student Team
032 */
033 public class SpreadsheetRowData implements Iterable<String> {
034 Map<String, String> fieldNamesToValue = new HashMap<String, String>();
035 List<String> fieldNames = new ArrayList<String>();
036
037 public boolean addData(String field, String data) {
038 if (fieldNamesToValue.containsKey(field)) {
039 return false;
040 }
041 fieldNamesToValue.put(field, data);
042 fieldNames.add(field);
043 return true;
044 }
045
046 public String getValue(String fieldName) {
047 return fieldNamesToValue.get(fieldName);
048 }
049
050 @Override
051 public Iterator<String> iterator() {
052 return new Iterator<String>() {
053 Iterator<String> iter = fieldNames.iterator();
054 String fieldName = null;
055 @Override
056 public boolean hasNext() {
057 return iter.hasNext();
058 }
059
060 @Override
061 public String next() {
062 fieldName = iter.next();
063 String nextVal = getValue(fieldName);
064 return nextVal;
065 }
066
067 @Override
068 public void remove() {
069 fieldNamesToValue.remove(fieldName);
070 }
071 };
072 }
073 }