List of usage examples for org.apache.commons.lang3.tuple Triple getMiddle
public abstract M getMiddle();
Gets the middle element from this triple.
From source file:blusunrize.immersiveengineering.api.ApiUtils.java
private static boolean handlePos(Vec3d pos, BlockPos posB, HashMap<BlockPos, Vec3d> halfScanned, HashSet<BlockPos> done, Predicate<Triple<BlockPos, Vec3d, Vec3d>> shouldStop, HashSet<Triple<BlockPos, Vec3d, Vec3d>> near) { final double DELTA_NEAR = .3; if (!done.contains(posB)) { if (halfScanned.containsKey(posB) && !pos.equals(halfScanned.get(posB))) { Triple<BlockPos, Vec3d, Vec3d> added = new ImmutableTriple<>(posB, halfScanned.get(posB), pos); boolean stop = shouldStop.test(added); done.add(posB);/*from w w w . j a v a2s.c o m*/ halfScanned.remove(posB); near.removeIf((t) -> t.getLeft().equals(posB)); if (stop) return true; for (int i = 0; i < 3; i++) { double coord = getDim(pos, i); double diff = coord - Math.floor(coord); if (diff < DELTA_NEAR) near.add( new ImmutableTriple<>(offsetDim(posB, i, -1), added.getMiddle(), added.getRight())); diff = Math.ceil(coord) - coord; if (diff < DELTA_NEAR) near.add(new ImmutableTriple<>(offsetDim(posB, i, 1), added.getMiddle(), added.getRight())); } } else { halfScanned.put(posB, pos); } } return false; }
From source file:blusunrize.immersiveengineering.common.items.ItemRailgun.java
@Override public void onUsingTick(ItemStack stack, EntityLivingBase user, int count) { int inUse = this.getMaxItemUseDuration(stack) - count; if (inUse > getChargeTime(stack) && inUse % 20 == user.getRNG().nextInt(20)) { user.world.playSound(null, user.posX, user.posY, user.posZ, IESounds.spark, SoundCategory.PLAYERS, .8f + (.2f * user.getRNG().nextFloat()), .5f + (.5f * user.getRNG().nextFloat())); Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry .getStoredShaderAndCase(stack); if (shader != null) { Vec3d pos = Utils.getLivingFrontPos(user, .4375, user.height * .75, user.getActiveHand() == EnumHand.MAIN_HAND ? user.getPrimaryHand() : user.getPrimaryHand().opposite(), false, 1);/*from w w w. j a va 2 s . com*/ shader.getMiddle().getEffectFunction().execute(user.world, shader.getLeft(), stack, shader.getRight().getShaderType(), pos, null, .0625f); } } }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
@Test public void testDistributeSeatsFirstCategoryIsBounded() throws Exception { List<TicketCategoryModification> categories = getPreSalesTicketCategoryModifications(true, 10, true, 10); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);// w w w. j a va2 s . co m Event event = pair.getKey(); TicketCategory firstCategory = eventManager.loadTicketCategories(event).stream() .filter(t -> t.getName().equals("defaultFirst")).findFirst() .orElseThrow(IllegalStateException::new); configurationManager.saveCategoryConfiguration(firstCategory.getId(), event.getId(), Collections.singletonList(new ConfigurationModification(null, ConfigurationKeys.MAX_AMOUNT_OF_TICKETS_BY_RESERVATION.getValue(), "1")), pair.getRight() + "_owner"); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true"); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true"); boolean result = waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH); assertTrue(result); List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager .distributeSeats(event).collect(Collectors.toList()); assertEquals(1, subscriptions.size()); Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions .get(0); assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress()); TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle(); assertEquals(Integer.valueOf(firstCategory.getId()), reservation.getTicketCategoryId()); assertEquals(Integer.valueOf(1), reservation.getAmount()); assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now())); }
From source file:de.pixida.logtest.reporting.XUnitReportGenerator.java
private void addTestCases(final Document doc, final Element rootElement) { for (final Entry<Job, List<Triple<LogSink, EvaluationResult, Long>>> resultSet : this.results.entrySet()) { // The class name usually includes its packet name which is displayed as tree in Jenkins. // This might lead to the following tree hierarchy: "some-log" -> "txt" -> ..results.. // "some-other-log" -> "txt" -> ..results.. // Furthermore, we down't know how the log source is represented as human readable string, so it may always contain // dots, e.g. "127.0.0.1:8082" for stream sources. // For now, replace all dots by a "-", such that the human readable identifier of the log source remains human readable and // all information is preserved. String className = resultSet.getKey().getLogReader().getDisplayName(); className = className.replace('.', '-'); for (final Triple<LogSink, EvaluationResult, Long> result : resultSet.getValue()) { final String testcaseName = result.getLeft().getDisplayName(); final Element testcase = doc.createElement("testcase"); testcase.setAttribute("classname", className); testcase.setAttribute("name", testcaseName); // Actually, set the job time, not the test time (tests run in parallel). The attribute is mandatory. final long msToSec = 1000; testcase.setAttribute("time", String.valueOf((double) result.getRight() / msToSec)); if (!result.getMiddle().isSuccess()) { final Element error = doc.createElement(result.getMiddle().isError() ? "error" : "failure"); assert result.getMiddle().getMessage() != null; error.setAttribute("type", result.getMiddle().getResult().toString()); error.setAttribute("message", result.getMiddle().getMessage()); testcase.appendChild(error); }// ww w. j a va2s . com rootElement.appendChild(testcase); } } }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
@Test public void testDistributeSeatsFirstCategoryIsUnbounded() throws Exception { List<TicketCategoryModification> categories = getPreSalesTicketCategoryModifications(false, AVAILABLE_SEATS, true, 10);/*w w w .j a v a2s . com*/ Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository); Event event = pair.getKey(); TicketCategory firstCategory = eventManager.loadTicketCategories(event).stream() .filter(t -> t.getName().equals("defaultFirst")).findFirst() .orElseThrow(IllegalStateException::new); configurationManager.saveCategoryConfiguration(firstCategory.getId(), event.getId(), Collections.singletonList(new ConfigurationModification(null, ConfigurationKeys.MAX_AMOUNT_OF_TICKETS_BY_RESERVATION.getValue(), "1")), pair.getRight() + "_owner"); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true"); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true"); boolean result = waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH); assertTrue(result); List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager .distributeSeats(event).collect(Collectors.toList()); assertEquals(1, subscriptions.size()); Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions .get(0); assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress()); TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle(); assertEquals(Integer.valueOf(firstCategory.getId()), reservation.getTicketCategoryId()); assertEquals(Integer.valueOf(1), reservation.getAmount()); assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now())); }
From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java
@Test public void StringExtensions_FindNewLine_UTF8() { for (Triple<String, Integer, Integer> t : TestDataUTF8) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_8); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_8, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_8, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, null); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, null); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); }//from www .j av a2 s .c o m for (Triple<String, Integer, Integer> t : TestDataUTF8CustomDelim) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_8); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_8, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_8, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_8, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); } }
From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java
@Test public void StringExtensions_FindNewLine_ASCII() { for (Triple<String, Integer, Integer> t : TestDataUTF8) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.US_ASCII); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.US_ASCII, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.US_ASCII, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, null); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, null); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); }/*from ww w . ja v a2s. c o m*/ for (Triple<String, Integer, Integer> t : TestDataUTF8CustomDelim) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.US_ASCII); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.US_ASCII, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.US_ASCII, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.US_ASCII, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); } }
From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java
@Test public void StringExtensions_FindNewLine_UTF16() { for (Triple<String, Integer, Integer> t : TestDataUTF16) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16LE); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16LE, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16LE, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, null); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, null); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); }//from ww w . j av a2s . c o m for (Triple<String, Integer, Integer> t : TestDataUTF16CustomDelim) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16LE); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16LE, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16LE, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16LE, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); } }
From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensionsTests.java
@Test public void StringExtensions_FindNewLine_UTF16BigEndian() { for (Triple<String, Integer, Integer> t : TestDataUTF16) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16BE); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16BE, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16BE, null); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, null); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, null); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); }/*from ww w . jav a2 s .co m*/ for (Triple<String, Integer, Integer> t : TestDataUTF16CustomDelim) { byte[] exactBuffer = t.getLeft().getBytes(StandardCharsets.UTF_16BE); byte[] largerBuffer = new byte[exactBuffer.length + 100]; System.arraycopy(exactBuffer, 0, largerBuffer, 0, exactBuffer.length); int forwardInExactBuffer = StringExtensions.findNewline(exactBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16BE, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInExactBuffer); int forwardInLargeBuffer = StringExtensions.findNewline(largerBuffer, 0, exactBuffer.length, false, StandardCharsets.UTF_16BE, customDelim); Assert.assertEquals(t.getMiddle().intValue(), forwardInLargeBuffer); int reverseInExactBuffer = StringExtensions.findNewline(exactBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInExactBuffer); int reverseInLargeBuffer = StringExtensions.findNewline(largerBuffer, Math.max(0, exactBuffer.length - 1), exactBuffer.length, true, StandardCharsets.UTF_16BE, customDelim); Assert.assertEquals(t.getRight().intValue(), reverseInLargeBuffer); } }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
@Test public void testAssignTicketToWaitingQueueUnboundedCategorySelected() { LocalDateTime start = LocalDateTime.now().minusHours(1); LocalDateTime end = LocalDateTime.now().plusHours(1); List<TicketCategoryModification> categories = Arrays.asList( new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()), new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null), new TicketCategoryModification(null, "default2", AVAILABLE_SEATS, new DateTimeModification(start.toLocalDate(), start.toLocalTime()), new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true"); Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository) .getKey();//from w w w .j av a 2 s. c om List<TicketCategory> ticketCategories = ticketCategoryRepository.findByEventId(event.getId()); TicketCategory first = ticketCategories.get(0); TicketCategory second = ticketCategories.get(1); TicketReservationModification tr2 = new TicketReservationModification(); tr2.setAmount(1); tr2.setTicketCategoryId(second.getId()); TicketReservationModification tr3 = new TicketReservationModification(); tr3.setAmount(1); tr3.setTicketCategoryId(first.getId()); reserveTickets(event, first, AVAILABLE_SEATS - 2); String reservationIdSingleFirst = reserveTickets(event, second, 1); String reservationIdSingleSecond = reserveTickets(event, second, 1); assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation()); assertTrue(waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", first.getId(), Locale.ENGLISH)); assertTrue(waitingQueueManager.subscribe(event, new CustomerName("John Doe 2", "John", "Doe 2", event), "john@doe2.com", second.getId(), Locale.ENGLISH)); ticketReservationManager.deleteOfflinePayment(event, reservationIdSingleFirst, false); ticketReservationManager.deleteOfflinePayment(event, reservationIdSingleSecond, false); List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager .distributeSeats(event).collect(Collectors.toList()); assertEquals(2, subscriptions.size()); Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime> subscriptionDetail = subscriptions .get(0); assertEquals("john@doe.com", subscriptionDetail.getLeft().getEmailAddress()); TicketReservationWithOptionalCodeModification reservation = subscriptionDetail.getMiddle(); assertEquals(Integer.valueOf(first.getId()), reservation.getTicketCategoryId()); assertEquals(Integer.valueOf(1), reservation.getAmount()); assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now())); subscriptionDetail = subscriptions.get(1); assertEquals("john@doe2.com", subscriptionDetail.getLeft().getEmailAddress()); reservation = subscriptionDetail.getMiddle(); assertEquals(Integer.valueOf(second.getId()), reservation.getTicketCategoryId()); assertEquals(Integer.valueOf(1), reservation.getAmount()); assertTrue(subscriptionDetail.getRight().isAfter(ZonedDateTime.now())); }