MidiDeviceScanner.java

1
package com.github.dakusui.symfonion.utils.midi;
2
3
import java.io.PrintStream;
4
import java.util.LinkedList;
5
import java.util.List;
6
import java.util.regex.Matcher;
7
import java.util.regex.Pattern;
8
9
import javax.sound.midi.MidiDevice;
10
import javax.sound.midi.MidiSystem;
11
import javax.sound.midi.MidiDevice.Info;
12
13
public abstract class MidiDeviceScanner {
14
  static abstract class RegexMidiDeviceScanner extends MidiDeviceScanner {
15
16
    private final Pattern regex;
17
18
    public RegexMidiDeviceScanner(PrintStream ps, Pattern regex) {
19
      super(ps);
20
      this.regex = regex;
21
    }
22
23
    @Override
24
    protected void start(Info[] allDevices) {
25
      PrintStream ps = getPrintStream();
26 1 1. start : removed call to java/io/PrintStream::println → NO_COVERAGE
      ps.println("     " + getTitle());
27
      //ps.printf("  io %s%n", MidiUtils.formatMidiDeviceInfo(null));
28 1 1. start : removed call to java/io/PrintStream::println → NO_COVERAGE
      ps.println("--------------------------------------------------------------------------------");
29
    }
30
31
    protected abstract String getTitle();
32
33
    @Override
34
    protected boolean matches(Info device) {
35
      Matcher m = regex.matcher(device.getName());
36 2 1. matches : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner$RegexMidiDeviceScanner::matches → NO_COVERAGE
2. matches : replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner$RegexMidiDeviceScanner::matches → NO_COVERAGE
      return m.find();
37
    }
38
39
    @Override
40
    protected void matched(Info device) {
41 1 1. matched : negated conditional → NO_COVERAGE
      String i = MidiUtils.isMidiDeviceForInput(device) ? "I" : " ";
42 1 1. matched : negated conditional → NO_COVERAGE
      String o = MidiUtils.isMidiDeviceForOutput(device) ? "O" : " ";
43
      getPrintStream().printf("* %1s%1s %s%n", i, o, MidiUtils.formatMidiDeviceInfo(device));
44
    }
45
46
    @Override
47
    protected void scanned(Info device) {
48
    }
49
50
    @Override
51
    protected void end(Info[] matchedDevices) {
52
    }
53
54
    @Override
55
    protected void didntMatch(Info device) {
56 1 1. didntMatch : negated conditional → NO_COVERAGE
      String i = MidiUtils.isMidiDeviceForInput(device) ? "I" : " ";
57 1 1. didntMatch : negated conditional → NO_COVERAGE
      String o = MidiUtils.isMidiDeviceForOutput(device) ? "O" : " ";
58
      getPrintStream().printf("  %1s%1s %s%n", i, o, MidiUtils.formatMidiDeviceInfo(device));
59
    }
60
  }
61
62
  private final PrintStream ps;
63
  private MidiDevice.Info[] matchedDevices = null;
64
  protected abstract void start(MidiDevice.Info[] allDevices);
65
66
  protected abstract boolean matches(MidiDevice.Info device);
67
68
  protected abstract void matched(MidiDevice.Info device);
69
70
  protected abstract void scanned(Info device);
71
72
  protected abstract void end(MidiDevice.Info[] matchedDevices);
73
74
  public MidiDeviceScanner(PrintStream ps) {
75
    this.ps = ps;
76
  }
77
78
  public void scan() {
79
    List<MidiDevice.Info> matched = new LinkedList<>();
80
    MidiDevice.Info[] allDevices = MidiSystem.getMidiDeviceInfo();
81
82 1 1. scan : removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::start → NO_COVERAGE
    start(allDevices);
83
    for (MidiDevice.Info cur : allDevices) {
84 1 1. scan : negated conditional → NO_COVERAGE
      if (matches(cur)) {
85 1 1. scan : removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::matched → NO_COVERAGE
        matched(cur);
86
        matched.add(cur);
87
      } else {
88 1 1. scan : removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::didntMatch → NO_COVERAGE
        didntMatch(cur);
89
      }
90 1 1. scan : removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::scanned → NO_COVERAGE
      scanned(cur);
91
    }
92 1 1. scan : removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::end → NO_COVERAGE
    end(matchedDevices = matched.toArray(new MidiDevice.Info[0]));
93
  }
94
95
96
  protected abstract void didntMatch(MidiDevice.Info info);
97
98
  public PrintStream getPrintStream() {
99 1 1. getPrintStream : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::getPrintStream → NO_COVERAGE
    return this.ps;
100
  }
101
102
103
  public MidiDevice.Info[] getMatchedDevices() {
104 1 1. getMatchedDevices : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::getMatchedDevices → NO_COVERAGE
    return this.matchedDevices;
105
  }
106
}

Mutations

26

1.1
Location : start
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

28

1.1
Location : start
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

36

1.1
Location : matches
Killed by : none
replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner$RegexMidiDeviceScanner::matches → NO_COVERAGE

2.2
Location : matches
Killed by : none
replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner$RegexMidiDeviceScanner::matches → NO_COVERAGE

41

1.1
Location : matched
Killed by : none
negated conditional → NO_COVERAGE

42

1.1
Location : matched
Killed by : none
negated conditional → NO_COVERAGE

56

1.1
Location : didntMatch
Killed by : none
negated conditional → NO_COVERAGE

57

1.1
Location : didntMatch
Killed by : none
negated conditional → NO_COVERAGE

82

1.1
Location : scan
Killed by : none
removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::start → NO_COVERAGE

84

1.1
Location : scan
Killed by : none
negated conditional → NO_COVERAGE

85

1.1
Location : scan
Killed by : none
removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::matched → NO_COVERAGE

88

1.1
Location : scan
Killed by : none
removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::didntMatch → NO_COVERAGE

90

1.1
Location : scan
Killed by : none
removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::scanned → NO_COVERAGE

92

1.1
Location : scan
Killed by : none
removed call to com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::end → NO_COVERAGE

99

1.1
Location : getPrintStream
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::getPrintStream → NO_COVERAGE

104

1.1
Location : getMatchedDevices
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceScanner::getMatchedDevices → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.15.3