Exemplo n.º 1
0
 @Override
 public void load(Entity pool) {
   if (pool.getClass() == Pool.class) {
     setDate(((Pool) pool).getDate());
     setActive(((Pool) pool).isActive());
     setQuestions(((Pool) pool).getQuestions());
     setById(false);
   } else {
     throw new EntityException("Cannot load " + pool.getClass() + " in " + Pool.class);
   }
 }
Exemplo n.º 2
0
 /**
  * Reset the content of a world to be the same than the one passed as argument
  *
  * @param initialWorld
  */
 public void reset(World initialWorld) {
   entities = new ArrayList<Entity>();
   for (Entity oldEntity : initialWorld.entities) {
     try {
       Entity newEntity = oldEntity.getClass().newInstance();
       newEntity.copy(oldEntity);
       addEntity(newEntity);
     } catch (Exception e) {
       throw new RuntimeException(
           "Cannot copy entity of class " + oldEntity.getClass().getName(), e);
     }
   }
   this.isDelayed = initialWorld.isDelayed;
   this.delay = initialWorld.delay;
   this.parameters = (initialWorld.parameters != null ? initialWorld.parameters.clone() : null);
   notifyEntityUpdateListeners();
   notifyWorldUpdatesListeners();
 }
Exemplo n.º 3
0
  public static EntityCategory fromEntity(Entity entity) {
    for (Class<? extends Entity> entityClass : map.keySet()) {
      if (entityClass.isAssignableFrom(entity.getClass())) {
        return map.get(entityClass);
      }
    }

    return null;
  }
Exemplo n.º 4
0
  public void setEntitys(ArrayList<Entity> realEntities) {
    for (Entity e : realEntities) {

      JsonEntity JE = new JsonEntity(e.getX(), e.getY(), e.isSolid(), e.getClass().getName());
      if (e.isSign()) {
        JE.setSignText(e.getSignText());
      }

      entities.add(JE);
    }
  }
Exemplo n.º 5
0
  @Test
  public void entityClassTest() {
    container = new DefaultEntityContainer();

    container.newEntity();
    container.newEntity(new UUID(0, 0));
    container.newEntity(TestEntity.class);
    container.newEntity(new UUID(0, 1), TestEntity.class);

    final HashSet<DefaultEntity> entities =
        (HashSet<DefaultEntity>) container.getEntitiesOfType(DefaultEntity.class);
    for (final Entity entity : entities) {
      Assert.assertEquals(DefaultEntity.class, entity.getClass());
    }
    final Stream<DefaultEntity> entityStream = container.streamEntitiesOfType(DefaultEntity.class);
    entityStream.forEach(e -> Assert.assertEquals(DefaultEntity.class, e.getClass()));

    final Class<? extends TestEntity> type =
        asType(container.getEntity(new UUID(0, 0)), TestEntity.class).getClass();
    Assert.assertEquals(
        type, container.getEntityAsType(new UUID(0, 0), TestEntity.class).getClass());
    Assert.assertNull(container.getEntityAsType(new UUID(0, 100), TestEntity.class));

    final HashSet<TestEntity> testEntities =
        (HashSet<TestEntity>) container.getEntitiesAsType(TestEntity.class);
    for (final Entity entity : testEntities) {
      Assert.assertEquals(type, entity.getClass());
    }
    final Stream<TestEntity> testEntityStream = container.streamEntitiesAsType(TestEntity.class);
    testEntityStream.forEach(e -> Assert.assertEquals(type, e.getClass()));

    final Optional<TestEntity> optEntity =
        container.getOptEntityAsType(new UUID(0, 0), TestEntity.class);
    Assert.assertTrue(optEntity.isPresent());
    Assert.assertEquals(type, optEntity.get().getClass());
  }
Exemplo n.º 6
0
  /** Update position and check for collision through entities */
  public void update() {
    if (!GameActivity.bpause) {
      for (Entity e : entities) {
        if (e.getClass() == Ball.class) {
          for (Entity d : entities) {
            if (d != e)
              if (((Ball) e).checkCollision(d)) {
                ((Player) d).randomDecalageIA =
                    new Random().nextFloat() * d.height / 2 - d.height / 2;
              }
          }
        }
      }

      for (Entity e : entities) {
        if (e instanceof Player) {
          if (e == user) e.update(user_y);
          else {
            e.update(enemy_y);
          }
        } else {
          if (!isIA && !ServerUDP.server) {
            e.update();
            e.dx = ball_dx;
            e.dy = ball_dy;
            e.pos_x = ball_x;
            e.pos_y = ball_y;
          }

          if (isIA) {
            Random rnd = new Random();
            enemy_y = e.pos_y + 100 - rnd.nextInt(200);
            e.update();
          }

          if (!isIA && ServerUDP.server) {
            e.update();
            ball_x = e.pos_x;
            ball_y = e.pos_y;
            ball_dx = e.dx;
            ball_dy = e.dy;
          }
        }
      }
    }
  }
