Coder Social home page Coder Social logo

java-util's Introduction

java-util

Maven Central Javadoc

Helpful Java utilities that are thoroughly tested and available on Maven Central. This library has no dependencies on other libraries for runtime. The.jarfile is 290K and works with JDK 1.8 through JDK 22. The .jar file classes are version 52 (JDK 1.8)

Compatibility

JPMS (Java Platform Module System)

This library is fully compatible with JPMS, commonly known as Java Modules. It includes a module-info.class file that specifies module dependencies and exports.

OSGi

This library also supports OSGi environments. It comes with pre-configured OSGi metadata in the MANIFEST.MF file, ensuring easy integration into any OSGi-based application.

Both of these features ensure that our library can be seamlessly integrated into modular Java applications, providing robust dependency management and encapsulation.


To include in your project:

Gradle
implementation 'com.cedarsoftware:java-util:2.13.0'
Maven
<dependency>
  <groupId>com.cedarsoftware</groupId>
  <artifactId>java-util</artifactId>
  <version>2.13.0</version>
</dependency>

Included in java-util:

Included in java-util:

  • ArrayUtilities - Provides utilities for working with Java arrays [], enhancing array operations.
  • ByteUtilities - Offers routines for converting byte[] to hexadecimal character arrays and vice versa, facilitating byte manipulation.
  • ClassUtilities - Includes utilities for class-related operations. For example, the method computeInheritanceDistance(source, destination) calculates the number of superclass steps between two classes, returning it as an integer. If no inheritance relationship exists, it returns -1. Distances for primitives and their wrappers are considered as 0, indicating no separation.

Sets

  • CompactSet - A memory-efficient Set that expands to a HashSet when size() > compactSize().
  • CompactLinkedSet - A memory-efficient Set that transitions to a LinkedHashSet when size() > compactSize().
  • CompactCILinkedSet - A compact, case-insensitive Set that becomes a LinkedHashSet when expanded.
  • CompactCIHashSet - A small-footprint, case-insensitive Set that expands to a HashSet.
  • CaseInsensitiveSet - A Set that ignores case sensitivity for Strings.
  • ConcurrentSet - A thread-safe Set not requiring elements to be comparable, unlike ConcurrentSkipListSet.
  • SealableSet - Allows toggling between read-only and writable states via a Supplier<Boolean>, managing immutability externally.
  • SealableNavigableSet - Similar to SealableSet but for NavigableSet, controlling immutability through an external supplier.

Maps

  • CompactMap - A Map with a small memory footprint that scales to a HashMap as needed.
  • CompactLinkedMap - A compact Map that extends to a LinkedHashMap for larger sizes.
  • CompactCILinkedMap - A small-footprint, case-insensitive Map that becomes a LinkedHashMap.
  • CompactCIHashMap - A compact, case-insensitive Map expanding to a HashMap.
  • CaseInsensitiveMap - Treats String keys in a case-insensitive manner.
  • LRUCache - Thread-safe LRU cache which implements the Map API. Supports "locking" or "threaded" strategy (selectable).
  • TrackingMap - Tracks access patterns to its keys, aiding in performance optimizations.
  • SealableMap - Allows toggling between sealed (read-only) and unsealed (writable) states, managed externally.
  • SealableNavigableMap - Extends SealableMap features to NavigableMap, managing state externally.

Lists

  • ConcurrentList - Provides a thread-safe List that can be either an independent or a wrapped instance.
  • SealableList - Enables switching between sealed and unsealed states for a List, managed via an external Supplier<Boolean>.

Additional Utilities

  • Converter - Facilitates type conversions, e.g., converting String to BigDecimal. Supports a wide range of conversions.
  • DateUtilities - Robustly parses date strings with support for various formats and idioms.
  • DeepEquals - Deeply compares two object graphs for equivalence, handling cycles and using custom equals() methods where available.
  • IOUtilities - Transfer APIs, close/flush APIs, compress/uncompress APIs.
  • EncryptionUtilities - Simplifies the computation of checksums and encryption using common algorithms.
  • Executor - Simplifies the execution of operating system commands with methods for output retrieval.
  • GraphComparator - Compares two object graphs and provides deltas, which can be applied to synchronize the graphs.
  • MathUtilities - Offers handy mathematical operations and algorithms.
  • ReflectionUtils - Provides efficient and simplified reflection operations.
  • StringUtilities - Contains helpful methods for common String manipulation tasks.
  • SystemUtilities - Offers utilities for interacting with the operating system and environment.
  • Traverser - Allows generalized actions on all objects within an object graph through a user-defined method.
  • UniqueIdGenerator - Generates unique identifiers with embedded timing information, suitable for use in clustered environments.

See changelog.md for revision history.


Sponsors

Alt text

YourKit supports open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of YourKit Java Profiler and YourKit .NET Profiler, innovative and intelligent tools for profiling Java and .NET applications.

Intellij IDEA from JetBrains Intellij IDEA


By: John DeRegnaucourt and Kenny Partlow

java-util's People

Contributors

bowbahdoe avatar dependabot[bot] avatar dreddergun avatar jdereg avatar jremes-foss avatar jsnyder4 avatar kpartlow avatar lipisak avatar marcobjorge avatar osiris-team avatar sapradhan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-util's Issues

An illegal reflective access operation has occurred

Hello, we use com.cedarsoftware.util.GraphComparator to find differences between two objects. Running the code with java 11 we get a warning while access private static final field "serialVersionUID". I would expect that static final fields are skipped from comparison.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.cedarsoftware.util.ReflectionUtils (file:......../files-2.1/com.cedarsoftware/java-util/2.0.0/7cdce491c29122dc4a959a69f51064ef63eed31/java-util-2.0.0.jar) to field java.util.UUID.serialVersionUID
WARNING: Please consider reporting this to the maintainers of com.cedarsoftware.util.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Thank you
Eddi

GraphComparator could not find the new member of ArrayList

I am having a problem while using your great library as I want to compare two ArrayLists for differences using GraphComparator. I deleted an element of one of the lists and when I compared the old list and new list it shows that there is OBJECT_ORPHAN command. But when I reversed it by comparing the new list and the old list, it should show that there is a new object but somehow it could not detect.

My code is like this:

List<UnifiedBucket> ubs= new ArrayList<>(); // Assume I already put elements in the list 
List<UnifiedBucket> ubsCopy = cloner.deepClone(ubs);
ubsCopy.remove(25);
ubsCopy.get(14).setRawPolicy(null);
List<GraphComparator.Delta> deltas = GraphComparator.compare(ubs, ubsCopy, getIdFetcher()); //This works fine as I could find the OBJECT_ORPHAN

for (GraphComparator.Delta delta : deltas) {
	if (delta.getCmd() != GraphComparator.Delta.Command.LIST_SET_ELEMENT) {
		System.out.println(delta);
	}
}

List<GraphComparator.Delta> deltas2 = GraphComparator.compare(ubsCopy, ubs, getIdFetcher()); //This does not work fine as I could not find the new element that is not deleted in the ubs list

for (GraphComparator.Delta delta : deltas2) {
	if (delta.getCmd() != GraphComparator.Delta.Command.LIST_SET_ELEMENT) {
		System.out.println(delta);
	}
}

Any reason why?

DeepEquals: issue for IGNORE_CUSTOM_EQUALS option

Hi,
I have found a possible issue in DeepEquals utility. It's possible to use the IGNORE_CUSTOM_EQUALS options (if you don't want to use custom equals implementation for specific classes). This option should be Set as it's loaded from options Map on line 176 in DeepEquals utility. But if you look at usage of this set the input parameter of contains method is Class on line 361 (it always be false if any class should be "blacklisted").

Thx.
JS

Cannot use fastLookup hash using DeepHashCode

fastLookup.put(deepHashCode(entry.getKey()), entry);

Unfortunately, hashCodes are not intended to be unique, so it's possible that two keys would have the same hash and the second will overwrite the first. In a Map with 110 entries using unique 4 char Strings, I found 4 keys with duplicate hashes.

At that point what you're really after is a unique id for each Object (key). This would fix the above problem but I just realised there is a more fundamental problem with the idea of trying to compare Maps in general: There might be cases where you consider two keys in a map to be deeply equal, but Java does not consider them equal, hence it's possible to have them both in the same Map. At that point, you're conflicting with the principle of the same key in a Map always resolving to the same value. Maybe at that point you can compare the Set of values the equal keys map to but that's skirting on the edges of what a Map really is...

`DeepEquals`: comparator of `SortedSet`s and `SortedMap`s is not considered, equality of ordered and unordered collections is inconsistent with JDK

The comparison of two SortedSets or SortedMaps with deepEquals does not work as expected, when the SortedSets or SortedMaps are not using the same comparator for ordering the elements. If not the same comparators are used, the method returns wrong results, as the iterators i1 and i2 used in compareOrderedCollection and compareSortedMap return elements in a different order.

With the default implementation of equals, this is not the case:

SortedMap<String, String> map1 = new TreeMap<>(Comparator.naturalOrder());
map1.put("a", "b");
map1.put("c", "d");
SortedMap<String, String> map2 = new TreeMap<>(Comparator.reverseOrder());
map2.put("a", "b");
map2.put("c", "d");
System.out.println(map1.equals(map2)); // true

In the JDK, the equals method of Sets and Maps does not consider the ordering in any case, even for SortedSets and SortedMaps. Instead SortedSets are considered to be equal to Sets (and respectively for Maps) when they contain exactly the same entries:

SortedSet<String> set1 = new TreeSet<>();
Set<String> set2 = new HashSet<>();
System.out.println(set1.equals(set2)); // true

Whereas deepEquals considers those two Sets to be not equal, because they are not both of the type SortedSets.

deepEquals not symmetric

    public static void main(String[] args) {
        class Foo {}

        System.out.println(DeepEquals.deepEquals(new ArrayList<String>(), new Foo())); //this print `false`, as expected
        System.out.println(DeepEquals.deepEquals(new Foo(), new ArrayList<String>())); //but this print `true`
    }

OSGi Support

Hello,

I'm trying to use your java-util in a OSGi environment and I found out that the library is not an OSGi bundle so I made some changes to make it a proper OSGi bundle and I'll submit a PR soon but I need some info:

  • I see that you have configured the Felix SCR plugin but I do not see any SCR code/descriptor
  • I see that you have set the DynamicImport-Package directive but I do not see any invocation of Class.forName or similar stuffs

Is there a reason for the two point above ?

Different implementations of Lists/Sets/Maps are treated unequal

In some cases it might be nice if we can support this use case

public void testOrderedCollection() {
    List<String> a = Lists.newArrayList("one", "two", "three", "four",
            "five");
    List<String> b = Lists.newLinkedList(a);
    assertTrue(DeepEquals.deepEquals(a, b));
    }

Problems when comparing unordered data structures

There seem to be some issues with DeepEquals in the handling of isContained within compareUnorderedCollection/compareUnorderedMap (i.e. colliding hashcode values):

a) Options (IGNORE_CUSTOM_EQUALS and ALLOW_STRINGS_TO_MATCH_NUMBERS) are not propagated.
b) When progagating options the Set of visited ItemsToCompare (or a copy if it) should be passed on to prevent StackOverFlow from occurring.

Source files without license headers

Hi
The following source files are without license headers:

./src/main/java/com/cedarsoftware/util/ProxyFactory.java

./src/test/java/com/cedarsoftware/util/TestByteUtilities.java
./src/test/java/com/cedarsoftware/util/TestDateUtilities.java
./src/test/java/com/cedarsoftware/util/TestExceptionUtilities.java
./src/test/java/com/cedarsoftware/util/TestHandshakeException.java
./src/test/java/com/cedarsoftware/util/TestInetAddressUnknownHostException.java
./src/test/java/com/cedarsoftware/util/TestProxyFactory.java
./src/test/java/com/cedarsoftware/util/TestStringUtilities.java
./src/test/java/com/cedarsoftware/util/TestUrlInvocationHandlerWhenExceptionsAreThrown.java
./src/test/java/com/cedarsoftware/util/TestUrlInvocationHandlerWithPlainReader.java

Please, confirm the licensing of code and/or content/s, and add license headers.

https://fedoraproject.org/wiki/Packaging:LicensingGuidelines?rd=Packaging/LicensingGuidelines#License_Clarification

Thanks in advance
Regards

Graph Comparator issue with Set order

#74

I believe this issue still persists when GraphComparator::deepEquals is used. Set comparisons are failing but UnorderedMap comparison with a dummy value succeed

Question or Feature request: Compare complex objects

We try to use you GraphComparator to compare two complex objects each other.

For a simple object it is working really good, but I'm not able to get it work with properties which are an List of other Complex Objects which could contain again a complex object.

Let me explain better, if we have for Example this object (we will represent it for simplicity by an json object):

{
	"id": 1,
	"name": "Master1",
	"details": [{
		"id": 1,
		"name": "Master1.Detail1"
	}, {
		"id": 2,
		"name": "Master2.Detail2",
		"subDetail": [{
			"id1": 1,
			"name": "Master2.Detail2.SubDetail1"
		}]
	}]
}

In This Case if we change name in SubDetail1 and compare old with new object we need also to be notified that the property in the third level of 3 complex objects changed.

Is this possible with you library? Can we do a workaround to get it work?

Floating point values compared using ==

The following test fails

test() {
    Class1 x = new Class1(true, Math.tan(Math.PI / 4), 1);
    Class1 y = new Class1(true, 1.0, 1);
    assertTrue(DeepEquals.deepEquals(x, y));
}

class Class1 {
    private boolean b;
    private double d;
    int i;

    public Class1(boolean b, double d, int i) {
        super();
        this.b = b;
        this.d = d;
        this.i = i;
    }

}

Is java8 support removed?

Hi! For a not-so-legacy code i've to use java8, but if I try to use this library i receive this error:

java: cannot access com.cedarsoftware.util.GraphComparator
bad class file: /.m2/repository/com/cedarsoftware/java-util/2.0.0/java-util-2.0.0.jar!/com/cedarsoftware/util/GraphComparator.class
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

I must use an older version? GraphComparator has the same features?

GraphComparator: JSON path in fieldName

Option to use whole JSON path in the fieldName in GraphComparator.

This would be greatly appreciated, because when having the same field names as leafs in different document branches, it's not obvious which one is shown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.