Search in sources :

Example 21 with Multiset

use of com.google.common.collect.Multiset in project Railcraft by Railcraft.

the class TileItemManipulator method processCart.

@Override
protected void processCart(EntityMinecart cart) {
    chests.clear();
    chests.add(invBuffer);
    chests.addAll(invCache.getAdjacentInventories());
    InventoryComposite cartInv = InventoryComposite.of(InventoryFactory.get(cart, getFacing().getOpposite()));
    if (cartInv.isEmpty()) {
        sendCart(cart);
        return;
    }
    this.cart = cartInv;
    switch(getMode()) {
        case TRANSFER:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                filterManifest.entrySet().stream().filter(entry -> transferredItems.count(entry.getElement()) < entry.getCount()).anyMatch(entry -> {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination(), StackFilters.matches(entry.getElement().get()));
                    if (!InvTools.isEmpty(moved)) {
                        setProcessing(true);
                        transferredItems.add(entry.getElement());
                        return true;
                    }
                    return false;
                });
                break;
            }
        case STOCK:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> destManifest = InvTools.createManifest(getDestination(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> destManifest.count(entry.getElement()) < entry.getCount()));
                break;
            }
        case EXCESS:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> sourceManifest = InvTools.createManifest(getSource(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> sourceManifest.count(entry.getElement()) > entry.getCount()));
                if (!isProcessing()) {
                    Predicate<ItemStack> keep = filterManifest.elementSet().stream().map(e -> StackFilters.matches(e.get())).reduce(StackFilters.none(), Predicate::or);
                    ItemStack moved = InvTools.moveOneItemExcept(getSource(), getDestination(), keep);
                    itemMoved(moved);
                }
                break;
            }
        case ALL:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                if (filterManifest.isEmpty()) {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination());
                    itemMoved(moved);
                } else {
                    moveItem(filterManifest.entrySet().stream());
                }
                break;
            }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EnumMap(java.util.EnumMap) Multiset(com.google.common.collect.Multiset) Predicate(java.util.function.Predicate) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IOException(java.io.IOException) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) StackFilters(mods.railcraft.common.util.inventory.filters.StackFilters) InventoryMapper(mods.railcraft.common.util.inventory.wrappers.InventoryMapper) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) ItemStack(net.minecraft.item.ItemStack) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) Stream(java.util.stream.Stream) HashMultiset(com.google.common.collect.HashMultiset) StackKey(mods.railcraft.common.util.collections.StackKey) MultiButtonController(mods.railcraft.common.gui.buttons.MultiButtonController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Slot(net.minecraft.inventory.Slot) mods.railcraft.common.util.inventory(mods.railcraft.common.util.inventory) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) Nullable(javax.annotation.Nullable) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) ItemStack(net.minecraft.item.ItemStack) Predicate(java.util.function.Predicate)

Example 22 with Multiset

use of com.google.common.collect.Multiset in project jackrabbit-oak by apache.

the class SegmentGraphTest method testSegmentGraph.

@Test
public void testSegmentGraph() throws Exception {
    ReadOnlyFileStore store = fileStoreBuilder(getStoreFolder()).buildReadOnly();
    try {
        Graph<UUID> segmentGraph = parseSegmentGraph(store, Predicates.<UUID>alwaysTrue());
        assertEquals(segments, newHashSet(segmentGraph.vertices()));
        Map<UUID, Set<UUID>> map = newHashMap();
        for (Entry<UUID, Multiset<UUID>> entry : segmentGraph.edges()) {
            map.put(entry.getKey(), entry.getValue().elementSet());
        }
        assertEquals(references, map);
    } finally {
        store.close();
    }
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) Multiset(com.google.common.collect.Multiset) UUID(java.util.UUID) Test(org.junit.Test)

Example 23 with Multiset

use of com.google.common.collect.Multiset in project jackrabbit-oak by apache.

the class SegmentGraphTest method testSegmentGraphWithFilter.

