Skip to content

Commit

Permalink
Merge pull request #79 from sclassen/removeGuavaDependency
Browse files Browse the repository at this point in the history
Remove guava dependency
  • Loading branch information
martinfrancois committed Jul 18, 2019
2 parents 51049fe + eee402d commit d6e13e9
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.dlsc.preferencesfx.model.Category;
import com.dlsc.preferencesfx.model.Group;
import com.dlsc.preferencesfx.model.Setting;
import com.google.common.collect.Lists;
import java.util.Arrays;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
Expand Down Expand Up @@ -85,47 +84,47 @@ private IntegerField setupCustomControl() {
// Theme
ListProperty<String> themesLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("IntelliJ", "Darkula", "Windows")
Arrays.asList("IntelliJ", "Darkula", "Windows")
)
);
ObjectProperty<String> themesObj = new SimpleObjectProperty<>("IntelliJ");

// IDE
ListProperty<String> ideLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("Subpixel", "Greyscale", "No Antializing")
Arrays.asList("Subpixel", "Greyscale", "No Antializing")
)
);
ObjectProperty<String> ideObj = new SimpleObjectProperty<>("Subpixel");

// Editor
ListProperty<String> editorLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("Subpixel", "Greyscale", "No Antializing")
Arrays.asList("Subpixel", "Greyscale", "No Antializing")
)
);
ObjectProperty<String> editorObj = new SimpleObjectProperty<>("Subpixel");

// Font size
ListProperty<String> fontLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("8", "10", "12", "14", "18", "20", "22", "24", "36", "72")
Arrays.asList("8", "10", "12", "14", "18", "20", "22", "24", "36", "72")
)
);
ObjectProperty<String> fontObj = new SimpleObjectProperty<>("24");

// Project opening
ListProperty<String> projectOpeningLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("Open project in new window", "Open project in the same window", "Confirm window to open project in")
Arrays.asList("Open project in new window", "Open project in the same window", "Confirm window to open project in")
)
);
ObjectProperty<String> projectOpeningObj = new SimpleObjectProperty<>("Open project in new window");

// Closing tool window
ListProperty<String> closingToolLst = new SimpleListProperty<>(
FXCollections.observableArrayList(
Lists.newArrayList("Terminate process", "Disconnect (if available)", "Ask")
Arrays.asList("Terminate process", "Disconnect (if available)", "Ask")
)
);
ObjectProperty<String> closingToolObj = new SimpleObjectProperty<>("Ask");
Expand Down
37 changes: 15 additions & 22 deletions preferencesfx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
<windowtitle>PreferencesFX API</windowtitle>
<additionalJOption>-J-Djavafx.javadoc=true
</additionalJOption>
<failOnError>false</failOnError>
<docfilessubdirs>true</docfilessubdirs>
</configuration>
<executions>
Expand All @@ -127,6 +126,7 @@

<!-- JUnit Tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<!-- Only Java 9+
Expand Down Expand Up @@ -172,13 +172,6 @@
</build>

<dependencies>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>

<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
Expand All @@ -197,20 +190,6 @@
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
Expand All @@ -224,6 +203,20 @@
<version>1.7.25</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.dlsc.formsfx.model.structure.Field;
import com.dlsc.formsfx.model.structure.Group;
import com.dlsc.formsfx.model.util.TranslationService;
import com.google.common.base.Strings;
import com.dlsc.preferencesfx.util.Strings;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dlsc.preferencesfx.history;

import com.dlsc.preferencesfx.model.Setting;
import com.google.common.collect.Lists;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.Callable;
import javafx.beans.binding.Bindings;
Expand Down Expand Up @@ -87,8 +87,8 @@ public Change(Setting setting, ObservableList<P> oldList, ObservableList<P> newL
*/
public Change(Setting setting, P oldValue, P newValue) {
this(setting, false);
this.oldList.set(FXCollections.observableArrayList(Lists.newArrayList(oldValue)));
this.newList.set(FXCollections.observableArrayList(Lists.newArrayList(newValue)));
this.oldList.set(FXCollections.observableArrayList(Arrays.asList(oldValue)));
this.newList.set(FXCollections.observableArrayList(Arrays.asList(newValue)));
}

private void setupBindings() {
Expand Down Expand Up @@ -192,7 +192,7 @@ public P getNewValue() {
}

public void setNewValue(P newValue) {
this.newList.set(FXCollections.observableArrayList(Lists.newArrayList(newValue)));
this.newList.set(FXCollections.observableArrayList(Arrays.asList(newValue)));
}

public Setting getSetting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import com.dlsc.formsfx.model.util.TranslationService;
import com.dlsc.preferencesfx.util.PreferencesFxUtils;
import com.dlsc.preferencesfx.util.Strings;
import com.dlsc.preferencesfx.view.CategoryView;
import com.google.common.base.Strings;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.dlsc.preferencesfx.model.Category;
import com.dlsc.preferencesfx.model.Group;
import com.dlsc.preferencesfx.model.Setting;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.dlsc.preferencesfx.model.Group;
import com.dlsc.preferencesfx.model.PreferencesFxModel;
import com.dlsc.preferencesfx.model.Setting;
import com.google.common.base.Strings;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import static com.dlsc.preferencesfx.util.Constants.WINDOW_WIDTH;

import com.dlsc.preferencesfx.model.Setting;
import com.google.common.hash.Hashing;
import com.google.gson.Gson;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
Expand Down Expand Up @@ -261,10 +259,7 @@ private String deprecatedHash(String key) {
* @return SHA-256 representation of breadcrumb
*/
public String hash(String key) {
Objects.requireNonNull(key);
return Hashing.sha256()
.hashString(key, StandardCharsets.UTF_8)
.toString();
return Strings.sha256(key);
}

public Preferences getPreferences() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.dlsc.preferencesfx.util;

import static java.util.Objects.requireNonNull;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
* Helper methods for working with strings.
*/
public class Strings {

private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();

/**
* Checks if a string is null or empty.
*
* @param string the string to test, may be {@code null}.
* @return {@code true} iff the string is not null and not empty
*/
public static boolean isNullOrEmpty(String string) {
return string == null || string.isEmpty();
}

/**
* Calculates the SHA-256 digest of a string.
*
* @param string the string to digest, must not be {@code null}.
* @return the SHA-256 digest of the input string
*/
public static String sha256(String string) {
requireNonNull(string);
try {
final MessageDigest digest = MessageDigest.getInstance("sha-256");
final byte[] hash = digest.digest(string.getBytes(StandardCharsets.UTF_8));
return hexString(hash);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

/**
* Calculates the HEX representation of a byte array.
*
* @param bytes the byte array, must not be {@code null}.
* @return the HEX representation of the byte array.
*/
public static String hexString(byte[] bytes) {
requireNonNull(bytes);
final int numBytes = bytes.length;
char[] hexChars = new char[numBytes * 2];
for (int i = 0; i < numBytes; i++) {
int v = bytes[i] & 0xFF;
hexChars[i * 2] = HEX_ARRAY[v >>> 4];
hexChars[(i * 2) + 1] = HEX_ARRAY[v & 0x0F];
}
return new String(hexChars);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dlsc.preferencesfx.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.junit.After;
Expand Down Expand Up @@ -87,4 +90,11 @@ public void loadObject() {
@Test
public void loadObservableList() {
}

@Test
public void shaHashing() {
StorageHandlerImpl storageHandler = new StorageHandlerImpl(StorageHandlerImplTest.class);
final String result = storageHandler.hash("test");
assertThat(result, is("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"));
}
}

0 comments on commit d6e13e9

Please sign in to comment.