Synthia
Generic and flexible data structure generator
AsInt.java
Go to the documentation of this file.
1
/*
2
Synthia, a data structure generator
3
Copyright (C) 2019-2021 Laboratoire d'informatique formelle
4
Université du Québec à Chicoutimi, Canada
5
6
This program is free software: you can redistribute it and/or modify
7
it under the terms of the GNU Lesser General Public License as published
8
by the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
package
ca.uqac.lif.synthia.util;
20
21
import
ca
.
uqac
.
lif
.
synthia
.
Picker
;
22
23
/**
24
* Utility picker that converts an input into an integer.
25
* @author Sylvain Hallé
26
* @ingroup API
27
*/
28
public
class
AsInt
implements
Picker
<Integer>
29
{
30
/**
31
* The picker from which to take the input objects.
32
*/
33
protected
Picker<?>
m_picker
;
34
35
/**
36
* Creates a new instance of the picker.
37
* @param picker The picker from which to take the input objects
38
*/
39
public
AsInt
(
Picker<?>
picker)
40
{
41
super();
42
m_picker
= picker;
43
}
44
45
@Override
46
public
Integer
pick
()
47
{
48
Object o =
m_picker
.
pick
();
49
if
(o ==
null
)
50
{
51
return
0;
52
}
53
if
(o instanceof Number)
54
{
55
return
((Number) o).intValue();
56
}
57
return
0;
58
}
59
60
@Override
61
public
AsInt
duplicate
(
boolean
with_state)
62
{
63
return
new
AsInt
(
m_picker
.
duplicate
(with_state));
64
}
65
66
@Override
67
public
void
reset
()
68
{
69
m_picker
.
reset
();
70
}
71
}
ca.uqac.lif.synthia.Picker
Picks an object.
Definition:
Picker.java:36
ca.uqac.lif.synthia.util.AsInt
Utility picker that converts an input into an integer.
Definition:
AsInt.java:28
ca.uqac.lif.synthia.util.AsInt.AsInt
AsInt(Picker<?> picker)
Creates a new instance of the picker.
Definition:
AsInt.java:39
ca.uqac.lif.synthia.util.AsInt.duplicate
AsInt duplicate(boolean with_state)
Creates a copy of the picker.
Definition:
AsInt.java:61
ca.uqac.lif.synthia.util.AsInt.m_picker
Picker<?> m_picker
The picker from which to take the input objects.
Definition:
AsInt.java:33
ca.uqac
ca.uqac.lif.synthia
Definition:
Bounded.java:19
ca.uqac.lif
ca
ca.uqac.lif.synthia.Picker.pick
T pick()
Picks an object.
ca.uqac.lif.synthia.util.AsInt.pick
Integer pick()
Picks an object.
Definition:
AsInt.java:46
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
ca.uqac.lif.synthia.Picker.reset
void reset()
Puts the picker back into its initial state.
ca.uqac.lif.synthia.util.AsInt.reset
void reset()
Puts the picker back into its initial state.
Definition:
AsInt.java:67
Source
Core
src
ca
uqac
lif
synthia
util
AsInt.java
Generated by
1.8.17