-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: add various ArrayUtil methods and use where applicable
...with the goal to increase readability and improve performance
- Loading branch information
Showing
13 changed files
with
207 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/ThrowingConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sebastian Thomschke and others. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sebastian Thomschke - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e.internal; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* @author <a href="https://sebthom.de/">Sebastian Thomschke</a> | ||
*/ | ||
@FunctionalInterface | ||
public interface ThrowingConsumer<I, X extends Throwable> extends Consumer<I> { | ||
|
||
static <T> ThrowingConsumer<T, RuntimeException> from(final Consumer<T> consumer) { | ||
return consumer::accept; | ||
} | ||
|
||
@Override | ||
default void accept(final I elem) { | ||
try { | ||
acceptOrThrow(elem); | ||
} catch (final RuntimeException rex) { | ||
throw rex; | ||
} catch (final Throwable t) { | ||
throw new RuntimeException(t); | ||
} | ||
} | ||
|
||
void acceptOrThrow(I elem) throws X; | ||
} |
35 changes: 35 additions & 0 deletions
35
org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/ThrowingPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sebastian Thomschke and others. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sebastian Thomschke - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lsp4e.internal; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@FunctionalInterface | ||
public interface ThrowingPredicate<I, X extends Throwable> extends Predicate<I> { | ||
|
||
static <T> ThrowingPredicate<T, RuntimeException> from(final Predicate<T> predicate) { | ||
return predicate::test; | ||
} | ||
|
||
@Override | ||
default boolean test(final I elem) { | ||
try { | ||
return testOrThrow(elem); | ||
} catch (final RuntimeException rex) { | ||
throw rex; | ||
} catch (final Throwable t) { | ||
throw new RuntimeException(t); | ||
} | ||
} | ||
|
||
boolean testOrThrow(I elem) throws X; | ||
} |
Oops, something went wrong.