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