Skip to content

Commit

Permalink
Released 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis committed Nov 18, 2018
1 parent df8ee58 commit 5e7ab62
Show file tree
Hide file tree
Showing 169 changed files with 8,326 additions and 7,443 deletions.
90 changes: 90 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
# Changelog

## 1.3.0 _(2018-11-18)_

**io.bytes**
- Removed _UncheckedInputStream_ and _UncheckedOutputStream_ classes

**io.chars**
- Removed _UncheckedReader_ and _UncheckedWriter_ classes

**io.lines**
- Removed _UncheckedLineReader_ and _UncheckedLineWriter_ classes

**lang.Strings**
- Added _containsIgnoreCase()_, _startsWithIgnoreCase()_ and _endsWithIgnoreCase()_ methods
- Added the _frequency()_ method
- Renamed the _isHex()_ method to _isHexadecimal()_

**lang.array.BooleanArrays**
- Added the _frequency()_ method

**lang.array.ByteArrays**
- Added the _frequency()_ method

**lang.array.CharArrays**
- Added the _frequency()_ method

**lang.array.DoubleArrays**
- Added the _frequency()_ method

**lang.array.FloatArrays**
- Added the _frequency()_ method

**lang.array.IntArrays**
- Added the _frequency()_ method

**lang.array.LongArrays**
- Added the _frequency()_ method

**lang.array.ObjectArrays**
- Added the _frequency()_ method

**lang.array.ShortArrays**
- Added the _frequency()_ method

**misc.BloomFilter**
- Renamed the _calculateOptionalNumberOfHashFunctions()_ method to _calculateOptimalNumberOfHashFunctions()_

**misc.StringFormatter**
- Added the _DEFAULT_ attribute
- Added the _toString()_ method

**misc.distances.LevenshteinDistance**
- Added the _DEFAULT_ attribute

**misc.quality**
- Added _Ensure_, _Equals_, _HashCode_ and _ToString_ classes

**misc.trees.TreeNode**
- Renamed the _parent()_ method to _optionalParent()_

**misc.tuples.Pair**
- Removed _toMutableEntry()_ and _toImmutableEntry()_ methods

**util.Comparators**
- Added the _normalize()_ method
- Removed _ARRAYS_ attributes
- Removed _array()_ methods

**util.collection.Lists**
- Renamed the _getFirst()_ method to _getOptionalFirst()_
- Renamed the _getLast()_ method to _getOptionalLast()_
- Added _concat()_ and _join()_ methods

**util.collection.Maps**
- Renamed the _ofEntriesOrdered()_ method to _ofOrdered()_

**util.collection.Sets**
- Added _union()_ and _intersect()_ methods

**util.function**
- Added the _Functions_ class

**util.iteration.Iterables**
- Renamed the _getFirst()_ method to _getOptionalFirst()_
- Renamed the _getLast()_ method to _getOptionalLast()_

**util.iteration.Iterables**
- Renamed the _getFirst()_ method to _getOptionalFirst()_
- Renamed the _getLast()_ method to _getOptionalLast()_


## 1.2.0 _(2018-09-09)_

**crypto**
Expand Down
53 changes: 23 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ To include and use Javanilla, you need to add the following dependency into your
<dependency>
<groupId>com.github.alexisjehan</groupId>
<artifactId>javanilla</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>
```

Or if you are using _Gradle_:
```xml
dependencies {
compile "com.github.alexisjehan:javanilla:1.2.0"
compile "com.github.alexisjehan:javanilla:1.3.0"
}
```

Expand All @@ -47,11 +47,11 @@ final var concatInputStream = InputStreams.concat(
// Write to both a buffered file OutputStream and a sampling one
final var teeOutputStream = OutputStreams.tee(
OutputStreams.buffered(fileOutputStream),
new RangeOutputStream(sampleOutputStream, 100L) // Write only the 100 firsts bytes
new RangeOutputStream(sampleOutputStream, 0L, 100L) // Write only the 100 firsts bytes
);
// Wrap the InputStream to be used in a foreach-style loop for a better readability
for (final var b : Iterables.wrap(concatInputStream)) {
teeOutputStream.write(b);
for (final var i : Iterables.wrap(concatInputStream)) {
teeOutputStream.write(i);
}
teeOutputStream.flush();
```
Expand Down Expand Up @@ -81,7 +81,7 @@ System.out.println(Strings.padLeft("foo", size)); // Prints " foo"
System.out.println(Strings.removeEnd("foo", 'o')); // Prints "fo"
System.out.println(Strings.replaceLast("foo", 'o', 'r')); // Prints "for"
System.out.println(Strings.concatMerge("Once upon a time ...", "... the end")); // Prints "Once upon a time ... the end"
System.out.println(Strings.isHex(ByteArrays.toHexString("foo".getBytes())) ? "yes" : "no"); // Prints "yes"
System.out.println(Strings.isHexadecimal(ByteArrays.toHexString("foo".getBytes())) ? "yes" : "no"); // Prints "yes"
final var withPadding = true;
System.out.println(Strings.isBase64(Base64.getEncoder().encodeToString("foo".getBytes()), withPadding) ? "yes" : "no"); // Prints "yes"
```
Expand All @@ -97,7 +97,7 @@ try {
throw new IOException("A checked Exception inside a lambda");
});
} catch (final UncheckedIOException e) {
System.out.println(Throwables.getRootCause(e).orElseThrow().getMessage()); // Prints "A checked Exception inside a lambda"
System.out.println(Throwables.getOptionalRootCause(e).orElseThrow().getMessage()); // Prints "A checked Exception inside a lambda"
}
```

Expand Down Expand Up @@ -139,22 +139,14 @@ System.out.println(Distances.MANHATTAN.calculate(0.0d, 0.0d, 1.0d, 1.0d)); // Pr
final var order = 1;
System.out.println(new MinkowskiDistance(order).calculate(0.0d, 1.0d, 2.0d, 3.0d)); // Prints 4
System.out.println(EditDistances.HAMMING.calculate("foo", "for")); // Prints 1
System.out.println(new LevenshteinDistance().calculate("append", "apple")); // Prints 3
System.out.println(LevenshteinDistance.DEFAULT.calculate("append", "apple")); // Prints 3
```

### Util examples
New _Comparator_ implementations:
New _Comparator_ implementation:
```java
System.out.println("foo10".compareTo("foo2")); // Prints -1
System.out.println(Comparators.NUMBER_AWARE.compare("foo10", "foo2")); // Prints 1
System.out.println(Comparators.DOUBLE_ARRAYS.compare(
DoubleArrays.of(0.0d, 1.0d, 2.0d),
DoubleArrays.of(0.0d, 1.0d)
)); // Prints 1
System.out.println(Comparators.<String>array().compare(
ObjectArrays.of("foo", "bar2"),
ObjectArrays.of("foo", "bar1")
)); // Prints 1
```

New _Bag_ collection type:
Expand Down Expand Up @@ -201,19 +193,20 @@ System.out.println(countIterator.getCount()); // Prints 4
| singleton | &#x2713; | | &#x2713; | | | &#x2713; |
| of | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; |

| | Lists | Sets | Maps | Bags | Iterables | Iterators |
| :------------: | :------: | :---------: | :----------------: | :------: | :-------: | :-------: |
| empty | | | | &#x2713; | &#x2713; | |
| nullToEmpty | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; |
| nullToDefault | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; |
| emptyToNull | &#x2713; | &#x2713; | &#x2713; | &#x2713; | | &#x2713; |
| emptyToDefault | &#x2713; | &#x2713; | &#x2713; | &#x2713; | | &#x2713; |
| unmodifiable | | | | &#x2713; | &#x2713; | &#x2713; |
| length | | | | | &#x2713; | &#x2713; |
| concat | | | | | &#x2713; | &#x2713; |
| join | | | | | &#x2713; | &#x2713; |
| singleton | | | | &#x2713; | &#x2713; | &#x2713; |
| of | | _ofOrdered_ | _ofEntriesOrdered_ | &#x2713; | &#x2713; | &#x2713; |
| | Lists | Sets | Maps | Bags | Iterables | Iterators |
| :------------: | :------: | :---------: | :---------: | :------: | :-------: | :-------: |
| empty | | | | &#x2713; | &#x2713; | |
| nullToEmpty | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; |
| nullToDefault | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; | &#x2713; |
| emptyToNull | &#x2713; | &#x2713; | &#x2713; | &#x2713; | | &#x2713; |
| emptyToDefault | &#x2713; | &#x2713; | &#x2713; | &#x2713; | | &#x2713; |
| isEmpty | | | | | | &#x2713; |
| unmodifiable | | | | &#x2713; | &#x2713; | &#x2713; |
| length | | | | | &#x2713; | &#x2713; |
| concat | &#x2713; | | | | &#x2713; | &#x2713; |
| join | &#x2713; | | | | &#x2713; | &#x2713; |
| singleton | | | | &#x2713; | &#x2713; | &#x2713; |
| of | | _ofOrdered_ | _ofOrdered_ | &#x2713; | &#x2713; | &#x2713; |

## Maven phases and goals
Compile, test and install the JAR in the local Maven repository:
Expand Down
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<maven.compiler.release>10</maven.compiler.release>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -69,13 +70,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.0</version>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0</version>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>0.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -111,7 +118,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ of this software and associated documentation files (the "Software"), to deal
*/
package com.github.alexisjehan.javanilla.io;

import java.io.*;
import com.github.alexisjehan.javanilla.io.bytes.InputStreams;
import com.github.alexisjehan.javanilla.misc.quality.Ensure;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

/**
* <p>An utility class that provides {@link Serializable} tools.</p>
Expand All @@ -48,22 +56,20 @@ private Serializables() {
*/
public static byte[] serialize(final Serializable serializable) {
final var byteArrayOutputStream = new ByteArrayOutputStream();
serialize(serializable, byteArrayOutputStream);
serialize(byteArrayOutputStream, serializable);
return byteArrayOutputStream.toByteArray();
}

/**
* <p>Serialize the given {@code Serializable} to an {@code OutputStream}.</p>
* @param serializable the {@code Serializable} object or {@code null}
* @param outputStream the {@code OutputStream} to write into
* @param serializable the {@code Serializable} or {@code null}
* @throws NullPointerException if the {@code OutputStream} is {@code null}
* @throws SerializationException might occurs with serialization or I/O operations
* @since 1.0.0
*/
public static void serialize(final Serializable serializable, final OutputStream outputStream) {
if (null == outputStream) {
throw new NullPointerException("Invalid OutputStream (not null expected)");
}
public static void serialize(final OutputStream outputStream, final Serializable serializable) {
Ensure.notNull("outputStream", outputStream);
try (final var objectOutputStream = new ObjectOutputStream(outputStream)) {
objectOutputStream.writeObject(serializable);
} catch (final Exception e) {
Expand All @@ -78,14 +84,11 @@ public static void serialize(final Serializable serializable, final OutputStream
* @return a new {@code Serializable} from the serialized data
* @throws NullPointerException if the {@code byte} array is {@code null}
* @throws SerializationException might occurs with serialization operations
* @throws ClassCastException if the type is different of the serialized data type
* @since 1.0.0
*/
public static <S extends Serializable> S deserialize(final byte[] bytes) {
if (null == bytes) {
throw new NullPointerException("Invalid bytes (not null expected)");
}
return deserialize(new ByteArrayInputStream(bytes));
Ensure.notNull("bytes", bytes);
return deserialize(InputStreams.of(bytes));
}

/**
Expand All @@ -95,14 +98,11 @@ public static <S extends Serializable> S deserialize(final byte[] bytes) {
* @return a new {@code Serializable} from the serialized data
* @throws NullPointerException if the {@code InputStream} is {@code null}
* @throws SerializationException might occurs with serialization or I/O operations
* @throws ClassCastException if the type is different of the serialized data type
* @since 1.0.0
*/
@SuppressWarnings("unchecked")
public static <S extends Serializable> S deserialize(final InputStream inputStream) {
if (null == inputStream) {
throw new NullPointerException("Invalid InputStream (not null expected)");
}
Ensure.notNull("inputStream", inputStream);
try (final var objectInputStream = new ObjectInputStream(inputStream)) {
return (S) objectInputStream.readObject();
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ of this software and associated documentation files (the "Software"), to deal
*/
package com.github.alexisjehan.javanilla.io;

import java.util.Objects;
import com.github.alexisjehan.javanilla.misc.quality.Ensure;

/**
* <p>A {@link RuntimeException} wrapping any serialization {@link Exception} thrown while working with the
Expand All @@ -46,6 +46,6 @@ public final class SerializationException extends RuntimeException {
* @since 1.0.0
*/
SerializationException(final Exception cause) {
super(Objects.requireNonNull(cause, "Invalid cause (not null expected)"));
super(Ensure.notNull("cause", cause));
}
}
Loading

0 comments on commit 5e7ab62

Please sign in to comment.