# Question regarding ClassScheduling.java

**URL:** https://forums.foundationdb.org/t/question-regarding-classscheduling-java/3233
**Category:** Using FoundationDB
**Tags:** bindings
**Created:** [March 28, 2022, 2:30pm UTC](https://forums.foundationdb.org/t/question-regarding-classscheduling-java/3233 "2022-03-28T14:30:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rajivr](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/rajivr/32/1100_2.png) [@rajivr](https://forums.foundationdb.org/u/rajivr)
#### Post date: [March 28, 2022, 2:30pm UTC](https://forums.foundationdb.org/t/question-regarding-classscheduling-java/3233/1 "2022-03-28T14:30:28Z")

</div>

I am currently writing the Tokio equivalent of [ClassScheduling.java](https://apple.github.io/foundationdb/class-scheduling-java.html#appendix-classscheduling-java) app.

As I was studying the Java code, I found the something potentially strange in the following code snippet.

```java
// in method simulateStudents
try {
  // ...
  if (mood.equals("add")) {
    c = allClasses.get(rand.nextInt(allClasses.size()));
    signup(db, studentID, c);
    myClasses.add(c);
  } // ...
}

private static void signup(TransactionContext db, final String s, final String c) {
  db.run((Transaction tr) -> {
    // ...
    if (tr.get(rec).join() != null)
      return null; // already signed up

    // ...
  });
}

```

In the unlikely event where `rand.nextInt` returns the same number twice, wouldn’t we end up adding the same class to `myClasses` array twice?

---

<div class="post-metadata">

### Author: ![alloc](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alloc/32/9_2.png) [@alloc](https://forums.foundationdb.org/u/alloc)
#### Post date: [March 29, 2022, 4:34pm UTC](https://forums.foundationdb.org/t/question-regarding-classscheduling-java/3233/2 "2022-03-29T16:34:44Z")

</div>

Yeah, I believe you would. I think `myClasses` should probably be a `Set` instead of a `List`. It looks like the `signup` method already anticipates that you might already be signed up for a class, though the surrounding code doesn’t

---

<div class="post-metadata">

### Author: ![rajivr](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/rajivr/32/1100_2.png) [@rajivr](https://forums.foundationdb.org/u/rajivr)
#### Post date: [March 30, 2022, 12:26am UTC](https://forums.foundationdb.org/t/question-regarding-classscheduling-java/3233/4 "2022-03-30T00:26:02Z")

</div>

Thanks for the reply @alloc 🙂

Another scenario that I just encountered while debugging an error in the Tokio Class Scheduling App.

In the following code, suppose both `oldC` and `newC` contain classes that the student has already signed up for. Basically the student is trying to switch between two classes she has already signed up for.

```java
private static void switchClasses(TransactionContext db, final String s, final String oldC, final String newC) {
  db.run((Transaction tr) -> {
    drop(tr, s, oldC);
    signup(tr, s, newC);
    return null;
  });
}

```

In this scenario, there is nothing to switch. However, from what I am understanding, we would be dropping `oldC`, and ignoring the second signup of `newC`.
