Example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair.

Prototype

public ImmutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

From source file:com.github.aptd.simulation.CMain.java

/**
 * returns the experiment data models/* ww w .  j a  va2 s .  com*/
 *
 * @param p_options commandline options
 * @return stream of experiments
 */
private static Stream<Pair<EDataModel, String>> datamodel(final CommandLine p_options) {
    final List<String> l_instances = Arrays.stream(p_options.getOptionValue("scenario").split(","))
            .map(String::trim).filter(i -> !i.isEmpty()).collect(Collectors.toList());

    final List<String> l_types = Arrays.stream(p_options.getOptionValue("scenariotype", "").split(","))
            .map(String::trim).filter(i -> !i.isEmpty()).collect(Collectors.toList());

    return StreamUtils.zip(l_instances.stream(),
            Stream.concat(l_types.stream(),
                    IntStream.range(0, l_instances.size() - l_types.size()).mapToObj(
                            i -> CConfiguration.INSTANCE.getOrDefault("xml", "default", "datamodel"))),
            (i, j) -> new ImmutablePair<>(EDataModel.from(j), i));
}

From source file:com.streamsets.pipeline.stage.it.DecimalTypeIT.java

@Test
public void zeroScale() throws Exception {
    executeUpdate("CREATE TABLE `tbl` (id int, dec decimal(2, 0)) PARTITIONED BY (dt string) STORED AS AVRO");

    HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().decimalConfig(2, 0).build();
    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build();

    List<Record> records = new LinkedList<>();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("id", Field.create(Field.Type.INTEGER, 1));
    map.put("dec", Field.create(BigDecimal.valueOf(12)));
    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));
    records.add(record);// w  ww.jav a 2 s  .c  o m

    processRecords(processor, hiveTarget, records);

    assertQueryResult("select * from tbl order by id", new QueryValidator() {
        @Override
        public void validateResultSet(ResultSet rs) throws Exception {
            assertResultSetStructure(rs, new ImmutablePair("tbl.id", Types.INTEGER),
                    new ImmutablePair("tbl.dec", Types.DECIMAL), new ImmutablePair("tbl.dt", Types.VARCHAR));

            Assert.assertTrue("Table tbl doesn't contain any rows", rs.next());
            Assert.assertEquals(1, rs.getLong(1));
            Assert.assertEquals(BigDecimal.valueOf(12), rs.getBigDecimal(2));

            Assert.assertFalse("Unexpected number of rows", rs.next());
        }
    });
}

From source file:com.flowpowered.commons.StringToUniqueIntegerMap.java

@Override
public List<Pair<Integer, String>> getItems() {
    List<Pair<Integer, String>> items = new ArrayList<>();
    for (Map.Entry<String, Integer> entry : store.getEntrySet()) {
        items.add(new ImmutablePair<>(entry.getValue(), entry.getKey()));
    }//from   w ww .j  a va2s  . c  o  m
    return items;
}

From source file:com.streamsets.pipeline.stage.it.DriftIT.java

@Test
public void testNewColumnInTheMiddle() throws Exception {
    HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().table("multiple").build();
    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build();

    List<Record> records = new LinkedList<>();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("id", Field.create(Field.Type.INTEGER, 1));
    map.put("value", Field.create(Field.Type.STRING, "exists"));
    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));
    records.add(record);/*from  ww  w  .j av  a 2 s .c om*/

    map = new LinkedHashMap<>();
    map.put("id", Field.create(Field.Type.INTEGER, 2));
    map.put("new_column", Field.create(Field.Type.STRING, "new value"));
    map.put("value", Field.create(Field.Type.STRING, "exists"));
    record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));
    records.add(record);

    processRecords(processor, hiveTarget, records);

    assertQueryResult("select * from multiple order by id", new QueryValidator() {
        @Override
        public void validateResultSet(ResultSet rs) throws Exception {
            assertResultSetStructure(rs, new ImmutablePair("multiple.id", Types.INTEGER),
                    new ImmutablePair("multiple.value", Types.VARCHAR),
                    new ImmutablePair("multiple.new_column", Types.VARCHAR),
                    new ImmutablePair("multiple.dt", Types.VARCHAR));

            Assert.assertTrue("Table tbl doesn't contain any rows", rs.next());
            Assert.assertEquals(1, rs.getLong(1));
            Assert.assertEquals("exists", rs.getString(2));
            Assert.assertEquals(null, rs.getString(3));

            Assert.assertTrue("Unexpected number of rows", rs.next());
            Assert.assertEquals(2, rs.getLong(1));
            Assert.assertEquals("exists", rs.getString(2));
            Assert.assertEquals("new value", rs.getString(3));

            Assert.assertFalse("Unexpected number of rows", rs.next());
        }
    });
}

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  2s . c o m*/

        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:fr.smile.liferay.EsigatePortlet.java

