Search in sources :

Example 6 with ResourceCollection

use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testExcludeByResources_ShouldIgnoreUnregisteredResources.

@Test
public void testExcludeByResources_ShouldIgnoreUnregisteredResources() {
    final Resource gold = createResource("gold");
    final ResourceCollection unfiltered = createResourceCollection(pus);
    final ResourceCollection filtered = ResourceCollectionUtils.exclude(unfiltered, gold);
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 7 with ResourceCollection

use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method createResourceCollection.

private ResourceCollection createResourceCollection(final Resource... resources) {
    final ResourceCollection resourceCollection = new ResourceCollection(data);
    resourceCollection.add(new IntegerMap<>(Arrays.stream(resources).collect(toList()), 42));
    return resourceCollection;
}
Also used : ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 8 with ResourceCollection

use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testExcludeByNames_ShouldIgnoreUnregisteredResourceNames.

@Test
public void testExcludeByNames_ShouldIgnoreUnregisteredResourceNames() {
    final Resource gold = createResource("gold");
    givenGameResources(pus);
    final ResourceCollection unfiltered = createResourceCollection(pus);
    final ResourceCollection filtered = ResourceCollectionUtils.exclude(unfiltered, gold.getName());
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 9 with ResourceCollection

use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.

the class ResourceCollectionUtilsTest method testGetProductionResources_ShouldIncludeAllResourcesExceptTechTokensAndVPs.

@Test
public void testGetProductionResources_ShouldIncludeAllResourcesExceptTechTokensAndVPs() {
    final Resource gold = createResource("gold");
    givenGameResources(gold, pus, techTokens, vps);
    final ResourceCollection unfiltered = createResourceCollection(gold, pus, techTokens, vps);
    final ResourceCollection filtered = ResourceCollectionUtils.getProductionResources(unfiltered);
    assertThat(filtered.getQuantity(gold), is(unfiltered.getQuantity(gold)));
    assertThat(filtered.getQuantity(pus), is(unfiltered.getQuantity(pus)));
    assertThat(filtered.getQuantity(techTokens), is(0));
    assertThat(filtered.getQuantity(vps), is(0));
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 10 with ResourceCollection

use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.

the class ProductionRepairPanel method getResources.

private ResourceCollection getResources() {
    if (bid) {
        // TODO bid only allows you to add PU's to the bid... maybe upgrading Bids so multiple resources can be given?
        // (actually, bids should
        // not cover repairing at all...)
        final String propertyName = id.getName() + " bid";
        final int bid = data.getProperties().get(propertyName, 0);
        final ResourceCollection bidCollection = new ResourceCollection(data);
        data.acquireReadLock();
        try {
            bidCollection.addResource(data.getResourceList().getResource(Constants.PUS), bid);
        } finally {
            data.releaseReadLock();
        }
        return bidCollection;
    }
    return id.getResources();
}
Also used : ResourceCollection(games.strategy.engine.data.ResourceCollection)

Aggregations

ResourceCollection (games.strategy.engine.data.ResourceCollection)23 Resource (games.strategy.engine.data.Resource)7 Test (org.junit.jupiter.api.Test)6 PlayerID (games.strategy.engine.data.PlayerID)4 ProductionRule (games.strategy.engine.data.ProductionRule)4 IntegerMap (games.strategy.util.IntegerMap)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Territory (games.strategy.engine.data.Territory)3 Unit (games.strategy.engine.data.Unit)3 UnitType (games.strategy.engine.data.UnitType)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Map (java.util.Map)3 GameData (games.strategy.engine.data.GameData)2 NamedAttachable (games.strategy.engine.data.NamedAttachable)2 ProductionFrontier (games.strategy.engine.data.ProductionFrontier)2 RepairRule (games.strategy.engine.data.RepairRule)2 TripleAUnit (games.strategy.triplea.TripleAUnit)2 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)2