1717
1818import java .io .IOException ;
1919import java .io .InputStream ;
20+ import java .util .Objects ;
2021
2122import de .learnlib .examples .DefaultLearningExample .DefaultDFALearningExample ;
2223import de .learnlib .examples .LearningExample .DFALearningExample ;
@@ -34,38 +35,41 @@ private DFABenchmarks() {
3435 // prevent instantiation
3536 }
3637
37- public static @ Nullable DFALearningExample <Integer > loadPots2 () {
38- return loadLearnLibV2Benchmark ("pots2" );
39- }
40-
4138 public static @ Nullable DFALearningExample <Integer > loadLearnLibV2Benchmark (String name ) {
42- String resourceName = "/automata/learnlibv2/" + name + ".dfa.gz" ;
43- if (DFABenchmarks .class .getResource (resourceName ) == null ) {
44- return null ;
45- }
39+ final String resourceName = "/automata/learnlibv2/" + name + ".dfa.gz" ;
40+ final InputStream resourceStream = DFABenchmarks .class .getResourceAsStream (resourceName );
4641
47- try (InputStream is = DFABenchmarks .class .getResourceAsStream (resourceName )) {
48- if (is == null ) {
49- LOGGER .warn ("Couldn't load resource '{}'" , resourceName );
50- return null ;
42+ if (resourceStream == null ) {
43+ LOGGER .info ("Couldn't find resource '{}'" , resourceName );
44+ } else {
45+ try (InputStream is = resourceStream ) {
46+ CompactDFA <Integer > dfa = LearnLibV2Serialization .getInstance ().readGenericDFA (is );
47+ return new DefaultDFALearningExample <>(dfa );
48+ } catch (IOException ex ) {
49+ LOGGER .error ("Could not load benchmark" , ex );
5150 }
52- CompactDFA <Integer > dfa = LearnLibV2Serialization .getInstance ().readGenericDFA (is );
53- return new DefaultDFALearningExample <>(dfa );
54- } catch (IOException ex ) {
55- LOGGER .error ("Could not load benchmark" , ex );
56- return null ;
5751 }
52+
53+ return null ;
54+ }
55+
56+ public static DFALearningExample <Integer > loadPots2 () {
57+ return Objects .requireNonNull (loadLearnLibV2Benchmark ("pots2" ),
58+ "Couldn't find 'pots2'. Are the correct JARs loaded?" );
5859 }
5960
60- public static @ Nullable DFALearningExample <Integer > loadPots3 () {
61- return loadLearnLibV2Benchmark ("pots3" );
61+ public static DFALearningExample <Integer > loadPots3 () {
62+ return Objects .requireNonNull (loadLearnLibV2Benchmark ("pots3" ),
63+ "Couldn't find 'pots3'. Are the correct JARs loaded?" );
6264 }
6365
64- public static @ Nullable DFALearningExample <Integer > loadPeterson2 () {
65- return loadLearnLibV2Benchmark ("peterson2" );
66+ public static DFALearningExample <Integer > loadPeterson2 () {
67+ return Objects .requireNonNull (loadLearnLibV2Benchmark ("peterson2" ),
68+ "Couldn't find 'peterson2'. Are the correct JARs loaded?" );
6669 }
6770
68- public static @ Nullable DFALearningExample <Integer > loadPeterson3 () {
69- return loadLearnLibV2Benchmark ("peterson3" );
71+ public static DFALearningExample <Integer > loadPeterson3 () {
72+ return Objects .requireNonNull (loadLearnLibV2Benchmark ("peterson3" ),
73+ "Couldn't find 'peterson3'. Are the correct JARs loaded?" );
7074 }
7175}
0 commit comments