Synthia
Generic and flexible data structure generator
AsLong.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 a long integer.
25  * @author Sylvain Hallé
26  * @ingroup API
27  */
28 public class AsLong implements Picker<Long>
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 AsLong(Picker<?> picker)
40  {
41  super();
42  m_picker = picker;
43  }
44 
45  @Override
46  public Long pick()
47  {
48  Object o = m_picker.pick();
49  if (o == null)
50  {
51  return 0L;
52  }
53  if (o instanceof Number)
54  {
55  return ((Number) o).longValue();
56  }
57  return 0L;
58  }
59 
60  @Override
61  public AsLong duplicate(boolean with_state)
62  {
63  return new AsLong(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.AsLong.pick
Long pick()
Picks an object.
Definition: AsLong.java:46
ca.uqac.lif.synthia.util.AsLong.reset
void reset()
Puts the picker back into its initial state.
Definition: AsLong.java:67
ca.uqac
ca.uqac.lif.synthia.util.AsLong
Utility picker that converts an input into a long integer.
Definition: AsLong.java:28
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.AsLong.duplicate
AsLong duplicate(boolean with_state)
Creates a copy of the picker.
Definition: AsLong.java:61
ca.uqac.lif.synthia.util.AsLong.m_picker
Picker<?> m_picker
The picker from which to take the input objects.
Definition: AsLong.java:33
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.AsLong.AsLong
AsLong(Picker<?> picker)
Creates a new instance of the picker.
Definition: AsLong.java:39