Example usage for org.apache.commons.lang3.tuple Pair of

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

Introduction

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

Prototype

public static <L, R> Pair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:com.streamsets.pipeline.stage.processor.tensorflow.TensorFlowProcessor.java

@Override
protected List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    String[] modelTags = new String[conf.modelTags.size()];
    modelTags = conf.modelTags.toArray(modelTags);

    if (Strings.isNullOrEmpty(conf.modelPath)) {
        issues.add(getContext().createConfigIssue(Groups.TENSOR_FLOW.name(),
                TensorFlowConfigBean.MODEL_PATH_CONFIG, Errors.TENSOR_FLOW_01));
        return issues;
    }/*from   w  w w. j a v a 2s  .  c om*/

    try {
        File exportedModelDir = new File(conf.modelPath);
        if (!exportedModelDir.isAbsolute()) {
            exportedModelDir = new File(getContext().getResourcesDirectory(), conf.modelPath).getAbsoluteFile();
        }
        this.savedModel = SavedModelBundle.load(exportedModelDir.getAbsolutePath(), modelTags);
    } catch (TensorFlowException ex) {
        issues.add(getContext().createConfigIssue(Groups.TENSOR_FLOW.name(),
                TensorFlowConfigBean.MODEL_PATH_CONFIG, Errors.TENSOR_FLOW_02, ex));
        return issues;
    }

    this.session = this.savedModel.session();
    this.conf.inputConfigs.forEach(inputConfig -> {
        Pair<String, Integer> key = Pair.of(inputConfig.operation, inputConfig.index);
        inputConfigMap.put(key, inputConfig);
    });

    errorRecordHandler = new DefaultErrorRecordHandler(getContext());

    return issues;
}

From source file:alfio.manager.EventNameManager.java

private Optional<String> getCroppedName(String cleanDisplayName) {
    String candidate = Arrays.stream(cleanDisplayName.split(SPACES_AND_PUNCTUATION))
            .map(w -> Pair.of(NUMBER_MATCHER.matcher(w).matches(), w))
            .map(p -> p.getKey() ? p.getValue() : StringUtils.left(p.getValue(), 1))
            .collect(Collectors.joining());
    if (isUnique(candidate)) {
        return Optional.of(candidate);
    }// ww w.  ja  v  a2s.c  om
    return Optional.empty();
}

From source file:com.blacklocus.qs.worker.WorkerQueueItemHandler.java

@SuppressWarnings("unchecked")
@Override//from  ww w.j a  v a2s  .c o m
public void withFuture(QSTaskModel task, final Future<Pair<QSTaskModel, Object>> future) {
    // I don't know if this is useful or not.

    QSWorker worker = workers.get(task.handler);
    if (worker == null) {
        throw new RuntimeException("No worker available for worker identifier: " + task.handler);
    }

    final TaskKitFactory factory = new TaskKitFactory(task, worker, logService, workerIdService);
    worker.withFuture(factory, new Future<Pair<TaskKitFactory, Object>>() {
        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            return future.cancel(mayInterruptIfRunning);
        }

        @Override
        public boolean isCancelled() {
            return future.isCancelled();
        }

        @Override
        public boolean isDone() {
            return future.isDone();
        }

        @Override
        public Pair<TaskKitFactory, Object> get() throws InterruptedException, ExecutionException {
            Pair<QSTaskModel, Object> theFuture = future.get();
            return Pair.of(factory, theFuture.getRight());
        }

        @Override
        public Pair<TaskKitFactory, Object> get(long timeout,
                @SuppressWarnings("NullableProblems") TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            Pair<QSTaskModel, Object> theFuture = future.get(timeout, unit);
            return Pair.of(factory, theFuture.getRight());
        }
    });
}

From source file:blusunrize.immersiveengineering.client.render.IEBipedLayerRenderer.java

public static void addWornPowerpack(EntityLivingBase living, ItemStack powerpack) {
    POWERPACK_PLAYERS.put(living.getUniqueID(), Pair.of(powerpack, 5));
}

From source file:com.astamuse.asta4d.web.form.field.impl.AbstractRadioAndCheckboxRenderer.java

