synchronized int allocate(GlowEntity entity){
  if (entity.id != 0) {
    throw new IllegalStateException("Entity already has an id assigned.");
  }
  int startedAt=lastId;
  for (int id=lastId + 1; id != startedAt; ++id) {
    if (id == -1 || id == 0)     continue;
    if (usedIds.add(id)) {
      entity.id=id;
      lastId=id;
      return id;
    }
  }
  throw new IllegalStateException("No free entity ids");
}

synchronized int allocate ( GlowEntity entity ) { if ( entity . id != 0 ) { throw new IllegalStateException ( "Entity already has an id assigned." ) ; } int startedAt = lastId ; for ( int id = lastId + 1 ; id != startedAt ; ++ id ) { if ( id == - 1 || id == 0 ) continue ; if ( usedIds . add ( id ) ) { entity . id = id ; lastId = id ; return id ; } } throw new IllegalStateException ( "No free entity ids" ) ; }
allocates the id for an entity . this method performs synchronization as it might be accessed by multiple world threads simultaneously .
