Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fuinorg/utils4j
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.9.0
Choose a base ref
...
head repository: fuinorg/utils4j
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.9.1
Choose a head ref
  • 18 commits
  • 88 files changed
  • 1 contributor

Commits on Sep 12, 2015

  1. Verified

    This commit was signed with the committer’s verified signature.
    SuperQ Ben Kochie
    Copy the full SHA
    947dedd View commit details
  2. Added examples

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    a7294ea View commit details
  3. Enhanced examples

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    48d0547 View commit details
  4. Copy the full SHA
    91b0559 View commit details
  5. Adjusted text

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    39fc6f7 View commit details
  6. Added locking example

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    26961b4 View commit details
  7. Shortened text

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    525883c View commit details
  8. Copy the full SHA
    3d04a33 View commit details
  9. Fixed two bugs

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    1c96b33 View commit details
  10. Doc

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    b4b65a6 View commit details
  11. Added some more tests

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    ba16832 View commit details
  12. Copy the full SHA
    bb427a6 View commit details
  13. Added file URL test

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    2fd153a View commit details
  14. Copy the full SHA
    93ab30e View commit details
  15. Copy the full SHA
    547ddce View commit details
  16. deployment

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    1cb102c View commit details
  17. Doc

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    aa3b62d View commit details
  18. Release 0.9.1

    michael-schnell committed Sep 12, 2015
    Copy the full SHA
    138cbd7 View commit details
