List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:com.acmutv.ontoqa.benchmark.extra.QuestionE02Test.java
/** * Tests the question-answering with parsing. * @throws QuestionException when the question is malformed. * @throws OntoqaFatalException when the question cannot be processed due to some fatal errors. *//*from w w w . j a v a2 s .c o m*/ @Test public void test_nlp() throws Exception { final Grammar grammar = Common.getGrammar(); final Ontology ontology = Common.getOntology(); final Pair<Query, Answer> result = CoreController.process(QUESTION, grammar, ontology); final Query query = result.getKey(); final Answer answer = result.getValue(); LOGGER.info("Query: {}", query); LOGGER.info("Answer: {}", answer); Assert.assertTrue(QUERY_1.equals(query.toString()) || QUERY_1_bis.equals(query.toString())); Assert.assertEquals(ANSWER, answer); }
From source file:com.galenframework.speclang2.reader.specs.SpecImageProcessor.java
@Override public Spec process(StringCharReader reader, String contextPath) { List<Pair<String, String>> parameters = Expectations.commaSeparatedRepeatedKeyValues().read(reader); SpecImage spec = new SpecImage(); spec.setImagePaths(new LinkedList<String>()); spec.setStretch(false);/*from w ww. j a v a 2 s.c o m*/ spec.setErrorRate(GalenConfig.getConfig().getImageSpecDefaultErrorRate()); spec.setTolerance(GalenConfig.getConfig().getImageSpecDefaultTolerance()); for (Pair<String, String> parameter : parameters) { if ("file".equals(parameter.getKey())) { if (contextPath != null) { spec.getImagePaths().add(contextPath + File.separator + parameter.getValue()); } else { spec.getImagePaths().add(parameter.getValue()); } } else if ("error".equals(parameter.getKey())) { spec.setErrorRate(SpecImage.ErrorRate.fromString(parameter.getValue())); } else if ("tolerance".equals(parameter.getKey())) { spec.setTolerance(parseIntegerParameter("tolerance", parameter.getValue())); } else if ("analyze-offset".equals(parameter.getKey())) { spec.setAnalyzeOffset(parseIntegerParameter("analyze-offset", parameter.getValue())); } else if ("stretch".equals(parameter.getKey())) { spec.setStretch(true); } else if ("area".equals(parameter.getKey())) { spec.setSelectedArea(parseRect(parameter.getValue())); } else if ("filter".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue()); spec.getOriginalFilters().add(filter); spec.getSampleFilters().add(filter); } else if ("filter-a".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue()); spec.getOriginalFilters().add(filter); } else if ("filter-b".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue()); spec.getSampleFilters().add(filter); } else if ("map-filter".equals(parameter.getKey())) { ImageFilter filter = parseImageFilter(parameter.getValue()); spec.getMapFilters().add(filter); } else if ("crop-if-outside".equals(parameter.getKey())) { spec.setCropIfOutside(true); } else { throw new SyntaxException("Unknown parameter: " + parameter.getKey()); } } if (spec.getImagePaths() == null || spec.getImagePaths().size() == 0) { throw new SyntaxException("There are no images defined"); } return spec; }
From source file:alfio.manager.WaitingQueueManager.java
private List<Integer> selectTicketsForPreReservation(int eventId, Pair<Integer, TicketCategoryStatisticView> p) { TicketCategoryStatisticView category = p.getValue(); Integer amount = p.getKey();//from w w w.j a v a 2s . com if (category.isBounded()) { return ticketRepository.selectFreeTicketsForPreReservation(eventId, amount, category.getId()); } return ticketRepository.selectNotAllocatedFreeTicketsForPreReservation(eventId, amount); }
From source file:alfio.manager.UploadedResourceIntegrationTest.java
@Before public void ensureConfiguration() { IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository); List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventAndUser = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);//from w ww . ja v a 2 s.c om event = eventAndUser.getKey(); user = eventAndUser.getValue() + "_owner"; }
From source file:com.dangdang.config.service.zookeeper.ZookeeperConfigGroup.java
/** * ??//from w ww . ja v a 2 s . c o m */ void loadNode() { final String nodePath = ZKPaths.makePath(configProfile.getVersionedRootNode(), node); GetChildrenBuilder childrenBuilder = client.getChildren(); try { List<String> children = childrenBuilder.watched().forPath(nodePath); if (children != null) { Map<String, String> configs = Maps.newHashMap(); for (String child : children) { Pair<String, String> keyValue = loadKey(ZKPaths.makePath(nodePath, child)); if (keyValue != null) { configs.put(keyValue.getKey(), keyValue.getValue()); } } super.putAll(configs); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:blusunrize.immersiveengineering.client.render.IEBipedLayerRenderer.java
@Override public void doRenderLayer(EntityLivingBase living, float limbSwing, float prevLimbSwing, float partialTicks, float rotation, float yaw, float pitch, float scale) { // if(Lib.BAUBLES && living instanceof EntityPlayer) // {/*from w ww . j av a 2 s . co m*/ // ItemStack belt = BaublesHelper.getBauble((EntityPlayer)living,3); // if(belt!=null && belt.getItem().equals(IEContent.itemManeuverGear)) // { // GlStateManager.pushMatrix(); // ModelBiped model = IEContent.itemManeuverGear.getArmorModel((EntityPlayer)living, belt, 2, null); // ClientUtils.bindTexture(IEContent.itemManeuverGear.getArmorTexture(belt, (EntityPlayer)living, 2, null)); // model.render(living, limbSwing, prevLimbSwing, rotation, yaw, pitch, scale); // GlStateManager.popMatrix(); // } // } if (!living.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty() && ItemNBTHelper.hasKey(living.getItemStackFromSlot(EntityEquipmentSlot.HEAD), "IE:Earmuffs")) { ItemStack earmuffs = ItemNBTHelper.getItemStack(living.getItemStackFromSlot(EntityEquipmentSlot.HEAD), Lib.NBT_Earmuffs); if (!earmuffs.isEmpty()) { GlStateManager.pushMatrix(); ModelBiped model = IEContent.itemEarmuffs.getArmorModel(living, earmuffs, EntityEquipmentSlot.HEAD, null); ClientUtils.bindTexture(IEContent.itemEarmuffs.getArmorTexture(earmuffs, living, EntityEquipmentSlot.HEAD, "overlay")); model.render(living, limbSwing, prevLimbSwing, rotation, yaw, pitch, scale); int colour = ((IColouredItem) earmuffs.getItem()).getColourForIEItem(earmuffs, 0); GlStateManager.color((colour >> 16 & 255) / 255f, (colour >> 8 & 255) / 255f, (colour & 255) / 255f); ClientUtils.bindTexture( IEContent.itemEarmuffs.getArmorTexture(earmuffs, living, EntityEquipmentSlot.HEAD, null)); model.render(living, limbSwing, prevLimbSwing, rotation, yaw, pitch, scale); GlStateManager.popMatrix(); } } if (!living.getItemStackFromSlot(EntityEquipmentSlot.CHEST).isEmpty() && ItemNBTHelper.hasKey(living.getItemStackFromSlot(EntityEquipmentSlot.CHEST), "IE:Powerpack")) { ItemStack powerpack = ItemNBTHelper.getItemStack(living.getItemStackFromSlot(EntityEquipmentSlot.CHEST), Lib.NBT_Powerpack); addWornPowerpack(living, powerpack); } if (POWERPACK_PLAYERS.containsKey(living.getUniqueID())) { Pair<ItemStack, Integer> entry = POWERPACK_PLAYERS.get(living.getUniqueID()); renderPowerpack(entry.getLeft(), living, limbSwing, prevLimbSwing, partialTicks, rotation, yaw, pitch, scale); int time = entry.getValue() - 1; if (time <= 0) POWERPACK_PLAYERS.remove(living.getUniqueID()); else POWERPACK_PLAYERS.put(living.getUniqueID(), Pair.of(entry.getLeft(), time)); } }
From source file:com.yahoo.pulsar.broker.loadbalance.impl.DeviationShedder.java
/** * Recommend that all of the returned bundles be unloaded based on observing excessive standard deviations according * to some metric.//from ww w. ja v a2s. c om * * @param loadData * The load data to used to make the unloading decision. * @param conf * The service configuration. * @return A map from all selected bundles to the brokers on which they reside. */ @Override public Map<String, String> findBundlesForUnloading(final LoadData loadData, final ServiceConfiguration conf) { final Map<String, String> result = new HashMap<>(); bundleTreeSetCache.clear(); metricTreeSetCache.clear(); double sum = 0; double squareSum = 0; final Map<String, BrokerData> brokerDataMap = loadData.getBrokerData(); // Treating each broker as a data point, calculate the sum and squared // sum of the evaluated broker metrics. // These may be used to calculate the standard deviation. for (Map.Entry<String, BrokerData> entry : brokerDataMap.entrySet()) { final double value = brokerValue(entry.getValue(), conf); sum += value; squareSum += value * value; metricTreeSetCache.add(new ImmutablePair<>(value, entry.getKey())); } // Mean cannot change by just moving around bundles. final double mean = sum / brokerDataMap.size(); double standardDeviation = Math.sqrt(squareSum / brokerDataMap.size() - mean * mean); final double deviationThreshold = getDeviationThreshold(conf); String lastMostOverloaded = null; // While the most loaded broker is above the standard deviation // threshold, continue to move bundles. while ((metricTreeSetCache.last().getKey() - mean) / standardDeviation > deviationThreshold) { final Pair<Double, String> mostLoadedPair = metricTreeSetCache.last(); final double highestValue = mostLoadedPair.getKey(); final String mostLoaded = mostLoadedPair.getValue(); final Pair<Double, String> leastLoadedPair = metricTreeSetCache.first(); final double leastValue = leastLoadedPair.getKey(); final String leastLoaded = metricTreeSetCache.first().getValue(); if (!mostLoaded.equals(lastMostOverloaded)) { // Reset the bundle tree set now that a different broker is // being considered. bundleTreeSetCache.clear(); for (String bundle : brokerDataMap.get(mostLoaded).getLocalData().getBundles()) { if (!result.containsKey(bundle)) { // Don't consider bundles that are already going to be // moved. bundleTreeSetCache.add(new ImmutablePair<>( bundleValue(bundle, brokerDataMap.get(mostLoaded), conf), bundle)); } } lastMostOverloaded = mostLoaded; } boolean selected = false; while (!(bundleTreeSetCache.isEmpty() || selected)) { Pair<Double, String> mostExpensivePair = bundleTreeSetCache.pollLast(); double loadIncurred = mostExpensivePair.getKey(); // When the bundle is moved, we want the now least loaded server // to have lower overall load than the // most loaded server does not. Thus, we will only consider // moving the bundle if this condition // holds, and otherwise we will try the next bundle. if (loadIncurred + leastValue < highestValue) { // Update the standard deviation and replace the old load // values in the broker tree set with the // load values assuming this move took place. final String bundleToMove = mostExpensivePair.getValue(); result.put(bundleToMove, mostLoaded); metricTreeSetCache.remove(mostLoadedPair); metricTreeSetCache.remove(leastLoadedPair); final double newHighLoad = highestValue - loadIncurred; final double newLowLoad = leastValue - loadIncurred; squareSum -= highestValue * highestValue + leastValue * leastValue; squareSum += newHighLoad * newHighLoad + newLowLoad * newLowLoad; standardDeviation = Math.sqrt(squareSum / brokerDataMap.size() - mean * mean); metricTreeSetCache.add(new ImmutablePair<>(newLowLoad, leastLoaded)); metricTreeSetCache.add(new ImmutablePair<>(newHighLoad, mostLoaded)); selected = true; } } if (!selected) { // Move on to the next broker if no bundle could be moved. metricTreeSetCache.pollLast(); } } return result; }
From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessor.java
private void triggerScaleDown(String streamSegmentName, boolean silent) { if (initialized.get()) { Pair<Long, Long> pair = cache.getIfPresent(streamSegmentName); long lastRequestTs = 0; if (pair != null && pair.getValue() != null) { lastRequestTs = pair.getValue(); }/*from ww w . j a v a 2 s .com*/ long timestamp = System.currentTimeMillis(); if (timestamp - lastRequestTs > configuration.getMuteDuration().toMillis()) { log.info("sending request for scale down for {}", streamSegmentName); Segment segment = Segment.fromScopedName(streamSegmentName); AutoScaleEvent event = new AutoScaleEvent(segment.getScope(), segment.getStreamName(), segment.getSegmentNumber(), AutoScaleEvent.DOWN, timestamp, 0, silent); writeRequest(event) .thenAccept(x -> cache.put(streamSegmentName, new ImmutablePair<>(0L, timestamp))); // mute only scale downs } } }
From source file:lineage2.gameserver.skills.skillclasses.Resurrect.java
/** * Method useSkill./*from w ww .j a v a 2s . c o m*/ * @param activeChar Creature * @param targets List<Creature> */ @Override public void useSkill(Creature activeChar, List<Creature> targets) { double percent = _power; if ((percent < 100) && !isHandler()) { double wit_bonus = _power * (BaseStats.WIT.calcBonus(activeChar) - 1); percent += wit_bonus > 20 ? 20 : wit_bonus; if (percent > 90) { percent = 90; } } for (Creature target : targets) { Loop: if (target != null) { if (target.getPlayer() == null) { continue; } for (GlobalEvent e : target.getEvents()) { if (!e.canRessurect((Player) activeChar, target, true)) { break Loop; } } if (target.isPet() && _canPet) { if (target.getPlayer() == activeChar) { ((PetInstance) target).doRevive(percent); } else { target.getPlayer().reviveRequest((Player) activeChar, percent, true); } } else if (target.isPlayer()) { if (_targetType == SkillTargetType.TARGET_PET) { continue; } Player targetPlayer = (Player) target; Pair<Integer, OnAnswerListener> ask = targetPlayer.getAskListener(false); ReviveAnswerListener reviveAsk = (ask != null) && (ask.getValue() instanceof ReviveAnswerListener) ? (ReviveAnswerListener) ask.getValue() : null; if (reviveAsk != null) { continue; } targetPlayer.reviveRequest((Player) activeChar, percent, false); } else { continue; } getEffects(activeChar, target, getActivateRate() > 0, false); } } if (isSSPossible()) { activeChar.unChargeShots(isMagic()); } }
From source file:io.pravega.service.server.host.stat.AutoScaleProcessor.java
private void triggerScaleDown(String streamSegmentName, boolean silent) { if (initialized.get()) { Pair<Long, Long> pair = cache.getIfPresent(streamSegmentName); long lastRequestTs = 0; if (pair != null && pair.getValue() != null) { lastRequestTs = pair.getValue(); }/* w ww . j av a 2 s .co m*/ long timestamp = System.currentTimeMillis(); if (timestamp - lastRequestTs > configuration.getMuteDuration().toMillis()) { log.debug("sending request for scale down for {}", streamSegmentName); Segment segment = Segment.fromScopedName(streamSegmentName); ScaleEvent event = new ScaleEvent(segment.getScope(), segment.getStreamName(), segment.getSegmentNumber(), ScaleEvent.DOWN, timestamp, 0, silent); writeRequest(event) .thenAccept(x -> cache.put(streamSegmentName, new ImmutablePair<>(0L, timestamp))); // mute only scale downs } } }