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.util.regex.Pattern; 024 025 public class BatchUpdateLine { 026 public static final Pattern pattern = Pattern.compile(","); 027 private String entity, parameterName, band, value; 028 private String line; 029 030 BatchUpdateLine(String line) { 031 this.line = trim(line); 032 if (!isComment() && numCommas() == 3) { 033 String[] tokens = pattern.split(line); 034 entity = trim(tokens[0]); 035 band = trim(tokens[1]); 036 if (band != null && band.trim().length() == 0) 037 band = null; 038 parameterName = trim(tokens[2]); 039 if (tokens.length == 4) 040 value = trim(tokens[3]); 041 else 042 value = null; 043 } else { 044 entity = parameterName = band = value = null; 045 } 046 } 047 048 public String getBand() { 049 return band; 050 } 051 052 public String getEntity() { 053 return entity; 054 } 055 056 public String getLine() { 057 return line; 058 } 059 060 public String getParameterName() { 061 return parameterName; 062 } 063 064 public String getValue() { 065 return value; 066 } 067 068 public boolean isComment() { 069 return (line == null || line.isEmpty() || line.startsWith("#")) ? true : false; 070 } 071 072 public int numCommas() { 073 return (line == null || line.isEmpty()) ? 0 : line.replaceAll("[^,]", "").length(); 074 } 075 076 public String toString() { 077 return line; 078 } 079 080 private String trim(String token) { 081 return (token != null) ? token.trim() : null; 082 } 083 }