diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 55aed6a..62baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ on: jobs: build: - uses: sentrysoftware/workflows/.github/workflows/maven-build.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-build.yml@v2 with: jdkVersion: "17" debug: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5a72abb..cf17156 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,7 +10,7 @@ on: jobs: deploy: - uses: sentrysoftware/workflows/.github/workflows/maven-central-deploy.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-central-deploy.yml@v2 with: jdkVersion: "17" secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14d640c..ba8ec25 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ on: jobs: release: - uses: sentrysoftware/workflows/.github/workflows/maven-central-release.yml@v3 + uses: metricshub/workflows/.github/workflows/maven-central-release.yml@v2 with: releaseVersion: ${{ inputs.releaseVersion }} developmentVersion: ${{ inputs.developmentVersion }} diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..e2556a1 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,12 @@ +overrides: +- files: + - "**/*.java" + options: + trailingComma: none + useTabs: true + tabWidth: 2 + semi: false + singleQuote: false + printWidth: 120 + arrowParens: avoid + endOfLine: auto \ No newline at end of file diff --git a/README.md b/README.md index d10aaff..6593df0 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # TableJoin Utility -![GitHub release (with filter)](https://img.shields.io/github/v/release/sentrysoftware/tablejoin) -![Build](https://img.shields.io/github/actions/workflow/status/sentrysoftware/tablejoin/deploy.yml) -![GitHub top language](https://img.shields.io/github/languages/top/sentrysoftware/tablejoin) -![License](https://img.shields.io/github/license/sentrysoftware/tablejoin) +![GitHub release (with filter)](https://img.shields.io/github/v/release/metricshub/tablejoin) +![Build](https://img.shields.io/github/actions/workflow/status/metricshub/tablejoin/deploy.yml) +![GitHub top language](https://img.shields.io/github/languages/top/metricshub/tablejoin) +![License](https://img.shields.io/github/license/metricshub/tablejoin) The TableJoin utility is designed for joining tables expressed in CSV or structed as list of String lists. It enhances the flexibility of data processing by allowing developers to perform joint operations on specified tables. -See [Project Documentation](https://sentrysoftware.org/tablejoin/) and the [Javadoc](https://sentrysoftware.org/tablejoin/apidocs/) for more information on how to use this library in your code. +See [Project Documentation](https://metricshub.org/tablejoin/) and the [Javadoc](https://metricshub.org/tablejoin/apidocs/) for more information on how to use this library in your code. ## Build instructions diff --git a/checkstyle.xml b/checkstyle.xml index 2098fe6..0dea1e6 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,65 +1,22 @@ + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" + "https://checkstyle.org/dtds/configuration_1_3.dtd"> - - - - - - - - - - - - - - - - - - - - + + + - - - - + + @@ -71,24 +28,22 @@ + + + + + + - - - - @@ -96,127 +51,131 @@ - + + + - - - - - - - - - - - - - - - - - - - - - + - - - - - - + + + + - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - - + + - + + + - - - - - - - - - - - - - - - - - - - + + + + - - - - - - + - + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index dee4576..1c5a6b4 100644 --- a/pom.xml +++ b/pom.xml @@ -2,12 +2,11 @@ 4.0.0 - org.sentrysoftware + org.metricshub oss-parent 2 - org.sentrysoftware tablejoin 1.1.00-SNAPSHOT @@ -15,11 +14,11 @@ TableJoin Utility for Java - Sentry Software - https://sentrysoftware.com + MetricsHub + https://metricshub.com - https://sentrysoftware.org/tablejoin + https://metricshub.org/tablejoin 2023 @@ -32,33 +31,26 @@ GitHub - https://github.com/sentrysoftware/tablejoin/issues/ + https://github.com/metricshub/tablejoin/issues/ - scm:git:https://github.com/sentrysoftware/tablejoin.git - https://github.com/sentrysoftware/tablejoin + scm:git:https://github.com/metricshub/tablejoin.git + https://github.com/metricshub/tablejoin HEAD Bertrand Martin (@bertysentry) - bertrand@sentrysoftware.com + bertrand@metricshub.com maintainer Nassim BOUTEKEDJIRET (@NassimBtk) - nassim@sentrysoftware.com - - maintainer - - - - Kawtar Bakour (@KawtarBK9) - kawtar@sentrysoftware.com + nassim@metricshub.com maintainer @@ -106,6 +98,34 @@ + + + + + com.hubspot.maven.plugins + prettier-maven-plugin + 0.21 + + 2.5.0 + false + false + + src/main/java/**/*.java + src/test/java/**/*.java + + + + + validate + + check + + + + + + + diff --git a/src/main/java/org/sentrysoftware/tablejoin/TableJoin.java b/src/main/java/org/metricshub/tablejoin/TableJoin.java similarity index 81% rename from src/main/java/org/sentrysoftware/tablejoin/TableJoin.java rename to src/main/java/org/metricshub/tablejoin/TableJoin.java index 86d7e8f..cc85f65 100644 --- a/src/main/java/org/sentrysoftware/tablejoin/TableJoin.java +++ b/src/main/java/org/metricshub/tablejoin/TableJoin.java @@ -1,8 +1,10 @@ +package org.metricshub.tablejoin; + /*- * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ * TableJoin Utility * ჻჻჻჻჻჻ - * Copyright (C) 2023 Sentry Software + * Copyright (C) 2023 - 2025 MetricsHub * ჻჻჻჻჻჻ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +19,9 @@ * limitations under the License. * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ */ -package org.sentrysoftware.tablejoin; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,9 +38,7 @@ */ public class TableJoin { - private TableJoin() { - - } + private TableJoin() {} /** * Joins to CSV-formatted tables (Strings) as an SQL JOIN statement would (INNER or LEFT JOIN) @@ -66,15 +64,15 @@ private TableJoin() { * When one of the arguments prevents the operation from working safely */ public static String join( - final String leftTable, - final String rightTable, - final int leftKeyColumnNumber, - final int rightKeyColumnNumber, - final String separator, - final String defaultRightLine, - final boolean wbemKeyType, - final boolean caseInsensitive) throws IllegalArgumentException { - + final String leftTable, + final String rightTable, + final int leftKeyColumnNumber, + final int rightKeyColumnNumber, + final String separator, + final String defaultRightLine, + final boolean wbemKeyType, + final boolean caseInsensitive + ) throws IllegalArgumentException { if (separator == null || "".equals(separator)) { throw new IllegalArgumentException("Separator cannot be null or empty"); } @@ -85,13 +83,14 @@ public static String join( final List defaultRightLineList = lineToList(defaultRightLine, ";"); final List> result = join( - leftTableList, - rightTableList, - leftKeyColumnNumber, - rightKeyColumnNumber, - defaultRightLineList, - wbemKeyType, - caseInsensitive); + leftTableList, + rightTableList, + leftKeyColumnNumber, + rightKeyColumnNumber, + defaultRightLineList, + wbemKeyType, + caseInsensitive + ); return tableToString(result, separator); } @@ -110,12 +109,10 @@ public static String join( protected static String tableToString(final List> table, final String separator) { if (table != null) { return table - .stream() - .filter(Objects::nonNull) - .map(line -> line - .stream() - .collect(Collectors.joining(separator)) + separator) - .collect(Collectors.joining("\n")); + .stream() + .filter(Objects::nonNull) + .map(line -> line.stream().collect(Collectors.joining(separator)) + separator) + .collect(Collectors.joining("\n")); } return null; } @@ -136,10 +133,10 @@ protected static String tableToString(final List> table, final Stri public static List> stringToTable(final String csvTable, final String separator) { if (csvTable != null) { return Stream - .of(csvTable.split("\n")) - .map(line -> lineToList(line, separator)) - .filter(line -> !line.isEmpty()) - .collect(Collectors.toList()); + .of(csvTable.split("\n")) + .map(line -> lineToList(line, separator)) + .filter(line -> !line.isEmpty()) + .collect(Collectors.toList()); } return null; } @@ -155,16 +152,12 @@ public static List> stringToTable(final String csvTable, final Stri */ public static List lineToList(String line, final String separator) { if (line != null && !line.isEmpty()) { - // Make sure the line ends with the separator line = !line.endsWith(separator) ? line + separator : line; // Make sure we don't change the integrity of the line with the split in case of empty cells final String[] split = line.split(separator, -1); - return Stream - .of(split) - .limit(split.length - 1L) - .collect(Collectors.toList()); + return Stream.of(split).limit(split.length - 1L).collect(Collectors.toList()); } return new ArrayList<>(); } @@ -192,14 +185,24 @@ public static List lineToList(String line, final String separator) { * @throws IllegalArgumentException * When one of the arguments prevents the operation from working safely */ - public static List> join(final List> leftTable, final List> rightTable, - final int leftKeyColumnNumber, final int rightKeyColumnNumber, final List defaultRightLine, - final boolean wbemKeyType, final boolean caseInsensitive) throws IllegalArgumentException { - + public static List> join( + final List> leftTable, + final List> rightTable, + final int leftKeyColumnNumber, + final int rightKeyColumnNumber, + final List defaultRightLine, + final boolean wbemKeyType, + final boolean caseInsensitive + ) throws IllegalArgumentException { // Sanity check if (leftKeyColumnNumber < 1 || rightKeyColumnNumber < 1) { - throw new IllegalArgumentException("Invalid key column number (leftKeyColumnNumber=" + leftKeyColumnNumber - + ", rightKeyColumnNumber=" + rightKeyColumnNumber + ")"); + throw new IllegalArgumentException( + "Invalid key column number (leftKeyColumnNumber=" + + leftKeyColumnNumber + + ", rightKeyColumnNumber=" + + rightKeyColumnNumber + + ")" + ); } if (leftTable == null) { @@ -216,32 +219,38 @@ public static List> join(final List> leftTable, final // Initialize the lookup table (a hash map) if (null != rightTable) { - - rightTableLookup = rightTable + rightTableLookup = + rightTable .stream() .filter(line -> rightKeyColumnNumber <= line.size()) - .collect(Collectors.toMap( + .collect( + Collectors.toMap( line -> getKey(line, rightKeyColumnNumber, wbemKeyType, caseInsensitive), Function.identity(), - (oldValue, newValue) -> oldValue)); + (oldValue, newValue) -> oldValue + ) + ); } else { rightTableLookup = new HashMap<>(); } // Stream the left table, line by line return leftTable - .stream() - .filter(leftLine -> isValidLeftLine(leftKeyColumnNumber, leftLine)) - .map(leftLine -> joinLine( - leftLine, - leftKeyColumnNumber, - defaultRightLine, - wbemKeyType, - caseInsensitive, - handleDefaultRightLine, - rightTableLookup)) - .filter(line -> !line.isEmpty()) - .collect(Collectors.toList()); + .stream() + .filter(leftLine -> isValidLeftLine(leftKeyColumnNumber, leftLine)) + .map(leftLine -> + joinLine( + leftLine, + leftKeyColumnNumber, + defaultRightLine, + wbemKeyType, + caseInsensitive, + handleDefaultRightLine, + rightTableLookup + ) + ) + .filter(line -> !line.isEmpty()) + .collect(Collectors.toList()); } /** @@ -256,8 +265,12 @@ public static List> join(final List> leftTable, final * Whether the matching is done case insensitive * @return {@link String} value */ - public static String getKey(final List line, final int keyColumnNumber, final boolean wbemKeyType, - final boolean caseInsensitive) { + public static String getKey( + final List line, + final int keyColumnNumber, + final boolean wbemKeyType, + final boolean caseInsensitive + ) { // Extract the key column from the line String key = line.get(keyColumnNumber - 1); // Special key options @@ -284,9 +297,13 @@ public static String getKey(final List line, final int keyColumnNumber, * @return true if the left line matches the conditions above */ public static boolean isValidLeftLine(final int leftKeyColumnNumber, final List leftLine) { - return leftKeyColumnNumber <= leftLine.size() - && !leftLine.isEmpty() - && !leftLine.get(leftKeyColumnNumber - 1).isEmpty(); + // @formatter:off + // CHECKSTYLE:OFF + return ( + leftKeyColumnNumber <= leftLine.size() && !leftLine.isEmpty() && !leftLine.get(leftKeyColumnNumber - 1).isEmpty() + ); + // CHECKSTYLE:ON + // @formatter:on } /** @@ -309,10 +326,15 @@ public static boolean isValidLeftLine(final int leftKeyColumnNumber, final List< * The right table when each row is indexed by the right key * @return a line representation, i.e. {@link List} of {@link String} values */ - public static List joinLine(final List leftLine, final int leftKeyColumnNumber, - final List defaultRightLine, final boolean wbemKeyType, final boolean caseInsensitive, - final boolean handleDefaultRightLine, final Map> rightTableLookup) { - + public static List joinLine( + final List leftLine, + final int leftKeyColumnNumber, + final List defaultRightLine, + final boolean wbemKeyType, + final boolean caseInsensitive, + final boolean handleDefaultRightLine, + final Map> rightTableLookup + ) { // Extract the key column from the left line String leftKey = getKey(leftLine, leftKeyColumnNumber, wbemKeyType, caseInsensitive); @@ -326,22 +348,18 @@ public static List joinLine(final List leftLine, final int leftK // sometimes with the matching right line from the right table, and sometimes // with the default right line - return Stream.concat( - leftLine.stream(), - rightLine != null ? rightLine.stream() : defaultRightLine.stream()) - .collect(Collectors.toList()); - + return Stream + .concat(leftLine.stream(), rightLine != null ? rightLine.stream() : defaultRightLine.stream()) + .collect(Collectors.toList()); } else { // No default right line, which means that we first need to check whether the // key is present in the right table if (rightLine != null) { - return Stream.concat(leftLine.stream(), rightLine.stream()) - .collect(Collectors.toList()); + return Stream.concat(leftLine.stream(), rightLine.stream()).collect(Collectors.toList()); } return new ArrayList<>(); } - } /** @@ -352,7 +370,6 @@ public static List joinLine(final List leftLine, final int leftK * @return Re-ordered WBEM path */ private static String normalizeWbemReference(String wbemPath) { - // wbemPath is in the form below: // class.key1="value1",key2="value2" // Split the WBEM path to have the class and the list of key properties @@ -389,4 +406,3 @@ private static String normalizeWbemReference(String wbemPath) { return result.toString(); } } - diff --git a/src/site/resources/css/site.css b/src/site/resources/css/site.css new file mode 100644 index 0000000..b7690bc --- /dev/null +++ b/src/site/resources/css/site.css @@ -0,0 +1,86 @@ +/*- + * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ + * Open MetricsHub Web Site + * ჻჻჻჻჻჻ + * Copyright (C) 2025 MetricsHub + * ჻჻჻჻჻჻ + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ + */ + +/* Poppins font */ +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-ExtraBold.woff2') format('woff2'), + url('../fonts/Poppins-ExtraBold.woff') format('woff'), + url('../fonts/Poppins-ExtraBold.ttf') format('truetype'), + local('Helvetica'); + font-weight: 800; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-Bold.woff2') format('woff2'), + url('../fonts/Poppins-Bold.woff') format('woff'), + url('../fonts/Poppins-Bold.ttf') format('truetype'), + local('Helvetica'); + font-weight: 700; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Poppins'; + src: url('../fonts/Poppins-Regular.woff2') format('woff2'), + url('../fonts/Poppins-Regular.woff') format('woff'), + url('../fonts/Poppins-Regular.ttf') format('truetype'), + local('Helvetica'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +/* MetricsHub fonts */ +:root { + --title-font: "Poppins", sans-serif; + --heading-font: "Poppins", sans-serif; + --content-font: "Poppins", sans-serif; + + --content-font-size: medium; + --banner-font-size: 40px; + --banner-font-weight: 800; + +} + + /* MetricsHub colors */ +body { + --main-fgcolor: #212529; + --banner-bgcolor: #266fd0; + --link-color: #266fd0; + --alternate-bgcolor: #266fd0; + --alternate-fgcolor: #fff; +} + +body.dark { + --link-color: #7cb6ff; + --main-bgcolor: #262626; + --main-fgcolor: #e9ecef; +} \ No newline at end of file diff --git a/src/site/resources/favicon.ico b/src/site/resources/favicon.ico new file mode 100644 index 0000000..61a2a88 Binary files /dev/null and b/src/site/resources/favicon.ico differ diff --git a/src/site/resources/fonts/Poppins-Bold.ttf b/src/site/resources/fonts/Poppins-Bold.ttf new file mode 100644 index 0000000..00559ee Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.ttf differ diff --git a/src/site/resources/fonts/Poppins-Bold.woff b/src/site/resources/fonts/Poppins-Bold.woff new file mode 100644 index 0000000..c979105 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.woff differ diff --git a/src/site/resources/fonts/Poppins-Bold.woff2 b/src/site/resources/fonts/Poppins-Bold.woff2 new file mode 100644 index 0000000..13e0e28 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Bold.woff2 differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.ttf b/src/site/resources/fonts/Poppins-ExtraBold.ttf new file mode 100644 index 0000000..df70936 Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.ttf differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.woff b/src/site/resources/fonts/Poppins-ExtraBold.woff new file mode 100644 index 0000000..0d7982a Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.woff differ diff --git a/src/site/resources/fonts/Poppins-ExtraBold.woff2 b/src/site/resources/fonts/Poppins-ExtraBold.woff2 new file mode 100644 index 0000000..ad86d02 Binary files /dev/null and b/src/site/resources/fonts/Poppins-ExtraBold.woff2 differ diff --git a/src/site/resources/fonts/Poppins-Regular.ttf b/src/site/resources/fonts/Poppins-Regular.ttf new file mode 100644 index 0000000..9f0c71b Binary files /dev/null and b/src/site/resources/fonts/Poppins-Regular.ttf differ diff --git a/src/site/resources/fonts/Poppins-Regular.woff2 b/src/site/resources/fonts/Poppins-Regular.woff2 new file mode 100644 index 0000000..964d6d2 Binary files /dev/null and b/src/site/resources/fonts/Poppins-Regular.woff2 differ diff --git a/src/site/resources/images/metricshub-logo.png b/src/site/resources/images/metricshub-logo.png new file mode 100644 index 0000000..89d6fb8 Binary files /dev/null and b/src/site/resources/images/metricshub-logo.png differ diff --git a/src/site/resources/images/sentry-logo-179x75px.png b/src/site/resources/images/sentry-logo-179x75px.png deleted file mode 100644 index 42e53f7..0000000 Binary files a/src/site/resources/images/sentry-logo-179x75px.png and /dev/null differ diff --git a/src/site/site.xml b/src/site/site.xml index d5e15b4..bc6dc21 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -4,7 +4,7 @@ org.sentrysoftware.maven sentry-maven-skin - 6.2.00 + 6.4.01 @@ -13,14 +13,15 @@ - images/sentry-logo-179x75px.png - https://sentrysoftware.com + images/metricshub-logo.png + https://metricshub.org + diff --git a/src/test/java/org/metricshub/tablejoin/TableJoinTest.java b/src/test/java/org/metricshub/tablejoin/TableJoinTest.java new file mode 100644 index 0000000..67ec3b1 --- /dev/null +++ b/src/test/java/org/metricshub/tablejoin/TableJoinTest.java @@ -0,0 +1,319 @@ +package org.metricshub.tablejoin; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; + +class TableJoinTest { + + @Test + void exception() { + assertAll( + "IllegalArgumentException", + () -> + assertThrows( + IllegalArgumentException.class, + () -> TableJoin.join("", "", 0, 1, ";", null, false, true), + "leftKeyColumn < 1 is illegal" + ), + () -> + assertThrows( + IllegalArgumentException.class, + () -> TableJoin.join("", "", 1, 0, ";", null, false, true), + "rightKeyColumn < 1 is illegal" + ), + () -> + assertThrows( + IllegalArgumentException.class, + () -> TableJoin.join("", "", 1, 1, "", null, false, true), + "empty separator is illegal" + ), + () -> + assertThrows( + IllegalArgumentException.class, + () -> TableJoin.join("", "", 1, 1, null, null, false, true), + "null separator is illegal" + ) + ); + } + + @Test + void nullTable() { + assertNull(TableJoin.join(null, "", 1, 1, ";", null, false, true)); + } + + @Test + void emptyTable() { + assertAll( + "Empty Table", + () -> + assertEquals( + "", + TableJoin.join("", "", 1, 1, ";", null, false, true), + "Empty left table must give empty result" + ), + () -> + assertEquals( + "", + TableJoin.join("1;A", null, 1, 1, ";", null, false, true), + "null right table must give empty result" + ), + () -> + assertEquals( + "", + TableJoin.join("1;A", "", 1, 1, ";", null, false, true), + "empty right table with null default right line must give empty result" + ), + () -> + assertEquals( + "", + TableJoin.join("1;A", null, 1, 1, ";", "", false, true), + "null right table with empty default right line must give empty result" + ), + () -> + assertEquals( + "", + TableJoin.join("1;A", "", 1, 1, ";", "", false, true), + "empty right table with empty default right line must give empty result" + ) + ); + } + + @Test + void keyColumns() { + String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; + String rightTable = "1;A;i;Good;\n3;C;iii;Good;"; + String expectedResult = "1;A;i;1;A;i;Good;\n3;C;iii;3;C;iii;Good;"; + assertAll( + "Key Columns", + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 1, Should match" + ), + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 1, Should match" + ), + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 1, Should match" + ), + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 1, Should match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 1, 2, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 1, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 1, 3, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 3, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 2, 1, ";", null, false, true), + "leftKeyColumn = 2, rightKeyColumn = 1, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 2, 3, ";", null, false, true), + "leftKeyColumn = 2, rightKeyColumn = 3, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 3, 1, ";", null, false, true), + "leftKeyColumn = 3, rightKeyColumn = 1, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 3, 2, ";", null, false, true), + "leftKeyColumn = 3, rightKeyColumn = 2, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 100, 1, ";", null, false, true), + "leftKeyColumn = 100, rightKeyColumn = 1, Should not match" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 1, 100, ";", null, false, true), + "leftKeyColumn = 1, rightKeyColumn = 100, Should not match" + ) + ); + } + + @Test + void caseInsensitive() { + String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; + String rightTable = "1;a;I;Good;\n3;c;III;Good;"; + String expectedResult = "1;A;i;1;a;I;Good;\n3;C;iii;3;c;III;Good;"; + assertAll( + "Case Insensitive", + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, true), + "Should match despite case difference" + ), + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), + "Should match despite case difference" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, false), + "Should not match because of case difference" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, false), + "Should not match because of case difference" + ) + ); + } + + @Test + void defaultRightLine() { + String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; + String rightTable = "1;a;I;Good;\n3;c;III;Good;"; + String expectedResult = "1;A;i;1;a;I;Good;\n2;B;ii;default;right;line;\n3;C;iii;3;c;III;Good;"; + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 1, 1, ";", "default;right;line;", false, true), + "Should contain 3 lines because of default right line" + ); + } + + @Test + void wbemKeyType() { + String leftTable = + "class.prop1=\"1\",prop2=\"A\";i;\nclass.prop1=\"2\",prop2=\"B\";ii;\nclass.prop1=\"3\",prop2=\"C\";iii;"; + String rightTable = "class.prop2=\"A\",prop1=\"1\";i;\nclass.prop2=\"C\",prop1=\"3\";iii;"; + String expectedResult = + "class.prop1=\"1\",prop2=\"A\";i;class.prop2=\"A\",prop1=\"1\";i;\nclass.prop1=\"3\",prop2=\"C\";iii;class.prop2=\"C\",prop1=\"3\";iii;"; + assertAll( + "WBEM Key Type", + () -> + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 1, 1, ";", null, true, true), + "Should match despite different property order" + ), + () -> + assertEquals( + "", + TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), + "Should not match because of different property order" + ) + ); + } + + @Test + void emptyLines() { + String leftTable = "\n1;A;i;\n\n2;B;ii;\n\n\n3;C;iii;\n\n"; + String rightTable = "\n1;A;i;Good;\n\n3;C;iii;Good;\n\n"; + String expectedResult = "1;A;i;1;A;i;Good;\n3;C;iii;3;C;iii;Good;"; + assertEquals( + expectedResult, + TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), + "Empty lines should be discarded from both tables" + ); + } + + @Test + void testStringToTable() { + final String csvTable = "\n1;A;i;\n\n2;B;ii;\n\n\n3;C;iii;\n\n"; + assertEquals( + Stream + .of(Arrays.asList("1", "A", "i"), Arrays.asList("2", "B", "ii"), Arrays.asList("3", "C", "iii")) + .collect(Collectors.toList()), + TableJoin.stringToTable(csvTable, ";") + ); + + assertNull(TableJoin.stringToTable(null, ";")); + assertEquals(Collections.emptyList(), TableJoin.stringToTable("\n\n\n", ";")); + final List emptyCells = Arrays.asList("", ""); + assertEquals( + Stream.of(emptyCells, emptyCells, emptyCells).collect(Collectors.toList()), + TableJoin.stringToTable("\n;;\n;;\n;;", ";") + ); + assertEquals( + Stream.of(Arrays.asList("", "a"), emptyCells, emptyCells).collect(Collectors.toList()), + TableJoin.stringToTable("\n;a;\n;;\n;;", ";") + ); + } + + @Test + void testLineToList() { + assertEquals(Collections.emptyList(), TableJoin.lineToList(null, ";")); + assertEquals(Collections.emptyList(), TableJoin.lineToList("", ";")); + assertEquals(Arrays.asList(""), TableJoin.lineToList(";", ";")); + assertEquals(Arrays.asList("", "", "", "", "", ""), TableJoin.lineToList(";;;;;;", ";")); + assertEquals(Arrays.asList("", "", "a", "", "", ""), TableJoin.lineToList(";;a;;;;", ";")); + assertEquals(Collections.emptyList(), TableJoin.lineToList("", ";")); + + // Test for line that ends without the ";" separator + final List list = Arrays.asList("a", "b", "c"); + assertEquals(list, TableJoin.lineToList("a;b;c", ";")); + assertEquals(list, TableJoin.lineToList("a;b;c;", ";")); + } + + @Test + void testTableToString() { + assertEquals(null, TableJoin.tableToString(null, ";")); + assertEquals("", TableJoin.tableToString(Collections.emptyList(), ";")); + assertEquals( + ";;;;;;", + TableJoin.tableToString(Collections.singletonList(Arrays.asList("", "", "", "", "", "")), ";") + ); + assertEquals( + ";;;;;;\n;;;;;;", + TableJoin.tableToString( + Stream + .of(Arrays.asList("", "", "", "", "", ""), Arrays.asList("", "", "", "", "", "")) + .collect(Collectors.toList()), + ";" + ) + ); + assertEquals( + ";;a;;;;\n;;;a;;;", + TableJoin.tableToString( + Stream + .of(Arrays.asList("", "", "a", "", "", ""), Arrays.asList("", "", "", "a", "", "")) + .collect(Collectors.toList()), + ";" + ) + ); + } +} diff --git a/src/test/java/org/sentrysoftware/tablejoin/TableJoinTest.java b/src/test/java/org/sentrysoftware/tablejoin/TableJoinTest.java deleted file mode 100644 index fef2851..0000000 --- a/src/test/java/org/sentrysoftware/tablejoin/TableJoinTest.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.sentrysoftware.tablejoin; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.junit.jupiter.api.Test; - -class TableJoinTest { - - @Test - void exception() { - assertAll("IllegalArgumentException", - () -> assertThrows(IllegalArgumentException.class, () -> TableJoin.join("", "", 0, 1, ";", null, false, true), "leftKeyColumn < 1 is illegal"), - () -> assertThrows(IllegalArgumentException.class, () -> TableJoin.join("", "", 1, 0, ";", null, false, true), "rightKeyColumn < 1 is illegal"), - () -> assertThrows(IllegalArgumentException.class, () -> TableJoin.join("", "", 1, 1, "", null, false, true), "empty separator is illegal"), - () -> assertThrows(IllegalArgumentException.class, () -> TableJoin.join("", "", 1, 1, null, null, false, true), "null separator is illegal") - ); - } - - @Test - void nullTable() { - assertNull(TableJoin.join(null, "", 1, 1, ";", null, false, true)); - } - - @Test - void emptyTable() { - assertAll("Empty Table", - () -> assertEquals("", TableJoin.join("", "", 1, 1, ";", null, false, true), "Empty left table must give empty result"), - () -> assertEquals("", TableJoin.join("1;A", null, 1, 1, ";", null, false, true), "null right table must give empty result"), - () -> assertEquals("", TableJoin.join("1;A", "", 1, 1, ";", null, false, true), "empty right table with null default right line must give empty result"), - () -> assertEquals("", TableJoin.join("1;A", null, 1, 1, ";", "", false, true), "null right table with empty default right line must give empty result"), - () -> assertEquals("", TableJoin.join("1;A", "", 1, 1, ";", "", false, true), "empty right table with empty default right line must give empty result") - - ); - } - - @Test - void keyColumns() { - String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; - String rightTable = "1;A;i;Good;\n3;C;iii;Good;"; - String expectedResult = "1;A;i;1;A;i;Good;\n3;C;iii;3;C;iii;Good;"; - assertAll("Key Columns", - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 1, Should match"), - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 1, Should match"), - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 1, Should match"), - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 1, Should match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 1, 2, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 1, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 1, 3, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 3, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 2, 1, ";", null, false, true), "leftKeyColumn = 2, rightKeyColumn = 1, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 2, 3, ";", null, false, true), "leftKeyColumn = 2, rightKeyColumn = 3, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 3, 1, ";", null, false, true), "leftKeyColumn = 3, rightKeyColumn = 1, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 3, 2, ";", null, false, true), "leftKeyColumn = 3, rightKeyColumn = 2, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 100, 1, ";", null, false, true), "leftKeyColumn = 100, rightKeyColumn = 1, Should not match"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 1, 100, ";", null, false, true), "leftKeyColumn = 1, rightKeyColumn = 100, Should not match") - ); - } - - @Test - void caseInsensitive() { - String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; - String rightTable = "1;a;I;Good;\n3;c;III;Good;"; - String expectedResult = "1;A;i;1;a;I;Good;\n3;C;iii;3;c;III;Good;"; - assertAll("Case Insensitive", - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, true), "Should match despite case difference"), - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, true), "Should match despite case difference"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 2, 2, ";", null, false, false), "Should not match because of case difference"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 3, 3, ";", null, false, false), "Should not match because of case difference") - ); - } - - @Test - void defaultRightLine() { - String leftTable = "1;A;i;\n2;B;ii;\n3;C;iii;"; - String rightTable = "1;a;I;Good;\n3;c;III;Good;"; - String expectedResult = "1;A;i;1;a;I;Good;\n2;B;ii;default;right;line;\n3;C;iii;3;c;III;Good;"; - assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 1, 1, ";", "default;right;line;", false, true), "Should contain 3 lines because of default right line"); - } - - @Test - void wbemKeyType() { - String leftTable = "class.prop1=\"1\",prop2=\"A\";i;\nclass.prop1=\"2\",prop2=\"B\";ii;\nclass.prop1=\"3\",prop2=\"C\";iii;"; - String rightTable = "class.prop2=\"A\",prop1=\"1\";i;\nclass.prop2=\"C\",prop1=\"3\";iii;"; - String expectedResult = "class.prop1=\"1\",prop2=\"A\";i;class.prop2=\"A\",prop1=\"1\";i;\nclass.prop1=\"3\",prop2=\"C\";iii;class.prop2=\"C\",prop1=\"3\";iii;"; - assertAll("WBEM Key Type", - () -> assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 1, 1, ";", null, true, true), "Should match despite different property order"), - () -> assertEquals("", TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), "Should not match because of different property order") - ); - } - - @Test - void emptyLines() { - String leftTable = "\n1;A;i;\n\n2;B;ii;\n\n\n3;C;iii;\n\n"; - String rightTable = "\n1;A;i;Good;\n\n3;C;iii;Good;\n\n"; - String expectedResult = "1;A;i;1;A;i;Good;\n3;C;iii;3;C;iii;Good;"; - assertEquals(expectedResult, TableJoin.join(leftTable, rightTable, 1, 1, ";", null, false, true), "Empty lines should be discarded from both tables"); - } - - @Test - void testStringToTable() { - final String csvTable = "\n1;A;i;\n\n2;B;ii;\n\n\n3;C;iii;\n\n"; - assertEquals( - Stream - .of( - Arrays.asList("1", "A", "i"), - Arrays.asList("2", "B", "ii"), - Arrays.asList("3", "C", "iii") - ) - .collect(Collectors.toList()), - TableJoin.stringToTable(csvTable, ";") - ); - - assertNull(TableJoin.stringToTable(null, ";")); - assertEquals(Collections.emptyList(), TableJoin.stringToTable("\n\n\n", ";")); - final List emptyCells = Arrays.asList("", ""); - assertEquals(Stream.of(emptyCells, emptyCells, emptyCells).collect(Collectors.toList()), TableJoin.stringToTable("\n;;\n;;\n;;", ";")); - assertEquals( - Stream - .of( - Arrays.asList("", "a"), - emptyCells, - emptyCells - ) - .collect(Collectors.toList() - ), - TableJoin.stringToTable("\n;a;\n;;\n;;", ";") - ); - } - - @Test - void testLineToList() { - assertEquals(Collections.emptyList(), TableJoin.lineToList(null, ";")); - assertEquals(Collections.emptyList(), TableJoin.lineToList("", ";")); - assertEquals(Arrays.asList(""), TableJoin.lineToList(";", ";")); - assertEquals(Arrays.asList("", "", "", "", "", ""), TableJoin.lineToList(";;;;;;", ";")); - assertEquals(Arrays.asList("","","a", "", "", ""), TableJoin.lineToList(";;a;;;;", ";")); - assertEquals(Collections.emptyList(), TableJoin.lineToList("", ";")); - - // Test for line that ends without the ";" separator - final List list = Arrays.asList("a","b","c"); - assertEquals(list, TableJoin.lineToList("a;b;c", ";")); - assertEquals(list, TableJoin.lineToList("a;b;c;", ";")); - } - - @Test - void testTableToString() { - assertEquals(null, TableJoin.tableToString(null, ";")); - assertEquals("", TableJoin.tableToString(Collections.emptyList(), ";")); - assertEquals( - ";;;;;;", - TableJoin.tableToString(Collections.singletonList(Arrays.asList("", "", "", "", "", "")), ";") - ); - assertEquals( - ";;;;;;\n;;;;;;", - TableJoin.tableToString( - Stream.of( - Arrays.asList("", "", "", "", "", ""), - Arrays.asList("", "", "", "", "", "") - ) - .collect(Collectors.toList()), - ";" - ) - ); - assertEquals(";;a;;;;\n;;;a;;;", - TableJoin.tableToString( - Stream.of( - Arrays.asList("", "", "a", "", "", ""), - Arrays.asList("", "", "", "a", "", "")) - .collect(Collectors.toList()), - ";" - ) - ); - } -} \ No newline at end of file