001    /*-----------------------------------------------------------------------
002     *  Copyright (C) 2006
003     *  Associated Universities, Inc. Washington DC, USA.
004     *  This program is free software; you can redistribute it and/or
005     *  modify it under the terms of the GNU General Public License as
006     *  published by the Free Software Foundation; either version 2 of
007     *  the License, or (at your option) any later version.
008     *
009     *  This program is distributed in the hope that it will be useful,
010     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     *  GNU General Public License for more details.
013     *
014     *  Correspondence concerning this software should be addressed as follows:
015     *         Internet email: switz@nrao.edu
016     *         Postal address: SSS Software
017     *                         National Radio Astronomy Observatory
018     *                         Post Office Box 0
019     *                         Socorro, NM 87801  USA
020     *-----------------------------------------------------------------------*/
021    package edu.nrao.sss.model.parameter;
022    
023    import java.io.BufferedReader;
024    import java.io.File;
025    import java.io.FileReader;
026    import java.io.IOException;
027    import java.util.ArrayList;
028    import java.util.HashMap;
029    import java.util.List;
030    import java.util.Map;
031    
032    public class BatchUpdateFile {
033            private final List<String> fileContents;
034            private final Map<Integer, Parameter> parameterMap;
035            private final String userName;
036    
037            public BatchUpdateFile(File file, String userName) throws IOException {
038                    fileContents = new ArrayList<String>();
039                    parameterMap = new HashMap<Integer, Parameter>();
040                    this.userName = userName;
041                    
042                    BufferedReader br = new BufferedReader(new FileReader(file));
043                    String currentLine;
044                    int lineNumber = 0;
045                    while ((currentLine = br.readLine()) != null) {
046                            lineNumber++;
047                            fileContents.add(currentLine);
048                            BatchUpdateLine buLine = new BatchUpdateLine(currentLine);
049                            if (!buLine.isComment()) {
050                                    Parameter parameter = new Parameter(userName, buLine.getParameterName(), buLine.getEntity(), buLine
051                                                    .getBand(), buLine.getValue());
052                                    parameterMap.put(new Integer(lineNumber), parameter);
053                            }
054                    }
055            }
056    
057            public List<String> getFileContents() {
058                    return fileContents;
059            }
060    
061            public Map<Integer, Parameter> getParameterMap() {
062                    return parameterMap;
063            }
064    
065            public String getUserName() {
066                    return userName;
067            }
068    }