Exemplo n.º 7
0
  @Test
  public void testCollection() throws Exception {
    UUID applicationId = createApplication("testOrganization", "testCollection");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");

    Entity user = em.create("user", properties);
    assertNotNull(user);

    properties = new LinkedHashMap<String, Object>();
    properties.put(
        "actor",
        new LinkedHashMap<String, Object>() {
          {
            put("displayName", "Ed Anuff");
            put("objectType", "person");
          }
        });
    properties.put("verb", "tweet");
    properties.put("content", "I ate a sammich");
    properties.put("ordinal", 3);

    Entity activity = em.create("activity", properties);
    assertNotNull(activity);

    logger.info("" + activity.getClass());
    logger.info(JsonUtils.mapToFormattedJsonString(activity));

    activity = em.get(activity.getUuid());

    logger.info("" + activity.getClass());
    logger.info(JsonUtils.mapToFormattedJsonString(activity));

    em.addToCollection(user, "activities", activity);

    // test queries on the collection

    properties = new LinkedHashMap<String, Object>();
    properties.put(
        "actor",
        new LinkedHashMap<String, Object>() {
          {
            put("displayName", "Ed Anuff");
            put("objectType", "person");
          }
        });
    properties.put("verb", "tweet2");
    properties.put("content", "I ate a pickle");
    properties.put("ordinal", 2);
    Entity activity2 = em.create("activity", properties);
    activity2 = em.get(activity2.getUuid());
    em.addToCollection(user, "activities", activity2);

    properties = new LinkedHashMap<String, Object>();
    properties.put(
        "actor",
        new LinkedHashMap<String, Object>() {
          {
            put("displayName", "Ed Anuff");
            put("objectType", "person");
          }
        });
    properties.put("verb", "tweet2");
    properties.put("content", "I ate an apple");
    properties.put("ordinal", 1);
    Entity activity3 = em.create("activity", properties);
    activity3 = em.get(activity3.getUuid());
    em.addToCollection(user, "activities", activity3);

    // empty query
    Query query = new Query();
    Results r = em.searchCollection(user, "activities", query);
    assertEquals(3, r.size()); // success

    // query verb
    query = new Query().addEqualityFilter("verb", "tweet2");
    r = em.searchCollection(user, "activities", query);
    assertEquals(2, r.size());

    // query verb, sort created
    query = new Query().addEqualityFilter("verb", "tweet2");
    query.addSort("created");
    r = em.searchCollection(user, "activities", query);
    assertEquals(2, r.size());
    List<Entity> entities = r.getEntities();
    assertEquals(entities.get(0).getUuid(), activity2.getUuid());
    assertEquals(entities.get(1).getUuid(), activity3.getUuid());

    // query verb, sort ordinal
    query = new Query().addEqualityFilter("verb", "tweet2");
    query.addSort("ordinal");
    r = em.searchCollection(user, "activities", query);
    assertEquals(2, r.size());
    entities = r.getEntities();
    assertEquals(entities.get(0).getUuid(), activity3.getUuid());
    assertEquals(entities.get(1).getUuid(), activity2.getUuid());

    // empty query, sort content
    query = new Query();
    query.addSort("content");
    r = em.searchCollection(user, "activities", query);
    assertEquals(3, r.size());
    entities = r.getEntities();
    logger.info(JsonUtils.mapToFormattedJsonString(entities));
    assertEquals(entities.get(0).getUuid(), activity2.getUuid());
    assertEquals(entities.get(1).getUuid(), activity.getUuid());
    assertEquals(entities.get(2).getUuid(), activity3.getUuid());

    // empty query, sort verb
    query = new Query();
    query.addSort("verb");
    r = em.searchCollection(user, "activities", query);
    assertEquals(3, r.size());

    // empty query, sort ordinal
    query = new Query();
    query.addSort("ordinal");
    r = em.searchCollection(user, "activities", query);
    assertEquals(3, r.size());
    entities = r.getEntities();
    assertEquals(entities.get(0).getUuid(), activity3.getUuid());
    assertEquals(entities.get(1).getUuid(), activity2.getUuid());
    assertEquals(entities.get(2).getUuid(), activity.getUuid());

    // query ordinal
    query = new Query().addEqualityFilter("ordinal", 2);
    r = em.searchCollection(user, "activities", query);
    assertEquals(1, r.size());

    // query ordinal and sort ordinal
    query = new Query().addEqualityFilter("ordinal", 2);
    query.addSort("ordinal");
    r = em.searchCollection(user, "activities", query);
    assertEquals(1, r.size());
  }
Exemplo n.º 8
0
 public EntityDao(Entity obj) {
   this.entityClass = obj.getClass();
 }
 Class getInstanceClass() {
   return _cacheEntity.getClass();
 }
Exemplo n.º 10
0
 public ReflectionTarget(Entity ent, String methodName, Object[] arguments) {
   target = ent;
   method = findEntityMethod(target.getClass(), methodName, arguments);
   this.arguments = arguments;
 }