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())));
}
}
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);
}
}
}
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));
}
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);
}
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);
}
}
Aggregations