Synthia
Generic and flexible data structure generator
Mutate.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  * Transforms an object from a picker by selecting a mutator and applying it
25  * to an object. Concretely, this picker is instantiated by
26  * providing two things:
27  * <ol>
28  * <li>An arbitrary {@link Picker} producing the objects of type <tt>T</tt>
29  * to transform</li>
30  * <li>Another picker providing a {@link Mutator} for objects of type
31  * <tt>T</tt></li>
32  * </ol>
33  * On each call to {@link Picker#pick() pick()}, an object and a mutator
34  * are obtained, and the mutator is applied to the object. The resulting
35  * "mutated" object is then returned.
36  * <p>
37  * As with any other picker, both sources are arbitrary. For example, one
38  * could use a {@link Choice} picker to provide a randomly-selected mutation
39  * from a set of choices to apply to each object.
40  *
41  * @param <T> The type of the objects transformed by this picker
42  * @ingroup API
43  */
44 public class Mutate<T> extends Mutator<T>
45 {
46  /**
47  * Mutates input objects
48  */
49  /*@ non_null @*/ protected Picker<Mutator<T>> m_mutations;
50 
51  public Mutate(/*@ non_null @*/ Picker<? extends T> picker, /*@ non_null @*/ Picker<Mutator<T>> mutations)
52  {
53  super(picker);
54  m_mutations = mutations;
55  }
56 
57  @Override
58  public T pick()
59  {
60  Mutator<T> mutator = m_mutations.pick();
61  mutator.setPicker(m_picker);
62  return mutator.pick();
63  }
64 
65  @Override
66  public Picker<T> duplicate(boolean with_state)
67  {
68  return new Mutate<T>(m_picker.duplicate(with_state), m_mutations.duplicate(with_state));
69  }
70 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.util.Mutate
Transforms an object from a picker by selecting a mutator and applying it to an object.
Definition: Mutate.java:44
ca.uqac.lif.synthia.util.Mutator.m_picker
Picker<? extends T > m_picker
The underlying picker producing the values to transform.
Definition: Mutator.java:38
ca.uqac.lif.synthia.util.Mutate.pick
T pick()
Picks an object.
Definition: Mutate.java:58
ca.uqac.lif.synthia.util.Mutate.m_mutations
Picker< Mutator< T > > m_mutations
Mutates input objects.
Definition: Mutate.java:49
ca.uqac
ca.uqac.lif.synthia.util.Mutator.setPicker
Mutator< T > setPicker(Picker<? extends T > picker)
Sets the picker producing the values to transform.
Definition: Mutator.java:55
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.Mutate.Mutate
Mutate(Picker<? extends T > picker, Picker< Mutator< T >> mutations)
Definition: Mutate.java:51
ca.uqac.lif.synthia.util.Mutator
A picker that applies a transformation ("mutation") on the value produced by another picker.
Definition: Mutator.java:33
ca.uqac.lif.synthia.util.Mutate.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: Mutate.java:66
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.