Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:08:50+00:00 2026-06-13T10:08:50+00:00

I am computing statistics grouped by an attribute. For each category of this attribute

  • 0

I am computing statistics grouped by an attribute. For each category of this attribute (given as Strings) I get values which I want to aggregate.

For this, I need a map from category to DescriptiveStatistics (provided by org.apache.commons.math.stat.descriptive). In this map, I’d have to check if, for a given category, the corresponding DescriptiveStatistics have been created yet. This check, and the creation of the new DescriptiveStatistics, should be done by the map.

I tested Apache’s LazyMap, but the non-genericity led me to Guava’s LoadingCache. Something along these lines works for me:

LoadingCache<String, DescriptiveStatistics> groupedStats =
        CacheBuilder.newBuilder()
        .build(new CacheLoader<String, DescriptiveStatistics>() {
            @Override
            public DescriptiveStatistics load(String key) {
                return new DescriptiveStatistics();
            }
        });

Is there a less “wordy” solution? One that wouldn’t require me to throw in an anonymous class just for instantiating objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:08:51+00:00Added an answer on June 13, 2026 at 10:08 am

    Your original code is exactly the code the Guava team would like you to write.

    We tend to avoid reflection (except, naturally, in com.google.common.reflect). It tends to be fragile and lose the benefits of compile-time checking — if a particular class doesn’t have a public no-arg constructor, and you used clazz.newInstance(), you wouldn’t find that out until runtime. Writing the direct implementation might cost you a line or two, but we consider the benefits worth it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the memory based computing model, the only running time calculations that need to
R is used for statistical computing. I don't know statistics never worked with R.
Updated: This question contains an error which makes the benchmark meaningless. I will attempt
Hello kind computing people, Okay this is super broad, but I thought I'd give
I'm trying to write my own Python code to compute t-statistics and p-values for
Working on computing the geometric mean of values in an array The function should
From here: https://computing.llnl.gov/tutorials/pthreads/#ConVarSignal Note that the pthread_cond_wait routine will automatically and atomically unlock mutex
I done computing intensive app using OpenCV for iOS . Of course it was
I'm computing a function f ( x ) = exp(- x ) in Matlab,
How similar is distributed computing and threading? I've found two papers coming to quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.