Synthia
Generic and flexible data structure generator
RandomSuffix.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.string;
20 
21 import ca.uqac.lif.synthia.Picker;
25 
26 /**
27  * Just like {@link RandomPrefix} but for suffixes.
28  * @author Marc-Antoine Plourde
29  * @ingroup API
30  */
31 public class RandomSuffix extends RandomPrefix
32 {
33 
34  public RandomSuffix(String string)
35  {
36  super(string);
37  }
38 
39  private RandomSuffix(String string, RandomInteger prefix_size)
40  {
41  super(string, prefix_size);
42  }
43 
44  @Override
45  public Shrinkable<String> shrink(String element, Picker<Float> decision, float magnitude)
46  {
47  if(element.isEmpty())
48  {
49  return new NothingPicker<>();
50  }
51  return new RandomSuffix(element, m_prefixSize.duplicate(true));
52  }
53 
54  @Override
55  public String pick()
56  {
57  return m_string.substring(m_prefixSize.pick(), m_string.length());
58  }
59 
60  @Override
61  public RandomSuffix duplicate(boolean with_state)
62  {
63  return new RandomSuffix(m_string, m_prefixSize.duplicate(with_state));
64  }
65 
66 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.string.RandomSuffix.RandomSuffix
RandomSuffix(String string)
Definition: RandomSuffix.java:34
ca.uqac.lif.synthia.Shrinkable
Interface signaling that a picker can be shrunk.
Definition: Shrinkable.java:36
ca.uqac.lif.synthia.string.RandomPrefix.m_string
String m_string
The string used to generate prefixes.
Definition: RandomPrefix.java:28
ca.uqac.lif.synthia.string.RandomSuffix.duplicate
RandomSuffix duplicate(boolean with_state)
Creates a copy of the picker.
Definition: RandomSuffix.java:61
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
ca.uqac.lif.synthia.string.RandomPrefix
Like RandomSubString, but this time, the Picker returns a prefix of the original strings of randomly ...
Definition: RandomPrefix.java:17
ca.uqac
ca.uqac.lif.synthia.random
Pickers that produce pseudo-random objects such as numbers.
Definition: AffineTransform.java:19
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.string.RandomSuffix.shrink
Shrinkable< String > shrink(String element, Picker< Float > decision, float magnitude)
Create a new RandomPrefix picker based on a given string.
Definition: RandomSuffix.java:45
ca.uqac.lif.synthia.string.RandomSuffix
Just like RandomPrefix but for suffixes.
Definition: RandomSuffix.java:31
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.uqac.lif.synthia.random.RandomInteger
Picks an integer uniformly in an interval.
Definition: RandomInteger.java:31
ca.uqac.lif.synthia.random.RandomInteger.pick
Integer pick()
Picks a random integer.
Definition: RandomInteger.java:118
ca
ca.uqac.lif.synthia.random.RandomInteger.duplicate
RandomInteger duplicate(boolean with_state)
Creates a copy of the RandomInteger picker.
Definition: RandomInteger.java:133
ca.uqac.lif.synthia.string.RandomSuffix.pick
String pick()
Picks an object.
Definition: RandomSuffix.java:55
ca.uqac.lif.synthia.string.RandomPrefix.m_prefixSize
RandomInteger m_prefixSize
RandomInteger picker to select the size of a generated prefix.
Definition: RandomPrefix.java:23