2203 |
28 Apr 06 |
nicklas |
1 |
/* |
2203 |
28 Apr 06 |
nicklas |
$Id$ |
2203 |
28 Apr 06 |
nicklas |
3 |
|
2203 |
28 Apr 06 |
nicklas |
Copyright (C) 2006 Nicklas Nordborg |
2203 |
28 Apr 06 |
nicklas |
5 |
|
2203 |
28 Apr 06 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
2203 |
28 Apr 06 |
nicklas |
Available at http://base.thep.lu.se/ |
2203 |
28 Apr 06 |
nicklas |
8 |
|
2203 |
28 Apr 06 |
nicklas |
BASE is free software; you can redistribute it and/or modify it |
2203 |
28 Apr 06 |
nicklas |
under the terms of the GNU General Public License as published by |
4479 |
05 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
2203 |
28 Apr 06 |
nicklas |
(at your option) any later version. |
2203 |
28 Apr 06 |
nicklas |
13 |
|
2203 |
28 Apr 06 |
nicklas |
BASE is distributed in the hope that it will be useful, but |
2203 |
28 Apr 06 |
nicklas |
WITHOUT ANY WARRANTY; without even the implied warranty of |
2203 |
28 Apr 06 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2203 |
28 Apr 06 |
nicklas |
General Public License for more details. |
2203 |
28 Apr 06 |
nicklas |
18 |
|
2203 |
28 Apr 06 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2203 |
28 Apr 06 |
nicklas |
21 |
*/ |
2203 |
28 Apr 06 |
nicklas |
22 |
package net.sf.basedb.util.parser; |
2203 |
28 Apr 06 |
nicklas |
23 |
|
7667 |
21 Mar 19 |
nicklas |
24 |
import java.util.Date; |
7667 |
21 Mar 19 |
nicklas |
25 |
|
7668 |
21 Mar 19 |
nicklas |
26 |
import net.sf.basedb.core.Type; |
7675 |
27 Mar 19 |
nicklas |
27 |
import net.sf.basedb.util.Values; |
2203 |
28 Apr 06 |
nicklas |
28 |
import net.sf.basedb.util.parser.FlatFileParser.Data; |
2203 |
28 Apr 06 |
nicklas |
29 |
|
2203 |
28 Apr 06 |
nicklas |
30 |
/** |
2203 |
28 Apr 06 |
nicklas |
Represents a mapping expression that gets a single value from |
2203 |
28 Apr 06 |
nicklas |
a line of data. A typical mapping expression |
2203 |
28 Apr 06 |
nicklas |
holds a reference to the column number or name, for example: |
2203 |
28 Apr 06 |
nicklas |
<pre class="code"> |
2203 |
28 Apr 06 |
nicklas |
\1\ |
2203 |
28 Apr 06 |
nicklas |
\row\ |
2203 |
28 Apr 06 |
nicklas |
Row: \row\, Col:\col\ |
2317 |
24 May 06 |
nicklas |
=2 * col('Radius') |
2203 |
28 Apr 06 |
nicklas |
</pre> |
2203 |
28 Apr 06 |
nicklas |
40 |
|
2203 |
28 Apr 06 |
nicklas |
The actual syntax for the mapping string depends on the parser used. |
2203 |
28 Apr 06 |
nicklas |
42 |
|
2203 |
28 Apr 06 |
nicklas |
@author Nicklas |
2203 |
28 Apr 06 |
nicklas |
@version 2.0 |
2203 |
28 Apr 06 |
nicklas |
@see net.sf.basedb.util.parser.FlatFileParser#getMapper(String) |
2302 |
22 May 06 |
nicklas |
@base.modified $Date$ |
2203 |
28 Apr 06 |
nicklas |
47 |
*/ |
2203 |
28 Apr 06 |
nicklas |
48 |
public interface Mapper |
2203 |
28 Apr 06 |
nicklas |
49 |
{ |
2203 |
28 Apr 06 |
nicklas |
50 |
/** |
2203 |
28 Apr 06 |
nicklas |
Get the value for the line of data. |
2203 |
28 Apr 06 |
nicklas |
@param data The line of data |
2203 |
28 Apr 06 |
nicklas |
@return A string value |
7703 |
11 Apr 19 |
nicklas |
@deprecated In 3.15, use {@link #getString(FlatFileParser.Data)} instead or |
7664 |
20 Mar 19 |
nicklas |
one of the other getXxxx() methods to get a given data type directly |
2203 |
28 Apr 06 |
nicklas |
56 |
*/ |
7664 |
20 Mar 19 |
nicklas |
57 |
@Deprecated |
2203 |
28 Apr 06 |
nicklas |
58 |
public String getValue(Data data); |
2225 |
09 May 06 |
nicklas |
59 |
|
2225 |
09 May 06 |
nicklas |
60 |
/** |
7666 |
20 Mar 19 |
nicklas |
Get the value for the line of data as a string. |
7666 |
20 Mar 19 |
nicklas |
@param data The line of data |
7666 |
20 Mar 19 |
nicklas |
@return A string value |
7666 |
20 Mar 19 |
nicklas |
@since 3.15 |
7666 |
20 Mar 19 |
nicklas |
65 |
*/ |
7666 |
20 Mar 19 |
nicklas |
66 |
public String getString(Data data); |
7666 |
20 Mar 19 |
nicklas |
67 |
|
7666 |
20 Mar 19 |
nicklas |
68 |
/** |
2225 |
09 May 06 |
nicklas |
Get the value for the line of data as an integer. |
2203 |
28 Apr 06 |
nicklas |
70 |
|
2225 |
09 May 06 |
nicklas |
@param data The line of data |
2225 |
09 May 06 |
nicklas |
@return The value as an integer |
2225 |
09 May 06 |
nicklas |
@throws NumberFormatException If the value can't be parsed as an integer |
2225 |
09 May 06 |
nicklas |
74 |
*/ |
2225 |
09 May 06 |
nicklas |
75 |
public Integer getInt(Data data); |
7668 |
21 Mar 19 |
nicklas |
76 |
|
7668 |
21 Mar 19 |
nicklas |
77 |
/** |
7668 |
21 Mar 19 |
nicklas |
Get the value for the line of data as a long. |
2225 |
09 May 06 |
nicklas |
79 |
|
7668 |
21 Mar 19 |
nicklas |
@param data The line of data |
7668 |
21 Mar 19 |
nicklas |
@return The value as an long |
7668 |
21 Mar 19 |
nicklas |
@throws NumberFormatException If the value can't be parsed as an long |
7668 |
21 Mar 19 |
nicklas |
@since 3.15 |
7668 |
21 Mar 19 |
nicklas |
84 |
*/ |
7668 |
21 Mar 19 |
nicklas |
85 |
public Long getLong(Data data); |
7668 |
21 Mar 19 |
nicklas |
86 |
|
2225 |
09 May 06 |
nicklas |
87 |
/** |
2225 |
09 May 06 |
nicklas |
Get the value for the line of data as a float. |
2225 |
09 May 06 |
nicklas |
89 |
|
2225 |
09 May 06 |
nicklas |
@param data The line of data |
2225 |
09 May 06 |
nicklas |
@return The value as a float |
2225 |
09 May 06 |
nicklas |
@throws NumberFormatException If the value can't be parsed as a float |
2225 |
09 May 06 |
nicklas |
93 |
*/ |
2225 |
09 May 06 |
nicklas |
94 |
public Float getFloat(Data data); |
2225 |
09 May 06 |
nicklas |
95 |
|
7668 |
21 Mar 19 |
nicklas |
96 |
/** |
7668 |
21 Mar 19 |
nicklas |
Get the value for the line of data as a double. |
7668 |
21 Mar 19 |
nicklas |
98 |
|
7668 |
21 Mar 19 |
nicklas |
@param data The line of data |
7668 |
21 Mar 19 |
nicklas |
@return The value as a double |
7668 |
21 Mar 19 |
nicklas |
@throws NumberFormatException If the value can't be parsed as a double |
7668 |
21 Mar 19 |
nicklas |
@since 3.15 |
7668 |
21 Mar 19 |
nicklas |
103 |
*/ |
7668 |
21 Mar 19 |
nicklas |
104 |
public Double getDouble(Data data); |
7668 |
21 Mar 19 |
nicklas |
105 |
|
7668 |
21 Mar 19 |
nicklas |
106 |
/** |
7668 |
21 Mar 19 |
nicklas |
Get the value for the line of data as a date. |
7668 |
21 Mar 19 |
nicklas |
108 |
|
7668 |
21 Mar 19 |
nicklas |
@param data The line of data |
7668 |
21 Mar 19 |
nicklas |
@return The value as a date |
7668 |
21 Mar 19 |
nicklas |
@since 3.15 |
7668 |
21 Mar 19 |
nicklas |
112 |
*/ |
7667 |
21 Mar 19 |
nicklas |
113 |
public Date getDate(Data data); |
2225 |
09 May 06 |
nicklas |
114 |
|
7668 |
21 Mar 19 |
nicklas |
115 |
@SuppressWarnings("unchecked") |
7668 |
21 Mar 19 |
nicklas |
116 |
public default <T> T getByType(Data data, Type type) |
7668 |
21 Mar 19 |
nicklas |
117 |
{ |
7668 |
21 Mar 19 |
nicklas |
118 |
T value = null; |
7668 |
21 Mar 19 |
nicklas |
119 |
if (type.isNumerical()) |
7668 |
21 Mar 19 |
nicklas |
120 |
{ |
7668 |
21 Mar 19 |
nicklas |
121 |
if (type == Type.DOUBLE) value = (T)getDouble(data); |
7668 |
21 Mar 19 |
nicklas |
122 |
else if (type == Type.FLOAT) value = (T)getFloat(data); |
7668 |
21 Mar 19 |
nicklas |
123 |
else if (type == Type.INT) value = (T)getInt(data); |
7668 |
21 Mar 19 |
nicklas |
124 |
else if (type == Type.LONG) value = (T)getLong(data); |
7668 |
21 Mar 19 |
nicklas |
125 |
} |
7668 |
21 Mar 19 |
nicklas |
126 |
else if (type.isTemporal()) |
7668 |
21 Mar 19 |
nicklas |
127 |
{ |
7668 |
21 Mar 19 |
nicklas |
128 |
value = (T)getDate(data); |
7668 |
21 Mar 19 |
nicklas |
129 |
} |
7675 |
27 Mar 19 |
nicklas |
130 |
else if (type == Type.BOOLEAN) |
7675 |
27 Mar 19 |
nicklas |
131 |
{ |
7675 |
27 Mar 19 |
nicklas |
132 |
value = (T)(Boolean)Values.getBoolean(getString(data)); |
7675 |
27 Mar 19 |
nicklas |
133 |
} |
7668 |
21 Mar 19 |
nicklas |
134 |
else |
7668 |
21 Mar 19 |
nicklas |
135 |
{ |
7668 |
21 Mar 19 |
nicklas |
136 |
value = (T)getString(data); |
7668 |
21 Mar 19 |
nicklas |
137 |
} |
7668 |
21 Mar 19 |
nicklas |
138 |
return value; |
7668 |
21 Mar 19 |
nicklas |
139 |
} |
7668 |
21 Mar 19 |
nicklas |
140 |
|
2203 |
28 Apr 06 |
nicklas |
141 |
} |