Showing with 2,191 additions and 2,185 deletions.
  1. +2 −7 .checkstyle
  2. +7 −8 META-INF/MANIFEST.MF
  3. +45 −150 README.md
  4. +0 −114 checkstyle.xml
  5. +22 −26 pom.xml
  6. +2 −2 src/main/java/org/fuin/utils4j/CancelableVolatile.java
  7. +24 −36 src/main/java/org/fuin/utils4j/ChangeTrackingMap.java
  8. +24 −36 src/main/java/org/fuin/utils4j/ChangeTrackingUniqueList.java
  9. +59 −0 src/main/java/org/fuin/utils4j/ClasspathURLStreamHandler.java
  10. +2 −4 src/main/java/org/fuin/utils4j/IllegalNullArgumentException.java
  11. +2 −4 src/main/java/org/fuin/utils4j/InvokeMethodFailedException.java
  12. +34 −51 src/main/java/org/fuin/utils4j/JaxbUtils.java
  13. +3 −6 src/main/java/org/fuin/utils4j/MergeException.java
  14. +48 −63 src/main/java/org/fuin/utils4j/PropertiesFile.java
  15. +8 −13 src/main/java/org/fuin/utils4j/PropertiesFilePreferences.java
  16. +17 −28 src/main/java/org/fuin/utils4j/PropertiesFilePreferencesFactory.java
  17. +10 −15 src/main/java/org/fuin/utils4j/Property.java
  18. +25 −35 src/main/java/org/fuin/utils4j/RandomAccessFileInputStream.java
  19. +36 −43 src/main/java/org/fuin/utils4j/RandomAccessFileOutputStream.java
  20. +0 −97 src/main/java/org/fuin/utils4j/SimpleVariable.java
  21. +6 −8 src/main/java/org/fuin/utils4j/Taggable.java
  22. +356 −397 src/main/java/org/fuin/utils4j/Utils4J.java
  23. +27 −85 src/main/java/org/fuin/utils4j/{StringVariableResolver.java → VariableResolver.java}
  24. +19 −16 src/main/java/org/fuin/utils4j/fileprocessor/FileHandlerResult.java
  25. +14 −8 src/main/java/org/fuin/utils4j/fileprocessor/FileOrder.java
  26. +11 −15 src/main/java/org/fuin/utils4j/fileprocessor/FileProcessor.java
  27. +1 −0 src/main/java/org/fuin/utils4j/fileprocessor/package-info.java
  28. +2 −2 src/main/java/org/fuin/utils4j/filter/AndFilter.java
  29. +2 −4 src/main/java/org/fuin/utils4j/filter/BooleanPropertyFilter.java
  30. +10 −16 src/main/java/org/fuin/utils4j/filter/ComparableFilter.java
  31. +2 −4 src/main/java/org/fuin/utils4j/filter/ComparablePropertyFilter.java
  32. +5 −6 src/main/java/org/fuin/utils4j/filter/IntegerPropertyFilter.java
  33. +1 −2 src/main/java/org/fuin/utils4j/filter/ListFilter.java
  34. +2 −2 src/main/java/org/fuin/utils4j/filter/OrFilter.java
  35. +10 −16 src/main/java/org/fuin/utils4j/filter/PropertyFilter.java
  36. +7 −12 src/main/java/org/fuin/utils4j/filter/RegExprFilter.java
  37. +3 −6 src/main/java/org/fuin/utils4j/filter/RegExprPropertyFilter.java
  38. +6 −12 src/main/java/org/fuin/utils4j/filter/StringFilter.java
  39. +6 −8 src/main/java/org/fuin/utils4j/filter/StringPropertyFilter.java
  40. +2 −4 src/main/java/org/fuin/utils4j/filter/TokenFilter.java
  41. +4 −6 src/main/java/org/fuin/utils4j/filter/TokenPropertyFilter.java
  42. +1 −0 src/main/java/org/fuin/utils4j/filter/package-info.java
  43. +1 −0 src/main/java/org/fuin/utils4j/package-info.java
  44. +1 −1 src/test/java/org/fuin/utils4j/CancelableVolatileTest.java
  45. +3 −4 src/test/java/org/fuin/utils4j/ChangeTrackingMapTest.java
  46. +38 −70 src/test/java/org/fuin/utils4j/ChangeTrackingUniqueListTest.java
  47. +22 −19 ...a/org/fuin/utils4j/Variable.java → test/java/org/fuin/utils4j/ClasspathURLStreamHandlerTest.java}
  48. +5 −7 src/test/java/org/fuin/utils4j/IllegalNullArgumentExceptionTest.java
  49. +4 −7 src/test/java/org/fuin/utils4j/InvokeMethodFailedExceptionTest.java
  50. +3 −5 src/test/java/org/fuin/utils4j/LockingFailedExceptionTest.java
  51. +6 −11 src/test/java/org/fuin/utils4j/PropertiesFilePreferencesTest.java
  52. +18 −34 src/test/java/org/fuin/utils4j/PropertiesFileTest.java
  53. +1 −1 src/test/java/org/fuin/utils4j/PropertyTest.java
  54. +1 −1 src/test/java/org/fuin/utils4j/RandomAccessFileInputStreamTest.java
  55. +5 −9 src/test/java/org/fuin/utils4j/RandomAccessFileOutputStreamTest.java
  56. +0 −139 src/test/java/org/fuin/utils4j/SimpleVariableTest.java
  57. +3 −5 src/test/java/org/fuin/utils4j/TestHelper.java
  58. +148 −178 src/test/java/org/fuin/utils4j/Utils4JTest.java
  59. +55 −66 src/test/java/org/fuin/utils4j/VariableResolverTest.java
  60. +103 −0 src/test/java/org/fuin/utils4j/examples/ChangeTrackingMapExample.java
  61. +95 −0 src/test/java/org/fuin/utils4j/examples/ChangeTrackingUniqueListExample.java
  62. +47 −0 src/test/java/org/fuin/utils4j/examples/ClasspathURLExample.java
  63. +74 −0 src/test/java/org/fuin/utils4j/examples/LockFileExample.java
  64. +88 −0 src/test/java/org/fuin/utils4j/examples/PropertiesFilePreferencesFactoryExample.java
  65. +67 −0 src/test/java/org/fuin/utils4j/examples/VariableResolverExample.java
  66. +95 −0 src/test/java/org/fuin/utils4j/examples/ZipDirExample.java
  67. +97 −0 src/test/java/org/fuin/utils4j/examples/filter/Person.java
  68. +82 −0 src/test/java/org/fuin/utils4j/examples/filter/SimpleFilterExample.java
  69. +7 −1 required-header.txt → src/test/java/org/fuin/utils4j/examples/package-info.java
  70. +52 −0 src/test/java/org/fuin/utils4j/fileprocessor/FileHandlerResultTest.java
  71. +52 −0 src/test/java/org/fuin/utils4j/fileprocessor/FileOrderTest.java
  72. +15 −11 src/test/java/org/fuin/utils4j/fileprocessor/FileProcessorTest.java
  73. +6 −12 src/test/java/org/fuin/utils4j/filter/AndFilterTest.java
  74. +3 −5 src/test/java/org/fuin/utils4j/filter/BooleanFilterTest.java
  75. +9 −15 src/test/java/org/fuin/utils4j/filter/BooleanPropertyFilterTest.java
  76. +11 −31 src/test/java/org/fuin/utils4j/filter/IntegerFilterTest.java
  77. +23 −28 src/test/java/org/fuin/utils4j/filter/IntegerPropertyFilterTest.java
  78. +3 −0 src/test/java/org/fuin/utils4j/filter/ListFilterTest.java
  79. +6 −12 src/test/java/org/fuin/utils4j/filter/OrFilterTest.java
  80. +1 −1 src/test/java/org/fuin/utils4j/filter/PropertyFilterTest.java
  81. +13 −25 src/test/java/org/fuin/utils4j/filter/RegExprFilterTest.java
  82. +25 −50 src/test/java/org/fuin/utils4j/filter/RegExprPropertyFilterTest.java
  83. +7 −13 src/test/java/org/fuin/utils4j/filter/StringFilterTest.java
  84. +20 −44 src/test/java/org/fuin/utils4j/filter/StringPropertyFilterTest.java
  85. +2 −3 src/test/java/org/fuin/utils4j/filter/TokenFilterTest.java
  86. +7 −10 src/test/java/org/fuin/utils4j/filter/TokenPropertyFilterTest.java
  87. BIN src/test/resources/myfile.zip
  88. BIN src/test/resources/myfile1.zip
