1

Basically what I am trying to do is store a list of objects in Firebase and I want them to all be named differently. These objects are going to be literal classes (like school classes) with information such as student roster and teacher ID etc you get it. If someone creates an object, how can I ensure that the name that is stored on the Firebase is not a duplicate.

I know it is not possible with java but what I'm after is something to the effect of:

string className = "bio101";
ClassObj className = new ClassObj(variable x, variable y);

This way I can fetch className from an EditText and name the object after that.

Any hints?

adjuremods
  • 2,938
  • 2
  • 12
  • 17
ThePeskyWabbit
  • 417
  • 1
  • 7
  • 23

3 Answers3

1

When you want to have a unique property in the Firebase Database, the solution is to store the items under that property.

So if your class names have to be unique, you should keep a list of the classes by their class name:

classes
    bio101
      fullName: "Biology 101"
      teacher: "ThePeskyWabbit"
    cs101
      fullName: "Computer Science 101"
      teacher: "PCGALI ANDROID"

With this type of structure, it is impossible to have the same class name twice.

Note that this topic has been covered quite a few times already, so you might want to also read a few of the other answers:

And probably others in this list.

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

By using Object you can convert check this for more info [1]: http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true

0

i think google's AutoValue can help you.

https://github.com/google/auto/blob/master/value/userguide/index.md

dong sheng
  • 266
  • 3
  • 10