Synthia
Generic and flexible data structure generator
Offset.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  * Takes the numerical value of a picker, and offsets it by an amount
25  * determined by another picker.
26  * @ingroup API
27  */
28 public class Offset extends Mutator<Number>
29 {
30  /**
31  * The picker determining the offset of each value.
32  */
33  /*@ non_null @*/ protected Picker<? extends Number> m_offset;
34 
35  /**
36  * Creates a new offset instance.
37  * @param picker The underlying picker producing the values to transform
38  * @param offset The picker determining the offset of each output value
39  */
40  public Offset(/*@ non_null @*/ Picker<? extends Number> picker, /*@ non_null @*/ Picker<? extends Number> offset)
41  {
42  super(picker);
43  m_offset = offset;
44  }
45 
46  @Override
47  public Float pick()
48  {
49  float n = (float) m_picker.pick();
50  float o = (float) m_offset.pick();
51  return (Float) (n + o);
52  }
53 
54  @Override
55  public Offset duplicate(boolean with_state)
56  {
57  Offset o = new Offset(m_picker.duplicate(with_state), m_offset.duplicate(with_state));
58  super.copyInto(o, with_state);
59  return o;
60  }
61 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.util.Offset.m_offset
Picker<? extends Number > m_offset
The picker determining the offset of each value.
Definition: Offset.java:33
ca.uqac.lif.synthia.util.Mutator< Number >::m_picker
Picker<? extends T > m_picker
The underlying picker producing the values to transform.
Definition: Mutator.java:38
ca.uqac.lif.synthia.util.Offset.Offset
Offset(Picker<? extends Number > picker, Picker<? extends Number > offset)
Creates a new offset instance.
Definition: Offset.java:40
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.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.Offset.pick
Float pick()
Definition: Offset.java:47
ca.uqac.lif.synthia.util.Offset
Takes the numerical value of a picker, and offsets it by an amount determined by another picker.
Definition: Offset.java:28
ca.uqac.lif.synthia.util.Offset.duplicate
Offset duplicate(boolean with_state)
Definition: Offset.java:55
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.