9 changes: 2 additions & 7 deletions .checkstyle
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<local-check-config name="Standard" location="checkstyle.xml" type="project" description="">
<property name="checkstyle.header.file" value="${basedir}/required-header.txt"/>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="true">
<local-check-config name="Standard" location="http://www.fuin.org/files/checkstyle-2015-09-12.xml" type="remote" description="">
<additional-data name="protect-config-file" value="false"/>
</local-check-config>
<fileset name="all" enabled="true" check-config-name="Standard" local="true">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="FileTypesFilter" enabled="true">
<filter-data value="java"/>
</filter>
<filter name="NonSrcDirs" enabled="true"/>
</fileset-config>
15 changes: 7 additions & 8 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -6,12 +6,11 @@ Bundle-License: http://www.fsf.org/licensing/licenses/lgpl.html
Bundle-ManifestVersion: 2
Bundle-Name: Utils4J
Bundle-SymbolicName: org.fuin.utils4j
Bundle-Vendor: Future Invent Informationsmanagement GmbH, Hamburg (Germa
ny)
Bundle-Version: 0.9.0
Export-Package: org.fuin.utils4j;version="0.9.0";uses:="javax.xml.bind,j
avax.xml.bind.annotation,javax.xml.bind.annotation.adapters",org.fuin.u
tils4j.filter;version="0.9.0",org.fuin.utils4j.fileprocessor;version="0
.9.0"
Bundle-Vendor: fuin.org (Germany)
Bundle-Version: 0.9.1
Export-Package: org.fuin.utils4j;version="0.9.1";uses:="javax.xml.bind,j
avax.xml.bind.annotation.adapters",org.fuin.utils4j.filter;version="0.9
.1",org.fuin.utils4j.fileprocessor;version="0.9.1"
Import-Package: javax.crypto,javax.crypto.spec,javax.xml.bind,javax.xml.
bind.annotation,javax.xml.bind.annotation.adapters
bind.annotation.adapters
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
195 changes: 45 additions & 150 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,175 +15,70 @@ A small Java library that contains several helpful utility classes.

