Beispiel #1
0
 @Override
 public String printWeightMisc() {
   String turretString =
       !tank.hasNoTurret()
           ? StringUtil.makeLength("Turret:", getPrintSize() - 5)
               + TestEntity.makeWeightString(getTankWeightTurret())
               + "\n"
           : "";
   String dualTurretString =
       !tank.hasNoDualTurret()
           ? StringUtil.makeLength("Front Turret:", getPrintSize() - 5)
               + TestEntity.makeWeightString(getTankWeightDualTurret())
               + "\n"
           : "";
   return turretString
       + dualTurretString
       + (getTankWeightLifting() != 0
           ? StringUtil.makeLength("Lifting Equip:", getPrintSize() - 5)
               + TestEntity.makeWeightString(getTankWeightLifting())
               + "\n"
           : "")
       + (getWeightPowerAmp() != 0
           ? StringUtil.makeLength("Power Amp:", getPrintSize() - 5)
               + TestEntity.makeWeightString(getWeightPowerAmp())
               + "\n"
           : "");
 }
Beispiel #2
0
  public float getTankWeightTurret() {
    float weight = 0f;

    // For omni vees, the base chassis sets a turret weight
    if (tank.isOmni() && tank.getBaseChassisTurretWeight() >= 0) {
      weight = tank.getBaseChassisTurretWeight();
    } else {
      // For non-omnis, count up the weight of eq in the turret
      for (Mounted m : tank.getEquipment()) {
        if ((m.getLocation() == tank.getLocTurret()) && !(m.getType() instanceof AmmoType)) {
          weight += m.getType().getTonnage(tank);
        }
      }
      // Turrets weight 10% of the weight of weapons in them
      weight = weight / 10.0f;
    }

    if (tank.isSupportVehicle()) {
      if (getEntity().getWeight() < 5) {
        return TestEntity.ceil(weight, CEIL_KILO);
      } else {
        return TestEntity.ceil(weight, CEIL_HALFTON);
      }
    } else {
      return TestEntity.ceilMaxHalf(weight, getWeightCeilingTurret());
    }
  }
 public static TestEntity getTestEntity() {
   TestEntity t = new TestEntity();
   t.setName(Utils.randomString(8));
   t.setDescription(Utils.randomString(32));
   t.setTemplate(false);
   t.setTimestampCreated(new Date());
   return t;
 }
 @Test
 @SuppressWarnings("unchecked")
 public void testGetContainerProperty() {
   TestEntity entity = createTestEntity();
   Property<String> containerProperty =
       (Property<String>) container.getContainerProperty(entity.getId(), TestEntity.TEST_PROPERTY);
   assertEquals("content", entity.getTestString(), containerProperty.getValue());
 }
Beispiel #5
0
  public void testGet() {
    EntityList<TestEntity> list = new EntityList<TestEntity>();
    TestEntity te1 = new TestEntity("hello");

    list.add(te1);

    // get() on a key which doesn't exist should return null
    assertNull(list.get(new Hash("good bye")));

    // get() on the key for te1 should find te1
    assertTrue(te1.equals(list.get(te1.getID())));
  }
 @Override
 public int compare(TestEntity entity1, TestEntity entity2) {
   if (entity1 == entity2) {
     return 0;
   }
   if (entity1 == null) {
     return -1;
   }
   if (entity2 == null) {
     return 1;
   }
   return new CompareToBuilder()
       .append(entity1.getUsername(), entity2.getUsername())
       .toComparison();
 }
Beispiel #7
0
 @Override
 public float getWeightControls() {
   if (tank.hasNoControlSystems()) {
     return 0;
   } else {
     return TestEntity.ceilMaxHalf(tank.getWeight() / 20.0f, getWeightCeilingControls());
   }
 }
Beispiel #8
0
  public void testSize() {
    EntityList<TestEntity> list = new EntityList<TestEntity>();
    TestEntity te1 = new TestEntity("hello");

    // A new list should have size 0
    assertEquals(list.size(), 0);

    list.add(te1);

    // We've added one entity so the size should be 1
    assertEquals(list.size(), 1);

    list.remove(te1.getID());

    // Now it's removed again the size should be back to 0
    assertEquals(list.size(), 0);
  }
Beispiel #9
0
  public void testHasRemovedEntities() {
    EntityList<TestEntity> list = new EntityList<TestEntity>();
    TestEntity te1 = new TestEntity("hello");

    // A new list shouldn't have any removed entities
    assertFalse(list.hasRemovedEntities());

    list.add(te1);

    // We've added 1 new entity, but it isn't removed yet
    assertFalse(list.hasRemovedEntities());

    list.remove(te1.getID());

    // Now we should have a removed entity
    assertTrue(list.hasRemovedEntities());
  }
  @Test
  public void createAndModifyEntity() throws Exception {
    UnitOfWork uow = this.module.newUnitOfWork();
    TestEntity entity = uow.newEntity(TestEntity.class);
    uow.complete();

    uow = this.module.newUnitOfWork();
    entity = uow.get(entity);
    entity.testString().set("NewTestString");
    uow.complete();

    uow = this.module.newUnitOfWork();
    entity = uow.get(entity);
    Assert.assertEquals(
        "New value did not store in indexing.", "NewTestString", entity.testString().get());
    uow.discard();
  }
Beispiel #11
0
  public void testRemove() {
    EntityList<TestEntity> list = new EntityList<TestEntity>();
    TestEntity te1 = new TestEntity("hello");
    TestEntity te2 = new TestEntity("good bye");

    // Add 2 entities
    list.add(te1);
    list.add(te2);

    // The size should be 2
    assertEquals(list.size(), 2);

    // Remove te2 only
    list.remove(te2.getID());

    // The size should now be 1
    assertEquals(list.size(), 1);
  }
