How to Create a Unique Int for Each Person Added - java

I am working on an app right now where a person will be able to add different people to a list and then reuse those people. After they select a person, they can move on to a screen where you check a bunch of boxes such as "carrot" or "potato". Each person that is added needs to have a unique "carrot" or "potato" int so it can be used later to count up all the amount of times that carrot or potato has been checked off.
How do I go about doing the int creating whenever a new person is added? I know what to do from there but I honestly have no idea what to do about this.
So if I have a person created named "nick" I can create an int called "carrotnick". I need that id to be displayed later on without me knowing that there is a nick on the end, only the carrot part. So it can't be completely random. Still needs to be displayed later on somehow.

Use sqlite and a table with auto incremental field so for each person which be added to table there is a unique id so you can either get ids after app restarted

Related

Best table structure for *set* of ManyToMany

I have 2 Java Entities - Students and Courses.
The relation between them is ManyToMany - each student has a lot of courses and each course can be taken by a lot of students.
Because there are a lot of repeated sets of courses, we decided to make a table of sets of courses, and every time a student wants to take a set of courses, he needs to look if there is already set like this, if there is, he'll use its id, and if not, he'll create this set. And if the student is done with this set, we'll set null in the setId field.
The problem is that the course table is dynamic - we can add and remove course any time (unless there is a student that uses this course), and there is no limit to the number of the courses - it can be even 150.
We need the search for the existence of a set, to be as quick as possible.
We thought about:
HashCode but this HashCode needs to be dynamic and it should support even 2^100 possibilities.
Concatenate the id's of the courses as a string and search that string to see if this set exists.
Assign for each course a prime number and the id of the set will the multiplication of the prime numbers - the problem with that is the biggest number (set of all the courses) can be too big, and the decomposition of the number can take a long time.
What can be the best implementation for that requirements? Any idea will be welcome!
(The reason that we don't want to use the traditional ManyToMany table is that a performance issue. There is a big calculation that causes this.)
Thanks!
A prediction...
100 courses will lead to a few dozen very popular "sets", plus tens of thousands of infrequent sets.
You will find that the number of "sets" will be too unwieldy to be practical.
I have face same problem in my project where I shows document listing with default columns and order and which came from one table and if user changes the order or make any field available in his listing then another entry make to that table and row id is set for current user.
Here in my case order was needful you can ignore that and store JSON for user Selected course list and if list already exist in table then in this case you can assign set id for that user.
HashCode will not unique.
Some time Concatenate will have blanks spacing issue so SortedSet<Integer> JSON is always same.
For example: SortedSet setA = new TreeSet();

Parse.com preventing player from rating level multiply times

I am using parse.com cloud storage, to implement level sharing/downloading and rating for built in level editor for my game, so players are allowed to built and test their own created levels, latter on they can share it with different players, that`s how I upload it to the parse.com cloud storage:
ParseObject testObject = new ParseObject("Levels");
testObject.put("file", new ParseFile(name + ".lvl", levelString.getBytes()));
testObject.put("author", authorName);
testObject.put("email", authorEmail);
testObject.saveInBackground();
It works fine, but I wanted to let players also rate downloaded levels (lets say 1-5 stars) it could be simple, by creating new two fields called rating and ratings count, so every time someone will vote, I would add it to ratings count and would ++ ratings count.
Problem is, how to prevent player from rating particular level multiple times? Thanks.
I have thought about this for a project of mine. In the end you will need two data points.
You need to track the counts per rank on the object (Level in your case)
You need to track UserLevelRating, at minimum a reference to the user, reference to the target (Level), and the rating given (if you will let people change ratings)
Depending on how you want to implement it, to prevent rating something twice, or to allow people to change the rating they have given something, you would do a query for the current user and the Level. If a record is returned they have already voted, so prevent them from voting again.
You could add some cloud code using before-safe or after-save logic to handle other things, such as changing the vote and updating the counts on the target (Level).
Here's a sample of the logic I would use for a simple single vote system without changing votes:
Test for existence of UserLevelRating record, if it exists prevent voting
Saving vote, include User=current user, Level=selected level, Rating=stars given
Cloud code, in after-save of UserLevelRating, looks at Level property, loads the level, calls increment on the property for the rating (e.g. if Rating=3, increment("Stars3") would be called)
Anytime you load a Level object you would have counts for each rating, and could produce the average.

Adding a limit to JList MULTIPLE_INTERVAL_SELECTION

I am programming a little java application but since my java skills are only 2 or 3 month old I am faced with some technical difficulties.
My problem is the following : A customer call a hotel and wants to rent a room. The employee (using the application) takes note of the customer name, phone and the dates where he will arrive and leave (that part is done). When the customer arrive to my hotel, the employee finds the reservation using the customer confirmation number. He now has an interface where he see's the available room for the selected class (economy, first class, etc.).
I want my employee to select X ammount of room, where X is the room ordered by the customer. I am using a JList to show the rooms number. The problem is I can only set the selection mode to a single or multiple lines :
myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
I read all the javadoc and tried to find an existing method to set a limit to the MULTIPLE_INTERVAL_SELECTION, but in vain.
Any suggestion?
PS. My english is not the best. I'm trying to make this as clear as possible.

Cassandra user maintained CF indexes

Heres a glimpse of a POJO I want to have as a standard column family in
Cassandra:
class Person {
string key
string name
string dob
List<String> phones
List<String> ids }
obviously my key is my primary index.
Not sure How to do the Lists? have to create a new CF for them, or add them all as columns?
OK, so I also want everything searchable via equality.
get Person where phone= 1112223333
get Person where firstname=Al and dob=yyyy-mm-dd
I'm talking about 100million Persons, with all columns mostly unique
So does that rule out the builtin Secondary Index?
I "get" having my own CF as an index, where Primary key is the phone and column names are the primary key into Person CF.
But If I need to delete a phone, given key=1234, how do I maintain the CF Index for phones.
TIA Jurgyman
First, secondary indexes are not going to be the right choice, because they work well in cases where you have low cardinality (i.e. a lot of repeating values). Phone numbers don't satisfy this. They will technically work, but will be inefficient as your cluster size grows.
You are correct that if you need a two-way lookup without secondary indexes, probably the best approach is to maintain your own index. This follows the general design philosophy of writing your data the way you need to read it. Coming from an RDBMS world this can take some getting used to, as you're accustomed to normalization.
I think the piece you're missing is that you'll want to store the phone number in BOTH places--your person CF and the index. This will allow you to look at phones for people and people for phones. When you need to add/remove phones, you'll do it in both places simultaneously. You're just moving the logic that keeps the relationship from the DBMS to your application.

Android: SQLite One-To-Many relationship on a table that has records changing orders frequently

Relevant question: Android: SQLite one-to-many design
This is my first post on here, and it's also my first time dealing with databases. If there are any clarifications, or corrections I can make, please let me know.
I'm trying to set up an SQLite database to better store items collected from an RSS Feed. I'm trying to have a 3 table set-up. It looks like this:
Table 1: The Channel Table (items stay in constant order)
_id | Feed Location | Channel Title | Channel Description | ...
Table 2: The Item Table (The items should be stored in chronological order for ease of access and deletion)
_id | Item Title |...| Channel ID | ...
Where Channel ID has the row number that the Channel the item is part of is located.
That part is pretty simple, but here's my problem. I want to be able to query items by the categories that are relevant to them. They're included in the XML that'll be parsed, and it'd be great to sort by those values. So I started to set up another table, and implement the same one-to-many relationship described above, but then I ran into a problem. Because the id's of those items are likely to change when more items are parsed, the id's aren't static, and I can't have the categories link the way I did earlier. Also, another challenge I found was the fact that each category might've ideally needed to point to many different items because the Items' could've been relevant to the same Category.
And that's where I'm stuck.
Now I'm not sure I understand your situation correctly: are the id's of the Category's non-static? That seems a bit strange, since the entire idea of an id is that it stays constant through out it's life time.
If that still is the case, I would try to implement my own id structure and assure that it's constant. You could perhaps calculate an id based on the category name (use a md5 or sha1 sum as id, overkill but guaranteed to stay static and unique). Having a unique id structure for your categories would then allow you to use the same table structure as before (on the items and channels).
It would perhaps even be an idea to make all letters in the category name lowercase and remove non-alpha/numeric values before calculating the id. This way you'd get rid of Categories that are most likely the same ("Category" would then equal "Cat-e-gory").
I'm not sure I actually answered your question, but I hope you can make some use of it :-)

Categories

Resources