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 8243869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:39:47+00:00 2026-06-07T21:39:47+00:00

I’m implementing an Statistics + Achievements system. Basically the structure is: An Achievement have

  • 0

I’m implementing an Statistics + Achievements system. Basically the structure is:

  • An Achievement have many related Statistics, this relations must associate each Achievement with the required Statistics (and it value). For example the Achievement1 needs the Statistic1 with value 50 (or greater) and the Statistic2 with value 100 (or greater).
  • Given an Statistic I need also know what are the related Achievements (in order to check them when the Statistic changes.

Both Stats and Achievements have an unique id.

My problem is I don´t know whats the best data(s) structure(s) for representing that. By the way I’m using:

SparseArray<HashMap<Statistic, Integer>> statisticsForAnAchievement;

For the first point where the index of the array is the Achievement ID and the HashMap contains the Statistic/TargetValue pairs. And a:

SparseArray<Collection<Achievement>> achievementsRelatedToAStatistic;

For the second point where the index is the StatisticID and the item is the collection of Achievements related.

Then I need to handle both objects keeping it coherence.

Is there an easier way of representing that? Thanks

  • 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-07T21:39:48+00:00Added an answer on June 7, 2026 at 9:39 pm

    As a Statistic(or a group of Statistics) describes an Achievement shouldn’t that/those Statistic/s be stored in the Achievement class? For example, an improved Achievement class:

    public class Achievement {
        SparseArray<Statistic> mStatistics = new SparseArray<Statistic>();
    
        // to get a reference to the statisctics that make this achievement
        public SparseArray<Statistic> getStatics() {
            return mStatistics;
        }
    
        // add a new Statistic to these Achievement
        public void addStatistic(int statisticId, Statistic newStat) {
            // if we don't already have this particular statistic, add it
            // or maybe update the underlining Statistic?!?
            if (mStatistics.get(statisticId) == null) {
                 mStatistic.add(newStat);
            }
        }
    
        // remove the Statistic
        public void removeStatistic(int statisticId) {
            mStatistic.delete(statisticId);
        }
    
        // check to see if this achievment has a statistic with this id
        public boolean hasStatistics(int statisticId) {
            return mStatistic.get(statisticId) == null ? false : true;
        }
    
        // rest of your code
    }
    

    Also, the Statistic class should store its target(the 50 value for Statistic1) value in it as a field.

    An Achievement have many related Statistics, this relations must
    associate each Achievement with the required Statistics (and it
    value). For example the Achievement1 needs the Statistic1 with value
    50 (or greater) and the Statistic2 with value 100 (or greater).

    The statistics are already stored in the achievments so all you have to do is store an array/list of ids of the achievments(or the achievements them self) and with this you’ll have access to the statistics that made those achievements.

    Given an Statistic I need also know what are the related Achievements
    (in order to check them when the Statistic changes.

    You would use the above array/list of achievements, iterate them and check to see if the achievement holds that particular Statistic:

    ArrayList<Achievement> relatedAchievements = new ArrayList<Achievement>();
    for (Achievement a : theListOfAchievments) {
         if (a.hasStatistics(targetStatistic)) {
              relatedAchievements.add(a); // at the end this will store the achievements related(that contain) the targetStatistic
         }
    }
    

    Another option is to have somewhere a static mapping that stores which achievements have a Statistic, mapping that would get updated each time one of the addStatictic or removeStatistic methods gets called.

    Regarding your code, if you don’t need the Statistic object and are happy with just holding a reference to its id then you could improve the statisticsForAnAchievement with:

    SparseArray<SparseIntArray> statisticsForAnAchievement;
    // the index of the SparseArray is the Achievement's id
    // the index of the SparseIntArray is the Statistic's id
    // the value of the SparseIntArray is the Statistic's value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.