|
If you shuffle the list before you sort it, doesn't that give you random output without needing a randomized Comparator?
|
# ? Feb 9, 2014 23:51 |
|
|
# ? Jun 10, 2024 23:24 |
|
bartkusa posted:If you shuffle the list before you sort it, doesn't that give you random output without needing a randomized Comparator? Do this. A randomized comparator isn't going to actually be random. For example, if you use a stable sort, then it'll be biased towards keeping same-valued elements in their original order.
|
# ? Feb 10, 2014 02:29 |
|
supermikhail posted:I have need of the following clever algorithm: Java code:
|
# ? Feb 10, 2014 07:33 |
|
Max Facetime posted:There's no explicit randomization: in the unlikely event that several Entries have the same UTC millisecond timestamp it's unspecified which one of them Stream#findFirst is going to pick. Keep in mind that "unspecified" is not the same as "random" - in fact it's very likely that the determination does not involve randomness at all. If you want to choose randomly when presented with multiple entries that have identical timestamps, you can assign each entry a random value and use that as a third tier to the comparator (phoneposting so no code, but it's fairly straightforward).
|
# ? Feb 10, 2014 08:47 |
|
Jabor posted:Keep in mind that "unspecified" is not the same as "random" - in fact it's very likely that the determination does not involve randomness at all. Well, sufficiently bad pseudo-randomness is indistinguishable from "unspecified" (as you could always use the Stream as a replacement for your source of bad pseudo-randomness).
|
# ? Feb 10, 2014 09:03 |
|
I've realized something, and now I'm completely confused. By the way,Max Facetime posted:
Is Java 8 this crazy with operators, or is it just pseudocode? Anyway. I remembered that the exact Date is not relevant for me; and how to select a random entry from several that are near each other in date... that's a whole other bag of worms.
|
# ? Feb 10, 2014 17:20 |
|
supermikhail posted:Is Java 8 this crazy with operators, or is it just pseudocode? -> is the lambda syntax. http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax
|
# ? Feb 10, 2014 21:24 |
|
I'm leaning heavily on Guava here, but maybe use Optional<Date> in a Multimap? Java code:
|
# ? Feb 10, 2014 21:42 |
|
supermikhail posted:I've realized something, and now I'm completely confused. By the way, Oh it compiles fine, but there's at least one runtime bug. The call Stream#sorted() is stateful so the filter() method has to be called before sorted() is called to avoid a NullPointerException. I added grouping of the Entries at 1 day resolution and then selecting properly randomly from them, so all cases are handled now, I think? Still no test runs but I made it a one-liner instead! Java code:
|
# ? Feb 10, 2014 22:40 |
|
I should have been clearer in my previous post. It's (practically) impossible to have two identical dates (except nulls), so the original question doesn't apply anymore. Instead, I'm trying to come up with a method that would retrieve the entries by approximate date (and random if they are nearby). But I don't want to manually set the margin of approximation. What would happen if I just took some percentage of random entries and selected the oldest from them? Maybe that's a question for the Math thread.
|
# ? Feb 10, 2014 22:40 |
|
Wouldn't that skew all your choices to the older side of the distribution, and make the newer ones never come up at all? Since they'd always be ignored in favour of the older picks I'm still not entirely sure what you want to do - like this thing about not manually setting the margin of approximation... what does determine it? It might help to lay out a step by step example of what you want to happen
|
# ? Feb 10, 2014 23:14 |
|
baka kaba posted:Wouldn't that skew all your choices to the older side of the distribution, and make the newer ones never come up at all? Since they'd always be ignored in favour of the older picks So the entries that do come up can either be updated to "now" (as the date), or "skipped". In any case they are in a different place the next time. This could for example be useful when you have many physical exercises to work on, and want to work on them uniformly. I've found that simple randomness can leave periods between reappearances of entries that are too long, and I'm trying to compensate for it. (The example is, by the way, just an example.) Basically, I'd like the method to watch out that entries do not get too old, but the definition of too old is problematic, considering that it should be relative to all the entries. Hope this explanation helps. So, as step-by-step as I know: from the collection get an entry randomly, or, if some are especially old, get one of those -> option a) move the entry to the newest end of the collection; option b) set the entry aside for a while, then (or when you run out of other entries) insert it back into the oldest entries -> repeat until tired. Maybe a solution lies in this reworking of my problem.
|
# ? Feb 11, 2014 01:23 |
|
Maybe turn it around? If some old entries don't get picked often enough then it means newer entries get picked too often. This might be easier to track. To compensate it might be enough to add a random change to skip such an entry, proportional to how many times it's been chosen recently.
|
# ? Feb 11, 2014 03:12 |
|
It looks likely that I will need to start writing Java code in the not too distant future. I am a competent developer in C++ and python but I haven't touched Java since CS101. What should I read to bring myself up to speed on how to Java properly? In the near term I will need to write library, which should be distributable on its own, and also some code that uses that library inside of Hadoop. I feel like I can probably muddle my way though the actual writing code part, but I know nothing about how a Java development workflow is supposed to work. Is Eclipse still the go-to IDE? What about build systems? How do I package code into a distributable library? How do I manage dependencies between projects? What things don't I know that I don't even know I don't know?
|
# ? Feb 12, 2014 23:43 |
|
Eclipse or IntelliJ are the preferred Java IDEs. Maven in an incredibly popular dependency-management/build system; however, it suffers from being a dependency-management and a build system. I've heard good things about Gradle, but never used it myself. If you want to learn idiomatic Java, I'd check out Java Concurrency in Practice. It would probably also be helpful to familiarize yourself with the Apache Commons and Guava libraries; these include the functionality that core Java doesn't, but should. Edit: vv +1 Effective Java. It is the book whose name I was trying to remember but couldn't. Gravity Pike fucked around with this message at 01:20 on Feb 13, 2014 |
# ? Feb 13, 2014 01:18 |
|
The answer to like 50 of your questions is Maven! Seriously read the docs and it will solve your dependencies, execute your build, run your tests, and create a neat and tidy package that is then callable from other maven projects. Eclipse is still the goto IDE, but I prefer Netbeans since it has tighter Maven integration out of the box. Another tool I hear good praise for is IntelliJ, you really can't go wrong with any of them, try em out and pick the one that least offends you. Also read Effective Java by Joshua Bloch once you're past the syntax to get some some deeper insight into Java design. e: Yeah also Java Concurrency in Practice is a must if you're writing any kind of multi threaded code.
|
# ? Feb 13, 2014 01:19 |
|
Janitor Prime posted:The answer to like 50 of your questions is Maven! Seriously read the docs and it will solve your dependencies, execute your build, run your tests, and create a neat and tidy package that is then callable from other maven projects. I'm going to second Gradle over Maven if you have the choice. The problem with Maven is that he only asked a few questions, but maven will still answer 50 of them like it or not. Eclipse has a not-entirely-undeserved reputation for severe bloat, although the IntelliJ debugger had some obnoxious tics when I last used it (What's that? You want to step per thread instead of stepping in a way that steps all threads simultaneously? Why would you possibly want to do that? ) You should probably take a look at both for each, then choose whatever your team is using.
|
# ? Feb 13, 2014 02:30 |
|
Seeing as how this is the Java thread this is probably the best place to start a serious discussion on Gradle. I've seen it brought up numerous times in other discussions and it seems to be gaining traction (especially with the Android stack), but from my quick glance I can't understand what problem it's trying to solve that Maven doesn't handle; other than it's not XML and it's not Maven. Please enlighten me!
|
# ? Feb 13, 2014 03:08 |
|
Janitor Prime posted:I can't understand what problem it's trying to solve that Maven doesn't handle; other than it's not XML and it's not Maven. That's not enough for you?
|
# ? Feb 13, 2014 03:36 |
|
I recently took up using Maven and it's great so far. My only grievance so far is that the documentation is a little schizophrenic. It is a bit overwhelming in it's usage scope though. How's the Gradle documentation?
|
# ? Feb 13, 2014 03:44 |
|
Janitor Prime posted:Seeing as how this is the Java thread this is probably the best place to start a serious discussion on Gradle. I've seen it brought up numerous times in other discussions and it seems to be gaining traction (especially with the Android stack), but from my quick glance I can't understand what problem it's trying to solve that Maven doesn't handle; other than it's not XML and it's not Maven. The good thing about maven is that it enforces its structure (good for new projects). The bad thing about maven is that it enforces its structure (bad for old projects looking to migrate to maven). If you want to do anything in maven that other people didnt provide a plugin for you have to write your own plugin. In gradle, you can achieve your crazy ideas with a few lines of groovy. Gradle plays well with the maven structure so if you like it you can keep on using it. This is just from the top of my head, there are obviously lots of other more serious reasons why one should use one over the other.
|
# ? Feb 13, 2014 04:18 |
|
I'm not an expert on Gradle, but from what I've learned one of the main reasons is that it is, or can be, smarter about recompiling only the code that does need recompiling, which could save time in larger projects.
|
# ? Feb 13, 2014 12:04 |
|
Related to the book recommendations above, I really enjoyed The Well Grounded Java Developer. It covers additions to java concurrency that weren't in Java Concurrency In Practice, as well as giving an intro to a lot of other Java topics.
|
# ? Feb 13, 2014 14:28 |
|
If you know a more elegant solution, share!code:
|
# ? Feb 15, 2014 14:14 |
|
supermikhail posted:If you know a more elegant solution, share! The jlabel automatically puts ellipsis if the text it has to display is longer than its bounds. To make a jlabel wrap the text it should put between <html></html> tags. What kind of layout do you have there that a jlabel can break? I can see that you have a JScrollPane, to which I presume you have disabled the vertical scrollbar. And then I presume the JPanel that is a child of that JScrollPane is Scrollable, so you have control over the width/height of the component. I can't really imagine how can a layout be broken, but if that's the case and there's nothing that can be done about it, probably your code is the best way to go.
|
# ? Feb 15, 2014 17:29 |
|
Oh, no. (Maybe my Java is broken.) The thing is thus: JPanel ( JScrollpane ( JLabel ) ) And I'm using the scrollpane to find out if the panel is about to be pierced by the label. For some reason if I stuffed a long text in the label before that, the panel resized out of the frame which didn't (and in any case I don't think resizing the frame for changing text is practical). So I guess I could just try to set the size of the label directly and it would do the magic without touching the fonts themselves. Or maybe it's just Netbeans.
|
# ? Feb 15, 2014 18:25 |
|
supermikhail posted:Oh, no. (Maybe my Java is broken.) So you have a JLabel in a JScrollPane? That sounds a bit weird. Why not use a JTextArea? And make it readonly (or disabled) and then it can properly handle multiline text for you. The layout of the panel handles the scrollpane, and the component in it. What layout manager are you using? GridBagLayout is a very flexible layout manager, it can handle pretty much any kind of layout you throw at it.
|
# ? Feb 15, 2014 19:58 |
|
Well, call me weird, but I don't want multiline text. I think design would be better for it. Anyway, labels really put ellipses in automatically, except you have to do some uncommon things to the properties. That'll sure clear some clutter. Thanks for your help.
|
# ? Feb 15, 2014 20:40 |
|
I feel that the probable inefficiency of this code is going to haunt me, so here is a bunch of it. If anyone could be bothered to take a look and post a comment, I would be very grateful.code:
|
# ? Feb 17, 2014 18:45 |
|
supermikhail posted:with Calendar and Date in it Use JodaTime.
|
# ? Feb 17, 2014 19:00 |
|
Brain Candy posted:Use JodaTime. Nice. That's going to make the code much clearer, if nothing else.
|
# ? Feb 17, 2014 19:36 |
|
Brain Candy posted:Use JodaTime. This should be in the OP, if not be the entirety of the OP.
|
# ? Feb 17, 2014 19:38 |
|
*Scroll down* *See Calendar* Ah! I know how he can make this- Brain Candy posted:Use JodaTime. Yeah. Java's built-in date/time implementation is pretty crap.
|
# ? Feb 17, 2014 20:29 |
|
Does anyone feel that JavaFX is ready for production?
|
# ? Feb 18, 2014 15:20 |
|
I like what I've seen of JDK 8's new java.time package, but I haven't had a chance to try it out yet. It looks like they took a lot of inspiration from JodaTime.
|
# ? Feb 18, 2014 17:57 |
|
That's because it was written mainly by the same person behind JodaTime. He keeps a blog of the work he's being doing on it http://blog.joda.org/
|
# ? Feb 18, 2014 18:57 |
|
Okay, so I'm having a bit of trouble with Linked Lists. Here's my assignment:quote:A circular list is a linked list in which the last link points back to the first link. They gave me this class to use to check to make sure the two classes I must make work Java code:
Java code:
Java code:
I'm also not sure what to do with method peek() and what to do with the constructor for the CircList class nor am I exactly sure what the class Link is supposed to do much less why some of the methods in class CircList are of type Link. I managed to get a pretty solid understanding of stacks yesterday in time for an assignment, but Linked Lists are throwing me for a loop and any insight would be extremely appreciated. edit: I did make an attempt to populate some of the methods with code, how well I did it or if it's even the right idea remains to be seen. FAT32 SHAMER fucked around with this message at 22:21 on Feb 20, 2014 |
# ? Feb 20, 2014 22:18 |
|
Basically in this assignment your Nodes are called Link, see how CircList has a next element of type Link in it? In your insert method you just create a new Link with the given id and attach it to the other links. The methods aren't of type Link, they return a Link! So the peek method should just return current Link, delete will remove current from the chain and return it etc.. Janitor Prime fucked around with this message at 23:43 on Feb 20, 2014 |
# ? Feb 20, 2014 23:41 |
|
Janitor Prime posted:Basically in this assignment your Nodes are called Link, see how CircList has a next element of type Link in it? In your insert method you just create a new Link with the given id and attach it to the other links. Okay, that makes WAY more sense! What should I do for the constructor since the current = new Link( id ) is in the insert method? Call method insert( long id )?
|
# ? Feb 20, 2014 23:57 |
|
|
# ? Jun 10, 2024 23:24 |
|
I think an empty constructor is appropriate for that data structure, you normally use it to set initial values for your variables but there really isn't anything to do here.
|
# ? Feb 21, 2014 00:08 |