From 33a562e10c6fe7a791bfc46735779e3cdc4e4967 Mon Sep 17 00:00:00 2001 From: Kevin Feichtinger Date: Thu, 28 Nov 2024 13:02:51 +0100 Subject: [PATCH] clean code --- .../travart/core/common/IDeserializer.java | 2 +- .../cps/travart/core/common/ILanguage.java | 14 ++++++------- .../at/jku/cps/travart/core/io/FileUtils.java | 9 +++++++-- .../core/sampler/DefaultCoreModelSampler.java | 20 ++++++++----------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/java/at/jku/cps/travart/core/common/IDeserializer.java b/src/main/java/at/jku/cps/travart/core/common/IDeserializer.java index 23e9a0f..67412a0 100644 --- a/src/main/java/at/jku/cps/travart/core/common/IDeserializer.java +++ b/src/main/java/at/jku/cps/travart/core/common/IDeserializer.java @@ -97,7 +97,7 @@ default T deserializeFromFile(final File file) throws IOException, NotSupportedV * reader. */ default Iterable fileExtensions() { - List extensions = new ArrayList(); + List extensions = new ArrayList<>(); supportedFormats().forEach(f -> extensions.add(f.extension())); return extensions; } diff --git a/src/main/java/at/jku/cps/travart/core/common/ILanguage.java b/src/main/java/at/jku/cps/travart/core/common/ILanguage.java index 58e2909..9079a53 100644 --- a/src/main/java/at/jku/cps/travart/core/common/ILanguage.java +++ b/src/main/java/at/jku/cps/travart/core/common/ILanguage.java @@ -63,7 +63,7 @@ public interface ILanguage { * the variability model. */ default IPrettyPrinter getPrinter() { - return new DefaultPrettyPrinter(this.getSerializer()); + return new DefaultPrettyPrinter<>(this.getSerializer()); } /** @@ -73,12 +73,12 @@ default IPrettyPrinter 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. diff --git a/src/main/java/at/jku/cps/travart/core/io/FileUtils.java b/src/main/java/at/jku/cps/travart/core/io/FileUtils.java index d7ffa91..f48068d 100644 --- a/src/main/java/at/jku/cps/travart/core/io/FileUtils.java +++ b/src/main/java/at/jku/cps/travart/core/io/FileUtils.java @@ -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 { @@ -33,7 +34,11 @@ public static Set getPathSet(final Path path, final String extension) thro public static Set 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 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); + } } } diff --git a/src/main/java/at/jku/cps/travart/core/sampler/DefaultCoreModelSampler.java b/src/main/java/at/jku/cps/travart/core/sampler/DefaultCoreModelSampler.java index 6a24e66..19db269 100644 --- a/src/main/java/at/jku/cps/travart/core/sampler/DefaultCoreModelSampler.java +++ b/src/main/java/at/jku/cps/travart/core/sampler/DefaultCoreModelSampler.java @@ -54,7 +54,6 @@ public class DefaultCoreModelSampler implements ISampler { private FeatureModel lastFm; - private IFeatureModel featureIdeFm; private Set> samples; private Set> invalidSamples; @@ -110,8 +109,7 @@ private void toFeatureIdeFm(final FeatureModel fm, final IFeatureModel featureId format.read(featureIdeFm, fm.toString()); } - private Set> sample(final IFeatureModel fm) - throws NotSupportedVariabilityTypeException { + private Set> sample(final IFeatureModel fm) { List> configurations = findConfigurations(fm); Set> configurables = new HashSet<>(); for (final List fmSample : configurations) { @@ -143,13 +141,11 @@ public String getName() { return configurables; } - private List> findConfigurations(final IFeatureModel fm) throws NotSupportedVariabilityTypeException { + private List> findConfigurations(final IFeatureModel fm) { FeatureModelFormula formula = new FeatureModelFormula(fm); - List samples = LongRunningWrapper.runMethod(new TWiseConfigurationGenerator(formula.getCNF(), 3)); -// List samples = LongRunningWrapper -// .runMethod(new RandomConfigurationGenerator(formula.getCNF(), 1_000_000)); - List> configurations = new ArrayList<>(samples.size()); - for (LiteralSet sample : samples) { + List configs = LongRunningWrapper.runMethod(new TWiseConfigurationGenerator(formula.getCNF(), 3)); + List> configurations = new ArrayList<>(configs.size()); + for (LiteralSet sample : configs) { List names = formula.getCNF().getVariables().convertToString(sample); configurations.add(names); } @@ -157,8 +153,8 @@ private List> findConfigurations(final IFeatureModel fm) throws Not } private Set> sampleInvalid(final IFeatureModel fm, - final Set> samples) throws NotSupportedVariabilityTypeException { - Set> invalidSamples = new HashSet<>(); + final Set> samples) { + invalidSamples = new HashSet<>(); for (Map sample : samples) { for (int count = 0; count < INVALID_COUNT; count++) { int featureSwitch = rand.nextInt(sample.size()); @@ -191,7 +187,7 @@ private boolean verifySampleAsFeatureIde(final IFeatureModel fm, final Map