Search in sources :

Example 46 with Triple

use of org.apache.commons.lang3.tuple.Triple in project polymap4-core by Polymap4.

the class ColorMap2FilterEditor method createRandomColorMap.

/**
 * Creates a new #colorMap with default color for values of the current #propertyName.
 */
protected void createRandomColorMap() throws IOException {
    colorMap.clear();
    // count occurences; maps property value into count
    Map<Object, AtomicInteger> valueOccurences = new HashMap(MAX_VALUES * 2);
    ProgressListener progress = new DefaultProgressListener();
    site().featureStore.get().getFeatures().accepts(feature -> {
        // get value
        Object value = feature.getProperty(propertyName).getValue();
        valueOccurences.computeIfAbsent(value, v -> new AtomicInteger()).incrementAndGet();
        // check MAX_VALUES
        if (valueOccurences.size() > MAX_VALUES) {
            progress.setCanceled(true);
        }
    }, progress);
    log.info("Color map entries: " + valueOccurences.size());
    if (progress.isCanceled()) {
        StatusDispatcher.handle(new Status(IStatus.INFO, CorePlugin.PLUGIN_ID, i18n.get("tooManyEntries", MAX_VALUES), null), Style.SHOW, Style.LOG);
    } else {
        valueOccurences.entrySet().stream().sorted((e1, e2) -> e2.getValue().get() - e1.getValue().get()).forEach(entry -> colorMap.add(new Triple(entry.getKey(), entry.getValue().get(), DefaultStyle.randomColor())));
    }
}
Also used : Color(java.awt.Color) Config(org.polymap.core.runtime.config.Config) ColumnLayoutFactory(org.polymap.core.ui.ColumnLayoutFactory) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) StylePlugin(org.polymap.core.style.StylePlugin) ProgressListener(org.opengis.util.ProgressListener) StatusDispatcher(org.polymap.core.ui.StatusDispatcher) IStatus(org.eclipse.core.runtime.IStatus) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Button(org.eclipse.swt.widgets.Button) Status(org.eclipse.core.runtime.Status) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) DefaultStyle(org.polymap.core.style.DefaultStyle) List(java.util.List) IMessages(org.polymap.core.runtime.i18n.IMessages) ColorChooser(org.polymap.core.style.ui.ColorChooser) SWT(org.eclipse.swt.SWT) Literal(org.opengis.filter.expression.Literal) LogFactory(org.apache.commons.logging.LogFactory) Messages(org.polymap.core.style.Messages) Label(org.eclipse.swt.widgets.Label) RWT(org.eclipse.rap.rwt.RWT) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) StylePropertyFieldSite(org.polymap.core.style.ui.StylePropertyFieldSite) StylePropertyEditor(org.polymap.core.style.ui.StylePropertyEditor) Configurable(org.polymap.core.runtime.config.Configurable) FormLayoutFactory(org.polymap.core.ui.FormLayoutFactory) HashMap(java.util.HashMap) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Mandatory(org.polymap.core.runtime.config.Mandatory) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Style(org.polymap.core.ui.StatusDispatcher.Style) UIUtils(org.polymap.core.ui.UIUtils) RGB(org.eclipse.swt.graphics.RGB) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IOException(java.io.IOException) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) CorePlugin(org.polymap.core.CorePlugin) PropertyName(org.opengis.filter.expression.PropertyName) FilterMappedColors(org.polymap.core.style.model.feature.FilterMappedColors) UIService(org.polymap.core.style.ui.UIService) Filter(org.opengis.filter.Filter) Log(org.apache.commons.logging.Log) FormDataFactory(org.polymap.core.ui.FormDataFactory) DefaultProgressListener(org.geotools.util.DefaultProgressListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProgressListener(org.opengis.util.ProgressListener) DefaultProgressListener(org.geotools.util.DefaultProgressListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) DefaultProgressListener(org.geotools.util.DefaultProgressListener)

Example 47 with Triple

use of org.apache.commons.lang3.tuple.Triple in project Solar by ArekkuusuJerii.

the class TileDilaton method pushExtension.

public void pushExtension(boolean powered) {
    if (!world.isRemote && !(!isActiveLazy() && !powered)) {
        ProfilerHelper.flagSection("[Dilaton] Redstone signal received");
        BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(getPos());
        EnumFacing facing = getFacingLazy();
        int range = powered ? getRedstonePower() + 1 : 16;
        int pointer = 0;
        if (isActiveLazy()) {
            ProfilerHelper.flagSection("[Dilaton] Locate nearest extension");
            boolean found = false;
            for (; pointer < range; pointer++) {
                if (!isPosValid(pos.move(facing)) || pointer >= range)
                    return;
                IBlockState state = world.getBlockState(pos);
                if (state.getBlock() == ModBlocks.DILATON_EXTENSION) {
                    world.setBlockToAir(pos);
                    found = true;
                    break;
                }
            }
            if (!found)
                return;
            if (!powered)
                pointer = 0;
        }
        ProfilerHelper.begin("[Dilaton] Gathering pushed blocks");
        if (!powered)
            facing = facing.getOpposite();
        List<Triple<IBlockState, NBTTagCompound, BlockPos>> pushed = Lists.newArrayList();
        List<BlockPos> removed = Lists.newArrayList();
        loop: for (; pointer < range; pointer++) {
            if (pos.move(facing).equals(getPos()) || !isPosValid(pos))
                break;
            IBlockState next = world.getBlockState(pos);
            if (next.getBlock() == Blocks.AIR)
                continue;
            float hardness = next.getBlockHardness(world, pos);
            if (hardness > 2000F || hardness < 0F)
                break;
            EnumPushReaction reaction;
            if (next.getMaterial() == Material.WATER)
                reaction = EnumPushReaction.IGNORE;
            else
                reaction = next.getMobilityFlag();
            switch(reaction) {
                case PUSH_ONLY:
                case NORMAL:
                    if (pushed.add(getStateTile(next, pos.toImmutable())) && pushed.size() > 15)
                        break loop;
                    else
                        ++range;
                    continue loop;
                case DESTROY:
                    removed.add(pos.toImmutable());
                    continue loop;
                case BLOCK:
                    break loop;
                case IGNORE:
            }
        }
        ProfilerHelper.interrupt("[Dilaton] Relocating pushed blocks");
        Set<BlockPos> deleted = Sets.newHashSet();
        if (pushed.size() <= 15) {
            pos.move(facing.getOpposite());
        }
        for (int i = 0, size = pushed.size(); i < size; i++) {
            if (isPosReplaceable(pos)) {
                for (int index = pushed.size() - 1; index >= 0; index--) {
                    Triple<IBlockState, NBTTagCompound, BlockPos> triplet = pushed.get(index);
                    if (setStateTile(triplet.getLeft(), triplet.getMiddle(), pos.toImmutable()))
                        removed.add(pos.toImmutable());
                    BlockPos oldPos = triplet.getRight();
                    if (deleted.add(oldPos))
                        deleted.removeIf(a -> a.equals(pos));
                    pos.move(facing.getOpposite());
                }
                deleted.forEach(delete -> {
                    if (world.getTileEntity(delete) != null)
                        world.removeTileEntity(delete);
                    world.setBlockToAir(delete);
                });
                break;
            } else if (!pushed.isEmpty())
                pushed.remove(pushed.size() - 1);
            pos.move(facing.getOpposite());
        }
        ProfilerHelper.flagSection("[Dilaton] Block drops");
        removed.forEach(p -> {
            IBlockState state = world.getBlockState(p);
            float chance = state.getBlock() instanceof BlockSnow ? -1.0F : 1.0F;
            state.getBlock().dropBlockAsItemWithChance(world, p, state, chance, 0);
            world.setBlockToAir(p);
        });
        ProfilerHelper.end();
        ProfilerHelper.flagSection("[Dilaton] Place extension");
        if (pos.equals(getPos().offset(facing.getOpposite()))) {
            if (isActiveLazy())
                world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(State.ACTIVE, false));
        } else if (!pos.equals(getPos())) {
            if (!isActiveLazy())
                world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(State.ACTIVE, true));
            IBlockState extension = ModBlocks.DILATON_EXTENSION.getDefaultState().withProperty(BlockDirectional.FACING, facing);
            world.setBlockState(pos, extension);
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) State(arekkuusu.solar.api.state.State) BlockSnow(net.minecraft.block.BlockSnow) Blocks(net.minecraft.init.Blocks) EnumFacing(net.minecraft.util.EnumFacing) Set(java.util.Set) ProfilerHelper(arekkuusu.solar.client.util.helper.ProfilerHelper) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Lists(com.google.common.collect.Lists) Material(net.minecraft.block.material.Material) BlockDirectional(net.minecraft.block.BlockDirectional) TileEntity(net.minecraft.tileentity.TileEntity) ModBlocks(arekkuusu.solar.common.block.ModBlocks) Triple(org.apache.commons.lang3.tuple.Triple) EnumPushReaction(net.minecraft.block.material.EnumPushReaction) BlockSnow(net.minecraft.block.BlockSnow) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Triple(org.apache.commons.lang3.tuple.Triple) BlockPos(net.minecraft.util.math.BlockPos) EnumPushReaction(net.minecraft.block.material.EnumPushReaction)

Example 48 with Triple

use of org.apache.commons.lang3.tuple.Triple in project EnderIO by SleepyTrousers.

the class WiredChargerRecipeCategory method register.

// -------------------------------------
public static void register(IModRegistry registry, IGuiHelper guiHelper) {
    registry.addRecipeCategories(new WiredChargerRecipeCategory(guiHelper));
    registry.addRecipeCategoryCraftingItem(new ItemStack(MachineObject.block_wired_charger.getBlockNN()), WiredChargerRecipeCategory.UID);
    registry.addRecipeCategoryCraftingItem(new ItemStack(MachineObject.block_wireless_charger.getBlockNN()), WiredChargerRecipeCategory.UID);
    registry.addRecipeClickArea(GuiWiredCharger.class, 176, 42, 16, 16, WiredChargerRecipeCategory.UID);
    long start = System.nanoTime();
    List<ItemStack> validItems = registry.getIngredientRegistry().getIngredients(ItemStack.class);
    List<WiredChargerRecipeWrapper> result = new ArrayList<WiredChargerRecipeWrapper>();
    ContainerWiredCharger.getValidPair(validItems).apply(new Callback<Triple<ItemStack, ItemStack, Integer>>() {

        @SuppressWarnings("null")
        @Override
        public void apply(@Nonnull Triple<ItemStack, ItemStack, Integer> e) {
            result.add(new WiredChargerRecipeWrapper(e.getLeft(), e.getMiddle(), e.getRight()));
        }
    });
    long end = System.nanoTime();
    registry.addRecipes(result, UID);
    registry.getRecipeTransferRegistry().addRecipeTransferHandler(ContainerWiredCharger.class, WiredChargerRecipeCategory.UID, ContainerWiredCharger.FIRST_RECIPE_SLOT, ContainerWiredCharger.NUM_RECIPE_SLOT, ContainerWiredCharger.FIRST_INVENTORY_SLOT, ContainerWiredCharger.NUM_INVENTORY_SLOT);
    Log.info(String.format("WiredChargerRecipeCategory: Added %d item charging recipes to JEI in %.3f seconds.", result.size(), (end - start) / 1000000000d));
}
Also used : ArrayList(java.util.ArrayList) Triple(org.apache.commons.lang3.tuple.Triple) ItemStack(net.minecraft.item.ItemStack)

Example 49 with Triple

use of org.apache.commons.lang3.tuple.Triple in project EnderIO by SleepyTrousers.

the class ContainerWiredCharger method addGhostslots.

public void addGhostslots(NNList<GhostSlot> ghostSlots) {
    NNList<ItemStack> empties = new NNList<>();
    NNList<ItemStack> fulls = new NNList<>();
    getValidPair(ItemHelper.getValidItems()).apply(new Callback<Triple<ItemStack, ItemStack, Integer>>() {

        @Override
        public void apply(@Nonnull Triple<ItemStack, ItemStack, Integer> e) {
            empties.add(e.getLeft());
            fulls.add(e.getMiddle());
        }
    });
    // JEI will cause initGui to be re-run after closing the recipe view, causing duplicate ghost
    ghostSlots.removeAllByClass(GhostBackgroundItemSlot.class);
    // slots
    final GhostBackgroundItemSlot ghost0 = new GhostBackgroundItemSlot(empties, getSlotFromInventory(0));
    ghost0.setDisplayStdOverlay(true);
    ghostSlots.add(ghost0);
    final GhostBackgroundItemSlot ghost1 = new GhostBackgroundItemSlot(fulls, getSlotFromInventory(1));
    ghost1.setDisplayStdOverlay(true);
    ghostSlots.add(ghost1);
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) GhostBackgroundItemSlot(com.enderio.core.client.gui.widget.GhostBackgroundItemSlot) NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack)

