Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
Your constructor should look like this:

code:
public AppController(BBRepository bbRepository, UserRepository userRepository) {
	this.bbRepository = bbRepository;
	this.userRepository = userRepository;
	}
I'm assuming your controller needs both the BBRepository and the Userrepository, so you should make sure that both are set in the constructor. If you set your dependencier to "private final" your IDE will give you proper hints if do it something wrong and unless you absolutely need to change dependencies at runtime that should be the standard.
Also you do not need the @Autowired annotation for constructor injection.

Adbot
ADBOT LOVES YOU

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst

Jabor posted:

I do most of my coding over remote desktop and it's fine, lol

(but the machine I'm remoting into is literally in the same city so latency is minimal)

My flatmate has his remote desktop on Azure and it works surprisingly well. The low refresh rate obviously sucks, but there is very little perceivable latency when typing.

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
The loop you are trying to replace here is either complete garbage or intentionally confusing.

Try to think about what that loop is actually doing and look on the official documentation for java streams which methods you need. Also think about why they are iterating over document instead of the entries in wordFrequency.

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
You need to look at the API of maps before you just guess code. Your IDE already tells you that you cannot stream maps. It should also tell you all methods that maps provide. If you are just using a text editor for some reason you need to look at the official documentation here https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Map.html

You really need to learn how to use documentation to see what is actually possible before writing code.
Also what are you filtering? And what are you using that map for?

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
That's more like it. You could look it up on stack overflow, but you need to do .max(Comparator.naturalOrder()) for it to work.

If you only need to know how often the most common word appears you are now done. If you want to also know what the most common word is, you need to use a different Comparator and you cannot use wordFrequency.values(), since that only contains the frequency of words and not the word itself.
Even if you don't have to do it for your homework, you should try to do it by yourself by looking at the Comparator and Map documentation.

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
You did the exact thing you want to do a couple of posts earlier.

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
Remove the parenthesis before k.getValue()

Adbot
ADBOT LOVES YOU

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
The only thing i would change is your sort method. You can do better using the built in Comparator functions. See:
https://www.baeldung.com/java-8-comparator-comparing

Refactoring other stuff there would just make it more complicated for marginally less repetition.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply