Synthia
Generic and flexible data structure generator
Mutator.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.petitpoucet.NodeFactory;
22 import ca.uqac.lif.petitpoucet.Part;
23 import ca.uqac.lif.petitpoucet.PartNode;
24 import ca.uqac.lif.synthia.Picker;
26 
27 /**
28  * A picker that applies a transformation ("mutation") on the value produced by
29  * another picker.
30  * @param <T> The type of the objects produced by the picker
31  * @ingroup API
32  */
33 public abstract class Mutator<T> implements Picker<T>
34 {
35  /**
36  * The underlying picker producing the values to transform.
37  */
38  /*@ non_null @*/ protected Picker<? extends T> m_picker;
39 
40  /**
41  * Creates a new instance of mutator.
42  * @param picker The underlying picker producing the values to transform
43  */
44  public Mutator(/*@ non_null @*/ Picker<? extends T> picker)
45  {
46  super();
47  m_picker = picker;
48  }
49 
50  /**
51  * Sets the picker producing the values to transform.
52  * @param picker The underlying picker producing the values to transform
53  * @return This picker
54  */
55  /*@ non_null @*/ public Mutator<T> setPicker(/*@ non_null @*/ Picker<? extends T> picker)
56  {
57  m_picker = picker;
58  return this;
59  }
60 
61  @Override
62  public void reset()
63  {
64  m_picker.reset();
65  }
66 
67  public PartNode getExplanation(Part p)
68  {
69  return getExplanation(p, NodeFactory.getFactory());
70  }
71 
72  public PartNode getExplanation(Part p, NodeFactory f)
73  {
74  int index = NthSuccessiveOutput.mentionedOutput(p);
75  if (index < 0)
76  {
77  // Not a valid part, end there
78  return null;
79  }
80  return getExplanationForOutput(index, p, f);
81  }
82 
83  protected PartNode getExplanationForOutput(int output_index, Part p, NodeFactory f)
84  {
85  return f.getPartNode(p, this);
86  }
87 
88  protected void copyInto(/*@ non_null @*/ Mutator<T> m, boolean with_state)
89  {
90  // Do nothing
91  }
92 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.util.Mutator.getExplanation
PartNode getExplanation(Part p)
Definition: Mutator.java:67
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
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.util.Mutator.getExplanation
PartNode getExplanation(Part p, NodeFactory f)
Definition: Mutator.java:72
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.explanation
Objects related to the explanation of results produced by pickers.
Definition: Explanation.java:19
ca.uqac.lif
ca.uqac.lif.synthia.util.Mutator.copyInto
void copyInto(Mutator< T > m, boolean with_state)
Definition: Mutator.java:88
ca
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.Mutator.getExplanationForOutput
PartNode getExplanationForOutput(int output_index, Part p, NodeFactory f)
Definition: Mutator.java:83
ca.uqac.lif.synthia.explanation.NthSuccessiveOutput.mentionedOutput
static int mentionedOutput(Part d)
Retrieves the output sequence index mentioned in a designator.
Definition: NthSuccessiveOutput.java:144
ca.uqac.lif.synthia.util.Mutator.Mutator
Mutator(Picker<? extends T > picker)
Creates a new instance of mutator.
Definition: Mutator.java:44
ca.uqac.lif.synthia.Picker.reset
void reset()
Puts the picker back into its initial state.
ca.uqac.lif.synthia.util.Mutator.reset
void reset()
Puts the picker back into its initial state.
Definition: Mutator.java:62
ca.uqac.lif.synthia.explanation.NthSuccessiveOutput
A Part pointing to the n-th output produced by a picker since its last call to reset().
Definition: NthSuccessiveOutput.java:36