4900 |
21 Apr 09 |
martin |
1 |
/** |
4900 |
21 Apr 09 |
martin |
$Id$ |
4900 |
21 Apr 09 |
martin |
3 |
|
4900 |
21 Apr 09 |
martin |
Copyright (C) 2009 Martin Svensson |
4900 |
21 Apr 09 |
martin |
5 |
|
4900 |
21 Apr 09 |
martin |
This file is part of BASE - BioArray Software Environment. |
4900 |
21 Apr 09 |
martin |
Available at http://base.thep.lu.se/ |
4900 |
21 Apr 09 |
martin |
8 |
|
4900 |
21 Apr 09 |
martin |
BASE is free software; you can redistribute it and/or |
4900 |
21 Apr 09 |
martin |
modify it under the terms of the GNU General Public License |
4900 |
21 Apr 09 |
martin |
as published by the Free Software Foundation; either version 3 |
4900 |
21 Apr 09 |
martin |
of the License, or (at your option) any later version. |
4900 |
21 Apr 09 |
martin |
13 |
|
4900 |
21 Apr 09 |
martin |
BASE is distributed in the hope that it will be useful, |
4900 |
21 Apr 09 |
martin |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4900 |
21 Apr 09 |
martin |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4900 |
21 Apr 09 |
martin |
GNU General Public License for more details. |
4900 |
21 Apr 09 |
martin |
18 |
|
4900 |
21 Apr 09 |
martin |
You should have received a copy of the GNU General Public License |
4900 |
21 Apr 09 |
martin |
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 |
Formatter to handle {@link Nameable} items. |
4900 |
21 Apr 09 |
martin |
@author martin |
4900 |
21 Apr 09 |
martin |
@version 2.12 |
4900 |
21 Apr 09 |
martin |
@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 |
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 |
Create a new formatter. |
4925 |
08 May 09 |
nicklas |
@param nullValue The string to return if a null item is |
4925 |
08 May 09 |
nicklas |
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 |
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 |
@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 |
} |