@Test
public void testSegmentGraphWithFilter() throws Exception {
    ReadOnlyFileStore store = fileStoreBuilder(getStoreFolder()).buildReadOnly();
    try {
        Predicate<UUID> filter = createRegExpFilter(".*(writer2|writer3).*", store.getSegmentIdProvider());
        Graph<UUID> segmentGraph = parseSegmentGraph(store, filter);
        assertEquals(filteredSegments, newHashSet(segmentGraph.vertices()));
        Map<UUID, Set<UUID>> map = newHashMap();
        for (Entry<UUID, Multiset<UUID>> entry : segmentGraph.edges()) {
            map.put(entry.getKey(), entry.getValue().elementSet());
        }
        assertEquals(filteredReferences, map);
    } finally {
        store.close();
    }
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) Multiset(com.google.common.collect.Multiset) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with Multiset

use of com.google.common.collect.Multiset in project hale by halestudio.

the class PropertyEntityDefinitionMapping method map.

/**
 * @see eu.esdihumboldt.hale.common.instance.index.IndexMapping#map(java.lang.Object)
 */
@Override
public List<IndexedPropertyValue> map(Instance instance) {
    List<IndexedPropertyValue> result = new ArrayList<>();
    for (PropertyEntityDefinition definition : definitions) {
        List<QName> propertyPath = definition.getPropertyPath().stream().map(cctx -> cctx.getChild().getName()).collect(Collectors.toList());
        Multiset<?> values = AlignmentUtil.getValues(instance, definition, false);
        result.add(new IndexedPropertyValue(propertyPath, values.elementSet().stream().map(v -> processValue(v, definition)).collect(Collectors.toList())));
    }
    return result;
}
Also used : HashSet(java.util.HashSet) List(java.util.List) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Multiset(com.google.common.collect.Multiset) Set(java.util.Set) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Example 25 with Multiset

use of com.google.common.collect.Multiset in project bayou by capergroup.

the class FeatureTest method testcfg.

@Test
public void testcfg() throws ParseException, IOException {
    File srcFolder;
    {
        File projRoot = new File(System.getProperty("user.dir")).getParentFile().getParentFile().getParentFile();
        srcFolder = new File(projRoot.getAbsolutePath() + File.separator + "src");
    }
    String testDir = srcFolder.getAbsolutePath() + File.separator + "test" + File.separator + "resources" + File.separator + "driver";
    String test_filename = "skeleton1.java";
    String src = read_file(testDir + File.separator + test_filename);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    Map options = new HashMap();
    parser.setCompilerOptions(options);
    parser.setSource(src.toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    cu.accept(new ASTVisitor() {

        @Override
        public boolean visit(MethodDeclaration method) {
            CFGFeature feature = new CFGFeature(method);
            Multiset<Integer> set = feature.gen_subgraph(4, true);
            System.out.println(set.toString());
            DecoratedSkeletonFeature sf = new DecoratedSkeletonFeature(method);
            System.out.println(sf.toString());
            return false;
        }
    });
}
Also used : DecoratedSkeletonFeature(edu.rice.cs.caper.bayou.core.dom_driver.DecoratedSkeletonFeature) HashMap(java.util.HashMap) Multiset(com.google.common.collect.Multiset) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) CFGFeature(edu.rice.cs.caper.bayou.core.dom_driver.CFGFeature) Test(org.junit.Test)

Aggregations

Multiset (com.google.common.collect.Multiset)34 HashMultiset (com.google.common.collect.HashMultiset)20 List (java.util.List)11 ArrayList (java.util.ArrayList)10 Set (java.util.Set)10 File (java.io.File)9 Map (java.util.Map)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Test (org.junit.Test)6 Collection (java.util.Collection)5 Entry (java.util.Map.Entry)5 UUID (java.util.UUID)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Lists (com.google.common.collect.Lists)4 Multimap (com.google.common.collect.Multimap)4 Predicate (java.util.function.Predicate)4 ConcurrentHashMultiset (com.google.common.collect.ConcurrentHashMultiset)3 ImmutableMap (com.google.common.collect.ImmutableMap)3