Formatted source, added/updated copyright headers
- Also added formatting settings for Eclipse IDE
This commit is contained in:
parent
8f3009300f
commit
c2d91726a7
@ -1,5 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Progressia
|
||||||
|
# Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
echoerr() { echo "$@" 1>&2; }
|
echoerr() { echo "$@" 1>&2; }
|
||||||
|
|
||||||
buildDebianPackage() {
|
buildDebianPackage() {
|
||||||
|
@ -100,6 +100,18 @@ Alternatively, specify another location outside of the project's root directory.
|
|||||||
Step 5 is required to specify that the game must run in some directory other than the project root,
|
Step 5 is required to specify that the game must run in some directory other than the project root,
|
||||||
which is the default in Eclipse.
|
which is the default in Eclipse.
|
||||||
|
|
||||||
|
### Applying formatting templates
|
||||||
|
|
||||||
|
Windcorp's Progressia repository is formatted with a style defined for Eclipse IDE in
|
||||||
|
`templates_and_presets/eclipse_ide`.
|
||||||
|
Please apply these templates to the project to automatically format the source in a similar fashion.
|
||||||
|
|
||||||
|
1. In project context menu, click 'Properties'.
|
||||||
|
2. In 'Java Code Style' > 'Code Templates', check 'Enable project specific settings', then click 'Import' and select
|
||||||
|
`templates_and_presets/eclipse_ide/CodeTemplates.xml`.
|
||||||
|
3. In 'Java Code Style' > 'Formatter', check 'Enable project specific settings', then click 'Import' and select
|
||||||
|
`templates_and_presets/eclipse_ide/FormatterProfile.xml`.
|
||||||
|
|
||||||
## Common problems
|
## Common problems
|
||||||
|
|
||||||
### Buildship plugin fails with a cryptic message
|
### Buildship plugin fails with a cryptic message
|
||||||
|
@ -3,9 +3,11 @@ package kdotjpg.opensimplex2.areagen;
|
|||||||
* This file has been modified in the following ways:
|
* This file has been modified in the following ways:
|
||||||
* - added a package declaration at line 1;
|
* - added a package declaration at line 1;
|
||||||
* - added missing @Override annotations;
|
* - added missing @Override annotations;
|
||||||
* - commented out line 965 due to unused variables.
|
* - commented out line 967 due to unused variables.
|
||||||
* The original version of this file can be found at
|
* The original version of this file can be found at
|
||||||
* https://raw.githubusercontent.com/KdotJPG/OpenSimplex2/master/java/areagen/OpenSimplex2S.java
|
* https://raw.githubusercontent.com/KdotJPG/OpenSimplex2/master/java/areagen/OpenSimplex2S.java
|
||||||
|
*
|
||||||
|
* @formatter:off
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -983,16 +985,3 @@ public class OpenSimplex2S {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
@ -23,7 +24,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class ArrayUtil {
|
public class ArrayUtil {
|
||||||
|
|
||||||
private ArrayUtil() {}
|
private ArrayUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static int firstIndexOf(byte[] array, byte element) {
|
public static int firstIndexOf(byte[] array, byte element) {
|
||||||
for (int i = 0; i < array.length; ++i) {
|
for (int i = 0; i < array.length; ++i) {
|
||||||
@ -68,7 +70,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(byte[] array, boolean ascending) {
|
public static boolean isSorted(byte[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -121,7 +124,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(short[] array, boolean ascending) {
|
public static boolean isSorted(short[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -174,7 +178,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(int[] array, boolean ascending) {
|
public static boolean isSorted(int[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -227,7 +232,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(long[] array, boolean ascending) {
|
public static boolean isSorted(long[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -280,7 +286,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(float[] array, boolean ascending) {
|
public static boolean isSorted(float[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -333,7 +340,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(double[] array, boolean ascending) {
|
public static boolean isSorted(double[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -414,7 +422,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static boolean isSorted(char[] array, boolean ascending) {
|
public static boolean isSorted(char[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((array[i] < array[i + 1]) != ascending) {
|
if ((array[i] < array[i + 1]) != ascending) {
|
||||||
return false;
|
return false;
|
||||||
@ -508,7 +517,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
public static <T extends Comparable<T>> boolean isSorted(T[] array, boolean ascending) {
|
public static <T extends Comparable<T>> boolean isSorted(T[] array, boolean ascending) {
|
||||||
for (int i = 0; i < array.length - 1; ++i) {
|
for (int i = 0; i < array.length - 1; ++i) {
|
||||||
if (array[i] == array[i + 1]) continue;
|
if (array[i] == array[i + 1])
|
||||||
|
continue;
|
||||||
|
|
||||||
int order = array[i].compareTo(array[i + 1]);
|
int order = array[i].compareTo(array[i + 1]);
|
||||||
|
|
||||||
@ -600,7 +610,9 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > arrayLength || offset < 0)
|
if (end > arrayLength || offset < 0)
|
||||||
throw new IllegalArgumentException("Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
|
throw new IllegalArgumentException(
|
||||||
|
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -615,7 +627,9 @@ public class ArrayUtil {
|
|||||||
throw new IllegalArgumentException("Start > end: " + start + " > " + end);
|
throw new IllegalArgumentException("Start > end: " + start + " > " + end);
|
||||||
|
|
||||||
if (end > arrayLength || start < 0)
|
if (end > arrayLength || start < 0)
|
||||||
throw new IllegalArgumentException("Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
|
throw new IllegalArgumentException(
|
||||||
|
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -22,16 +23,25 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class PrimitiveUtil {
|
public class PrimitiveUtil {
|
||||||
|
|
||||||
private PrimitiveUtil() {}
|
private PrimitiveUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED = new HashMap<>();
|
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED = new HashMap<>();
|
||||||
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Class<?> boxed : new Class<?>[] {
|
for (
|
||||||
Boolean.class, Byte.class, Short.class, Character.class,
|
Class<?> boxed : new Class<?>[] {
|
||||||
Integer.class, Long.class, Float.class, Double.class
|
Boolean.class,
|
||||||
}) {
|
Byte.class,
|
||||||
|
Short.class,
|
||||||
|
Character.class,
|
||||||
|
Integer.class,
|
||||||
|
Long.class,
|
||||||
|
Float.class,
|
||||||
|
Double.class
|
||||||
|
}
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -11,7 +11,11 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
@ -35,10 +39,14 @@ import java.util.stream.LongStream;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains static methods to create {@link Stream Streams} that synchronize their
|
* Contains static methods to create {@link Stream Streams} that synchronize
|
||||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* their
|
||||||
|
* <a href=
|
||||||
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> on a given monitor.
|
* terminal operations</a> on a given monitor.
|
||||||
* @author Javapony (<a href="mailto:kvadropups@gmail.com">kvadropups@gmail.com</a>)
|
*
|
||||||
|
* @author Javapony
|
||||||
|
* (<a href="mailto:kvadropups@gmail.com">kvadropups@gmail.com</a>)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// SonarLint: "Stream.peek" should be used with caution (java:S3864)
|
// SonarLint: "Stream.peek" should be used with caution (java:S3864)
|
||||||
@ -1063,20 +1071,30 @@ public class SyncStreams {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link Stream} to make all
|
* Wraps the given {@link Stream} to make all
|
||||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* <a href=
|
||||||
* terminal operations</a> acquire the provided monitor's lock before execution. Intermediate operations
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* return streams that are also synchronized on the same object. The created stream will behave identically
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* to the provided stream in all other aspects. Use this to synchronize access to stream's source.
|
* execution. Intermediate operations
|
||||||
* <p><i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and {@link Stream#spliterator()
|
* return streams that are also synchronized on the same object. The created
|
||||||
* spliterator()} methods return regular non-synchronized iterators and spliterators respectively</i>. It
|
* stream will behave identically
|
||||||
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
|
* <p>
|
||||||
|
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
||||||
|
* {@link Stream#spliterator()
|
||||||
|
* spliterator()} methods return regular non-synchronized iterators and
|
||||||
|
* spliterators respectively</i>. It
|
||||||
* is the user's responsibility to avoid concurrency issues:
|
* is the user's responsibility to avoid concurrency issues:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
* Iterator<T> it = stream.iterator();
|
* Iterator<T> it = stream.iterator();
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Usage example:
|
* Usage example:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||||
* ...
|
* ...
|
||||||
@ -1087,9 +1105,11 @@ public class SyncStreams {
|
|||||||
*
|
*
|
||||||
* @param <T> the class of objects in the Stream
|
* @param <T> the class of objects in the Stream
|
||||||
* @param stream the stream to wrap.
|
* @param stream the stream to wrap.
|
||||||
* @param monitor the object that the stream will use for synchronization. When {@code null}, the stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
|
* When {@code null}, the stream
|
||||||
* will synchronize on itself.
|
* will synchronize on itself.
|
||||||
* @return a {@link SyncStream SyncStream<T>} synchronized on {@code monitor} and backed by {@code stream}.
|
* @return a {@link SyncStream SyncStream<T>} synchronized on
|
||||||
|
* {@code monitor} and backed by {@code stream}.
|
||||||
* @throws NullPointerException if {@code stream == null}.
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
*/
|
*/
|
||||||
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
||||||
@ -1099,20 +1119,31 @@ public class SyncStreams {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link IntStream} to make all
|
* Wraps the given {@link IntStream} to make all
|
||||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* <a href=
|
||||||
* terminal operations</a> acquire the provided monitor's lock before execution. Intermediate operations
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* return streams that are also synchronized on the same object. The created stream will behave identically
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* to the provided stream in all other aspects. Use this to synchronize access to stream's source.
|
* execution. Intermediate operations
|
||||||
* <p><i>The returned {@code IntStream}'s {@link IntStream#iterator() iterator()} and
|
* return streams that are also synchronized on the same object. The created
|
||||||
* {@link IntStream#spliterator() spliterator()} methods return regular non-synchronized iterators and
|
* stream will behave identically
|
||||||
* spliterators respectively</i>. It is the user's responsibility to avoid concurrency issues:
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
|
* <p>
|
||||||
|
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
||||||
|
* iterator()} and
|
||||||
|
* {@link IntStream#spliterator() spliterator()} methods return regular
|
||||||
|
* non-synchronized iterators and
|
||||||
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
* PrimitiveIterator.OfInt it = stream.iterator();
|
* PrimitiveIterator.OfInt it = stream.iterator();
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Usage example:
|
* Usage example:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||||
* ...
|
* ...
|
||||||
@ -1122,9 +1153,11 @@ public class SyncStreams {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream the stream to wrap.
|
* @param stream the stream to wrap.
|
||||||
* @param monitor the object that the stream will use for synchronization. When {@code null}, the stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
|
* When {@code null}, the stream
|
||||||
* will synchronize on itself.
|
* will synchronize on itself.
|
||||||
* @return a {@link SyncIntStream} synchronized on {@code monitor} and backed by {@code stream}.
|
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
||||||
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException if {@code stream == null}.
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
*/
|
*/
|
||||||
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
||||||
@ -1134,20 +1167,31 @@ public class SyncStreams {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link LongStream} to make all
|
* Wraps the given {@link LongStream} to make all
|
||||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* <a href=
|
||||||
* terminal operations</a> acquire the provided monitor's lock before execution. Intermediate operations
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* return streams that are also synchronized on the same object. The created stream will behave identically
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* to the provided stream in all other aspects. Use this to synchronize access to stream's source.
|
* execution. Intermediate operations
|
||||||
* <p><i>The returned {@code LongStream}'s {@link LongStream#iterator() iterator()} and
|
* return streams that are also synchronized on the same object. The created
|
||||||
* {@link LongStream#spliterator() spliterator()} methods return regular non-synchronized iterators and
|
* stream will behave identically
|
||||||
* spliterators respectively</i>. It is the user's responsibility to avoid concurrency issues:
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
|
* <p>
|
||||||
|
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
||||||
|
* iterator()} and
|
||||||
|
* {@link LongStream#spliterator() spliterator()} methods return regular
|
||||||
|
* non-synchronized iterators and
|
||||||
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
* PrimitiveIterator.OfLong it = stream.iterator();
|
* PrimitiveIterator.OfLong it = stream.iterator();
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Usage example:
|
* Usage example:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||||
* ...
|
* ...
|
||||||
@ -1157,9 +1201,11 @@ public class SyncStreams {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream the stream to wrap.
|
* @param stream the stream to wrap.
|
||||||
* @param monitor the object that the stream will use for synchronization. When {@code null}, the stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
|
* When {@code null}, the stream
|
||||||
* will synchronize on itself.
|
* will synchronize on itself.
|
||||||
* @return a {@link SyncLongStream} synchronized on {@code monitor} and backed by {@code stream}.
|
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
||||||
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException if {@code stream == null}.
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
*/
|
*/
|
||||||
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
||||||
@ -1169,20 +1215,31 @@ public class SyncStreams {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link DoubleStream} to make all
|
* Wraps the given {@link DoubleStream} to make all
|
||||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* <a href=
|
||||||
* terminal operations</a> acquire the provided monitor's lock before execution. Intermediate operations
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* return streams that are also synchronized on the same object. The created stream will behave identically
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* to the provided stream in all other aspects. Use this to synchronize access to stream's source.
|
* execution. Intermediate operations
|
||||||
* <p><i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator() iterator()} and
|
* return streams that are also synchronized on the same object. The created
|
||||||
* {@link DoubleStream#spliterator() spliterator()} methods return regular non-synchronized iterators and
|
* stream will behave identically
|
||||||
* spliterators respectively</i>. It is the user's responsibility to avoid concurrency issues:
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
|
* <p>
|
||||||
|
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
||||||
|
* iterator()} and
|
||||||
|
* {@link DoubleStream#spliterator() spliterator()} methods return regular
|
||||||
|
* non-synchronized iterators and
|
||||||
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
* PrimitiveIterator.OfDouble it = stream.iterator();
|
* PrimitiveIterator.OfDouble it = stream.iterator();
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Usage example:
|
* Usage example:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||||
* ...
|
* ...
|
||||||
@ -1192,9 +1249,11 @@ public class SyncStreams {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream the stream to wrap.
|
* @param stream the stream to wrap.
|
||||||
* @param monitor the object that the stream will use for synchronization. When {@code null}, the stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
|
* When {@code null}, the stream
|
||||||
* will synchronize on itself.
|
* will synchronize on itself.
|
||||||
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and backed by {@code stream}.
|
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
||||||
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException if {@code stream == null}.
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
*/
|
*/
|
||||||
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
||||||
@ -1205,6 +1264,7 @@ public class SyncStreams {
|
|||||||
/*
|
/*
|
||||||
* Private constructor
|
* Private constructor
|
||||||
*/
|
*/
|
||||||
private SyncStreams() {}
|
private SyncStreams() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
public class SyntaxException extends Exception {
|
public class SyntaxException extends Exception {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -110,9 +111,12 @@ public class CharArrayIterator implements CharacterIterator {
|
|||||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||||
|
|
||||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required exception safety.
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
// SonarLint: "toString()" and "clone()" methods should not return null (java:S2225)
|
// exception safety.
|
||||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable and superclass is Object.
|
// SonarLint: "toString()" and "clone()" methods should not return null
|
||||||
|
// (java:S2225)
|
||||||
|
// The clause is unreachable: CharacterArrayIterator implements Cloneable
|
||||||
|
// and superclass is Object.
|
||||||
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -23,11 +24,11 @@ import ru.windcorp.jputil.ArrayUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CharConsumers {
|
public class CharConsumers {
|
||||||
|
|
||||||
private CharConsumers() {}
|
private CharConsumers() {
|
||||||
|
}
|
||||||
|
|
||||||
public static CharConsumer fillArray(char[] array, int offset, int length) {
|
public static CharConsumer fillArray(char[] array, int offset, int length) {
|
||||||
return new ArrayFiller(array, offset, length);
|
return new ArrayFiller(array, offset, length);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.function.IntSupplier;
|
import java.util.function.IntSupplier;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class EscapeException extends Exception {
|
public class EscapeException extends Exception {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -102,7 +103,14 @@ public class Escaper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(), true, true);
|
public static final Escaper JAVA = new Escaper(
|
||||||
|
'\\',
|
||||||
|
'u',
|
||||||
|
"tbnrf'\"".toCharArray(),
|
||||||
|
"\t\b\n\r\f\'\"".toCharArray(),
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
private final char escapeChar;
|
private final char escapeChar;
|
||||||
private final char unicodeEscapeChar;
|
private final char unicodeEscapeChar;
|
||||||
@ -113,9 +121,13 @@ public class Escaper {
|
|||||||
private final boolean strict;
|
private final boolean strict;
|
||||||
|
|
||||||
protected Escaper(
|
protected Escaper(
|
||||||
char escapeChar, char unicodeEscapeChar,
|
char escapeChar,
|
||||||
char[] safes, char[] unsafes,
|
char unicodeEscapeChar,
|
||||||
boolean preferUnicode, boolean strict) {
|
char[] safes,
|
||||||
|
char[] unsafes,
|
||||||
|
boolean preferUnicode,
|
||||||
|
boolean strict
|
||||||
|
) {
|
||||||
this.escapeChar = escapeChar;
|
this.escapeChar = escapeChar;
|
||||||
this.unicodeEscapeChar = unicodeEscapeChar;
|
this.unicodeEscapeChar = unicodeEscapeChar;
|
||||||
this.safes = safes;
|
this.safes = safes;
|
||||||
@ -131,13 +143,19 @@ public class Escaper {
|
|||||||
throw new IllegalArgumentException("Duplicate unsafe character '" + unsafes[duplicate] + "'");
|
throw new IllegalArgumentException("Duplicate unsafe character '" + unsafes[duplicate] + "'");
|
||||||
|
|
||||||
for (char c : safes) {
|
for (char c : safes) {
|
||||||
if (c == escapeChar) throw new IllegalArgumentException("Safe characters contain escape chatacter");
|
if (c == escapeChar)
|
||||||
if (c == unicodeEscapeChar) throw new IllegalArgumentException("Safe characters contain Unicode escape chatacter");
|
throw new IllegalArgumentException("Safe characters contain escape chatacter");
|
||||||
|
if (c == unicodeEscapeChar)
|
||||||
|
throw new IllegalArgumentException("Safe characters contain Unicode escape chatacter");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (char c : unsafes) {
|
for (char c : unsafes) {
|
||||||
if (c == escapeChar) throw new IllegalArgumentException("Unsafe characters contain escape chatacter (escape character is escaped automatically)");
|
if (c == escapeChar)
|
||||||
if (c == unicodeEscapeChar) throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
throw new IllegalArgumentException(
|
||||||
|
"Unsafe characters contain escape chatacter (escape character is escaped automatically)"
|
||||||
|
);
|
||||||
|
if (c == unicodeEscapeChar)
|
||||||
|
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,11 +169,15 @@ public class Escaper {
|
|||||||
|
|
||||||
public void escape(CharReader src, int length, CharPredicate until, CharConsumer output) {
|
public void escape(CharReader src, int length, CharPredicate until, CharConsumer output) {
|
||||||
int end;
|
int end;
|
||||||
if (length < 0) end = Integer.MAX_VALUE;
|
if (length < 0)
|
||||||
else end = src.getPosition() + length;
|
end = Integer.MAX_VALUE;
|
||||||
while (src.has() &&
|
else
|
||||||
|
end = src.getPosition() + length;
|
||||||
|
while (
|
||||||
|
src.has() &&
|
||||||
src.getPosition() < end &&
|
src.getPosition() < end &&
|
||||||
(until == null || !until.test(src.current())))
|
(until == null || !until.test(src.current()))
|
||||||
|
)
|
||||||
escape(src.consume(), output);
|
escape(src.consume(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +202,8 @@ public class Escaper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SonarLint: Assignments should not be made from within sub-expressions (java:S1121)
|
// SonarLint: Assignments should not be made from within sub-expressions
|
||||||
|
// (java:S1121)
|
||||||
// Seems self-evident enough
|
// Seems self-evident enough
|
||||||
@SuppressWarnings("squid:S1121")
|
@SuppressWarnings("squid:S1121")
|
||||||
|
|
||||||
@ -195,14 +218,18 @@ public class Escaper {
|
|||||||
|
|
||||||
public int getEscapedLength(CharReader src, int length, CharPredicate until) {
|
public int getEscapedLength(CharReader src, int length, CharPredicate until) {
|
||||||
int end;
|
int end;
|
||||||
if (length < 0) end = Integer.MAX_VALUE;
|
if (length < 0)
|
||||||
else end = src.getPosition() + length;
|
end = Integer.MAX_VALUE;
|
||||||
|
else
|
||||||
|
end = src.getPosition() + length;
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
while (src.has() &&
|
while (
|
||||||
|
src.has() &&
|
||||||
src.getPosition() < end &&
|
src.getPosition() < end &&
|
||||||
(until == null || !until.test(src.current()))) {
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
result += getEscapedLength(src.consume());
|
result += getEscapedLength(src.consume());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,11 +253,15 @@ public class Escaper {
|
|||||||
|
|
||||||
public void unescape(CharReader src, int length, CharPredicate until, CharConsumer output) throws EscapeException {
|
public void unescape(CharReader src, int length, CharPredicate until, CharConsumer output) throws EscapeException {
|
||||||
int end;
|
int end;
|
||||||
if (length < 0) end = Integer.MAX_VALUE;
|
if (length < 0)
|
||||||
else end = src.getPosition() + length;
|
end = Integer.MAX_VALUE;
|
||||||
while (src.has() &&
|
else
|
||||||
|
end = src.getPosition() + length;
|
||||||
|
while (
|
||||||
|
src.has() &&
|
||||||
src.getPosition() < end &&
|
src.getPosition() < end &&
|
||||||
(until == null || !until.test(src.current()))) {
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
output.accept(unescapeOneSequence(src));
|
output.accept(unescapeOneSequence(src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,12 +282,10 @@ public class Escaper {
|
|||||||
|
|
||||||
if (src.current() == unicodeEscapeChar) {
|
if (src.current() == unicodeEscapeChar) {
|
||||||
src.next();
|
src.next();
|
||||||
return (char) (
|
return (char) (hexValue(src.consume()) << (4 * 3) |
|
||||||
hexValue(src.consume()) << (4 * 3) |
|
|
||||||
hexValue(src.consume()) << (4 * 2) |
|
hexValue(src.consume()) << (4 * 2) |
|
||||||
hexValue(src.consume()) << (4 * 1) |
|
hexValue(src.consume()) << (4 * 1) |
|
||||||
hexValue(src.consume()) << (4 * 0)
|
hexValue(src.consume()) << (4 * 0));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
||||||
@ -279,14 +308,18 @@ public class Escaper {
|
|||||||
|
|
||||||
public int getUnescapedLength(CharReader src, int length, CharPredicate until) {
|
public int getUnescapedLength(CharReader src, int length, CharPredicate until) {
|
||||||
int end;
|
int end;
|
||||||
if (length < 0) end = Integer.MAX_VALUE;
|
if (length < 0)
|
||||||
else end = src.getPosition() + length;
|
end = Integer.MAX_VALUE;
|
||||||
|
else
|
||||||
|
end = src.getPosition() + length;
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
while (src.has() &&
|
while (
|
||||||
|
src.has() &&
|
||||||
src.getPosition() < end &&
|
src.getPosition() < end &&
|
||||||
(until == null || !until.test(src.current()))) {
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
skipOneSequence(src);
|
skipOneSequence(src);
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
@ -425,13 +458,20 @@ public class Escaper {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private static int hexValue(char c) throws EscapeException {
|
private static int hexValue(char c) throws EscapeException {
|
||||||
if (c < '0') throw thisIsNotAHexDigit(c);
|
if (c < '0')
|
||||||
if (c <= '9') return c - '0';
|
throw thisIsNotAHexDigit(c);
|
||||||
if (c < 'A') throw thisIsNotAHexDigit(c);
|
if (c <= '9')
|
||||||
if (c <= 'F') return c - 'A';
|
return c - '0';
|
||||||
if (c < 'a') throw thisIsNotAHexDigit(c);
|
if (c < 'A')
|
||||||
if (c <= 'f') return c - 'a';
|
throw thisIsNotAHexDigit(c);
|
||||||
if (c == CharReader.DONE) throw new EscapeException("Incomplete Unicode escape sequence at the end");
|
if (c <= 'F')
|
||||||
|
return c - 'A';
|
||||||
|
if (c < 'a')
|
||||||
|
throw thisIsNotAHexDigit(c);
|
||||||
|
if (c <= 'f')
|
||||||
|
return c - 'a';
|
||||||
|
if (c == CharReader.DONE)
|
||||||
|
throw new EscapeException("Incomplete Unicode escape sequence at the end");
|
||||||
throw thisIsNotAHexDigit(c);
|
throw thisIsNotAHexDigit(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -11,7 +11,11 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -76,7 +80,8 @@ public class FancyCharacterIterator implements CharacterIterator {
|
|||||||
StringBuilder sb = new StringBuilder("\"");
|
StringBuilder sb = new StringBuilder("\"");
|
||||||
sb.append(data);
|
sb.append(data);
|
||||||
sb.append("\"\n ");
|
sb.append("\"\n ");
|
||||||
for (int i = 0; i < obj.getIndex(); ++i) sb.append(' ');
|
for (int i = 0; i < obj.getIndex(); ++i)
|
||||||
|
sb.append(' ');
|
||||||
sb.append("^ Here.");
|
sb.append("^ Here.");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@ -84,9 +89,12 @@ public class FancyCharacterIterator implements CharacterIterator {
|
|||||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||||
|
|
||||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required exception safety.
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
// SonarLint: "toString()" and "clone()" methods should not return null (java:S2225)
|
// exception safety.
|
||||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable and superclass is Object.
|
// SonarLint: "toString()" and "clone()" methods should not return null
|
||||||
|
// (java:S2225)
|
||||||
|
// The clause is unreachable: CharacterArrayIterator implements Cloneable
|
||||||
|
// and superclass is Object.
|
||||||
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class IndentedStringBuilder {
|
public class IndentedStringBuilder {
|
||||||
@ -65,7 +66,8 @@ public class IndentedStringBuilder {
|
|||||||
protected void updateIndent() {
|
protected void updateIndent() {
|
||||||
if (indentLevel < indentCache.length) {
|
if (indentLevel < indentCache.length) {
|
||||||
indent = indentCache[indentLevel];
|
indent = indentCache[indentLevel];
|
||||||
if (indent != null) return;
|
if (indent != null)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] fill = getIndentFill();
|
char[] fill = getIndentFill();
|
||||||
@ -115,7 +117,8 @@ public class IndentedStringBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IndentedStringBuilder appendRaw(String str) {
|
public IndentedStringBuilder appendRaw(String str) {
|
||||||
if (str.isEmpty()) return this; // Do not append indent
|
if (str.isEmpty())
|
||||||
|
return this; // Do not append indent
|
||||||
|
|
||||||
if (!indentApplied) {
|
if (!indentApplied) {
|
||||||
sb.append(indent);
|
sb.append(indent);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -33,7 +34,8 @@ import ru.windcorp.jputil.ArrayUtil;
|
|||||||
|
|
||||||
public class StringUtil {
|
public class StringUtil {
|
||||||
|
|
||||||
private StringUtil() {}
|
private StringUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final String NULL_PLACEHOLDER = "[null]";
|
private static final String NULL_PLACEHOLDER = "[null]";
|
||||||
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
||||||
@ -153,9 +155,12 @@ public class StringUtil {
|
|||||||
String nullSupplier
|
String nullSupplier
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (separator == null) throw new IllegalArgumentException(new NullPointerException());
|
if (separator == null)
|
||||||
if (supplier == null) return nullSupplier;
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
if (length == 0) return empty;
|
if (supplier == null)
|
||||||
|
return nullSupplier;
|
||||||
|
if (length == 0)
|
||||||
|
return empty;
|
||||||
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
return supplierToStringExactly(
|
return supplierToStringExactly(
|
||||||
@ -258,9 +263,12 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String[] split(String src, char separator, int arrayLength) {
|
public static String[] split(String src, char separator, int arrayLength) {
|
||||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
if (arrayLength < 0)
|
||||||
else if (arrayLength == 0) return new String[0];
|
throw illegalArrayLength(arrayLength);
|
||||||
else if (arrayLength == 1) return new String[] { src };
|
else if (arrayLength == 0)
|
||||||
|
return new String[0];
|
||||||
|
else if (arrayLength == 1)
|
||||||
|
return new String[] { src };
|
||||||
|
|
||||||
String[] result = new String[arrayLength];
|
String[] result = new String[arrayLength];
|
||||||
|
|
||||||
@ -299,17 +307,19 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String[] split(String src, int arrayLength, char... separator) {
|
public static String[] split(String src, int arrayLength, char... separator) {
|
||||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
if (arrayLength < 0)
|
||||||
else if (arrayLength == 0) return new String[0];
|
throw illegalArrayLength(arrayLength);
|
||||||
else if (arrayLength == 1) return new String[] { src };
|
else if (arrayLength == 0)
|
||||||
|
return new String[0];
|
||||||
|
else if (arrayLength == 1)
|
||||||
|
return new String[] { src };
|
||||||
|
|
||||||
String[] result = new String[arrayLength];
|
String[] result = new String[arrayLength];
|
||||||
|
|
||||||
int resultIndex = 0;
|
int resultIndex = 0;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
charLoop:
|
charLoop: for (char c : src.toCharArray()) {
|
||||||
for (char c : src.toCharArray()) {
|
|
||||||
if ((resultIndex + 1) < arrayLength) {
|
if ((resultIndex + 1) < arrayLength) {
|
||||||
for (char h : separator) {
|
for (char h : separator) {
|
||||||
if (c == h) {
|
if (c == h) {
|
||||||
@ -331,7 +341,8 @@ public class StringUtil {
|
|||||||
public static int count(String src, CharPredicate test) {
|
public static int count(String src, CharPredicate test) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (char c : src.toCharArray()) {
|
for (char c : src.toCharArray()) {
|
||||||
if (test.test(c)) i++;
|
if (test.test(c))
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
@ -342,17 +353,19 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String[] split(String src, int arrayLength, CharPredicate test) {
|
public static String[] split(String src, int arrayLength, CharPredicate test) {
|
||||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
if (arrayLength < 0)
|
||||||
else if (arrayLength == 0) return new String[0];
|
throw illegalArrayLength(arrayLength);
|
||||||
else if (arrayLength == 1) return new String[] { src };
|
else if (arrayLength == 0)
|
||||||
|
return new String[0];
|
||||||
|
else if (arrayLength == 1)
|
||||||
|
return new String[] { src };
|
||||||
|
|
||||||
String[] result = new String[arrayLength];
|
String[] result = new String[arrayLength];
|
||||||
|
|
||||||
int resultIndex = 0;
|
int resultIndex = 0;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
charLoop:
|
charLoop: for (char c : src.toCharArray()) {
|
||||||
for (char c : src.toCharArray()) {
|
|
||||||
if (
|
if (
|
||||||
(resultIndex + 1) < arrayLength
|
(resultIndex + 1) < arrayLength
|
||||||
&&
|
&&
|
||||||
@ -372,15 +385,20 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits {@code src} at index {@code at} discarding the character at that index.
|
* Splits {@code src} at index {@code at} discarding the character at that
|
||||||
|
* index.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str} excluding
|
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
||||||
|
* excluding
|
||||||
* the specified character and {@code ""}.
|
* the specified character and {@code ""}.
|
||||||
* <p>
|
* <p>
|
||||||
|
*
|
||||||
* @param src the String to split
|
* @param src the String to split
|
||||||
* @param at index to split at
|
* @param at index to split at
|
||||||
* @throws IllegalArgumentException if the index is out of bounds for {@code src}
|
* @throws IllegalArgumentException if the index is out of bounds for
|
||||||
* @return an array containing the substrings, in order of encounter in {@code src}.
|
* {@code src}
|
||||||
|
* @return an array containing the substrings, in order of encounter in
|
||||||
|
* {@code src}.
|
||||||
* Its length is always 2.
|
* Its length is always 2.
|
||||||
*/
|
*/
|
||||||
public static String[] splitAt(String src, int at) {
|
public static String[] splitAt(String src, int at) {
|
||||||
@ -405,30 +423,38 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits {@code src} at indices {@code at} discarding characters at those indices.
|
* Splits {@code src} at indices {@code at} discarding characters at those
|
||||||
|
* indices.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length outputs.
|
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
|
||||||
|
* outputs.
|
||||||
* Duplicate indices produce extra zero-length outputs.
|
* Duplicate indices produce extra zero-length outputs.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* splitAt("a.b.c", new int[] {1, 3}) -> {"a", "b", "c"}
|
* splitAt("a.b.c", 1, 3) -> {"a", "b", "c"}
|
||||||
* splitAt("a..b", new int[] {1, 2}) -> {"a", "", "b"}
|
* splitAt("a..b", 1, 2) -> {"a", "", "b"}
|
||||||
* splitAt(".b.", new int[] {0, 2}) -> {"", "b", ""}
|
* splitAt(".b.", 0, 2) -> {"", "b", ""}
|
||||||
* splitAt("a.b", new int[] {1, 1, 1}) -> {"a", "", "", "b"}
|
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* @param src the String to split
|
* @param src the String to split
|
||||||
* @param at indices to split at, in any order
|
* @param at indices to split at, in any order
|
||||||
* @throws IllegalArgumentException if some index is out of bounds for {@code src}
|
* @throws IllegalArgumentException if some index is out of bounds for
|
||||||
* @return an array containing the substrings, in order of encounter in {@code src}.
|
* {@code src}
|
||||||
|
* @return an array containing the substrings, in order of encounter in
|
||||||
|
* {@code src}.
|
||||||
* Its length is always {@code at.length + 1}.
|
* Its length is always {@code at.length + 1}.
|
||||||
*/
|
*/
|
||||||
public static String[] splitAt(String src, int... at) {
|
public static String[] splitAt(String src, int... at) {
|
||||||
Objects.requireNonNull(src, "src");
|
Objects.requireNonNull(src, "src");
|
||||||
Objects.requireNonNull(at, "at");
|
Objects.requireNonNull(at, "at");
|
||||||
|
|
||||||
if (at.length == 0) return new String[] {src};
|
if (at.length == 0)
|
||||||
if (at.length == 1) return splitAt(src, at[0]);
|
return new String[] { src };
|
||||||
|
if (at.length == 1)
|
||||||
|
return splitAt(src, at[0]);
|
||||||
|
|
||||||
int[] indices; // Always sorted
|
int[] indices; // Always sorted
|
||||||
|
|
||||||
@ -481,8 +507,7 @@ public class StringUtil {
|
|||||||
char current;
|
char current;
|
||||||
int resultIndex = 0;
|
int resultIndex = 0;
|
||||||
|
|
||||||
mainLoop:
|
mainLoop: for (int srcIndex = 0; srcIndex < src.length(); ++srcIndex) {
|
||||||
for (int srcIndex = 0; srcIndex < src.length(); ++srcIndex) {
|
|
||||||
current = src.charAt(srcIndex);
|
current = src.charAt(srcIndex);
|
||||||
|
|
||||||
for (char c : remove) {
|
for (char c : remove) {
|
||||||
@ -528,12 +553,15 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (endPos < beginPos) {
|
if (endPos < beginPos) {
|
||||||
throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos="
|
throw new IllegalArgumentException(
|
||||||
+ endPos + ", beginPos=" + beginPos + ")");
|
"endPos must be greater than or equal to beginPos (endPos="
|
||||||
|
+ endPos + ", beginPos=" + beginPos + ")"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPos >= Math.min(a.length, b.length)) {
|
if (endPos >= Math.min(a.length, b.length)) {
|
||||||
return false; // At least one of the arrays does not contain at least one of the required elements
|
return false; // At least one of the arrays does not contain at
|
||||||
|
// least one of the required elements
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = beginPos; i < endPos; ++i) {
|
for (int i = beginPos; i < endPos; ++i) {
|
||||||
@ -563,9 +591,12 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified character
|
* Finds and returns the index of the specified appearance of the specified
|
||||||
* in the given array. The search starts at index 0.<p>
|
* character
|
||||||
* Examples:<p>
|
* in the given array. The search starts at index 0.
|
||||||
|
* <p>
|
||||||
|
* Examples:
|
||||||
|
* <p>
|
||||||
* <table border="1">
|
* <table border="1">
|
||||||
* <tr>
|
* <tr>
|
||||||
* <th align="center"><code>src</code></th>
|
* <th align="center"><code>src</code></th>
|
||||||
@ -573,15 +604,38 @@ public class StringUtil {
|
|||||||
* <th align="center"><code>skip</code></th>
|
* <th align="center"><code>skip</code></th>
|
||||||
* <th align="center">returns</th>
|
* <th align="center">returns</th>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr align="center"><td><code>a<u>.</u>b.c</code></td><td><code>'.'</code></td><td><code>0</code></td><td><code>1</code></td></tr>
|
* <tr align="center">
|
||||||
* <tr align="center"><td><code>a.b<u>.</u>c</code></td><td><code>'.'</code></td><td><code>1</code></td><td><code>3</code></td></tr>
|
* <td><code>a<u>.</u>b.c</code></td>
|
||||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'.'</code></td><td><code>2</code></td><td><code>-1</code></td></tr>
|
* <td><code>'.'</code></td>
|
||||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'d'</code></td><td><i>any</i></td><td><code>-1</code></td></tr>
|
* <td><code>0</code></td>
|
||||||
|
* <td><code>1</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a.b<u>.</u>c</code></td>
|
||||||
|
* <td><code>'.'</code></td>
|
||||||
|
* <td><code>1</code></td>
|
||||||
|
* <td><code>3</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a.b.c</code></td>
|
||||||
|
* <td><code>'.'</code></td>
|
||||||
|
* <td><code>2</code></td>
|
||||||
|
* <td><code>-1</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a.b.c</code></td>
|
||||||
|
* <td><code>'d'</code></td>
|
||||||
|
* <td><i>any</i></td>
|
||||||
|
* <td><code>-1</code></td>
|
||||||
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
|
*
|
||||||
* @param src - the array to search in.
|
* @param src - the array to search in.
|
||||||
* @param target - the character to search for.
|
* @param target - the character to search for.
|
||||||
* @param skip - the amount of <code>target</code> characters to be skipped.
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* @return The index of the <code>skip+1</code>th <code>target</code> character or -1, if none found.
|
* skipped.
|
||||||
|
* @return The index of the <code>skip+1</code>th <code>target</code>
|
||||||
|
* character or -1, if none found.
|
||||||
* @see StringUtil#indexFromEnd(char[], char, int)
|
* @see StringUtil#indexFromEnd(char[], char, int)
|
||||||
*/
|
*/
|
||||||
public static int indexFromBeginning(char[] src, char target, int skip) {
|
public static int indexFromBeginning(char[] src, char target, int skip) {
|
||||||
@ -598,9 +652,13 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified character
|
* Finds and returns the index of the specified appearance of the specified
|
||||||
* in the given array. The search starts at index <code>src.length - 1</code>.<p>
|
* character
|
||||||
* Examples:<p>
|
* in the given array. The search starts at index
|
||||||
|
* <code>src.length - 1</code>.
|
||||||
|
* <p>
|
||||||
|
* Examples:
|
||||||
|
* <p>
|
||||||
* <table border="1">
|
* <table border="1">
|
||||||
* <tr>
|
* <tr>
|
||||||
* <th align="center"><code>src</code></th>
|
* <th align="center"><code>src</code></th>
|
||||||
@ -608,15 +666,38 @@ public class StringUtil {
|
|||||||
* <th align="center"><code>skip</code></th>
|
* <th align="center"><code>skip</code></th>
|
||||||
* <th align="center">returns</th>
|
* <th align="center">returns</th>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr align="center"><td><code>a.b<u>.</u>c</code></td><td><code>'.'</code></td><td><code>0</code></td><td><code>3</code></td></tr>
|
* <tr align="center">
|
||||||
* <tr align="center"><td><code>a<u>.</u>b.c</code></td><td><code>'.'</code></td><td><code>1</code></td><td><code>1</code></td></tr>
|
* <td><code>a.b<u>.</u>c</code></td>
|
||||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'.'</code></td><td><code>2</code></td><td><code>-1</code></td></tr>
|
* <td><code>'.'</code></td>
|
||||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'d'</code></td><td><i>any</i></td><td><code>-1</code></td></tr>
|
* <td><code>0</code></td>
|
||||||
|
* <td><code>3</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a<u>.</u>b.c</code></td>
|
||||||
|
* <td><code>'.'</code></td>
|
||||||
|
* <td><code>1</code></td>
|
||||||
|
* <td><code>1</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a.b.c</code></td>
|
||||||
|
* <td><code>'.'</code></td>
|
||||||
|
* <td><code>2</code></td>
|
||||||
|
* <td><code>-1</code></td>
|
||||||
|
* </tr>
|
||||||
|
* <tr align="center">
|
||||||
|
* <td><code>a.b.c</code></td>
|
||||||
|
* <td><code>'d'</code></td>
|
||||||
|
* <td><i>any</i></td>
|
||||||
|
* <td><code>-1</code></td>
|
||||||
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
|
*
|
||||||
* @param src - the array to search in.
|
* @param src - the array to search in.
|
||||||
* @param target - the character to search for.
|
* @param target - the character to search for.
|
||||||
* @param skip - the amount of <code>target</code> characters to be skipped.
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* @return The index of the <code>skip+1</code>th <code>target</code>character
|
* skipped.
|
||||||
|
* @return The index of the <code>skip+1</code>th
|
||||||
|
* <code>target</code>character
|
||||||
* from the end of the array or -1, if none found.
|
* from the end of the array or -1, if none found.
|
||||||
* @see StringUtil#indexFromBeginning(char[], char, int)
|
* @see StringUtil#indexFromBeginning(char[], char, int)
|
||||||
*/
|
*/
|
||||||
@ -792,8 +873,12 @@ public class StringUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, Collection<String> result, Iterable<String>[] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
Collection<String> result,
|
||||||
|
Iterable<String>[] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result.add(sb.toString());
|
result.add(sb.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -811,15 +896,21 @@ public class StringUtil {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
int length = 1;
|
int length = 1;
|
||||||
for (String[] array : parts) length *= array.length;
|
for (String[] array : parts)
|
||||||
|
length *= array.length;
|
||||||
String[] result = new String[length];
|
String[] result = new String[length];
|
||||||
|
|
||||||
buildCombinations(sb, result, new int[] { 0 }, parts, 0);
|
buildCombinations(sb, result, new int[] { 0 }, parts, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
String[] result,
|
||||||
|
int[] resultIndex,
|
||||||
|
String[][] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result[resultIndex[0]++] = sb.toString();
|
result[resultIndex[0]++] = sb.toString();
|
||||||
} else {
|
} else {
|
||||||
@ -887,8 +978,7 @@ public class StringUtil {
|
|||||||
result[1] = 'x';
|
result[1] = 'x';
|
||||||
|
|
||||||
for (int digit = 0; digit < digits; ++digit) {
|
for (int digit = 0; digit < digits; ++digit) {
|
||||||
result[(digits - digit - 1) + 2] =
|
result[(digits - digit - 1) + 2] = hexDigit(x, digit);
|
||||||
hexDigit(x, digit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -902,8 +992,10 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static char hexDigit(int value) {
|
public static char hexDigit(int value) {
|
||||||
if (value < 0xA) return (char) ('0' + value);
|
if (value < 0xA)
|
||||||
else return (char) ('A' - 0xA + value);
|
return (char) ('0' + value);
|
||||||
|
else
|
||||||
|
return (char) ('A' - 0xA + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String replaceAll(String source, String substring, String replacement) {
|
public static String replaceAll(String source, String substring, String replacement) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class UncheckedEscapeException extends RuntimeException {
|
public class UncheckedEscapeException extends RuntimeException {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -85,11 +86,14 @@ public class WordReader implements Iterator<String> {
|
|||||||
while (true) {
|
while (true) {
|
||||||
c = nextChar();
|
c = nextChar();
|
||||||
|
|
||||||
if (isExhausted) break;
|
if (isExhausted)
|
||||||
|
break;
|
||||||
|
|
||||||
if (Character.isWhitespace(c)) {
|
if (Character.isWhitespace(c)) {
|
||||||
if (length == 0) continue;
|
if (length == 0)
|
||||||
else break;
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wordBuffer.length == length) {
|
if (wordBuffer.length == length) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,20 +14,22 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractCharReader implements CharReader {
|
public abstract class AbstractCharReader implements CharReader {
|
||||||
|
|
||||||
protected static final int DEFAULT_MARK_STACK_SIZE = 8;
|
protected static final int DEFAULT_MARK_STACK_SIZE = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current position of this CharReader. The reader maps its input to positions starting from 0.
|
* Current position of this CharReader. The reader maps its input to
|
||||||
* Positions that are negative or lower than 0 are invalid. {@link #current()}
|
* positions starting from 0.
|
||||||
|
* Positions that are negative or lower than 0 are invalid.
|
||||||
|
* {@link #current()}
|
||||||
* will throw an exception if position is invalid.
|
* will throw an exception if position is invalid.
|
||||||
*/
|
*/
|
||||||
protected int position = 0;
|
protected int position = 0;
|
||||||
@ -80,7 +82,8 @@ public abstract class AbstractCharReader implements CharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMarksCapacity() {
|
private void ensureMarksCapacity() {
|
||||||
if (nextMark < marks.length) return;
|
if (nextMark < marks.length)
|
||||||
|
return;
|
||||||
int[] newMarks = new int[closestGreaterPowerOf2(nextMark)];
|
int[] newMarks = new int[closestGreaterPowerOf2(nextMark)];
|
||||||
System.arraycopy(marks, 0, newMarks, 0, nextMark);
|
System.arraycopy(marks, 0, newMarks, 0, nextMark);
|
||||||
marks = newMarks;
|
marks = newMarks;
|
||||||
@ -96,7 +99,8 @@ public abstract class AbstractCharReader implements CharReader {
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
sb.append("\"\n ");
|
sb.append("\"\n ");
|
||||||
for (int i = 0; i < position; ++i) sb.append(' ');
|
for (int i = 0; i < position; ++i)
|
||||||
|
sb.append(' ');
|
||||||
sb.append("^ (pos " + position + ")");
|
sb.append("^ (pos " + position + ")");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -23,7 +24,6 @@ import ru.windcorp.jputil.ArrayUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ArrayCharReader extends AbstractCharReader {
|
public class ArrayCharReader extends AbstractCharReader {
|
||||||
|
|
||||||
@ -42,7 +42,8 @@ public class ArrayCharReader extends AbstractCharReader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public char current() {
|
public char current() {
|
||||||
if (position >= length) return DONE;
|
if (position >= length)
|
||||||
|
return DONE;
|
||||||
if (position < 0)
|
if (position < 0)
|
||||||
throw new IllegalStateException("Position " + position + " is invalid");
|
throw new IllegalStateException("Position " + position + " is invalid");
|
||||||
return array[position + offset];
|
return array[position + offset];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,12 +14,12 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class BufferedCharReader extends AbstractCharReader {
|
public abstract class BufferedCharReader extends AbstractCharReader {
|
||||||
|
|
||||||
@ -42,7 +42,9 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquires the next character.
|
* Acquires the next character.
|
||||||
* @return the character or {@link #DONE} if the end of the reader has been reached
|
*
|
||||||
|
* @return the character or {@link #DONE} if the end of the reader has been
|
||||||
|
* reached
|
||||||
*/
|
*/
|
||||||
protected abstract char pullChar();
|
protected abstract char pullChar();
|
||||||
|
|
||||||
@ -65,7 +67,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int pullChars(int offset, int length) {
|
private int pullChars(int offset, int length) {
|
||||||
if (exhausted || length == 0) return 0;
|
if (exhausted || length == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
int pulled = pullChars(buffer, offset, length);
|
int pulled = pullChars(buffer, offset, length);
|
||||||
if (pulled != length) {
|
if (pulled != length) {
|
||||||
@ -82,7 +85,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getPosition() >= bufferNextIndex) {
|
if (getPosition() >= bufferNextIndex) {
|
||||||
if (exhausted) return DONE;
|
if (exhausted)
|
||||||
|
return DONE;
|
||||||
|
|
||||||
ensureBufferCapacity();
|
ensureBufferCapacity();
|
||||||
|
|
||||||
@ -92,7 +96,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
int pulled = pullChars(bufferNextIndex, needToPull);
|
int pulled = pullChars(bufferNextIndex, needToPull);
|
||||||
bufferNextIndex += pulled;
|
bufferNextIndex += pulled;
|
||||||
|
|
||||||
if (exhausted) return DONE;
|
if (exhausted)
|
||||||
|
return DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO test the shit out of current()
|
// TODO test the shit out of current()
|
||||||
@ -101,7 +106,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureBufferCapacity() {
|
private void ensureBufferCapacity() {
|
||||||
if (getPosition() < buffer.length) return;
|
if (getPosition() < buffer.length)
|
||||||
|
return;
|
||||||
char[] newBuffer = new char[closestGreaterPowerOf2(getPosition())];
|
char[] newBuffer = new char[closestGreaterPowerOf2(getPosition())];
|
||||||
System.arraycopy(buffer, 0, newBuffer, 0, bufferNextIndex);
|
System.arraycopy(buffer, 0, newBuffer, 0, bufferNextIndex);
|
||||||
buffer = newBuffer;
|
buffer = newBuffer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -26,7 +27,6 @@ import ru.windcorp.jputil.chars.Escaper;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// SonarLint: Constants should not be defined in interfaces (java:S1214)
|
// SonarLint: Constants should not be defined in interfaces (java:S1214)
|
||||||
@ -38,7 +38,9 @@ public interface CharReader {
|
|||||||
char DONE = '\uFFFF';
|
char DONE = '\uFFFF';
|
||||||
|
|
||||||
char current();
|
char current();
|
||||||
|
|
||||||
int getPosition();
|
int getPosition();
|
||||||
|
|
||||||
int setPosition(int position);
|
int setPosition(int position);
|
||||||
|
|
||||||
default char next() {
|
default char next() {
|
||||||
@ -94,7 +96,8 @@ public interface CharReader {
|
|||||||
default char[] getChars(int length) {
|
default char[] getChars(int length) {
|
||||||
char[] result = new char[length];
|
char[] result = new char[length];
|
||||||
int from = getChars(result);
|
int from = getChars(result);
|
||||||
if (from != length) Arrays.fill(result, from, length, DONE);
|
if (from != length)
|
||||||
|
Arrays.fill(result, from, length, DONE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +107,8 @@ public interface CharReader {
|
|||||||
|
|
||||||
default String getString(int length) {
|
default String getString(int length) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < length && !isEnd(); ++i) sb.append(consume());
|
for (int i = 0; i < length && !isEnd(); ++i)
|
||||||
|
sb.append(consume());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +118,10 @@ public interface CharReader {
|
|||||||
|
|
||||||
default boolean match(CharSequence seq) {
|
default boolean match(CharSequence seq) {
|
||||||
for (int i = 0; i < seq.length(); ++i) {
|
for (int i = 0; i < seq.length(); ++i) {
|
||||||
if (isEnd()) return false;
|
if (isEnd())
|
||||||
if (current() != seq.charAt(i)) return false;
|
return false;
|
||||||
|
if (current() != seq.charAt(i))
|
||||||
|
return false;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +141,10 @@ public interface CharReader {
|
|||||||
|
|
||||||
default boolean match(char[] array) {
|
default boolean match(char[] array) {
|
||||||
for (int i = 0; i < array.length; ++i) {
|
for (int i = 0; i < array.length; ++i) {
|
||||||
if (isEnd()) return false;
|
if (isEnd())
|
||||||
if (current() != array[i]) return false;
|
return false;
|
||||||
|
if (current() != array[i])
|
||||||
|
return false;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +178,10 @@ public interface CharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips to the end of the current line. Both <code>"\n"</code>, <code>"\r"</code>
|
* Skips to the end of the current line. Both <code>"\n"</code>,
|
||||||
|
* <code>"\r"</code>
|
||||||
* and <code>"\r\n"</code> are considered line separators.
|
* and <code>"\r\n"</code> are considered line separators.
|
||||||
|
*
|
||||||
* @return the amount of characters in the skipped line
|
* @return the amount of characters in the skipped line
|
||||||
*/
|
*/
|
||||||
default int skipLine() {
|
default int skipLine() {
|
||||||
@ -209,7 +219,8 @@ public interface CharReader {
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
char[] result = new char[length];
|
char[] result = new char[length];
|
||||||
for (int i = 0; i < length; ++i) result[i] = consume();
|
for (int i = 0; i < length; ++i)
|
||||||
|
result[i] = consume();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +245,8 @@ public interface CharReader {
|
|||||||
reset();
|
reset();
|
||||||
|
|
||||||
char[] result = new char[length];
|
char[] result = new char[length];
|
||||||
for (int i = 0; i < result.length; ++i) result[i] = consume();
|
for (int i = 0; i < result.length; ++i)
|
||||||
|
result[i] = consume();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,13 +254,15 @@ public interface CharReader {
|
|||||||
mark();
|
mark();
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
while (consume() != DONE) result++;
|
while (consume() != DONE)
|
||||||
|
result++;
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mark();
|
int mark();
|
||||||
|
|
||||||
int forget();
|
int forget();
|
||||||
|
|
||||||
default int reset() {
|
default int reset() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -29,11 +30,11 @@ import ru.windcorp.jputil.chars.CharSupplier;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CharReaders {
|
public class CharReaders {
|
||||||
|
|
||||||
private CharReaders() {}
|
private CharReaders() {
|
||||||
|
}
|
||||||
|
|
||||||
public static CharReader wrap(char[] array, int offset, int length) {
|
public static CharReader wrap(char[] array, int offset, int length) {
|
||||||
return new ArrayCharReader(array, offset, length);
|
return new ArrayCharReader(array, offset, length);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -22,7 +23,6 @@ import java.io.Reader;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ReaderCharReader extends BufferedCharReader {
|
public class ReaderCharReader extends BufferedCharReader {
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ public class ReaderCharReader extends BufferedCharReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ru.windcorp.jputil.chars.reader.BufferedCharReader#pullChars(char[], int, int)
|
* @see ru.windcorp.jputil.chars.reader.BufferedCharReader#pullChars(char[],
|
||||||
|
* int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected int pullChars(char[] buffer, int offset, int length) {
|
protected int pullChars(char[] buffer, int offset, int length) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,14 +14,14 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class StringCharReader extends AbstractCharReader {
|
public class StringCharReader extends AbstractCharReader {
|
||||||
|
|
||||||
@ -37,7 +37,9 @@ public class StringCharReader extends AbstractCharReader {
|
|||||||
|
|
||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > str.length() || offset < 0)
|
if (end > str.length() || offset < 0)
|
||||||
throw new IllegalArgumentException("String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")");
|
throw new IllegalArgumentException(
|
||||||
|
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
@ -48,7 +50,8 @@ public class StringCharReader extends AbstractCharReader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public char current() {
|
public char current() {
|
||||||
if (position >= length) return DONE;
|
if (position >= length)
|
||||||
|
return DONE;
|
||||||
if (position < 0)
|
if (position < 0)
|
||||||
throw new IllegalStateException("Position " + position + " is invalid");
|
throw new IllegalStateException("Position " + position + " is invalid");
|
||||||
return str.charAt(position + offset);
|
return str.charAt(position + offset);
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* JPUtil
|
||||||
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -44,7 +45,8 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> second) {
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> second
|
||||||
|
) {
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
@ -53,7 +55,8 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
BiConsumer<? super T, ? super U> first,
|
BiConsumer<? super T, ? super U> first,
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> second) {
|
ThrowingBiConsumer<? super T, ? super U, E> second
|
||||||
|
) {
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
@ -62,7 +65,8 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> first,
|
ThrowingBiConsumer<? super T, ? super U, E> first,
|
||||||
BiConsumer<? super T, ? super U> second) {
|
BiConsumer<? super T, ? super U> second
|
||||||
|
) {
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -38,21 +39,30 @@ public interface ThrowingConsumer<T, E extends Exception> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first, ThrowingConsumer<? super T, ? extends E> second) {
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(Consumer<? super T> first, ThrowingConsumer<? super T, ? extends E> second) {
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
|
Consumer<? super T> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first, Consumer<? super T> second) {
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
Consumer<? super T> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -27,14 +28,18 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
R apply(T t) throws E;
|
R apply(T t) throws E;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default Function<T, R> withHandler(BiConsumer<? super T, ? super E> handler, Function<? super T, ? extends R> value) {
|
default Function<T, R> withHandler(
|
||||||
|
BiConsumer<? super T, ? super E> handler,
|
||||||
|
Function<? super T, ? extends R> value
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
try {
|
try {
|
||||||
return apply(t);
|
return apply(t);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (handler != null) handler.accept(t, (E) e);
|
if (handler != null)
|
||||||
|
handler.accept(t, (E) e);
|
||||||
return value == null ? null : value.apply(t);
|
return value == null ? null : value.apply(t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -54,19 +59,22 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, ? extends E> first,
|
ThrowingFunction<? super T, I, ? extends E> first,
|
||||||
ThrowingFunction<? super I, ? extends R, ? extends E> second) {
|
ThrowingFunction<? super I, ? extends R, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
Function<? super T, I> first,
|
Function<? super T, I> first,
|
||||||
ThrowingFunction<? super I, ? extends R, E> second) {
|
ThrowingFunction<? super I, ? extends R, E> second
|
||||||
|
) {
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, E> first,
|
ThrowingFunction<? super T, I, E> first,
|
||||||
Function<? super I, ? extends R> second) {
|
Function<? super I, ? extends R> second
|
||||||
|
) {
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -33,7 +34,8 @@ public interface ThrowingSupplier<T, E extends Exception> {
|
|||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (handler != null) handler.accept((E) e);
|
if (handler != null)
|
||||||
|
handler.accept((E) e);
|
||||||
return value == null ? null : value.get();
|
return value == null ? null : value.get();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -22,7 +23,6 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Javapony
|
* @author Javapony
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class FunctionIterator<T, E> implements Iterator<E> {
|
public class FunctionIterator<T, E> implements Iterator<E> {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -46,7 +47,8 @@ public class PeekingIterator<E> implements Iterator<E> {
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SonarLint: "Iterator.next()" methods should throw "NoSuchElementException" (java:S2272)
|
// SonarLint: "Iterator.next()" methods should throw
|
||||||
|
// "NoSuchElementException" (java:S2272)
|
||||||
// peek() throws NoSuchElementException as expected
|
// peek() throws NoSuchElementException as expected
|
||||||
@SuppressWarnings("squid:S2272")
|
@SuppressWarnings("squid:S2272")
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -48,8 +49,10 @@ public class RangeIterator<E> implements Iterator<E> {
|
|||||||
public E next() {
|
public E next() {
|
||||||
update();
|
update();
|
||||||
if (nextIndex >= from + amount) {
|
if (nextIndex >= from + amount) {
|
||||||
throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex
|
throw new NoSuchElementException(
|
||||||
+ " which exceeds upper boundary " + (from + amount));
|
"RangeIterator about to retrieve element " + nextIndex
|
||||||
|
+ " which exceeds upper boundary " + (from + amount)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
E result = parent.next();
|
E result = parent.next();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -46,7 +47,8 @@ public class Reiterator<E> implements Iterable<E> {
|
|||||||
public E next() {
|
public E next() {
|
||||||
E result;
|
E result;
|
||||||
synchronized (source) {
|
synchronized (source) {
|
||||||
if (!hasNext()) throw new NoSuchElementException();
|
if (!hasNext())
|
||||||
|
throw new NoSuchElementException();
|
||||||
result = data.get(index);
|
result = data.get(index);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
public abstract class AbstractSelectorOperator implements SelectorOperator {
|
public abstract class AbstractSelectorOperator implements SelectorOperator {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import ru.windcorp.jputil.SyntaxException;
|
import ru.windcorp.jputil.SyntaxException;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import ru.windcorp.jputil.SyntaxException;
|
import ru.windcorp.jputil.SyntaxException;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* JPUtil
|
* JPUtil
|
||||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
* Copyright (C) 2019-2021 OLEGSHA/Javapony and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -33,11 +34,10 @@ public class SelectorSystem<T> {
|
|||||||
public static final char EXPRESSION_OPEN = '(';
|
public static final char EXPRESSION_OPEN = '(';
|
||||||
public static final char EXPRESSION_CLOSE = ')';
|
public static final char EXPRESSION_CLOSE = ')';
|
||||||
|
|
||||||
private final Collection<Selector<T>> selectors =
|
private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
||||||
Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
|
||||||
|
|
||||||
private final Collection<SelectorOperator> operators =
|
private final Collection<SelectorOperator> operators = Collections
|
||||||
Collections.synchronizedCollection(new ArrayList<SelectorOperator>());
|
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||||
|
|
||||||
private String stackPrefix = null;
|
private String stackPrefix = null;
|
||||||
|
|
||||||
@ -125,8 +125,7 @@ public class SelectorSystem<T> {
|
|||||||
synchronized (getSelectorOperators()) {
|
synchronized (getSelectorOperators()) {
|
||||||
synchronized (getSelectors()) {
|
synchronized (getSelectors()) {
|
||||||
|
|
||||||
tokenCycle:
|
tokenCycle: while (tokens.hasNext()) {
|
||||||
while (tokens.hasNext()) {
|
|
||||||
token = tokens.next();
|
token = tokens.next();
|
||||||
|
|
||||||
for (SelectorOperator operator : getSelectorOperators()) {
|
for (SelectorOperator operator : getSelectorOperators()) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
public class Progressia {
|
public class Progressia {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
public interface Proxy {
|
public interface Proxy {
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||||
@ -51,9 +69,11 @@ public class Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCamera().setAnchor(new EntityAnchor(
|
getCamera().setAnchor(
|
||||||
|
new EntityAnchor(
|
||||||
getWorld().getEntityRenderable(entity)
|
getWorld().getEntityRenderable(entity)
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
import ru.windcorp.progressia.Proxy;
|
import ru.windcorp.progressia.Proxy;
|
||||||
@ -40,7 +41,10 @@ public class ClientProxy implements Proxy {
|
|||||||
try {
|
try {
|
||||||
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(() -> Typefaces.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))));
|
RenderTaskQueue.waitAndInvoke(
|
||||||
|
() -> Typefaces
|
||||||
|
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))
|
||||||
|
);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw CrashReports.report(e, "ClientProxy failed");
|
throw CrashReports.report(e, "ClientProxy failed");
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||||
@ -41,6 +59,7 @@ public class ClientState {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientState() {}
|
private ClientState() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
import ru.windcorp.progressia.ProgressiaLauncher;
|
import ru.windcorp.progressia.ProgressiaLauncher;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
public enum AudioFormat {
|
public enum AudioFormat {
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import org.lwjgl.openal.*;
|
import org.lwjgl.openal.*;
|
||||||
@ -57,8 +75,10 @@ public class AudioManager {
|
|||||||
lastSoundIndex = 0;
|
lastSoundIndex = 0;
|
||||||
}
|
}
|
||||||
speaker = soundSpeakers.get(lastSoundIndex);
|
speaker = soundSpeakers.get(lastSoundIndex);
|
||||||
} while (speaker.getState()
|
} while (
|
||||||
.equals(Speaker.State.PLAYING_LOOP));
|
speaker.getState()
|
||||||
|
.equals(Speaker.State.PLAYING_LOOP)
|
||||||
|
);
|
||||||
return speaker;
|
return speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +88,17 @@ public class AudioManager {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception("ERROR: The selected sound is not loaded or" +
|
throw new Exception(
|
||||||
" not exists");
|
"ERROR: The selected sound is not loaded or" +
|
||||||
|
" not exists"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Speaker initSpeaker(String soundID) {
|
public static Speaker initSpeaker(String soundID) {
|
||||||
Speaker speaker = getLastSpeaker();
|
Speaker speaker = getLastSpeaker();
|
||||||
try {
|
try {
|
||||||
findSoundType(soundID).initSpeaker(speaker);
|
findSoundType(soundID).initSpeaker(speaker);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex) {
|
||||||
{
|
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
return speaker;
|
return speaker;
|
||||||
@ -86,8 +107,7 @@ public class AudioManager {
|
|||||||
public static Speaker initMusicSpeaker(String soundID) {
|
public static Speaker initMusicSpeaker(String soundID) {
|
||||||
try {
|
try {
|
||||||
findSoundType(soundID).initSpeaker(musicSpeaker);
|
findSoundType(soundID).initSpeaker(musicSpeaker);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex) {
|
||||||
{
|
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
return musicSpeaker;
|
return musicSpeaker;
|
||||||
@ -103,8 +123,7 @@ public class AudioManager {
|
|||||||
public static void loadSound(String path, String id, AudioFormat format) {
|
public static void loadSound(String path, String id, AudioFormat format) {
|
||||||
if (format == AudioFormat.MONO) {
|
if (format == AudioFormat.MONO) {
|
||||||
soundsBuffer.add(AudioReader.readAsMono(path, id));
|
soundsBuffer.add(AudioReader.readAsMono(path, id));
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
soundsBuffer.add(AudioReader.readAsStereo(path, id));
|
soundsBuffer.add(AudioReader.readAsStereo(path, id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,8 +147,7 @@ public class AudioManager {
|
|||||||
return deviceCapabilities;
|
return deviceCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createBuffers()
|
public static void createBuffers() {
|
||||||
{
|
|
||||||
for (int i = 0; i < SOUNDS_NUM; ++i) {
|
for (int i = 0; i < SOUNDS_NUM; ++i) {
|
||||||
soundSpeakers.add(new Speaker());
|
soundSpeakers.add(new Speaker());
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
public class AudioSystem {
|
public class AudioSystem {
|
||||||
@ -9,8 +27,10 @@ public class AudioSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void loadAudioData() {
|
static void loadAudioData() {
|
||||||
AudioManager.loadSound("assets/sounds/block_destroy_clap.ogg",
|
AudioManager.loadSound(
|
||||||
|
"assets/sounds/block_destroy_clap.ogg",
|
||||||
"Progressia:BlockDestroy",
|
"Progressia:BlockDestroy",
|
||||||
AudioFormat.MONO);
|
AudioFormat.MONO
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -10,18 +28,17 @@ public class Music extends Namespaced {
|
|||||||
private float pitch = 1.0f;
|
private float pitch = 1.0f;
|
||||||
private float gain = 1.0f;
|
private float gain = 1.0f;
|
||||||
|
|
||||||
|
public Music(String id) {
|
||||||
public Music(String id)
|
|
||||||
{
|
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Music(String id,
|
public Music(
|
||||||
|
String id,
|
||||||
Vec3 position,
|
Vec3 position,
|
||||||
Vec3 velocity,
|
Vec3 velocity,
|
||||||
float pitch,
|
float pitch,
|
||||||
float gain)
|
float gain
|
||||||
{
|
) {
|
||||||
this(id);
|
this(id);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
@ -29,8 +46,7 @@ public class Music extends Namespaced {
|
|||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play(boolean loop)
|
public void play(boolean loop) {
|
||||||
{
|
|
||||||
Speaker speaker = AudioManager.initMusicSpeaker(this.getId());
|
Speaker speaker = AudioManager.initMusicSpeaker(this.getId());
|
||||||
speaker.setGain(gain);
|
speaker.setGain(gain);
|
||||||
speaker.setPitch(pitch);
|
speaker.setPitch(pitch);
|
||||||
@ -48,13 +64,17 @@ public class Music extends Namespaced {
|
|||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
public void setVelocity(Vec3 velocity) {
|
public void setVelocity(Vec3 velocity) {
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 getPosition() { return position; }
|
public Vec3 getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
public float getGain() {
|
public float getGain() {
|
||||||
return gain;
|
return gain;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -12,18 +30,17 @@ public class SoundEffect
|
|||||||
private float pitch = 1.0f;
|
private float pitch = 1.0f;
|
||||||
private float gain = 1.0f;
|
private float gain = 1.0f;
|
||||||
|
|
||||||
|
public SoundEffect(String id) {
|
||||||
public SoundEffect(String id)
|
|
||||||
{
|
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundEffect(String id,
|
public SoundEffect(
|
||||||
|
String id,
|
||||||
Vec3 position,
|
Vec3 position,
|
||||||
Vec3 velocity,
|
Vec3 velocity,
|
||||||
float pitch,
|
float pitch,
|
||||||
float gain)
|
float gain
|
||||||
{
|
) {
|
||||||
this(id);
|
this(id);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
@ -31,8 +48,7 @@ public class SoundEffect
|
|||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play(boolean loop)
|
public void play(boolean loop) {
|
||||||
{
|
|
||||||
Speaker speaker = AudioManager.initSpeaker(this.getId());
|
Speaker speaker = AudioManager.initSpeaker(this.getId());
|
||||||
speaker.setGain(gain);
|
speaker.setGain(gain);
|
||||||
speaker.setPitch(pitch);
|
speaker.setPitch(pitch);
|
||||||
@ -50,7 +66,9 @@ public class SoundEffect
|
|||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPosition(Vec3 position) {
|
public void setPosition(Vec3 position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@ -11,7 +29,8 @@ import static org.lwjgl.openal.AL10.*;
|
|||||||
|
|
||||||
public class AudioReader {
|
public class AudioReader {
|
||||||
|
|
||||||
private AudioReader() {}
|
private AudioReader() {
|
||||||
|
}
|
||||||
|
|
||||||
// TODO fix converting from mono-stereo
|
// TODO fix converting from mono-stereo
|
||||||
private static SoundType readAsSpecified(String path, String id, int format) {
|
private static SoundType readAsSpecified(String path, String id, int format) {
|
||||||
@ -22,8 +41,12 @@ public class AudioReader {
|
|||||||
|
|
||||||
ShortBuffer rawAudio = decodeVorbis(res, channelBuffer, rateBuffer);
|
ShortBuffer rawAudio = decodeVorbis(res, channelBuffer, rateBuffer);
|
||||||
|
|
||||||
return new SoundType(id, rawAudio, format,
|
return new SoundType(
|
||||||
rateBuffer.get(0));
|
id,
|
||||||
|
rawAudio,
|
||||||
|
format,
|
||||||
|
rateBuffer.get(0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SoundType readAsMono(String path, String id) {
|
public static SoundType readAsMono(String path, String id) {
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -12,7 +30,8 @@ public class Listener {
|
|||||||
|
|
||||||
private static final Listener INSTANCE = new Listener();
|
private static final Listener INSTANCE = new Listener();
|
||||||
|
|
||||||
private Listener() {}
|
private Listener() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Listener getInstance() {
|
public static Listener getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
@ -72,9 +91,17 @@ public class Listener {
|
|||||||
private void applyParams() {
|
private void applyParams() {
|
||||||
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
||||||
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||||
alListenerfv(AL_ORIENTATION, new float[] {
|
alListenerfv(
|
||||||
oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z
|
AL_ORIENTATION,
|
||||||
});
|
new float[] {
|
||||||
|
oriAt.x,
|
||||||
|
oriAt.y,
|
||||||
|
oriAt.z,
|
||||||
|
oriUp.x,
|
||||||
|
oriUp.y,
|
||||||
|
oriUp.z
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
@ -12,8 +30,12 @@ public class SoundType extends Namespaced {
|
|||||||
private int format;
|
private int format;
|
||||||
private int audioBuffer;
|
private int audioBuffer;
|
||||||
|
|
||||||
public SoundType(String id, ShortBuffer rawAudio,
|
public SoundType(
|
||||||
int format, int sampleRate) {
|
String id,
|
||||||
|
ShortBuffer rawAudio,
|
||||||
|
int format,
|
||||||
|
int sampleRate
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
this.rawAudio = rawAudio;
|
this.rawAudio = rawAudio;
|
||||||
this.sampleRate = sampleRate;
|
this.sampleRate = sampleRate;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -85,8 +103,7 @@ public class Speaker {
|
|||||||
final int speakerState = alGetSourcei(sourceData, AL_SOURCE_STATE);
|
final int speakerState = alGetSourcei(sourceData, AL_SOURCE_STATE);
|
||||||
if (speakerState == AL_PLAYING) {
|
if (speakerState == AL_PLAYING) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
state = State.NOT_PLAYING;
|
state = State.NOT_PLAYING;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -143,8 +160,7 @@ public class Speaker {
|
|||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public State getState()
|
public State getState() {
|
||||||
{
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms;
|
package ru.windcorp.progressia.client.comms;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms;
|
package ru.windcorp.progressia.client.comms;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.comms.CommsChannel;
|
import ru.windcorp.progressia.common.comms.CommsChannel;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -33,7 +51,8 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PacketControl onInputEvent(InputEvent event) {
|
public PacketControl onInputEvent(InputEvent event) {
|
||||||
if (!predicate.test(event)) return null;
|
if (!predicate.test(event))
|
||||||
|
return null;
|
||||||
|
|
||||||
PacketControl packet = new PacketControl(
|
PacketControl packet = new PacketControl(
|
||||||
packetId,
|
packetId,
|
||||||
|
@ -1,11 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||||
|
|
||||||
public class ControlTriggerRegistry extends NamespacedInstanceRegistry<ControlTrigger> {
|
public class ControlTriggerRegistry extends NamespacedInstanceRegistry<ControlTrigger> {
|
||||||
|
|
||||||
private static final ControlTriggerRegistry INSTANCE =
|
private static final ControlTriggerRegistry INSTANCE = new ControlTriggerRegistry();
|
||||||
new ControlTriggerRegistry();
|
|
||||||
|
|
||||||
public static ControlTriggerRegistry getInstance() {
|
public static ControlTriggerRegistry getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -35,7 +53,8 @@ public class ControlTriggers {
|
|||||||
) {
|
) {
|
||||||
return of(
|
return of(
|
||||||
id,
|
id,
|
||||||
(input, control) -> {},
|
(input, control) -> {
|
||||||
|
},
|
||||||
predicate
|
predicate
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -77,7 +96,8 @@ public class ControlTriggers {
|
|||||||
) {
|
) {
|
||||||
return of(
|
return of(
|
||||||
id,
|
id,
|
||||||
(input, control) -> {},
|
(input, control) -> {
|
||||||
|
},
|
||||||
createCheckedCompoundPredicate(inputType, predicates)
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -117,25 +137,20 @@ public class ControlTriggers {
|
|||||||
return of(
|
return of(
|
||||||
id,
|
id,
|
||||||
InputEvent.class,
|
InputEvent.class,
|
||||||
(input, control) -> {},
|
(input, control) -> {
|
||||||
|
},
|
||||||
predicates
|
predicates
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static
|
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
||||||
<I extends InputEvent>
|
|
||||||
BiConsumer<InputEvent, ControlData>
|
|
||||||
createCheckedDataWriter(
|
|
||||||
Class<I> inputType,
|
Class<I> inputType,
|
||||||
BiConsumer<I, ControlData> dataWriter
|
BiConsumer<I, ControlData> dataWriter
|
||||||
) {
|
) {
|
||||||
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static
|
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(
|
||||||
<I extends InputEvent>
|
|
||||||
Predicate<InputEvent>
|
|
||||||
createCheckedCompoundPredicate(
|
|
||||||
Class<I> inputType,
|
Class<I> inputType,
|
||||||
Predicate<I>[] predicates
|
Predicate<I>[] predicates
|
||||||
) {
|
) {
|
||||||
@ -171,6 +186,7 @@ public class ControlTriggers {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControlTriggers() {}
|
private ControlTriggers() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.Client;
|
import ru.windcorp.progressia.client.Client;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.localhost;
|
package ru.windcorp.progressia.client.comms.localhost;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.localhost;
|
package ru.windcorp.progressia.client.comms.localhost;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,15 +14,15 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics;
|
package ru.windcorp.progressia.client.graphics;
|
||||||
|
|
||||||
import glm.vec._4.Vec4;
|
import glm.vec._4.Vec4;
|
||||||
|
|
||||||
public class Colors {
|
public class Colors {
|
||||||
|
|
||||||
public static final Vec4
|
public static final Vec4 WHITE = toVector(0xFFFFFFFF),
|
||||||
WHITE = toVector(0xFFFFFFFF),
|
|
||||||
BLACK = toVector(0xFF000000),
|
BLACK = toVector(0xFF000000),
|
||||||
|
|
||||||
GRAY_4 = toVector(0xFF444444),
|
GRAY_4 = toVector(0xFF444444),
|
||||||
@ -45,7 +45,8 @@ public class Colors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Vec4 multiplyRGB(Vec4 color, float multiplier, Vec4 output) {
|
public static Vec4 multiplyRGB(Vec4 color, float multiplier, Vec4 output) {
|
||||||
if (output == null) output = new Vec4();
|
if (output == null)
|
||||||
|
output = new Vec4();
|
||||||
return color.mul(multiplier, multiplier, multiplier, 1, output);
|
return color.mul(multiplier, multiplier, multiplier, 1, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics;
|
package ru.windcorp.progressia.client.graphics;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -40,7 +41,8 @@ public class GUI {
|
|||||||
void affect(List<Layer> layers);
|
void affect(List<Layer> layers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections.synchronizedList(new ArrayList<>());
|
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
|
||||||
|
.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
private static class ModifiableInput extends Input {
|
private static class ModifiableInput extends Input {
|
||||||
@Override
|
@Override
|
||||||
@ -51,7 +53,8 @@ public class GUI {
|
|||||||
|
|
||||||
private static final ModifiableInput THE_INPUT = new ModifiableInput();
|
private static final ModifiableInput THE_INPUT = new ModifiableInput();
|
||||||
|
|
||||||
private GUI() {}
|
private GUI() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void addBottomLayer(Layer layer) {
|
public static void addBottomLayer(Layer layer) {
|
||||||
modify(layers -> layers.add(layer));
|
modify(layers -> layers.add(layer));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics;
|
package ru.windcorp.progressia.client.graphics;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@ -22,6 +40,7 @@ public class FaceCulling {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FaceCulling() {}
|
private FaceCulling() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -37,7 +38,8 @@ public class GraphicsBackend {
|
|||||||
|
|
||||||
private static boolean faceCullingEnabled = false;
|
private static boolean faceCullingEnabled = false;
|
||||||
|
|
||||||
private GraphicsBackend() {}
|
private GraphicsBackend() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
startRenderThread();
|
startRenderThread();
|
||||||
@ -73,7 +75,8 @@ public class GraphicsBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void onFrameResized(long window, int newWidth, int newHeight) {
|
static void onFrameResized(long window, int newWidth, int newHeight) {
|
||||||
if (window != windowHandle) return;
|
if (window != windowHandle)
|
||||||
|
return;
|
||||||
|
|
||||||
InputHandler.handleFrameResize(newWidth, newHeight);
|
InputHandler.handleFrameResize(newWidth, newHeight);
|
||||||
FRAME_SIZE.set(newWidth, newHeight);
|
FRAME_SIZE.set(newWidth, newHeight);
|
||||||
@ -113,7 +116,8 @@ public class GraphicsBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setFaceCulling(boolean useFaceCulling) {
|
public static void setFaceCulling(boolean useFaceCulling) {
|
||||||
if (useFaceCulling == faceCullingEnabled) return;
|
if (useFaceCulling == faceCullingEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (useFaceCulling) {
|
if (useFaceCulling) {
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,14 +14,16 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
|
|
||||||
public class GraphicsInterface {
|
public class GraphicsInterface {
|
||||||
|
|
||||||
private GraphicsInterface() {}
|
private GraphicsInterface() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Thread getRenderThread() {
|
public static Thread getRenderThread() {
|
||||||
return GraphicsBackend.getRenderThread();
|
return GraphicsBackend.getRenderThread();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@ -46,8 +47,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ModifiableKeyEvent THE_KEY_EVENT =
|
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
||||||
new ModifiableKeyEvent();
|
|
||||||
|
|
||||||
static void handleKeyInput(
|
static void handleKeyInput(
|
||||||
long window,
|
long window,
|
||||||
@ -56,7 +56,8 @@ public class InputHandler {
|
|||||||
int action,
|
int action,
|
||||||
int mods
|
int mods
|
||||||
) {
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
|
return;
|
||||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||||
dispatch(THE_KEY_EVENT);
|
dispatch(THE_KEY_EVENT);
|
||||||
|
|
||||||
@ -94,14 +95,15 @@ public class InputHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT =
|
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
|
||||||
new ModifiableCursorMoveEvent();
|
|
||||||
|
|
||||||
static void handleMouseMoveInput(
|
static void handleMouseMoveInput(
|
||||||
long window,
|
long window,
|
||||||
double x, double y
|
double x,
|
||||||
|
double y
|
||||||
) {
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
|
return;
|
||||||
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
||||||
|
|
||||||
InputTracker.initializeCursorPosition(x, y);
|
InputTracker.initializeCursorPosition(x, y);
|
||||||
@ -127,15 +129,15 @@ public class InputHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT =
|
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
||||||
new ModifiableWheelScrollEvent();
|
|
||||||
|
|
||||||
static void handleWheelScroll(
|
static void handleWheelScroll(
|
||||||
long window,
|
long window,
|
||||||
double xoffset,
|
double xoffset,
|
||||||
double yoffset
|
double yoffset
|
||||||
) {
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
|
return;
|
||||||
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||||
dispatch(THE_WHEEL_SCROLL_EVENT);
|
dispatch(THE_WHEEL_SCROLL_EVENT);
|
||||||
}
|
}
|
||||||
@ -155,8 +157,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ModifiableFrameResizeEvent THE_FRAME_RESIZE_EVENT =
|
private static final ModifiableFrameResizeEvent THE_FRAME_RESIZE_EVENT = new ModifiableFrameResizeEvent();
|
||||||
new ModifiableFrameResizeEvent();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import glm.vec._2.d.Vec2d;
|
import glm.vec._2.d.Vec2d;
|
||||||
@ -24,12 +25,14 @@ import gnu.trove.set.hash.TIntHashSet;
|
|||||||
public class InputTracker {
|
public class InputTracker {
|
||||||
|
|
||||||
private static final Vec2d CURSOR_POSITION = new Vec2d(
|
private static final Vec2d CURSOR_POSITION = new Vec2d(
|
||||||
Double.NaN, Double.NaN
|
Double.NaN,
|
||||||
|
Double.NaN
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
||||||
|
|
||||||
private InputTracker() {}
|
private InputTracker() {
|
||||||
|
}
|
||||||
|
|
||||||
public static double getCursorX() {
|
public static double getCursorX() {
|
||||||
return CURSOR_POSITION.x;
|
return CURSOR_POSITION.x;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -27,7 +28,8 @@ import ru.windcorp.progressia.client.graphics.GUI;
|
|||||||
|
|
||||||
class LWJGLInitializer {
|
class LWJGLInitializer {
|
||||||
|
|
||||||
private LWJGLInitializer() {}
|
private LWJGLInitializer() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
checkEnvironment();
|
checkEnvironment();
|
||||||
@ -90,12 +92,16 @@ class LWJGLInitializer {
|
|||||||
private static void setupWindowCallbacks() {
|
private static void setupWindowCallbacks() {
|
||||||
long handle = GraphicsBackend.getWindowHandle();
|
long handle = GraphicsBackend.getWindowHandle();
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(handle,
|
glfwSetFramebufferSizeCallback(
|
||||||
GraphicsBackend::onFrameResized);
|
handle,
|
||||||
|
GraphicsBackend::onFrameResized
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
||||||
glfwSetMouseButtonCallback(handle,
|
glfwSetMouseButtonCallback(
|
||||||
InputHandler::handleMouseButtonInput);
|
handle,
|
||||||
|
InputHandler::handleMouseButtonInput
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import java.lang.ref.PhantomReference;
|
import java.lang.ref.PhantomReference;
|
||||||
@ -33,14 +34,18 @@ public class OpenGLObjectTracker {
|
|||||||
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
||||||
|
|
||||||
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
||||||
GLPhantomReference<OpenGLDeletable> glRef =
|
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(
|
||||||
new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(), glDeleter);
|
object,
|
||||||
|
DELETE_QUEUE,
|
||||||
|
object.getHandle(),
|
||||||
|
glDeleter
|
||||||
|
);
|
||||||
TO_DELETE.add(glRef);
|
TO_DELETE.add(glRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteAllObjects() {
|
public static void deleteAllObjects() {
|
||||||
for (GLPhantomReference<OpenGLDeletable> glRef
|
for (
|
||||||
: TO_DELETE
|
GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE
|
||||||
) {
|
) {
|
||||||
glRef.clear();
|
glRef.clear();
|
||||||
}
|
}
|
||||||
@ -66,20 +71,24 @@ public class OpenGLObjectTracker {
|
|||||||
/**
|
/**
|
||||||
* Creates a new phantom reference that refers to the given object and
|
* Creates a new phantom reference that refers to the given object and
|
||||||
* is registered with the given queue.
|
* is registered with the given queue.
|
||||||
*
|
* <p>
|
||||||
* <p> It is possible to create a phantom reference with a {@code null}
|
* It is possible to create a phantom reference with a {@code null}
|
||||||
* queue, but such a reference is completely useless: Its {@code get}
|
* queue, but such a reference is completely useless: Its {@code get}
|
||||||
* method will always return {@code null} and, since it does not have a queue,
|
* method will always return {@code null} and, since it does not have a
|
||||||
|
* queue,
|
||||||
* it will never be enqueued.
|
* it will never be enqueued.
|
||||||
*
|
*
|
||||||
* @param referent the object the new phantom reference will refer to
|
* @param referent the object the new phantom reference will refer to
|
||||||
* @param q the queue with which the reference is to be registered,
|
* @param q the queue with which the reference is to be
|
||||||
|
* registered,
|
||||||
* or {@code null} if registration is not required
|
* or {@code null} if registration is not required
|
||||||
*/
|
*/
|
||||||
public GLPhantomReference(T referent,
|
public GLPhantomReference(
|
||||||
|
T referent,
|
||||||
ReferenceQueue<? super T> q,
|
ReferenceQueue<? super T> q,
|
||||||
int referentGLhandle,
|
int referentGLhandle,
|
||||||
IntConsumer GLDeleter) {
|
IntConsumer GLDeleter
|
||||||
|
) {
|
||||||
super(referent, q);
|
super(referent, q);
|
||||||
this.referentGLhandle = referentGLhandle;
|
this.referentGLhandle = referentGLhandle;
|
||||||
this.GLDeleter = GLDeleter;
|
this.GLDeleter = GLDeleter;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import ru.windcorp.jputil.functions.ThrowingRunnable;
|
import ru.windcorp.jputil.functions.ThrowingRunnable;
|
||||||
@ -22,8 +23,7 @@ import ru.windcorp.progressia.common.util.TaskQueue;
|
|||||||
|
|
||||||
public class RenderTaskQueue {
|
public class RenderTaskQueue {
|
||||||
|
|
||||||
private static final TaskQueue HANDLER =
|
private static final TaskQueue HANDLER = new TaskQueue(GraphicsInterface::isRenderThread);
|
||||||
new TaskQueue(GraphicsInterface::isRenderThread);
|
|
||||||
|
|
||||||
public static void schedule(Runnable task) {
|
public static void schedule(Runnable task) {
|
||||||
HANDLER.schedule(task);
|
HANDLER.schedule(task);
|
||||||
@ -43,7 +43,9 @@ public class RenderTaskQueue {
|
|||||||
|
|
||||||
public static <E extends Exception> void waitAndInvoke(
|
public static <E extends Exception> void waitAndInvoke(
|
||||||
ThrowingRunnable<E> task
|
ThrowingRunnable<E> task
|
||||||
) throws InterruptedException, E {
|
)
|
||||||
|
throws InterruptedException,
|
||||||
|
E {
|
||||||
HANDLER.waitAndInvoke(task);
|
HANDLER.waitAndInvoke(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
|
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.resource.Resource;
|
import ru.windcorp.progressia.common.resource.Resource;
|
||||||
@ -61,8 +62,7 @@ public class CombinedShader extends Shader {
|
|||||||
String contents = resource.readAsString();
|
String contents = resource.readAsString();
|
||||||
|
|
||||||
int versionIndex;
|
int versionIndex;
|
||||||
for (versionIndex = 0; versionIndex < contents.length(); ++versionIndex)
|
for (versionIndex = 0; versionIndex < contents.length(); ++versionIndex) {
|
||||||
{
|
|
||||||
if (!Character.isWhitespace(contents.codePointAt(versionIndex)))
|
if (!Character.isWhitespace(contents.codePointAt(versionIndex)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -71,12 +71,14 @@ public class CombinedShader extends Shader {
|
|||||||
if (contents.codePointAt(versionIndex) == '#') {
|
if (contents.codePointAt(versionIndex) == '#') {
|
||||||
final String versionAnnotation = "#version ";
|
final String versionAnnotation = "#version ";
|
||||||
|
|
||||||
if (contents.regionMatches(
|
if (
|
||||||
|
contents.regionMatches(
|
||||||
versionIndex,
|
versionIndex,
|
||||||
versionAnnotation,
|
versionAnnotation,
|
||||||
0,
|
0,
|
||||||
versionAnnotation.length()
|
versionAnnotation.length()
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
contents = contents.substring(
|
contents = contents.substring(
|
||||||
versionIndex
|
versionIndex
|
||||||
+ versionAnnotation.length()
|
+ versionAnnotation.length()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -58,6 +59,8 @@ public class Program implements OpenGLDeletable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHandle() { return handle; }
|
public int getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -47,10 +48,14 @@ public class Shader implements OpenGLDeletable {
|
|||||||
public static ShaderType guessByResourceName(String resource) {
|
public static ShaderType guessByResourceName(String resource) {
|
||||||
resource = resource.toLowerCase(Locale.ENGLISH);
|
resource = resource.toLowerCase(Locale.ENGLISH);
|
||||||
|
|
||||||
if (resource.contains("vertex")) return VERTEX;
|
if (resource.contains("vertex"))
|
||||||
if (resource.contains("fragment")) return FRAGMENT;
|
return VERTEX;
|
||||||
if (resource.contains("vsh")) return VERTEX;
|
if (resource.contains("fragment"))
|
||||||
if (resource.contains("fsh")) return FRAGMENT;
|
return FRAGMENT;
|
||||||
|
if (resource.contains("vsh"))
|
||||||
|
return VERTEX;
|
||||||
|
if (resource.contains("fsh"))
|
||||||
|
return FRAGMENT;
|
||||||
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Cannot deduce shader type from resource name \"" +
|
"Cannot deduce shader type from resource name \"" +
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -51,63 +52,102 @@ public class AttributeVertexArray extends Attribute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, boolean normalized, int stride,
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
ByteBuffer pointer
|
ByteBuffer pointer
|
||||||
) {
|
) {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, GL_BYTE, normalized, stride, pointer
|
size,
|
||||||
|
GL_BYTE,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, boolean normalized, int stride,
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
FloatBuffer pointer
|
FloatBuffer pointer
|
||||||
) {
|
) {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, GL_FLOAT, normalized, stride, pointer
|
size,
|
||||||
|
GL_FLOAT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, boolean normalized, int stride,
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
IntBuffer pointer
|
IntBuffer pointer
|
||||||
) {
|
) {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, GL_INT, normalized, stride, pointer
|
size,
|
||||||
|
GL_INT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, boolean normalized, int stride,
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
ShortBuffer pointer
|
ShortBuffer pointer
|
||||||
) {
|
) {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, GL_SHORT, normalized, stride, pointer
|
size,
|
||||||
|
GL_SHORT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, int type, boolean normalized, int stride,
|
int size,
|
||||||
|
int type,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
long pointer
|
long pointer
|
||||||
) {
|
) {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, type, normalized, stride, pointer
|
size,
|
||||||
|
type,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(
|
public void set(
|
||||||
int size, int type, boolean normalized, int stride,
|
int size,
|
||||||
VertexBufferObject vbo, long offset
|
int type,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
VertexBufferObject vbo,
|
||||||
|
long offset
|
||||||
) {
|
) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
handle,
|
handle,
|
||||||
size, type, normalized, stride, offset
|
size,
|
||||||
|
type,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
offset
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************
|
/*
|
||||||
* Progressia
|
* Progressia
|
||||||
* Copyright (C) 2020 Wind Corporation
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -14,7 +14,8 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*******************************************************************************/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user