* * *

##Examples
##Features

###ZIP directory
Compress a complete directory and it's subdirectories with a single line of code using Utils4J
###URL support for "classpath:" scheme
```Java
// Given a local directory "mydir" on drive "c:" that contains
// three files "x.txt", "y.txt" and "z.txt"
File dirToZip = new File("c:/mydir");

// Run the ZIP command
Utils4J.zipDir(dirToZip, "abc/def", new File("c:/myfile1.zip"));
// The archive will contain the following structure:
// abc/def/x.txt
// abc/def/y.txt
// abc/def/z.txt

// Run the ZIP command again
Utils4J.zipDir(dirToZip, "", new File("c:/myfile2.zip"));
// The second archive will contain the following structure:
// x.txt
// y.txt
// z.txt
URL url = Utils4J.url("classpath:org/fuin/utils4j/test.properties");
```
A full example can be found here: [ClasspathURLExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ClasspathURLExample.java)

###Decompress a ZIP archive
Decompress a zip file with a single line of code using Utils4J
```Java
// ZIP archive to decompress
File zipFile = new File("c:/myfile.zip");

// Target directory
File targetDir = new File("c:/test");

// Unzip the content into the target directory
Utils4J.unzip(zipFile, targetDir);
###Variable resolver
Resolves variable references in a map and prevents on cycles.
```
a=1
b=${a}/2
c=${b}/3
```
After calling the resolver a map is returned that has the replaced values:
```
a=1
b=1/2
c=1/2/3
```
A full example can be found here: [VariableResolverExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/VariableResolverExample.java)

###Tracking changes of a list
This is a wrapper for lists that keeps track of all changes made to the list. This means adding, replacing or deleting elements is tracked - not the changes to the objects itself. It's also possible to revert (undo) all changes made to the list. A restriction is that no duplicate elements are allowed in the list.
###ZIP and UNZIP
Compress and descompress a complete directory and it's subdirectories with a single line of code
```Java
// Create a standard string list
List list = new ArrayList();

// Add some initial content
list.add("one");
list.add("two");
list.add("three");

// Wrap the list to track changes
final ChangeTrackingUniqueList trackingList = new ChangeTrackingUniqueList(list);

// Add and remove some items
trackingList.add("four");
trackingList.add("five");
trackingList.remove("three");
final File zipDir = new File(Utils4J.getTempDir(), "mydir");
final File zipFile = new File(Utils4J.getTempDir(), "myfile1.zip");
Utils4J.zipDir(zipDir, "abc/def", zipFile);
Utils4J.unzip(zipFile, Utils4J.getTempDir());
```
A full example can be found here: [ZipDirExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ZipDirExample.java)

// Print the status
// Output: true
System.out.println("HAS CHANGED:");
###Tracking changes of a list / map
This is a wrapper for lists that keeps track of all changes made to the list. This means adding, replacing or deleting elements is tracked - not the changes to the objects itself. It's also possible to revert (undo) all changes made to the list. A restriction is that no duplicate elements are allowed in the list.
```Java
List<String> list = new ArrayList<>();
ChangeTrackingUniqueList<String> trackingList = new ChangeTrackingUniqueList<>(list);
System.out.println(trackingList.isChanged());
System.out.println();

// Print the deleted items
// Output: "three"
System.out.println("DELETED:");
printList(trackingList.getDeleted());

// Print the added items
// Output: "four", "five"
System.out.println("ADDED:");
printList(trackingList.getAdded());

