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