Skip to content

Commit

Permalink
Update 0.6.0 see changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
cassandrus committed Jan 24, 2024
1 parent 5c1c217 commit caf7e0f
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 15 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/gradle-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Gradle Package

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
junit-tests:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: JDK 21 / Setup
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Gradle / Task (Build)
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.5
arguments: build
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.6.0

- Added more features to RegEx engine
- Added github workflow
- Updated baseline JDK -> 21

### 0.5.0

- Added Strings.toHexString(bytes[]) method
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Java Commons

[![JDK version](https://img.shields.io/badge/Java-20-green.svg)](https://shields.io/)
[![JDK version](https://img.shields.io/badge/Java-21-green.svg)](https://shields.io/)
[![License](https://img.shields.io/badge/License-Apache%202.0-brown.svg)](https://shields.io/)

* Discuss in
Expand All @@ -17,7 +17,7 @@ Deplant projects. It can be used independently if needed.

```groovy
dependencies {
implementation 'tech.deplant.commons:commons-core:0.5.0'
implementation 'tech.deplant.commons:commons-core:0.6.0'
}
```

Expand All @@ -28,6 +28,6 @@ dependencies {
<dependency>
<groupId>tech.deplant.commons</groupId>
<artifactId>commons-core</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
</dependency>
```
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,39 @@ java {
}

tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_20
targetCompatibility = JavaVersion.VERSION_20
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(20)
languageVersion = JavaLanguageVersion.of(21)
}
options.compilerArgs += "--enable-preview"
}

tasks.withType(JavaExec).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(20)
languageVersion = JavaLanguageVersion.of(21)
}
jvmArgs += "--enable-preview"
}

tasks.withType(Test) {
useJUnitPlatform()
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(20)
languageVersion = JavaLanguageVersion.of(21)
}
jvmArgs += "--enable-preview"
}

tasks.withType(Javadoc).configureEach {
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(20)
languageVersion = JavaLanguageVersion.of(21)
}
failOnError false
options.addBooleanOption('html5', true)
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
options.addBooleanOption('-enable-preview', true)
options.addStringOption('-release', '20')
options.addStringOption('-release', '21')
options.addBooleanOption('-ignore-source-errors', true)
options.addStringOption('Xdoclint:none', '-quiet')
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.java.installations.fromEnv=JAVA_HOME
org.gradle.java.installations.auto-detect=true
org.gradle.java.installations.auto-download=false
# product version
v_version=0.5.0
v_version=0.6.0
# dependencies
junitVersion=5.9.1
# publishing
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
28 changes: 28 additions & 0 deletions src/main/java/tech/deplant/commons/regex/RegExpBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tech.deplant.commons.regex;

import tech.deplant.commons.Strings;

import java.util.Set;
import java.util.regex.Pattern;

Expand All @@ -16,4 +18,30 @@ default Pattern toPattern() {
return Pattern.compile(build());
}

default String substr(int startIndex, String source, int... groups) {
var newSource = Strings.substr(source, startIndex);
return substr(newSource, groups);
}

default String substr(int startIndex, int endIndex, String source, int... groups) {
var newSource = Strings.substr(source, startIndex, endIndex);
return substr(newSource, groups);
}

default String substr(String source, int... groups) {
var builder = new StringBuilder();

var matcher = toPattern().matcher(source);
if (!matcher.find()) {
return "";
}
if (groups.length == 0) {
return matcher.group();
}
for (int gr : groups) {
builder.append(matcher.group(gr));
}
return builder.toString();
}

}
11 changes: 11 additions & 0 deletions src/main/java/tech/deplant/commons/regex/Special.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ public record Special(String sym) implements RegExpBuilder {
public static Special LATIN_LOWER = new Special("a-z");
public static Special LATIN_UPPER = new Special("A-Z");
public static Special DIGIT = new Special("\\d");

public static Special NOT_DIGIT = new Special("\\D");
public static Special ALPHANUM = new Special("\\w");

public static Special NOT_ALPHANUM = new Special("\\W");

public static Special WHITESPACE = new Special("\\s");

public static Special NOT_WHITESPACE = new Special("\\S");

public static Special NUL = new Special("\\0");
public static Special ANY = new Special(".");
public static Special PLUS = new Special("+");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.deplant.commons.test.unit;
package tech.deplant.commons.test.unit.regexp;

import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tech.deplant.commons.test.unit.regexp;

import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import tech.deplant.commons.regex.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@Execution(ExecutionMode.CONCURRENT)
public class SpecialCharsTests {

@Test
public void digits_search_test() {
var expr = Special.DIGIT;
assertEquals("7", expr.substr("da dy7%uss8"));
assertEquals("8", expr.substr(6,"da dy7%uss8"));
}

@Test
public void not_digits_search_test() {
var expr = Special.NOT_DIGIT;
assertEquals("d", expr.substr("da dy7%uss8"));
assertEquals("%", expr.substr(6,"da dy7%uss8"));
}

@Test
public void alphanum_search_test() {
var expr = Special.ALPHANUM;
assertEquals("d", expr.substr("da dy7%uss8"));
assertEquals("u", expr.substr(6,"da dy7%uss8"));
}

@Test
public void not_alphanum_search_test() {
var expr = Special.NOT_ALPHANUM;
assertEquals(" ", expr.substr("da dy7%uss8"));
assertEquals("%", expr.substr(6,"da dy7%uss8"));
}

}

0 comments on commit caf7e0f

Please sign in to comment.