// Revert all changes
System.out.println(trackingList.getDeleted());
System.out.println(trackingList.getAdded());
trackingList.revert();

System.out.println("REVERTED:");
// Output: "one", "two", "three"
printList(trackingList);
```
A list example can be found here: [ChangeTrackingUniqueListExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ChangeTrackingUniqueListExample.java)
A map example can be found here: [ChangeTrackingMapExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ChangeTrackingMapExample.java)

###Tracking changes of a map
This is a wrapper for maps that keeps track of all changes made to the map. This means adding, replacing or deleting elements is tracked - not the changes to the objects itself. It's also possible to revert (undo) all changes made to the map.
###Easy file locking
```Java
// Create a standard map
Map map = new HashMap();

// Add some initial content
map.put("one", Integer.valueOf(1));
map.put("two", Integer.valueOf(2));
map.put("three", Integer.valueOf(3));

// Wrap the map to track changes
ChangeTrackingMap trackingMap = new ChangeTrackingMap(map);

// Add/change/remove item
trackingMap.put("four", Integer.valueOf(4));
trackingMap.put("three", Integer.valueOf(10));
trackingMap.remove("one");

// Print the status
// Output: true
System.out.println("HAS CHANGED:");
System.out.println(trackingMap.isChanged());
System.out.println();

// Print the added items
// Output: "four=4"
System.out.println("ADDED:");
printMap(trackingMap.getAdded());

// Print the changed items
// Output: "three=3"
System.out.println("CHANGED:");
printMap(trackingMap.getChanged());

// Print the removed items
// Output: "one=1"
System.out.println("REMOVED:");
printMap(trackingMap.getRemoved());

// Revert all changes
trackingMap.revert();

System.out.println("REVERTED:");
// Output: "one=1", "two=2", "three=3"
printMap(trackingMap);
FileLock lock = Utils4J.lockRandomAccessFile(randomAccessFile, tryLockMax, tryWaitMillis);
try {
// Do something...
} finally {
lock.release();
}
```
A full example can be found here: [LockFileExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/LockFileExample.java)

###Properties file preferences
Shows the use of a directory and properties file based [Preferences API](http://docs.oracle.com/javase/7/docs/technotes/guides/preferences/) implementation. It's basically a replacement for the registry based implementation on Windows.
```Java
// Create an application wide preferences directory
// named "config" in the current startup directory
final File systemPrefDir = new File("./config");
if (!systemPrefDir.exists()) {
systemPrefDir.mkdir();
}

// Create a user preferences directory with your
// applications name in the user's home directory
final File userHomeDir = new File(System.getProperty("user.home"));
final File userPrefDir = new File(userHomeDir, ".myapp");
if (!userPrefDir.exists()) {
userPrefDir.mkdir();
}

// Set both directories as system properties
System.setProperty(PropertiesFilePreferencesFactory.SYSTEM_PREF_DIR,
systemPrefDir.toString());
System.setProperty(PropertiesFilePreferencesFactory.USER_PREF_DIR,
userPrefDir.toString());

// Set the factory
System.setProperty("java.util.prefs.PreferencesFactory",
PropertiesFilePreferencesFactory.class.getName());

// Write something to the preferences
final Preferences userPrefs = Preferences.userRoot();
userPrefs.putInt("a", 1);
userPrefs.put("b", "test");
```
A file ${user.home}/.myapp/preferences.properties will be created:
```
# DO NOT EDIT!
# Created by org.fuin.utils4j.PropertiesFilePreferences
# yyyy-MM-dd HH:mm:ss
a=1
b=test
System.setProperty("java.util.prefs.PreferencesFactory", PropertiesFilePreferencesFactory.class.getName());
Preferences userPrefs = Preferences.userRoot();
```
A full example can be found here: [PropertiesFilePreferencesFactoryExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/PropertiesFilePreferencesFactoryExample.java)

* * *

114 changes: 0 additions & 114 deletions checkstyle.xml

This file was deleted.

Loading