protected Renderer retrieveAndCreateValueMap(final String editTargetSelector,
        final String displayTargetSelector) {
    Renderer render = Renderer.create();
    if (PrepareRenderingDataUtil.retrieveStoredDataFromContextBySelector(editTargetSelector) == null) {

        final List<Pair<String, String>> inputList = new LinkedList<>();

        final List<OptionValuePair> optionList = new LinkedList<>();

        render.add(editTargetSelector, new ElementSetter() {
            @Override//from  w  ww. j av  a2s. co  m
            public void set(Element elem) {
                inputList.add(Pair.of(elem.id(), elem.attr("value")));
            }
        });

        render.add(":root", new Renderable() {
            @Override
            public Renderer render() {
                Renderer render = Renderer.create();
                for (Pair<String, String> input : inputList) {
                    String id = input.getLeft();
                    final String value = input.getRight();
                    if (StringUtils.isEmpty(id)) {
                        if (allowNonIdItems()) {
                            optionList.add(new OptionValuePair(value, value));
                        } else {
                            String msg = "The target item[%s] must have id specified.";
                            throw new IllegalArgumentException(String.format(msg, editTargetSelector));
                        }
                    } else {
                        render.add(SelectorUtil.attr("for", id), Renderer.create("label", new ElementSetter() {
                            @Override
                            public void set(Element elem) {
                                optionList.add(new OptionValuePair(value, elem.text()));
                            }
                        }));
                        render.add(":root", new Renderable() {
                            @Override
                            public Renderer render() {
                                PrepareRenderingDataUtil.storeDataToContextBySelector(editTargetSelector,
                                        displayTargetSelector, new OptionValueMap(optionList));
                                return Renderer.create();
                            }
                        });
                    }
                } // end for loop
                return render;
            }
        });
    }
    return render;
}

From source file:enumj.EnumeratorTest.java

@Test
public void testOf_Iterator() {
    System.out.println("of iterator");
    EnumeratorGenerator.generatorPairs().limit(100)
            .map(p -> Pair.of(p.getLeft().ofIteratorEnumerator(), p.getRight().ofIteratorEnumerator()))
            .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight())));
    EnumeratorGenerator.generatorPairs().limit(100)
            .map(p -> Pair.of(p.getLeft().ofIteratorEnumerator(), p.getRight().onEnumerator()))
            .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight())));
}

From source file:net.malisis.blocks.tileentity.SwapperTileEntity.java

private Pair<IBlockState, NBTTagCompound> getWorldState(BlockPos pos) {
    IBlockState worldState = getWorld().getBlockState(pos);

    if (worldState.getBlock() == Blocks.bedrock)
        return Pair.of(null, null);

    TileEntity te = getWorld().getTileEntity(pos);
    if (te == null)
        return Pair.of(worldState, null);
    NBTTagCompound nbt = new NBTTagCompound();
    te.writeToNBT(nbt);/*www.j a  va2  s.c  om*/
    return Pair.of(worldState, nbt);
}

From source file:de.tntinteractive.portalsammler.sources.MlpSourceV1.java

@Override
public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui,
        final SecureStore store) throws Exception {
    final WebDriver driver = this
            .createDriver("https://financepilot-pe.mlp.de/p04pepe/entry?rzid=XC&rzbk=0752");

    final WebElement userField = driver.findElement(By.id("txtBenutzerkennung"));
    userField.sendKeys(settings.get(USER, gui));

    final WebElement passwordField = driver.findElement(By.className("XPassword"));
    passwordField.sendKeys(settings.get(PASSWORD, gui));

    passwordField.submit();//from   w ww  .  j  av  a2 s .c  o m

    int newDocs = 0;
    int knownDocs = 0;
    try {
        clickLink(driver, "Postfach");

        clickButton(driver, "Dokumente anzeigen");

        final WebElement table = driver.findElement(By.id("tblKontoauszuege"));
        final WebElement tBody = table.findElement(By.xpath("tbody"));
        final FileDownloader d = new FileDownloader(driver);

        for (final WebElement tr : tBody.findElements(By.tagName("tr"))) {
            final List<WebElement> tds = tr.findElements(By.tagName("td"));
            final DocumentInfo doc = DocumentInfo.create(this.getId(), DocumentFormat.PDF);
            if (tds.get(2).getText().isEmpty()) {
                continue;
            }
            doc.addKeywords(tds.get(0).getText());
            doc.addKeywords(tds.get(1).getText());
            doc.setDate(parseDate(tds.get(2).getText()));

            if (!store.containsDocument(doc)) {
                final WebElement link = tds.get(0).findElement(By.tagName("a"));
                final byte[] file = d.downloadFile(link);
                store.storeDocument(doc, file);
                newDocs++;
            } else {
                knownDocs++;
            }
        }
    } finally {
        clickButton(driver, "Abmelden");
    }
    return Pair.of(newDocs, knownDocs);
}

From source file:com.hortonworks.registries.storage.util.StorageUtils.java

public static List<Pair<Field, Object>> getAnnotatedFieldValues(Storable storable,
        Class<? extends Annotation> clazz)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    List<Pair<Field, Object>> res = new ArrayList<>();
    for (Field field : storable.getClass().getDeclaredFields()) {
        if (field.getAnnotation(clazz) != null) {
            Object val = ReflectionHelper.invokeGetter(field.getName(), storable);
            if (val != null) {
                res.add(Pair.of(field, val));
            }/*w w  w.j  av  a  2 s  .  com*/
        }
    }
    return res;
}

From source file:com.quartercode.jtimber.rh.agent.asm.InsertChildAccessorsClassAdapter.java

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {

    fields.add(Pair.of(name, Type.getType(desc)));

    return super.visitField(access, name, desc, signature, value);
}