src/core/net/sf/basedb/util/formatter/NameableFormatter.java

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