-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cffb1ef
commit 05c2620
Showing
5 changed files
with
220 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Source/Core/src/ca/uqac/lif/synthia/util/CompositePicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Synthia, a data structure generator | ||
Copyright (C) 2019-2020 Laboratoire d'informatique formelle | ||
Université du Québec à Chicoutimi, Canada | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package ca.uqac.lif.synthia.util; | ||
|
||
import ca.uqac.lif.synthia.Picker; | ||
|
||
/** | ||
* Picker that merges the result of other pickers into a | ||
* composite data structure. Descendants of this class use a | ||
* different data structure. | ||
*/ | ||
public abstract class CompositePicker<T> implements Picker<T> | ||
{ | ||
/** | ||
* The pickers used to generate the values | ||
*/ | ||
/*@ non_null @*/ protected Picker<?>[] m_pickers; | ||
|
||
/** | ||
* Creates a new composite picker | ||
* @param pickers The pickers used to generate the values | ||
*/ | ||
public CompositePicker(/*@ non_null @*/ Picker<?> ... pickers) | ||
{ | ||
super(); | ||
m_pickers = pickers; | ||
} | ||
|
||
@Override | ||
public Picker<T> duplicate(boolean with_state) | ||
{ | ||
Picker<?>[] duplicates = new Picker<?>[m_pickers.length]; | ||
for (int i = 0; i < m_pickers.length; i++) | ||
{ | ||
duplicates[i] = m_pickers[i].duplicate(with_state); | ||
} | ||
return newPicker(duplicates); | ||
} | ||
|
||
@Override | ||
public T pick() | ||
{ | ||
Object[] out = new Object[m_pickers.length]; | ||
for (int i = 0; i < m_pickers.length; i++) | ||
{ | ||
out[i] = m_pickers[i].pick(); | ||
} | ||
return getOutput(out); | ||
} | ||
|
||
@Override | ||
public void reset() | ||
{ | ||
for (int i = 0; i < m_pickers.length; i++) | ||
{ | ||
m_pickers[i].reset(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a duplicate of the current picker | ||
* @param pickers The internal pickers, already duplicated | ||
* @return A new instance of the picker | ||
*/ | ||
protected abstract CompositePicker<T> newPicker(Picker<?> ... pickers); | ||
|
||
/** | ||
* Creates the output composite object from the internal | ||
* values that have been picked | ||
* @param objects The internal values | ||
* @return The composite object | ||
*/ | ||
protected abstract T getOutput(Object ... objects); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Synthia, a data structure generator | ||
Copyright (C) 2019-2020 Laboratoire d'informatique formelle | ||
Université du Québec à Chicoutimi, Canada | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package ca.uqac.lif.synthia.util; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import ca.uqac.lif.synthia.Picker; | ||
|
||
/** | ||
* Picker that merges the result of other pickers into a set. | ||
*/ | ||
public class ListPicker extends CompositePicker<Set<Object>> | ||
{ | ||
/** | ||
* Creates a new set picker | ||
* @param pickers The pickers used to generate the values | ||
*/ | ||
public ListPicker(Picker<?> ... pickers) | ||
{ | ||
super(pickers); | ||
} | ||
|
||
@Override | ||
public ListPicker newPicker(Picker<?> ... pickers) | ||
{ | ||
return new ListPicker(pickers); | ||
} | ||
|
||
@Override | ||
public Set<Object> getOutput(Object ... values) | ||
{ | ||
Set<Object> set = new HashSet<Object>(values.length); | ||
for (Object v : values) | ||
{ | ||
set.add(v); | ||
} | ||
return set; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Synthia, a data structure generator | ||
Copyright (C) 2019-2020 Laboratoire d'informatique formelle | ||
Université du Québec à Chicoutimi, Canada | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package ca.uqac.lif.synthia.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import ca.uqac.lif.synthia.Picker; | ||
|
||
/** | ||
* Picker that merges the result of other pickers into an array. | ||
*/ | ||
public class SetPicker extends CompositePicker<List<Object>> | ||
{ | ||
/** | ||
* Creates a new list picker | ||
* @param pickers The pickers used to generate the values | ||
*/ | ||
public SetPicker(Picker<?> ... pickers) | ||
{ | ||
super(pickers); | ||
} | ||
|
||
@Override | ||
public SetPicker newPicker(Picker<?> ... pickers) | ||
{ | ||
return new SetPicker(pickers); | ||
} | ||
|
||
@Override | ||
public List<Object> getOutput(Object ... values) | ||
{ | ||
List<Object> list = new ArrayList<Object>(values.length); | ||
for (Object v : values) | ||
{ | ||
list.add(v); | ||
} | ||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters