Quantcast
Channel: User Jonathan - Stack Overflow
Browsing all 40 articles
Browse latest View live
↧

Answer by Jonathan for BeanUtils.copyProperties() vs DozerBeanMapper.map()

You might check out my ModelMapper. It will intelligently map properties (fields/methods) even if the names are not exactly the same. Defining specific properties to be mapped or skipped is simple and...

View Article


Answer by Jonathan for Designing a Guava LoadingCache with variable entry expiry

Another alternative is my ExpiringMap (I'm the author), which supports variable entry expiration:Map<String, String> map = ExpiringMap.builder().variableExpiration().build();map.put("foo", "bar",...

View Article


Answer by Jonathan for What's the design pattern for object to object...

The related pattern is Assembler where you assemble some object given the contents of another. Since writing assemblers can be tedious and error-prone, you can use an object mapping library to do the...

View Article

Answer by Jonathan for Retrieve generic type information with reflection

The only way this is workable is if you subclass StringObjectKeyValueStore:class FriendStore extends StringObjectKeyValueStore<Friend>{}The you can resolve V for a particular type, such as...

View Article

Answer by Jonathan for How to determine generic parameter of one of...

This is straightforward using TypeTools (which I authored):Class<?> typeArg = TypeResolver.resolveRawArgument(MyClass2.class, MyClass1.class);assert typeArg == MyClass3.class;

View Article


Answer by Jonathan for Create instance of generic type in Java?

Here's an implementation of createContents that uses TypeTools (which I authored) to resolve the raw class represented by E:E createContents() throws Exception { return...

View Article

Answer by Jonathan for Get actual type of generic type argument on abstract...

You might check out TypeTools (which I authored) for this:Class<T> t = (Class<T>)TypeResolver.resolveRawArgument(BaseDao.class, getClass());

View Article

Answer by Jonathan for Handling connection failures in apache-camel

For automatic RabbitMQ resource recovery (Connections/Channels/Consumers/Queues/Exchanages/Bindings) when failures occur, check out Lyra (which I authored). Example usage:Config config = new Config()...

View Article


Answer by Jonathan for Create instance of generic type in Java when...

What you're trying to do can work so long as E is parameterized in a type definition somewhere. For example:Parameterized<E> pe = new Parameterized<E>();This will not allow you to resolve E...

View Article


Answer by Jonathan for Spring dependency injection generic service class

Having a deep hierarchy you'll need to use something like TypeTools (which I authored):class DeviceDao extends BaseDao<Device> {}Class<?> entityType =...

View Article

Answer by Jonathan for How to verify the (generic (generic argument))?

Check out TypeTools (which I authored) for this. Example:List<String> stringList = new ArrayList<String>() {};Class<?> stringType = TypeResolver.resolveRawArgument(List.class,...

View Article

Answer by Jonathan for How to simplify retry code block with java 8 features

Using Failsafe (which I authored):RetryPolicy retryPolicy = new RetryPolicy() .retryOn(ExecutionException.class) .withMaxRetries(3);Failsafe.with(retryPolicy) .onRetry(r -> LOG.debug("retrying..."))...

View Article

Answer by Jonathan for Circuit breaker design pattern implementation

For a simple, straightforward circuit breaker implementation, check out Failsafe (which I authored). Ex:CircuitBreaker breaker = new CircuitBreaker() .withFailureThreshold(5) .withSuccessThreshold(3)...

View Article


Answer by Jonathan for Retry Task Framework

Check out Failsafe (which I authored). It's a simple, zero-dependency library for performing retries, and supports synchronous and asynchronous retries, Java 8 integration, event listeners, integration...

View Article

Answer by Jonathan for How to check does interface with generic fit to class

You can use something like TypeTools (a library that I authored) to resolve type arguments so long as the argument is captured in a type definition. For example:interface DummyStringInterface extends...

View Article


Answer by Jonathan for How to get generic type "T" of class when reused in...

If you are using my TypeTools library, this becomes pretty simple:Class<?> t = TypeResolver.resolveRawArgument(Parent.class, Child.class);

View Article

Answer by Jonathan for JUnit terminates child threads

The basic technique that Eyal Schneider outlined in his answer is what my ConcurrentUnit library is intended to accomplish. The general usage is:Spawn some threadsHave the main thread wait or...

View Article


Answer by Jonathan for Singleton pattern with Go generics

I ended up solving this using the atomic.Pointer API, and rolled it into a simple library for others to use if they're interested: singlet. Re-working the original post with singlet looks like...

View Article

Best way to link to another package in doc.go files

What's the best way to link to a doc in another package when writing package docs in a doc.go file? Unfortunately, the normal approach of referencing an imported package doesn't work in doc.go files...

View Article

Answer by Jonathan for Listing each branch and its last revision's date in Git

Here's a variation that sorts by date and puts the branch name before the date, which I find more readable:git branch -v --sort='-authordate:iso8601'...

View Article
Browsing all 40 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>