src/core/net/sf/basedb/util/export/spotdata/ExportableFieldFormatter.java

Code
Comments
Other
Rev Date Author Line
4925 08 May 09 nicklas 1 /**
4925 08 May 09 nicklas 2   $Id$
4925 08 May 09 nicklas 3
4925 08 May 09 nicklas 4   Copyright (C) 2009 Nicklas Nordborg
4925 08 May 09 nicklas 5
4925 08 May 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4925 08 May 09 nicklas 7   Available at http://base.thep.lu.se/
4925 08 May 09 nicklas 8
4925 08 May 09 nicklas 9   BASE is free software; you can redistribute it and/or
4925 08 May 09 nicklas 10   modify it under the terms of the GNU General Public License
4925 08 May 09 nicklas 11   as published by the Free Software Foundation; either version 3
4925 08 May 09 nicklas 12   of the License, or (at your option) any later version.
4925 08 May 09 nicklas 13
4925 08 May 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4925 08 May 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4925 08 May 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4925 08 May 09 nicklas 17   GNU General Public License for more details.
4925 08 May 09 nicklas 18
4925 08 May 09 nicklas 19   You should have received a copy of the GNU General Public License
4925 08 May 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4925 08 May 09 nicklas 21 */
4925 08 May 09 nicklas 22 package net.sf.basedb.util.export.spotdata;
4925 08 May 09 nicklas 23
4925 08 May 09 nicklas 24 import net.sf.basedb.util.formatter.Formatter;
4925 08 May 09 nicklas 25
4925 08 May 09 nicklas 26 /**
4925 08 May 09 nicklas 27   Formatter implementation that formats an exportable field
4925 08 May 09 nicklas 28   by returning the column title. See {@link ExportableField#getTitle()}.
4925 08 May 09 nicklas 29   <p>
4925 08 May 09 nicklas 30   Note! Do not confuse this formatter with the formatter returned
4925 08 May 09 nicklas 31   from {@link ExportableField#getFormatter()}. That formatter is about
4925 08 May 09 nicklas 32   formatting the exported values, while this formatter is about
4925 08 May 09 nicklas 33   formatting the column header.
4925 08 May 09 nicklas 34
4925 08 May 09 nicklas 35   @author Nicklas
4925 08 May 09 nicklas 36   @version 2.12
4925 08 May 09 nicklas 37   @base.modified $Date$
4925 08 May 09 nicklas 38 */
4925 08 May 09 nicklas 39 public class ExportableFieldFormatter
4925 08 May 09 nicklas 40   implements Formatter<ExportableField>
4925 08 May 09 nicklas 41 {
4925 08 May 09 nicklas 42
4925 08 May 09 nicklas 43   private String nullValue = "";
4925 08 May 09 nicklas 44   
4925 08 May 09 nicklas 45   /**
4925 08 May 09 nicklas 46     Create a new formatter. Null values are formatted as an empty string.
4925 08 May 09 nicklas 47   */
4925 08 May 09 nicklas 48   public ExportableFieldFormatter()
4925 08 May 09 nicklas 49   {}
4925 08 May 09 nicklas 50   
4925 08 May 09 nicklas 51   /**
4925 08 May 09 nicklas 52     Create a new formatter.
4925 08 May 09 nicklas 53     @param nullValue The string to return if a null item is 
4925 08 May 09 nicklas 54       passed to {@link #format(ExportableField)}
4925 08 May 09 nicklas 55   */
4925 08 May 09 nicklas 56   public ExportableFieldFormatter(String nullValue)
4925 08 May 09 nicklas 57   {
4925 08 May 09 nicklas 58     this.nullValue = nullValue;
4925 08 May 09 nicklas 59   }
4925 08 May 09 nicklas 60
4925 08 May 09 nicklas 61   
4925 08 May 09 nicklas 62   /*
4925 08 May 09 nicklas 63     From the Formatter interface
4925 08 May 09 nicklas 64     -------------------------------------------
4925 08 May 09 nicklas 65   */
4925 08 May 09 nicklas 66   @Override
4925 08 May 09 nicklas 67   public String format(ExportableField value)
4925 08 May 09 nicklas 68   {
4925 08 May 09 nicklas 69     return value == null ? nullValue : value.getTitle();
4925 08 May 09 nicklas 70   }
4925 08 May 09 nicklas 71   /**
4925 08 May 09 nicklas 72     @throws UnsupportedOperationException Always
4925 08 May 09 nicklas 73   */
4925 08 May 09 nicklas 74   @Override
4925 08 May 09 nicklas 75   public ExportableField parseString(String value)
4925 08 May 09 nicklas 76   {
4925 08 May 09 nicklas 77     throw new UnsupportedOperationException("parseString: " + value);
4925 08 May 09 nicklas 78   }
4925 08 May 09 nicklas 79   // -------------------------------------------
4925 08 May 09 nicklas 80
4925 08 May 09 nicklas 81 }