Quantcast
Channel: User muued - Stack Overflow
Browsing latest articles
Browse All 38 View Live

Comment by muued on How to remove a method using Javassist?

run java -cp javassist.jar javassist.cRepair

View Article



Comment by muued on Sorting (a stream of) doubles by absolute magnitude

I am constructing it by myself. I could also store them in a double[]. Just used the Stream for the summaryStatistics.

View Article

Comment by muued on Sorting (a stream of) doubles by absolute magnitude

So your suggestion is to just use the sum function and let the JDK do the tricky part? This would mean ignoring the API note and raise the question why they put it there in the first place....

View Article

Comment by muued on Schedule to run a method at periodic time´

if the docs specify 4 parameters and you only give 3, it clearly won't compile

View Article

Comment by muued on Why I'm getting different java versions

please post the output of /usr/libexec/java_home -V

View Article


Comment by muued on Why I'm getting different java versions

The pictures should tell you this is about OS X. There is no update-alternatives command in (vanilla) OS X.

View Article

Comment by muued on Why I'm getting different java versions

@chinna_82 how is a question rephrasing your question an answer?

View Article

Comment by muued on Fastest way to permute bits in a Java array

i can't imagine that twofold conversion would give you a speedup compared to working on a byte[] directly. I added such a solution to my answer.

View Article


Comment by muued on Picking a random element from a set

