Synthia
Generic and flexible data structure generator
ArrayPicker.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 
22 import ca.uqac.lif.synthia.Picker;
26 
27 /**
28  * Picker that merges the result of other pickers into an array.
29  * @ingroup API
30  */
31 public class ArrayPicker extends CompositePicker<Object[]> implements Shrinkable<Object[]>
32 {
33  /**
34  * Creates a new array picker
35  * @param pickers The pickers used to generate the values
36  */
37  public ArrayPicker(Picker<?> ... pickers)
38  {
39  super(pickers);
40  }
41 
42  /**
43  * Returns a new array picker
44  * @param pickers The pickers used to generate the values
45  * @return The new array picker
46  */
47  @Override
48  public ArrayPicker newPicker(Picker<?> ... pickers)
49  {
50  return new ArrayPicker(pickers);
51  }
52 
53 
54  /**
55  * Return an array of values
56  * @param values The values to return
57  * @return The values
58  */
59  @Override
60  public Object[] getOutput(Object ... values)
61  {
62  return values;
63  }
64 
65  @SuppressWarnings({ "rawtypes", "unchecked" })
66  @Override
67  public ArrayPicker shrink(Object[] o, Picker<Float> decision, float magnitude)
68  {
69  Picker[] shrunk_pickers = new Picker[m_pickers.length];
70  for (int i = 0; i < m_pickers.length; i++)
71  {
72  if (!(m_pickers[i] instanceof Shrinkable))
73  {
74  throw new CannotShrinkException(m_pickers[i]);
75  }
76  shrunk_pickers[i] = ((Shrinkable<Object>) m_pickers[i]).shrink(o[i], decision, 1);
77  }
78  return new ArrayPicker(shrunk_pickers);
79  }
80 
81  @Override
82  public ArrayPicker shrink(Object[] o)
83  {
84  return shrink(o, RandomFloat.instance, 1);
85  }
86 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.Shrinkable
Interface signaling that a picker can be shrunk.
Definition: Shrinkable.java:36
ca.uqac.lif.synthia.util.ArrayPicker.getOutput
Object[] getOutput(Object ... values)
Return an array of values.
Definition: ArrayPicker.java:60
ca.uqac.lif.synthia.collection
Pickers generating and manipulating collections, such as lists and sets.
Definition: ComparableList.java:19
ca.uqac.lif.synthia.random.RandomFloat.instance
static final transient RandomFloat instance
A public static instance of RandomFloat.
Definition: RandomFloat.java:45
ca.uqac.lif.synthia.collection.CompositePicker.m_pickers
Picker<?>[] m_pickers
The pickers used to generate the values.
Definition: CompositePicker.java:34
ca.uqac.lif.synthia.util.ArrayPicker
Picker that merges the result of other pickers into an array.
Definition: ArrayPicker.java:31
ca.uqac
ca.uqac.lif.synthia.random
Pickers that produce pseudo-random objects such as numbers.
Definition: AffineTransform.java:19
ca.uqac.lif.synthia.collection.CompositePicker
Picker that merges the result of other pickers into a composite data structure.
Definition: CompositePicker.java:29
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.util.ArrayPicker.shrink
ArrayPicker shrink(Object[] o, Picker< Float > decision, float magnitude)
Definition: ArrayPicker.java:67
ca.uqac.lif
ca.uqac.lif.synthia.util.ArrayPicker.newPicker
ArrayPicker newPicker(Picker<?> ... pickers)
Returns a new array picker.
Definition: ArrayPicker.java:48
ca
ca.uqac.lif.synthia.util.ArrayPicker.ArrayPicker
ArrayPicker(Picker<?> ... pickers)
Creates a new array picker.
Definition: ArrayPicker.java:37
ca.uqac.lif.synthia.random.RandomFloat
Picks a floating point number uniformly in an interval.
Definition: RandomFloat.java:30
ca.uqac.lif.synthia.CannotShrinkException
An exception to throw when a picker can't pick an other element.
Definition: CannotShrinkException.java:25
ca.uqac.lif.synthia.util.ArrayPicker.shrink
ArrayPicker shrink(Object[] o)
Definition: ArrayPicker.java:82