001 package org.LiveGraph.dataFile.common; 002 003 004 /** 005 * This convenience class defines special tags for the LiveGraph data file format. 006 * 007 * <p style="font-size:smaller;">This product includes software developed by the 008 * <strong>LiveGraph</strong> project and its contributors.<br /> 009 * (<a href="http://www.live-graph.org" target="_blank">http://www.live-graph.org</a>)<br /> 010 * Copyright (c) 2007 G. Paperin.<br /> 011 * All rights reserved. 012 * </p> 013 * <p style="font-size:smaller;">File: DataFormatTools.java</p> 014 * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or 015 * without modification, are permitted provided that the following terms and conditions are met: 016 * </p> 017 * <p style="font-size:smaller;">1. Redistributions of source code must retain the above 018 * acknowledgement of the LiveGraph project and its web-site, the above copyright notice, 019 * this list of conditions and the following disclaimer.<br /> 020 * 2. Redistributions in binary form must reproduce the above acknowledgement of the 021 * LiveGraph project and its web-site, the above copyright notice, this list of conditions 022 * and the following disclaimer in the documentation and/or other materials provided with 023 * the distribution.<br /> 024 * 3. All advertising materials mentioning features or use of this software or any derived 025 * software must display the following acknowledgement:<br /> 026 * <em>This product includes software developed by the LiveGraph project and its 027 * contributors.<br />(http://www.live-graph.org)</em><br /> 028 * 4. All advertising materials distributed in form of HTML pages or any other technology 029 * permitting active hyper-links that mention features or use of this software or any 030 * derived software must display the acknowledgment specified in condition 3 of this 031 * agreement, and in addition, include a visible and working hyper-link to the LiveGraph 032 * homepage (http://www.live-graph.org). 033 * </p> 034 * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY 035 * OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 037 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 038 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 039 * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 040 * </p> 041 * 042 * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>) 043 * @version {@value org.LiveGraph.LiveGraph#version} 044 */ 045 public class DataFormatTools { 046 047 /** 048 * Every comment line must start with this tag. 049 */ 050 public static final String TAGComment = "#"; 051 052 /** 053 * Every file description line must start with this tag. 054 */ 055 public static final String TAGFileInfo = "@"; 056 057 /** 058 * An alternatice separator definition in the first line of the file must be 059 * ocated wetween two instances of this tag. 060 */ 061 public static final String TAGSepDefinition = TAGComment + TAGComment; 062 063 /** 064 * This is the default data separator tag. 065 */ 066 public static final String DefaultSeparator = ","; 067 068 069 /** 070 * In order to read the data correctly a tag must not be confused with data value. 071 * This method checks whther a separator tag is valid. Note that while this method 072 * check for most common problems, it does not guarantee a correct separator. 073 * 074 * @param separator A proposed data deparator string. 075 * @return {@code true} if the specified separetor tag can be used with {@code double} 076 * data values; {@code false} if the specified tag is not valid. 077 */ 078 public static String isValidSeparator(String separator) { 079 080 if (null == separator) 081 return "The saparator may not be a null string"; 082 083 try { 084 double d = Double.parseDouble(separator); 085 return "Separator may not represent a legal real value (" + d + ")"; 086 } catch (NumberFormatException e) {} 087 088 String SEP = separator.toUpperCase(); 089 if (SEP.equals("P") || SEP.equals("F") || SEP.equals("A") || SEP.equals("B") || SEP.equals("C") 090 || SEP.equals("D") || SEP.equals("E") || SEP.equals("F") || SEP.equals("H") || SEP.equals("NAN") 091 || SEP.equals("INFINITY") || SEP.equals("^") || SEP.equals("-") || SEP.equals("+") 092 || SEP.equals(".") || SEP.equals("..") || SEP.equals("...")) 093 return "Illegal separator (" + separator + ")"; 094 095 if (separator.contains("\n") || separator.contains("\r")) 096 return "Separator may not contain any line feeds or carriage returns"; 097 098 return null; 099 } 100 101 }