The iterator returned here should not be able to remove elements from dta (this can be achieved via guava's Iterators.unmodifiableIterator for example). Otherwise the default implementations of e.g....

View Article


Comment by muued on UML Exception Handler Notation

Your picture and wording suggest you are using Enterprise Architect, which is exactly the source of my confusion, since the concepts don't seem to match the specification. The InterruptFlow in the...

View Article

Answer by muued for How to retrieve list of favorite tags that is sorted...

You could use the following approach:static class Helper { String name; String tag; Helper(final String name, final String tag) { this.name = name; this.tag = tag; }}static void getFavourites() { final...

View Article

Answer by muued for Is this an acceptable implementation of the insertion...

You would have to linearly iterate the linked list in the inner loop instead of get(i), since LinkedList does not support RandomAccess.Otherwise every element access needs i steps to find the...

View Article

Answer by muued for Why does the first line throw NullPointerException but...

As already mentioned, laces[1] is null and you thus can't call any methods on it.You can use Objects.toString to get a null-safe String representation, eg System.out.println(Objects.toString(laces[1]));

View Article


Answer by muued for Inmutable instances/functional interfaces in Java

Sadly, the Java collection types lack immutable collections, but google guava comes with lots of immutable collections (see...

View Article

Answer by muued for Why return type cannot change when overloading a method...

You can answer this yourself by asking yourself which method would be called in the following scenario:public static void main(String[] args) { Object result = method1(2, 4);}

View Article


Answer by muued for Decoding Huffman file from canonical form

Your map contains the relevant information, but it maps symbols to codes.Yet, the data you are trying to decode comprises codes.Thus your map cant be used to get the symbols corresponding to the codes...

View Article

Answer by muued for Resolution of absolute path in java.nio

A Path always refers to some FileSystem. To use a Path as argument that refers to a different FileSystem than the Path used to call the method doesn't really sound like a typical use case. Thus, if an...

View Article


Answer by muued for How do I use Java's MidiSystem.write() function?

According to https://docs.oracle.com/javase/tutorial/sound/SPI-providing-MIDI.html :There are three standard MIDI file formats, all of which an implementation of the Java Sound API can support: Type 0,...

View Article

Answer by muued for Java Decode Run Length Assignment

I suggest you try to split your decode methods into two main logical parts:One for the case that you are actually performing a RLE and the other for the case where you have a sequence of non-repeated...

View Article

Answer by muued for How to get final package name?

There is no 1:1 relation between Statements and Expressions. E.g. ExpressionStmt contains just one Expression, but WhileStmt contains a condition Expression and a body comprising a further Statement....

View Article

Answer by muued for Understanding typesafety anomaly with Java generics

I guess you are aware, that generic types are gone at run time. Now, to see what's happening behind the scenes, let's look at this piece of codepublic static Class<?> getClass(final Object...

View Article


Answer by muued for Java 8 list manipulation

Duplicates in you stream may lead to duplicates in the categories list, when they are not contained in the categories list beforehand, since the filter method is applied for all items, before one of...

View Article


Answer by muued for Java Generics, Type Inference, Inheritance?

You have to remind yourself that the classes are compiled one by one. Java generics are not templates as in other languages. There will only be one compiled class and not one class per type it is used...

View Article

Answer by muued for how to get the height of avl tree in java

The default approach is to use recursion to determine the height.private int height(AVLNode t) { return t == null ? -1 : 1 + Math.max(height(t.left), height(t.right));}

View Article

Answer by muued for How does a hashSet admit elements

Use this answer:How does a Java HashMap handle different objects with the same hash code?and the information, that HashSet<E> is just a HashMap<E, Object>.

View Article


Answer by muued for Need help in figuring out what is wrong with basic...

your Buffer::getInstance method has the null check the wrong way, change it topublic static synchronized Buffer getInstance(){ if(instance == null){ instance = new Buffer(); } return instance;}

View Article

Answer by muued for Collections.unmodifiableList with custom objects, prevent...

Make Bar implement an Immutable Interface providing the getters only, eg ImmutableBar. Pass the instances of Bar as ImmutableBars to the GUI.

View Article

Answer by muued for Java Generic Types Mismatch Error

The system has to assume that T and U are two different types, since you gave them two different names. But you can just remove the additional generic type from your second ctor like that:public class...

View Article

Answer by muued for How to initialize a map using a lambda?

Google Guava's Maps class provides some nice utility methods for this.Additionally, there is the ImmutableMap class and its static methods.Have a look at: ImmutableMap.of(key1, value1, key2, value2,...

View Article



Answer by muued for Joining a List inside a map

Google Guava has a nice helper method for this:com.google.common.collect.Maps.transformValues(map, x -> x.stream().collect(joining("|")));using pure java, this would...

View Article

Answer by muued for Avoid Log4j/Slf4j debug enabled checks

By using Log4j2 and Java 8, you can easily make use of lambdas as described here, so in your case using debug(Message, Supplier) e.g. log.debug("Here is the data: {}", () ->...

View Article

Answer by muued for Limit groupBy in Java 8

This would give you the desired result, but it still categorizes all the elements of the stream:final int N = 10;final HashMap<String, List<StudentClass>> groupByTeachers =...

View Article

Answer by muued for JavaScript "or"-functionality in PHP

have a look at this answer.You can use the elvis operator like this:$phone = $row['phone'] ?: $row['mobile'];This would be shorter than$phone = $row['phone'] ? $row['phone'] : $row['mobile'];

View Article


Answer by muued for Should I do `Thread.currentThread().interrupt()` before...

I suggest throwing a ClosedByInterruptException. Although it belongs to the NIO library, it has a better defined API than the old InterruptedIOException, making it easier to handle. For example:try {...

View Article

Why is `Stream.collect` type-safe and `Stream.toArray(IntFunction)` is not?

Consider the following code fragmentString strings[] = {"test"};final List<String> collect = java.util.Arrays.stream(strings).collect(java.util.stream.Collectors.toList());final Double[] array =...

View Article

Answer by muued for Java algorithm to split time in decreasing portions

Say n is the size of your list, then you can determine your chunking factor a as follows:a = requiredConclusionTime/(2^n - 1).Then list item i gets a * 2^i time.See Geometric Progression at Wikipedia

View Article


Answer by muued for Merge multiple List into single List by maintaining order...

You could doList<Integer> one = Arrays.asList(1, 2, 3);List<Integer> two = Arrays.asList(4, 5, 6);List<Integer> three = Arrays.asList(7, 8, 9);List<List<Integer>> lists =...

View Article


UML Exception Handler Notation

What is the notation for an Exception Handler in UML activity diagrams? Is it just the lightning bolt? Or more than that?According to the specification v2.5.1 page 404:An ExceptionHandler is shown by...

View Article
Browsing latest articles
Browse All 38 View Live




Latest Images