Synthia
Generic and flexible data structure generator
NothingPicker.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.petitpoucet.function.ExplanationQueryable;
26 import ca.uqac.lif.synthia.Picker;
28 
29 /**
30  * A {@link RelativePicker} that only throws a {@link NoMoreElementException}
31  * when the {@link #pick()} method is called.
32  *
33  * @param <T> The type of the picker (but not really important here).
34  * @ingroup API
35  */
36 public class NothingPicker<T> implements Shrinkable<T>, ExplanationQueryable
37 {
38  /**
39  * Creates a new instance of the picker.
40  */
41  public NothingPicker()
42  {
43  super();
44  }
45 
46  @Override
47  public NothingPicker<T> shrink(T o, Picker<Float> decision, float m)
48  {
49  return new NothingPicker<T>();
50  }
51 
52  @Override
53  public void reset()
54  {
55  //Nothing to do here.
56  }
57 
58  @Override
59  public T pick()
60  {
61  throw new NoMoreElementException();
62  }
63 
64  @Override
65  public Picker<T> duplicate(boolean with_state)
66  {
67  return new NothingPicker<T>();
68  }
69 
70  @Override
71  public PartNode getExplanation(Part p)
72  {
73  return getExplanation(p, NodeFactory.getFactory());
74  }
75 
76  @Override
77  public PartNode getExplanation(Part p, NodeFactory arg1)
78  {
79  // Nothing is the end of the chain
80  return null;
81  }
82 
83  @Override
84  public Shrinkable<T> shrink(T o)
85  {
86  return shrink(o, null, 1);
87  }
88 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.util.NothingPicker.pick
T pick()
Picks an object.
Definition: NothingPicker.java:59
ca.uqac.lif.synthia.Shrinkable
Interface signaling that a picker can be shrunk.
Definition: Shrinkable.java:36
ca.uqac.lif.synthia.util.NothingPicker.NothingPicker
NothingPicker()
Creates a new instance of the picker.
Definition: NothingPicker.java:41
ca.uqac.lif.synthia.util.NothingPicker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: NothingPicker.java:65
ca.uqac.lif.synthia.util.NothingPicker.getExplanation
PartNode getExplanation(Part p)
Definition: NothingPicker.java:71
ca.uqac
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.util.NothingPicker.shrink
NothingPicker< T > shrink(T o, Picker< Float > decision, float m)
Shrinks a picker.
Definition: NothingPicker.java:47
ca.uqac.lif.synthia.util.NothingPicker.reset
void reset()
Puts the picker back into its initial state.
Definition: NothingPicker.java:53
ca.uqac.lif
ca.uqac.lif.synthia.util.NothingPicker
A RelativePicker that only throws a NoMoreElementException when the pick() method is called.
Definition: NothingPicker.java:36
ca
ca.uqac.lif.synthia.util.NothingPicker.getExplanation
PartNode getExplanation(Part p, NodeFactory arg1)
Definition: NothingPicker.java:77
ca.uqac.lif.synthia.util.NothingPicker.shrink
Shrinkable< T > shrink(T o)
Shrinks a picker with default parameters.
Definition: NothingPicker.java:84
ca.uqac.lif.synthia.NoMoreElementException
An exception to throw when a picker can't pick an other element.
Definition: NoMoreElementException.java:25