Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
coemgen1992 committed Nov 28, 2024
1 parent 2d0c268 commit 33a562e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ default T deserializeFromFile(final File file) throws IOException, NotSupportedV
* reader.
*/
default Iterable<String> fileExtensions() {
List<String> extensions = new ArrayList<String>();
List<String> extensions = new ArrayList<>();
supportedFormats().forEach(f -> extensions.add(f.extension()));
return extensions;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/at/jku/cps/travart/core/common/ILanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface ILanguage<T> {
* the variability model.
*/
default IPrettyPrinter<T> getPrinter() {
return new DefaultPrettyPrinter<T>(this.getSerializer());
return new DefaultPrettyPrinter<>(this.getSerializer());
}

/**
Expand All @@ -73,12 +73,12 @@ default IPrettyPrinter<T> getPrinter() {
*/
String getName();

/**
* Returns an abbreviation, typically an acronym of the variability type name.
*
* @return the abbreviated version of the variability type name.
*/
String getAbbreviation();
/**
* Returns an abbreviation, typically an acronym of the variability type name.
*
* @return the abbreviated version of the variability type name.
*/
String getAbbreviation();

/**
* Returns a iterable of file extensions for which this language is applicable.
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/at/jku/cps/travart/core/io/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class FileUtils {

Expand All @@ -33,7 +34,11 @@ public static Set<Path> getPathSet(final Path path, final String extension) thro

public static Set<Path> getPathSetForLevel(final Path path, final String extension, final int level)
throws IOException {
return Files.walk(path, level).filter(Files::isRegularFile)
.filter(f -> f.getFileName().toString().endsWith(extension)).collect(Collectors.toSet());
try (Stream<Path> stream = Files.walk(path, level)) {
return stream.filter(Files::isRegularFile)
.filter(f -> f.getFileName().toString().endsWith(extension)).collect(Collectors.toSet());
} catch (IOException e) {
throw new IOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class DefaultCoreModelSampler implements ISampler<FeatureModel> {

private FeatureModel lastFm;

private IFeatureModel featureIdeFm;
private Set<Map<IConfigurable, Boolean>> samples;
private Set<Map<IConfigurable, Boolean>> invalidSamples;

Expand Down Expand Up @@ -110,8 +109,7 @@ private void toFeatureIdeFm(final FeatureModel fm, final IFeatureModel featureId
format.read(featureIdeFm, fm.toString());
}

private Set<Map<IConfigurable, Boolean>> sample(final IFeatureModel fm)
throws NotSupportedVariabilityTypeException {
private Set<Map<IConfigurable, Boolean>> sample(final IFeatureModel fm) {
List<List<String>> configurations = findConfigurations(fm);
Set<Map<IConfigurable, Boolean>> configurables = new HashSet<>();
for (final List<String> fmSample : configurations) {
Expand Down Expand Up @@ -143,22 +141,20 @@ public String getName() {
return configurables;
}

private List<List<String>> findConfigurations(final IFeatureModel fm) throws NotSupportedVariabilityTypeException {
private List<List<String>> findConfigurations(final IFeatureModel fm) {
FeatureModelFormula formula = new FeatureModelFormula(fm);
List<LiteralSet> samples = LongRunningWrapper.runMethod(new TWiseConfigurationGenerator(formula.getCNF(), 3));
// List<LiteralSet> samples = LongRunningWrapper
// .runMethod(new RandomConfigurationGenerator(formula.getCNF(), 1_000_000));
List<List<String>> configurations = new ArrayList<>(samples.size());
for (LiteralSet sample : samples) {
List<LiteralSet> configs = LongRunningWrapper.runMethod(new TWiseConfigurationGenerator(formula.getCNF(), 3));
List<List<String>> configurations = new ArrayList<>(configs.size());
for (LiteralSet sample : configs) {
List<String> names = formula.getCNF().getVariables().convertToString(sample);
configurations.add(names);
}
return configurations;
}

private Set<Map<IConfigurable, Boolean>> sampleInvalid(final IFeatureModel fm,
final Set<Map<IConfigurable, Boolean>> samples) throws NotSupportedVariabilityTypeException {
Set<Map<IConfigurable, Boolean>> invalidSamples = new HashSet<>();
final Set<Map<IConfigurable, Boolean>> samples) {
invalidSamples = new HashSet<>();
for (Map<IConfigurable, Boolean> sample : samples) {
for (int count = 0; count < INVALID_COUNT; count++) {
int featureSwitch = rand.nextInt(sample.size());
Expand Down Expand Up @@ -191,7 +187,7 @@ private boolean verifySampleAsFeatureIde(final IFeatureModel fm, final Map<IConf
IFeature feature = FeatureUtils.getFeature(fm, entry.getKey().getName());
if (feature != null) {
String featureName = FeatureUtils.getName(feature);
if (entry.getValue()) {
if (Boolean.TRUE.equals(entry.getValue())) {
config.setManual(featureName, Selection.SELECTED);
} else {
config.setManual(featureName, Selection.UNSELECTED);
Expand Down

0 comments on commit 33a562e

Please sign in to comment.