src/core/net/sf/basedb/util/formatter/IdentifiableFormatter.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.formatter;
4925 08 May 09 nicklas 23
4925 08 May 09 nicklas 24 import net.sf.basedb.core.Identifiable;
4925 08 May 09 nicklas 25
4925 08 May 09 nicklas 26 /**
4925 08 May 09 nicklas 27    Formatter to handle {@link Identifiable} items. The formatter
4925 08 May 09 nicklas 28    returns the ID of the item. This formatter can not parse strings.
4925 08 May 09 nicklas 29
4925 08 May 09 nicklas 30   @author Nicklas
4925 08 May 09 nicklas 31   @version 2.12
4925 08 May 09 nicklas 32   @base.modified $Date$
4925 08 May 09 nicklas 33 */
4925 08 May 09 nicklas 34 public class IdentifiableFormatter
4925 08 May 09 nicklas 35   implements Formatter<Identifiable>
4925 08 May 09 nicklas 36 {
4925 08 May 09 nicklas 37   private String nullValue = "";
4925 08 May 09 nicklas 38   
4925 08 May 09 nicklas 39   /**
4925 08 May 09 nicklas 40     Create a new formatter. Null values are formatted as an empty string.
4925 08 May 09 nicklas 41   */
4925 08 May 09 nicklas 42   public IdentifiableFormatter()
4925 08 May 09 nicklas 43   {}
4925 08 May 09 nicklas 44   
4925 08 May 09 nicklas 45   /**
4925 08 May 09 nicklas 46     Create a new formatter.
4925 08 May 09 nicklas 47     @param nullValue The string to return if a null item is 
4925 08 May 09 nicklas 48       passed to {@link #format(Identifiable)}
4925 08 May 09 nicklas 49   */
4925 08 May 09 nicklas 50   public IdentifiableFormatter(String nullValue)
4925 08 May 09 nicklas 51   {
4925 08 May 09 nicklas 52     this.nullValue = nullValue;
4925 08 May 09 nicklas 53   }
4925 08 May 09 nicklas 54
4925 08 May 09 nicklas 55   /*
4925 08 May 09 nicklas 56     From the Formatter interface
4925 08 May 09 nicklas 57     -------------------------------------------
4925 08 May 09 nicklas 58   */
4925 08 May 09 nicklas 59   @Override
4925 08 May 09 nicklas 60   public String format(Identifiable value)
4925 08 May 09 nicklas 61   {
4925 08 May 09 nicklas 62     return value == null ? nullValue : Integer.toString(value.getId());
4925 08 May 09 nicklas 63   }
4925 08 May 09 nicklas 64   /**
4925 08 May 09 nicklas 65     @throws UnsupportedOperationException Always
4925 08 May 09 nicklas 66   */
4925 08 May 09 nicklas 67   @Override
4925 08 May 09 nicklas 68   public Identifiable parseString(String value)
4925 08 May 09 nicklas 69   {
4925 08 May 09 nicklas 70     throw new UnsupportedOperationException("parseString: " + value);
4925 08 May 09 nicklas 71   }
4925 08 May 09 nicklas 72   // -------------------------------------------
4925 08 May 09 nicklas 73
4925 08 May 09 nicklas 74 }