/**
 * @param request// w w  w .  j  ava  2  s  .c  o  m
 * @return
 * @throws PortletException
 */
public Pair<String, String> getBaseUrl(PortletRequest request) throws PortletException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("calculate the portlet resource/action URLs");
    }
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    Layout layout = themeDisplay.getLayout();

    String instanceID = portletDisplay.getInstanceId();

    if (StringUtils.isEmpty(instanceID)) {
        instanceID = URL_INSTANCE_ID;
    }

    String baseUrl = "";

    try {
        baseUrl = new StringBuilder().append(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay))
                .append("/-/esigate").toString();
    } catch (PortalException e) {
        throw new PortletException(e);
    } catch (SystemException e) {
        throw new PortletException(e);
    }

    String baseActionURL = new StringBuilder().append(baseUrl).append("/action/").append(instanceID)
            .append("/s/").append(request.getWindowState()).append("/l/1/param/").toString();
    String baseResourceURL = new StringBuilder(baseUrl).append("/resource/").append(instanceID)
            .append("?p_p_resource_id=").toString();

    if (LOG.isDebugEnabled()) {
        LOG.debug("baseURL is " + baseUrl);
        LOG.debug("baseActionURL is " + baseActionURL);
        LOG.debug("baseResourceURL is " + baseResourceURL);
    }

    return new ImmutablePair<>(baseResourceURL, baseActionURL);

}

From source file:com.jaspersoft.jasperserver.jrsh.completion.completer.RepositoryNameCompleter.java

public List<Pair<String, Boolean>> download(String path) {
    List<Pair<String, Boolean>> list = new ArrayList<>();
    if (!isResourceExist(path)) {
        return list;
    }//  ww  w. j a  v a 2s  .  c o  m

    List<ClientResourceLookup> lookups;
    ClientResourceListWrapper entity = SessionFactory.getSharedSession().resourcesService().resources()
            .parameter(FOLDER_URI, path).parameter(RECURSIVE, "false").search().getEntity();

    if (entity != null) {
        lookups = entity.getResourceLookups();
    } else {
        // empty folder
        lookups = Collections.emptyList();
    }

    for (ClientResourceLookup lookup : lookups) {
        String uri = lookup.getUri();
        String type = lookup.getResourceType();

        if ("folder".equals(type)) {
            list.add(new ImmutablePair<String, Boolean>(uri, true));
        } else {
            list.add(new ImmutablePair<String, Boolean>(uri, false));
        }
    }
    return list;
}

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();
        }//from  www. jav  a 2 s .  c  o  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
        }
    }
}

From source file:io.lavagna.service.MailTicketService.java

@Transactional(readOnly = true)
private ImmutablePair<Card, User> createCard(String name, String description, String username, int columnId) {
    if (!userRepository.userExists(EMAIL_PROVIDER, username)) {
        userRepository.createUser(EMAIL_PROVIDER, username, null, null, null, true);
    }//from  w  ww .j a  v a 2  s  .co m
    User user = userRepository.findUserByName(EMAIL_PROVIDER, username);

    Card card = cardService.createCardFromTop(name, columnId, new Date(), user);
    cardDataService.updateDescription(card.getId(), description, new Date(), user.getId());

    return new ImmutablePair<>(card, user);
}

From source file:com.hybris.datahub.outbound.adapter.TmallAdapter.java

private List<ErrorData> processItems(final TargetSystemPublication targetSystemPublication,
        final TargetItemMetadata targetItemMetadata) {
    final List<ErrorData> errors = Lists.newArrayList();
    final TransactionTemplate template = new TransactionTemplate(transactionManager);
    Pair<Integer, Long> elementsAndLastId = new ImmutablePair<>(0, 0L);
    do {/*from  ww  w.jav a2s . co  m*/
        final Long lastProcessedId = elementsAndLastId.getRight();
        elementsAndLastId = template.execute(status -> {
            final List<? extends TargetItem> items = getItems(targetItemMetadata, targetSystemPublication,
                    makePageable(lastProcessedId));
            final Pair<Integer, Long> pageElementsAndLastId;
            if (!CollectionUtils.isEmpty(items)) {
                for (final TargetItem targetItem : items) {
                    errors.addAll(doPublish(targetItem, targetSystemPublication));
                }
                pageElementsAndLastId = new ImmutablePair<>(items.size(),
                        getLastProcessedId(lastProcessedId, items));
            } else {
                pageElementsAndLastId = new ImmutablePair<>(0, 0L);
            }
            return pageElementsAndLastId;
        });
    } while (elementsAndLastId.getRight() > 0);
    return errors;
}