Example 50 with Triple

use of org.apache.commons.lang3.tuple.Triple in project eol-globi-data by jhpoelen.

the class StudyImporterForSaproxylic method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    try {
        final Model model = ModelFactory.createDefaultModel();
        NavigableSet<Triple<String, String, String>> triples = DBMaker.newTempTreeSet();
        Tripler add = triple -> {
            Resource resource = model.createResource("sx:" + triple.getLeft());
            Property property = model.createProperty("sx:" + triple.getMiddle());
            String obj = triple.getRight();
            if (StringUtils.startsWith(obj, "{")) {
                Resource food = model.createResource("sx:" + obj);
                model.add(resource, property, food);
            } else if (StringUtils.startsWith(obj, "http")) {
                model.add(resource, property, model.createResource(obj));
            } else if (StringUtils.isNotBlank(obj)) {
                model.add(resource, property, obj);
            }
        };
        parseReferences(add, getDataset().getResource("sx_txt/Reference.txt"));
        parseLocalities(add, getDataset().getResource("sx_txt/Locality.txt"));
        parseTaxa(add, getDataset().getResource("sx_txt/Taxon.txt"));
        parseTaxonRanks(add, getDataset().getResource("sx_txt/TaxonRank.txt"));
        parseOccurrences(add, getDataset().getResource("sx_txt/Occurrence.txt"));
        parseAssociations(add, getDataset().getResource("sx_txt/SX_Association.txt"));
        parseInteractionTypeMap(add, getDataset().getResource("interaction_type_map.tsv"));
        // associations -> occurrences, taxa, reference
        String queryString = "SELECT ?sourceTaxonName ?sourceLifeStage ?interactionTypeId ?targetTaxonName ?targetLifeStage ?referenceCitation ?localityName ?studyTitle " + "WHERE {" + "      ?interaction <sx:mentioned_by> ?studyTitle . " + "      ?studyTitle <sx:hasName> ?referenceCitation . " + "      ?sourceSpecimen <sx:participates_in> ?interaction . " + "      ?targetSpecimen <sx:participates_in> ?interaction . " + "      ?sourceSpecimen ?inter ?targetSpecimen . " + "      ?inter <sx:equivalentTo> ?interactionTypeId . " + "      ?sourceSpecimen <sx:classifiedAs> ?sourceTaxon . " + "      ?sourceTaxon <sx:hasName> ?sourceTaxonName . " + "      ?targetSpecimen <sx:classifiedAs> ?targetTaxon . " + "      ?targetTaxon <sx:hasName> ?targetTaxonName . " + "      ?sourceSpecimen <sx:inStage> ?sourceLifeStage . " + "      ?targetSpecimen <sx:inStage> ?targetLifeStage . " + "      ?targetSpecimen <sx:foundAt> ?locality . " + "      ?locality <sx:hasName> ?localityName . " + "}";
        Query query = QueryFactory.create(queryString);
        QueryExecution qe = QueryExecutionFactory.create(query, model);
        ResultSet results = qe.execSelect();
        toInteractions(results);
        qe.close();
    } catch (IOException e) {
        throw new StudyImporterException("failed to access resource", e);
    }
}
Also used : CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) Query(com.hp.hpl.jena.query.Query) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) ModelFactory(com.hp.hpl.jena.rdf.model.ModelFactory) QueryExecutionFactory(com.hp.hpl.jena.query.QueryExecutionFactory) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) Property(com.hp.hpl.jena.rdf.model.Property) Map(java.util.Map) Triple(org.apache.commons.lang3.tuple.Triple) QueryFactory(com.hp.hpl.jena.query.QueryFactory) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) ResultSetFormatter(com.hp.hpl.jena.query.ResultSetFormatter) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) Iterator(java.util.Iterator) SelectorImpl(com.hp.hpl.jena.rdf.model.impl.SelectorImpl) IOException(java.io.IOException) NavigableSet(java.util.NavigableSet) ResultSet(com.hp.hpl.jena.query.ResultSet) Resource(com.hp.hpl.jena.rdf.model.Resource) File(java.io.File) List(java.util.List) QuerySolution(com.hp.hpl.jena.query.QuerySolution) TreeMap(java.util.TreeMap) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Model(com.hp.hpl.jena.rdf.model.Model) DBMaker(org.mapdb.DBMaker) QueryExecution(com.hp.hpl.jena.query.QueryExecution) InputStream(java.io.InputStream) Query(com.hp.hpl.jena.query.Query) Resource(com.hp.hpl.jena.rdf.model.Resource) IOException(java.io.IOException) QueryExecution(com.hp.hpl.jena.query.QueryExecution) Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) Model(com.hp.hpl.jena.rdf.model.Model) ResultSet(com.hp.hpl.jena.query.ResultSet) Property(com.hp.hpl.jena.rdf.model.Property)

Aggregations

Triple (org.apache.commons.lang3.tuple.Triple)51 ArrayList (java.util.ArrayList)20 ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)18 List (java.util.List)13 Pair (org.apache.commons.lang3.tuple.Pair)10 Test (org.junit.Test)8 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 Organization (alfio.model.user.Organization)5 Event (alfio.model.Event)4 Ticket (alfio.model.Ticket)4 TicketReservation (alfio.model.TicketReservation)4 IOException (java.io.IOException)4 BlockPos (net.minecraft.util.math.BlockPos)4 Mutable (org.apache.commons.lang3.mutable.Mutable)4 Triple (org.apache.hyracks.algebricks.common.utils.Triple)4 alfio.model (alfio.model)3 TicketCategory (alfio.model.TicketCategory)3 TemplateManager (alfio.util.TemplateManager)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3