Skip to content

Commit

Permalink
javadoc/code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Nov 6, 2023
1 parent 6124a29 commit f0af7a9
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 46 deletions.
48 changes: 47 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<java.version>8</java.version>
<assertj.version>3.24.2</assertj.version>

<lombok.version>1.18.30</lombok.version>

<!-- just avoid some warnings -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -72,6 +74,12 @@
<version>2.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -109,6 +117,14 @@
</jdkToolchain>
<target>${java.version}</target>
<release>${java.version}</release>
<encoding>UTF-8</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand All @@ -130,7 +146,33 @@
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>

<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.20.0</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- <plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
Expand Down Expand Up @@ -242,6 +284,10 @@
<additionalOptions>
<additionalOption>-Xdoclint:none</additionalOption>
</additionalOptions>
<sourcepath>
${project.build.directory}/delombok
${project.build.directory}/generated-sources/apt
</sourcepath>
</configuration>
<executions>
<execution>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module org.meeuw.i18n.languages {
requires java.validation;
requires lombok;

exports org.meeuw.i18n.languages;
}
88 changes: 43 additions & 45 deletions src/main/java/org/meeuw/i18n/languages/LanguageCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Stream;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Getter;


/**
* A ISO 639-3 language code.
*/
@Getter
public class LanguageCode {

static final Map<String, LanguageCode> KNOWN;
Expand Down Expand Up @@ -41,12 +44,29 @@ public class LanguageCode {

}

/**
* The three-letter 639-3 identifier
*/
@Size(min = 3, max = 3)
@NotNull
private final String id;

/**
* Equivalent 639-2 identifier of the bibliographic applications
* code set, if there is one
*/
private final String part2B;

/**
* Equivalent 639-2 identifier of the terminology applications code
* set, if there is one
*/
private final String part2T;


/**
* Equivalent 639-1 identifier, if there is one
*/
@Size(min = 2, max = 2)
@NotNull
private final String part1;
Expand Down Expand Up @@ -76,67 +96,45 @@ private LanguageCode(
this.comment = comment;
}

/**
* Returns a stream of all known language codes.
*/
public static Stream<LanguageCode> stream() {
return KNOWN.values().stream();
}

public static Optional<LanguageCode> getByCode(String code) {
return Optional.ofNullable(KNOWN.get(code));
}

public static Optional<LanguageCode> getByPart1(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart1())).findFirst();
}

public static Optional<LanguageCode> getByPart2B(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart2B())).findFirst();
}

public static Optional<LanguageCode> getByPart2T(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart2T())).findFirst();
}


/**
* The three-letter 639-3 identifier
* Retrieves a {@link LanguageCode} by its three-letter identifier {@link #getId()}
*/
public String getId() {
return id;
public static Optional<LanguageCode> getByCode(String code) {
return Optional.ofNullable(KNOWN.get(code));
}



/**
* Equivalent 639-2 identifier of the bibliographic applications
* code set, if there is one
* Retrieves a {@link LanguageCode} by its Part1 code {@link #getPart1()}
*/
public String getPart2B() {
return part2B;
public static Optional<LanguageCode> getByPart1(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart1())).findFirst();
}

/**
* Equivalent 639-2 identifier of the terminology applications code
* set, if there is one
* Retrieves a {@link LanguageCode} by its Part2B code {@link #getPart2B()}
*/
public String getPart2T() {
return part2T;
public static Optional<LanguageCode> getByPart2B(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart2B())).findFirst();
}



/**
* Equivalent 639-1 identifier, if there is one
* Retrieves a {@link LanguageCode} by its Part2T code {@link #getPart2T()}
*/
public String getPart1() {
return part1;
}

public Type getLanguageType() {
return languageType;
}

public String getRefName() {
return refName;
public static Optional<LanguageCode> getByPart2T(String code) {
return KNOWN.values().stream().filter(i -> code.equals(i.getPart2T())).findFirst();
}

public String getComment() {
return comment;
}


@Override
public String toString() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/meeuw/i18n/languages/Scope.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.meeuw.i18n.languages;

/**
* The 'scope' of the language as defined in ISO-639-3
*/
public enum Scope {

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/meeuw/i18n/languages/Type.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.meeuw.i18n.languages;


/**
* The 'type' of the language as defined in ISO-639-3
*/
public enum Type {
/**
* Ancient
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/meeuw/i18n/languages/LanguageCodeTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
package org.meeuw.i18n.languages;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;

@SuppressWarnings("OptionalGetWithoutIsPresent")
class LanguageCodeTest {

@Test
public void stream() {
LanguageCode.stream().forEach(System.out::println);
}

@Test
public void get() {
assertThat(LanguageCode.getByCode("nld").get().getRefName()).isEqualTo("Dutch");
}

@Test
public void getByPart1() {
assertThat(LanguageCode.getByPart1("nl").get().getRefName()).isEqualTo("Dutch");
}

@Test
public void getByPart2T() {
assertThat(LanguageCode.getByPart2T("nld").get().getRefName()).isEqualTo("Dutch");
}

@Test
public void getByPart2B() {
assertThat(LanguageCode.getByPart2B("dut").get().getRefName()).isEqualTo("Dutch");
}

@Test
public void getUnknown() {
assertThat(LanguageCode.getByCode("doesntexist")).isEmpty();
}



}

0 comments on commit f0af7a9

Please sign in to comment.