Beispiel #12
0
 public void setTestNotNull(TestEntity testNotNull) {
   if (testNotNull == null) {
     throw new DaoException(
         "To-one property 'testIdNotNull' has not-null constraint; cannot set to-one to null");
   }
   this.testNotNull = testNotNull;
   testIdNotNull = testNotNull.getId();
   testNotNull__resolvedKey = testIdNotNull;
 }
Beispiel #13
0
 public float getTankWeightLifting() {
   switch (tank.getMovementMode()) {
     case HOVER:
     case VTOL:
     case HYDROFOIL:
     case SUBMARINE:
     case WIGE:
       return TestEntity.ceilMaxHalf(tank.getWeight() / 10.0f, getWeightCeilingLifting());
     default:
       return 0f;
   }
 }
Beispiel #14
0
 @Override
 public float getWeightPowerAmp() {
   if (!engine.isFusion() && (engine.getEngineType() != Engine.FISSION)) {
     int weight = 0;
     for (Mounted m : tank.getWeaponList()) {
       WeaponType wt = (WeaponType) m.getType();
       if (wt.hasFlag(WeaponType.F_ENERGY)
           && !(wt instanceof CLChemicalLaserWeapon)
           && !(wt instanceof VehicleFlamerWeapon)) {
         weight += wt.getTonnage(tank);
       }
       if ((m.getLinkedBy() != null)
           && (m.getLinkedBy().getType() instanceof MiscType)
           && m.getLinkedBy().getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
         weight += ((MiscType) m.getLinkedBy().getType()).getTonnage(tank);
       }
     }
     return TestEntity.ceil(weight / 10f, getWeightCeilingPowerAmp());
   }
   return 0;
 }
Beispiel #15
0
 public void post(TestEntity entity) {
   print("post: " + entity == null ? null : entity.toString());
 }
Beispiel #16
0
 @Override
 public String printWeightControls() {
   return StringUtil.makeLength("Controls:", getPrintSize() - 5)
       + TestEntity.makeWeightString(getWeightControls())
       + "\n";
 }
 @Override
 @CachePut(cacheNames = "primary", key = "#result.id")
 public TestEntity putRefersToResult(TestEntity arg1) {
   arg1.setId(Long.MIN_VALUE);
   return arg1;
 }
Beispiel #18
0
 public void setTestEntity(TestEntity testEntity) {
   this.testEntity = testEntity;
   testId = testEntity == null ? null : testEntity.getId();
   testEntity__resolvedKey = testId;
 }
  @Test
  public void testReplaceSimpleSearchable() {
    TestEntity se1 =
        new TestEntity("ISPN-1949", "Allow non-indexed values in indexed caches", 10, "note");
    cache.put(se1.getId(), se1);
    cache.put("name2", "some string value");
    cache.put("name3", "some string value");
    cache.put("name3", new NotIndexedType("some string value"));

    SearchManager qf = Search.getSearchManager(cache);

    Query ispnIssueQuery =
        qf.buildQueryBuilderForClass(TestEntity.class)
            .get()
            .keyword()
            .onField("name")
            .ignoreAnalyzer()
            .matching("ISPN-1949")
            .createQuery();

    assertEquals(1, qf.getQuery(ispnIssueQuery).list().size());

    cache.put(se1.getId(), "some string value");

    assertEquals(0, qf.getQuery(ispnIssueQuery).list().size());

    AnotherTestEntity indexBEntity = new AnotherTestEntity("ISPN-1949");
    cache.put("name", indexBEntity);
    assertEquals(1, qf.getQuery(ispnIssueQuery).list().size());

    TestEntity se2 =
        new TestEntity(
            "HSEARCH-1077",
            "Mutable SearchFactory should return which classes are actually going to be indexed",
            10,
            "note");
    cache.replace("name", indexBEntity, se2);
    assertEquals(0, qf.getQuery(ispnIssueQuery).list().size());

    Query searchIssueQuery =
        qf.buildQueryBuilderForClass(TestEntity.class)
            .get()
            .keyword()
            .onField("name")
            .ignoreAnalyzer()
            .matching("HSEARCH-1077")
            .createQuery();
    assertEquals(1, qf.getQuery(searchIssueQuery).list().size());

    // a failing atomic replace should not change the index:
    cache.replace("name", "notMatching", "notImportant");
    assertEquals(1, qf.getQuery(searchIssueQuery).list().size());
    assertEquals(0, qf.getQuery(ispnIssueQuery).list().size());

    cache.remove("name");
    assertEquals(0, qf.getQuery(searchIssueQuery).list().size());

    cache.put("name", se2);
    assertEquals(1, qf.getQuery(searchIssueQuery).list().size());
    cache.put("name", "replacement String");
    assertEquals(0, qf.getQuery(searchIssueQuery).list().size());

    cache.put("name", se1);
    assertEquals(1, qf.getQuery(ispnIssueQuery).list().size());
    cache.put("second name", se1);
    assertEquals(2, qf.getQuery(ispnIssueQuery).list().size());
    assertEquals(2, qf.getQuery(ispnIssueQuery, TestEntity.class).list().size());

    // now actually replace one with a different indexed type (matches same query)
    cache.replace("name", se1, indexBEntity);
    assertEquals(2, qf.getQuery(ispnIssueQuery).list().size());
    assertEquals(1, qf.getQuery(ispnIssueQuery, TestEntity.class).list().size());
    assertEquals(1, qf.getQuery(ispnIssueQuery, AnotherTestEntity.class).list().size());

    // replace with a non indexed type
    cache.replace("name", indexBEntity, new NotIndexedType("this is not indexed"));
    assertEquals(1, qf.getQuery(ispnIssueQuery).list().size());
  }