|
tkinnun0 posted:I don't see relatedLinks being initialized, so it's probably null. Another thing is that arrays in Java do not expand after creation. Thanks! That took care of it. I've been switching between Java, JavaScript, Sling and PHP too much the past few days and I've pretty much just been cross-eyed because of it.
|
# ? Oct 21, 2009 19:27 |
|
|
# ? May 9, 2024 14:50 |
|
In an Apache Tapestry page, static variables should be shared among all instances, right? Meaning that assuming you preserve thread safety, the various instances can happily share a single resource object?
|
# ? Oct 22, 2009 09:44 |
|
yatagan posted:In an Apache Tapestry page, static variables should be shared among all instances, right? Meaning that assuming you preserve thread safety, the various instances can happily share a single resource object? After extensive testing, this is definitely true, but you have to create instance level accessor methods if the static components are in different classes. New question: Do you think it's bad form to do this? code:
|
# ? Oct 23, 2009 08:35 |
|
yatagan posted:Do you think it's bad form to do this? No, Strings are immutable and while arrays are not, the responsibility for the array contents is clearly passed to the called method.
|
# ? Oct 23, 2009 09:16 |
|
yatagan posted:
Since you know the size after the iteration, why don't you just pass it in instead of making two arrays?
|
# ? Oct 23, 2009 13:42 |
|
I have a slightly challenging design problem, looking for second opinions... Given 1) A slow InputStream with an arbitrarily large unknown amount of data (up to several gigabytes) 2) A vertically scrolling viewer that swaps in chunks of data from the InputStream as requested by the user 3) Enough disk space to cache everything, but we want to minimize its use. So... I figure I need some kind of caching mechanism between the InputStream and the viewer to provide random access, if not per character, at least by some arbitrarily sized chunk. The best idea I've been able to come up with is some kind of two file solution. One index file that maps offsets of chunks from the stream to offsets in a second file containing the data. Chunks of data would be written to the file as requested by the user by scrolling. So you'd ask the index file where bytes 50k - 55k are, if they don't exist then seek in the InputStream and write the data to the data file and update the index, otherwise read from its existing location in the data file. Does anyone know of a better way to tackle this? Or know of any existing packages/design patterns?
|
# ? Oct 23, 2009 15:31 |
What's a good way of figuring out the difference between two calendar objects and offsetting another calendar object by that amount? Right now I'm using Calendar.getTimeInMillis(), which returns a long, and then just casting it to an int and using Calendar.add(). There's got to be a better way than that. Maybe using a loop and increment it one day at a time and just count the number of iterations to get to the other calendar?
|
|
# ? Oct 24, 2009 01:51 |
|
yatagan posted:
code:
|
# ? Oct 24, 2009 02:19 |
|
funkatron3000 posted:I have a slightly challenging design problem, looking for second opinions...
|
# ? Oct 24, 2009 02:27 |
|
Functions: still a more fundamental tool of abstraction than anonymous classes. Just put this somewhere in your project. Unfortunately, it's still not bound anywhere in the standard libraries that I know of. code:
code:
|
# ? Oct 24, 2009 02:39 |
|
rjmccall posted:Functions: still a more fundamental tool of abstraction than anonymous classes. This gives a warning for a reason. If T is also generic, T[] will be of the erased type. Arrays do not play nicely with generics.
|
# ? Oct 24, 2009 03:38 |
|
Brain Candy posted:This gives a warning for a reason. Yes, but in this case the warning can be safely ignored because of untypable guarantees made by Array.newInstance. The only way you can "break" this method is by passing (say) Integer.TYPE instead of an object class, and it will still throw an exception instead of being quietly wrong. Brain Candy posted:If T is also generic, T[] will be of the erased type. Arrays do not play nicely with generics. That is not the reason it gives a warning. Also, the situation you describe is impossible without intentionally working around the type system; you cannot construct a Class object with a generic parameter type. Sadly, this does mean that you can't use my function on collections whose type parameter is itself parameterized, because you can't provide an appropriate Class. This is all Yet Another Compelling Reason why dynamically-checked array types were a terrible mistake. Also, I must note that every implementation of Collection.toArray has to do exactly what I'm describing here, uncheckable cast and all.
|
# ? Oct 24, 2009 07:14 |
|
fletcher posted:What's a good way of figuring out the difference between two calendar objects and offsetting another calendar object by that amount? Well, the simple and straightforward way is code:
|
# ? Oct 24, 2009 11:58 |
|
Fly posted:I think it's nicer to use a more expressive syntax:
|
# ? Oct 24, 2009 18:36 |
|
rjmccall posted:Also, I must note that every implementation of Collection.toArray has to do exactly what I'm describing here, uncheckable cast and all. don't use arrays.
|
# ? Oct 24, 2009 18:54 |
|
The whole point of this conversation was that the guy was using an API that wanted an array instead of a collection.
|
# ? Oct 24, 2009 21:01 |
|
Mustach posted:The whole point of this conversation was that the guy was using an API that wanted an array instead of a collection. Yes, yes, but if you use arrays enough to require a helper method you've got more problems than making the arrays.
|
# ? Oct 24, 2009 22:52 |
|
Mustach posted:This makes me . Initializing an array is not worth having an entire class definition sitting around in your jar.
|
# ? Oct 25, 2009 04:22 |
|
Brain Candy posted:Yes, yes, but if you use arrays enough to require a helper method you've got more problems than making the arrays. Heaven save us from the vicious tyranny of having too many helper functions.
|
# ? Oct 25, 2009 09:21 |
|
rjmccall posted:Heaven save us from the vicious tyranny of having too many helper functions. Way to miss the point!
|
# ? Oct 25, 2009 19:03 |
|
Brain Candy posted:Yes, yes, but if you use arrays enough to require a helper method you've got more problems than making the arrays. This is easy to say without actually sitting in front of code/libs which you may or may not have the power to change.
|
# ? Oct 26, 2009 05:45 |
|
epswing posted:This is easy to say without actually sitting in front of code/libs which you may or may not have the power to change. And sometimes even if you do have the power to change it, that doesn't mean you should go editing library files to better mesh with your code.
|
# ? Oct 26, 2009 06:17 |
|
If only there were some way to hide the interaction with bad code without re-writting it.
|
# ? Oct 26, 2009 14:06 |
|
Brain Candy posted:If only there were some way to hide the interaction with bad code without re-writting it. Wait what? Or do you mean "hide so that I don't have to stare at it but I still have to write it" type of hide?
|
# ? Oct 26, 2009 14:58 |
|
I have a problem, and absolutely no idea what the cause could be. Code is essentially like this:code:
Is there any possible explanation for such behavior? I could try to give some more specific details, but I don't know if they'd really be helpful.
|
# ? Nov 2, 2009 22:01 |
|
Kilson posted:I can see the code entering doThing1(), because of the log statement. However, at some point in doThing1(), something is happening to cause all the rest of the code to be skipped. All remaining code in doThing1(), and even all remaining code in someMethod() is simply not executed. I tried the catch(Throwable) to see if I was missing something, but there's nothing. Alternatively, pepper in some more log statements to narrow down the problem.
|
# ? Nov 2, 2009 22:22 |
|
Jethro posted:Can you step through it in a debugger? Not easily (this is a part of a big application that depends on third-party jar files and communication with multiple external servers to produce the error). I'll certainly try to set all this up locally and see if I can get it to work. quote:Alternatively, pepper in some more log statements to narrow down the problem. I know exactly which line of my code that's the last one to be executed. Beyond that, it goes into a third-party jar to do some axis communication. That still leaves me questioning exactly how this can cause my problem. It's as if the entire callstack is being obliterated and the program is silently continuing on its merry way. Any kind of problem should either be caught (by catch(Throwable t)) or cause a program crash, right?
|
# ? Nov 2, 2009 22:47 |
|
Ok this may sound retarded but it's bugging me and I can't find an explanation anywhere: "fagsfags".compareTo("123") indicates that numeric strings are always less than lower-case alphabetical ones, so can this approach safely be used to differentiate the two? For my purposes I'm butchering a string, and I want to see if the substring contains some numbers. Is this approach acceptable? Edit: I just realised I can accomplish the same thing much more elegantly with Character.isDigit(string), cool. The Sweetling fucked around with this message at 02:58 on Nov 3, 2009 |
# ? Nov 3, 2009 02:42 |
|
Also: http://www.asciitable.com/
|
# ? Nov 3, 2009 08:05 |
|
Kilson posted:I know exactly which line of my code that's the last one to be executed. Beyond that, it goes into a third-party jar to do some axis communication. That still leaves me questioning exactly how this can cause my problem. If it is hanging, then you can create a thread stack dump (`kill -QUIT <pid>` on Linux/Unix) to see why that thread is waiting.
|
# ? Nov 3, 2009 17:11 |
|
Kilson posted:I have a problem, and absolutely no idea what the cause could be. Code is essentially like this: That is the expected behaviour according to your code assuming doSomeStuff(); throws an instance of RuntimeException (aka unchecked exception). Exception is basically a directive to tell the program to stop doing immediately whatever it is doing and return back in the call stack to the point until some mechanism catches the exception, in this case that is the catch(Throwable t) in someMethod. Because the thrown exception sort of backtracks itself all the way to the beginning of that try..catch block and then skips over to the matching catch block, any method on that level after the method that caused the exception to be thrown isn't called. If you want to run doThing2() anyway, you need to place it into another try..catch block or if it's something you always want to run afterwards doThing1(), you could place it into a finally block to ensure it's run after everything is run in try block.
|
# ? Nov 3, 2009 17:34 |
|
Unless he did a fantastically bad job of explaining his problem, I think he was saying that the program was dieing, but even once he added in the try...catch no exceptions were being caught. If this was actually his problem, then you have some excellent question deciphering skills.
|
# ? Nov 3, 2009 19:19 |
|
Jethro posted:Unless he did a fantastically bad job of explaining his problem, I think he was saying that the program was dieing, but even once he added in the try...catch no exceptions were being caught. Well English is my third language so there's always margin for error. I did read the question through multiple times to try to understand it since it's a bit vague and by the wonderful process of elimination came to the conclusion that's the issue. There's of course possibility for infinite loops and maybe even System.exit(); somewhere in there but without additional details I'm just going to go for the seemingly simplest (well, simplest for me) solution. tl;dr: I'm once again trying to cover my rear end on this wonderful subforum.
|
# ? Nov 3, 2009 21:17 |
|
Jethro posted:Unless he did a fantastically bad job of explaining his problem, I think he was saying that the program was dieing, but even once he added in the try...catch no exceptions were being caught. You are correct. If there's an exception thrown in doThing1(), I'm not expecing doThing2() to be executed. I'm expecting the exception to be caught where it should be caught, and for execution of the main method to continue. The problem is that even with catch(Throwable t), there's nothing being caught. The execution simply stops. Furthermore, anything in the main method AFTER the try/catch block is also not getting executed. As I said, it makes no sense whatsoever, which is why I'm asking if anyone has ever seen anything like it, or has any ideas of what I can try. (I haven't had a chance to seriously try the debugger yet, been working on on-site interop testing all week :puke:)
|
# ? Nov 3, 2009 22:42 |
|
Install a custom SecurityManager just before the code is called such that checkExit() throws a SecurityException every time. Then in the finally block remove the manager so that you can actually exit normally. If you reach the catch block with a SecurityException, some brilliant soul decided to handle an error by calling Runtime.exit() or Runtime.halt().
|
# ? Nov 3, 2009 23:18 |
|
Kilson posted:You are correct. If there's an exception thrown in doThing1(), I'm not expecing doThing2() to be executed. I'm expecting the exception to be caught where it should be caught, and for execution of the main method to continue. edit: or install VisualVM from Sun and see what's going on. http://java.sun.com/javase/6/docs/technotes/guides/visualvm/index.html
|
# ? Nov 3, 2009 23:22 |
|
It doesn't stop or exit, it just continues running (after skipping whatever code it skips) as if nothing ever happened.
|
# ? Nov 4, 2009 05:33 |
|
Kilson posted:It doesn't stop or exit, it just continues running (after skipping whatever code it skips) as if nothing ever happened. I've had this happen to me before in tomcat/spring. I couldn't believe it. Everything in a controller was in a try/catch(Throwable) { log('hi!') }, something was breaking, yet the page would still partially load in the browser, no errors. Never could explain why/how.
|
# ? Nov 4, 2009 07:02 |
|
So I'm writing this program that detects deadlock, given a number of resources, process, requests, and releases. I wrote out my design, everything looks gravy. The actual program itself isn't turning out so well. I've isolated the problem (I think) to this little segment of code, that is supposed to take the n+1 power of an n x n matrix.code:
|
# ? Nov 4, 2009 11:21 |
|
|
# ? May 9, 2024 14:50 |
|
FreshShoez posted:Is there anyone who could help me out? Your first loop doesn't even copy the matrices, it misses the outside edge. Your "oh god why" fourth order quadratic time clusterfuck loop does something that I'm not going to bother figuring out. Try this: http://math.nist.gov/javanumerics/jama/ Or this: http://www.ujmp.org/ Or this: http://acs.lbl.gov/~hoschek/colt/ Or this: http://commons.apache.org/math/
|
# ? Nov 4, 2009 11:45 |