# Tag Info

5

Exception Handling What are you doing in the exceptional case? Printing an error message (ugly stack trace, actually) and returning null. Now the caller has to handle the problem of the function returning null. You've said: I don't need error-handling except that I know I provided the wrong path. Well, want is the caller doing when it gets the null? ...

4

You don't need to loop. Lets look at what $0 \le i \le 10$ and $i\ \%\ 5$ results in. $$\begin{array}{l|l l l l l} i & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ i\ \%\ 5 & 0 & 1 & 2 & 3 & 4 & 0 & 1 & 2 & 3 & 4 & 0\\ \end{array}$$ From here we can see that if \\$...

3

Since you are handling the file in the same method of the extraction, you have to deal with the exception. I suggest that you separate the logic of the file reading and the logic of the parsing in two separate methods, so the method that handles the file will handle the exception. public static Stream<String> readFileAsLines(final String filePath) { ...

2

Technical improvements use albumMap.values() to get a Collection<Album> directly instantiated as list, which supports positional access get(index). So no need for array and filling loop. See Listing 1. use some of Android's ListView interfaces which usually provide a convenient method on their underlying data model like getItemAtPosition(position). ...

2

From @pepijno 's answer: What I've seen the most when it comes to builder patterns is that the object (in your case Animal) will get constructed in the build method of the builder. It is preferred to create instances of objects with all the data that the object should have, eg not creating invalid states of an object. That is true. However his following ...

2

What I've seen the most when it comes to builder patterns is that the object (in your case Animal) will get constructed in the build method of the builder. It is preferred to create instances of objects with all the data that the object should have, eg not creating invalid states of an object. This prevents you from having illegal state in your program which ...

1

I think I didn't write my question folloing the expectations of this forum. BTW, here is the solution for future readers. I wonder if this is the best way to achive it since I am creating a new instance (new Status) each time before the flux is closed. I would appreciated if someone can comment on bellow code. Honestly I still stumble on Lambda skill. ...

1

I changed some local variables and make them static variables, why ? because these are created and destroyed if you use serveral times the method onFling. The main Idea is to improve the performance and decrease the space your method uses. Also I refactorized some pieces of code class MyGestureDetector extends SimpleOnGestureListener { private ...

1

I have some suggestions for your code: String[][] a = new String[365][30]; int i = 0; int j = 0; for (Element row : rows) { Elements cells = row.getElementsByTag("td"); for (Element cell : cells) { a[j][i] = cell.text().concat(", "); i++; } j++; i = 0; } You are storing a m * n matrix of values retrieved by jsoup in a 2d ...

1

Since the code is not compiling, it will be hard to do a proper code review. In my opinion, you should rename the variable cmd in both of the methods, since it can be confusing. BinaryTree#put method In my opinion, it's a bad choice to use the range operators (<, >, <=, >=) with the compareTo method; since you always get one of those values (-1, 0 &...

1

Here is another method which uses one for loop public int[] squareUp(int n) { int[] arr = new int[n*n]; int counter1 = 1; int counter2 = n; for(int i=arr.length-1;i>=0;i--){ if((i+1)%n==0){ counter2 = (i+1)/n; counter1=1; } if(counter2>=counter1){ arr[i] = counter1; } else{ arr[i] = 0; } ...

1

I am not familiar with Android so I don't know how you get albumMap into the click event. Can you get selected Album (album object) into the event? If not.. I assume albumMap is a map between position to Album. If so I suggest the name postion2album. if not please update your post and clarify what this map is. So all you need to do is albumMap[...

1

When you want to test things that happened asynchronously, one solution is to give them some time to happen as you did. A bit more practical approach is to check if the assert condition is met in a loop and sleep a bit between the checks. if the condition is met no need to continue waiting. eventually, it needs to stop after a few tries or you have an ...

1

I think most people would be surprised and annoyed by an iterator that mutated previously yielded values every time you called next. While it makes sense to take what you can from the concept of an iterator, the thing you're trying to make isn't an iterator. (Perhaps the idea of a "cursor" would be more applicable, IDK.) Your proposed interface {hasCurrent, ...

Only top voted, non community-wiki answers of a minimum length are eligible