Synthia
Generic and flexible data structure generator
PickSmallerComparator.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.relative;
20 
21 import java.util.Comparator;
22 
23 import ca.uqac.lif.synthia.Picker;
24 
25 /**
26  * A variant of {@link PickIf} that selects an element if it is smaller than
27  * a reference object. In order for the "smaller" condition to be evaluated,
28  * the picker must be passed an instance of {@link Comparator}.
29  *
30  * @author Sylvain Hallé
31  *
32  * @param <T> The type of objects manipulated by this picker
33  * @ingroup API
34  */
35 public class PickSmallerComparator<T> extends PickIf<T>
36 {
37  /**
38  * A comparator for objects of type T.
39  */
40  protected Comparator<T> m_comparator;
41 
42  /**
43  * The reference object that candidate values are compared to.
44  */
45  protected T m_reference;
46 
47  /**
48  * Creates a new instance of the picker.
49  * @param source The source of objects
50  * @param o The reference object that candidate values are compared to
51  * @param c The comparator used to compare the reference to candidate values
52  */
53  public PickSmallerComparator(Picker<? extends T> source, T o, Comparator<T> c)
54  {
55  super(source);
56  m_reference = o;
57  m_comparator = c;
58  }
59 
60  @Override
61  public PickSmallerComparator<T> duplicate(boolean with_state)
62  {
64  if (with_state)
65  {
67  }
68  return ps;
69  }
70  public PickSmallerComparator<T> getSmaller(T o, Comparator<T> c)
71  {
74  return ps;
75  }
76 
77  @Override
78  protected boolean select(T element)
79  {
80  return m_comparator.compare(element, m_reference) < 0;
81  }
82 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
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.lif.synthia.relative.PickSmallerComparator.PickSmallerComparator
PickSmallerComparator(Picker<? extends T > source, T o, Comparator< T > c)
Creates a new instance of the picker.
Definition: PickSmallerComparator.java:53
ca.uqac.lif.synthia.relative.PickSmallerComparator.duplicate
PickSmallerComparator< T > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: PickSmallerComparator.java:61
ca.uqac.lif.synthia.relative.PickSmallerComparator.select
boolean select(T element)
Method to evaluate if an element is satisfying a condition.
Definition: PickSmallerComparator.java:78
ca.uqac
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.relative.PickSmallerComparator.getSmaller
PickSmallerComparator< T > getSmaller(T o, Comparator< T > c)
Definition: PickSmallerComparator.java:70
ca.uqac.lif
ca.uqac.lif.synthia.relative.PickIf
Returns object from a picker satisfying a condition.
Definition: PickIf.java:39
ca
ca.uqac.lif.synthia.relative.PickSmallerComparator.m_reference
T m_reference
The reference object that candidate values are compared to.
Definition: PickSmallerComparator.java:45
ca.uqac.lif.synthia.relative.PickSmallerComparator.m_comparator
Comparator< T > m_comparator
A comparator for objects of type T.
Definition: PickSmallerComparator.java:40
ca.uqac.lif.synthia.relative.PickIf.m_maxIteration
int m_maxIteration
The maximal number of iteration that the while loop of the pick() method can do.
Definition: PickIf.java:45
ca.uqac.lif.synthia.relative.PickSmallerComparator
A variant of PickIf that selects an element if it is smaller than a reference object.
Definition: PickSmallerComparator.java:35
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.