Skip to content

Commit 3589680

Browse files
committed
Simplify code in a few places (nits)
1 parent 0798afd commit 3589680

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/main/java/engineering/swat/watch/impl/mac/NativeEventStream.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.Closeable;
4343
import java.io.IOException;
4444
import java.nio.file.Path;
45+
import java.util.Arrays;
4546

4647
import org.checkerframework.checker.nullness.qual.Nullable;
4748

@@ -100,7 +101,7 @@ public NativeEventStream(Path path, NativeEventHandler handler) throws IOExcepti
100101

101102
public synchronized void open() {
102103
if (!closed) {
103-
throw new IllegalStateException("Stream is already open");
104+
return;
104105
} else {
105106
closed = false;
106107
}
@@ -158,9 +159,7 @@ private boolean any(int bits, int mask) {
158159
}
159160

160161
private Pointer createFSEventStream(FSEventStreamCallback callback) {
161-
try (
162-
var pathsToWatch = new Strings(path.toString());
163-
) {
162+
try (var pathsToWatch = new Strings(path.toString())) {
164163
var allocator = CF.CFAllocatorGetDefault();
165164
var context = Pointer.NULL;
166165
var sinceWhen = FSE.FSEventsGetCurrentEventId();
@@ -181,7 +180,7 @@ private Pointer createDispatchQueue() {
181180
@Override
182181
public synchronized void close() {
183182
if (closed) {
184-
throw new IllegalStateException("Stream is already closed");
183+
return;
185184
} else {
186185
closed = true;
187186
}
@@ -236,13 +235,9 @@ public CFArrayRef toCFArray() {
236235
}
237236

238237
private static CFStringRef[] createCFStrings(String[] pathsToWatch) {
239-
var n = pathsToWatch.length;
240-
241-
var strings = new CFStringRef[n];
242-
for (int i = 0; i < n; i++) {
243-
strings[i] = CFStringRef.createCFString(pathsToWatch[i]);
244-
}
245-
return strings;
238+
return Arrays.stream(pathsToWatch)
239+
.map(CFStringRef::createCFString)
240+
.toArray(CFStringRef[]::new);
246241
}
247242

248243
private static CFArrayRef createCFArray(CFStringRef[] strings) {

0 commit comments

Comments
 (0)