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:net.malisis.blocks.vanishingoption.VanishingOptionsGui.java

@Override
public void construct() {

    UIWindow window = new UIWindow(this, "gui.vanishingoptions.title", 200, 220);

    window.add(new UILabel(this, "Direction").setPosition(0, 20));
    window.add(new UILabel(this, "Delay").setPosition(55, 20));
    window.add(new UILabel(this, "Inversed").setPosition(90, 20));

    int i = 0;//from w w w  . j ava2  s.  c om
    for (EnumFacing dir : EnumFacing.VALUES) {
        DirectionState state = vanishingOptions.getDirectionState(dir);
        int y = i * 14 + 30;
        UICheckBox cb = new UICheckBox(this, dir.name());
        cb.setPosition(2, y).setChecked(state.shouldPropagate).register(this);
        cb.attachData(Pair.of(dir, DataType.PROPAGATION));

        UITextField textField = new UITextField(this, "" + state.delay).setSize(27, 0).setPosition(55, y)
                .setDisabled(!state.shouldPropagate).register(this);
        textField.attachData(Pair.of(dir, DataType.DELAY));

        UICheckBox invCb = new UICheckBox(this).setPosition(105, y).setDisabled(!state.shouldPropagate)
                .setChecked(state.inversed).register(this);
        invCb.attachData(Pair.of(dir, DataType.INVERSED));

        window.add(cb);
        window.add(textField);
        window.add(invCb);

        configs.put(dir, Triple.of(cb, textField, invCb));

        i++;
    }

    UIContainer cont = new UIContainer<UIContainer>(this, 50, 60).setPosition(0, 40, Anchor.RIGHT);

    duration = new UITextField(this, "" + vanishingOptions.getDuration()).setSize(30, 0)
            .setPosition(0, 10, Anchor.CENTER).register(this);
    duration.attachData(Pair.of(null, DataType.DURATION));
    cont.add(new UILabel(this, "Duration").setPosition(0, 0, Anchor.CENTER));
    cont.add(duration);

    UIInventory inv = new UIInventory(this, inventoryContainer.getInventory(1));
    inv.setPosition(0, 40, Anchor.CENTER);
    cont.add(new UILabel(this, "Block").setPosition(0, 30, Anchor.CENTER));
    cont.add(inv);

    window.add(cont);

    UIPlayerInventory playerInv = new UIPlayerInventory(this, inventoryContainer.getPlayerInventory());
    window.add(playerInv);

    addToScreen(window);

    if (tileEntity != null)
        TileEntityUtils.linkTileEntityToGui(tileEntity, this);
}

From source file:io.mandrel.data.analysis.AnalysisService.java

protected Analysis buildReport(Spider spider, Blob blob) {
    Analysis report;/*www  .  jav  a2s.c o m*/
    if (blob.getMetadata().getUri().getScheme().startsWith("http")) {
        HttpAnalysis temp = new HttpAnalysis();

        // Robots.txt
        Uri pageURL = blob.getMetadata().getUri();
        String robotsTxtUrl = pageURL.getScheme() + "://" + pageURL.getHost() + ":" + pageURL.getPort()
                + "/robots.txt";
        ExtendedRobotRules robotRules = RobotsTxtUtils.getRobotRules(robotsTxtUrl);
        temp.robotRules(robotRules);

        // Sitemaps
        if (robotRules != null && robotRules.getSitemaps() != null) {
            Map<String, List<AbstractSiteMap>> sitemaps = new HashMap<>();
            robotRules.getSitemaps().forEach(url -> {
                List<AbstractSiteMap> results = getSitemapsForUrl(url);
                sitemaps.put(url, results);
            });
            temp.sitemaps(sitemaps);
        }
        report = temp;
    } else {
        report = new Analysis();
    }

    if (spider.getExtractors() != null) {
        Map<String, Instance<?>> cachedSelectors = new HashMap<>();

        // Page extraction
        if (spider.getExtractors().getData() != null) {
            Map<String, List<Document>> documentsByExtractor = spider.getExtractors().getData().stream().map(
                    ex -> Pair.of(ex.getName(), extractorService.extractThenFormat(cachedSelectors, blob, ex)))
                    .filter(pair -> pair != null && pair.getKey() != null && pair.getValue() != null)
                    .collect(Collectors.toMap(key -> key.getLeft(), value -> value.getRight()));
            report.documents(documentsByExtractor);
        }

        // Link extraction
        if (spider.getExtractors().getOutlinks() != null) {
            Map<String, Pair<Set<Link>, Set<Link>>> outlinksByExtractor = spider.getExtractors().getOutlinks()
                    .stream().map(ol -> {
                        return Pair.of(ol.getName(), extractorService.extractAndFilterOutlinks(spider,
                                blob.getMetadata().getUri(), cachedSelectors, blob, ol));
                    }).collect(Collectors.toMap(key -> key.getLeft(), value -> value.getRight()));

            report.outlinks(Maps.transformEntries(outlinksByExtractor, (key, entries) -> entries.getLeft()));
            report.filteredOutlinks(
                    Maps.transformEntries(outlinksByExtractor, (key, entries) -> entries.getRight()));
        }

    }

    report.metadata(blob.getMetadata());
    return report;
}

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

private Pair<IBlockState, NBTTagCompound> getStoredState(int x, int y, int z) {
    return Pair.of(states[x][y][z], tileEntities[x][y][z]);
}

From source file:com.nttec.everychan.ui.ShareActivity.java

private void handleIntent(Intent intent) {
    ArrayAdapter<Pair<TabModel, SerializablePage>> adapter = new ArrayAdapter<Pair<TabModel, SerializablePage>>(
            this, 0) {
        private final int drawablePadding = (int) (getResources().getDisplayMetrics().density * 5 + 0.5f);

        @Override/*w w w.  j a  v a 2  s.c o m*/
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView == null
                    ? getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView;
            TextView tv = (TextView) view.findViewById(android.R.id.text1);
            tv.setEllipsize(TextUtils.TruncateAt.END);
            tv.setSingleLine();
            tv.setText(getItem(position).getLeft().title);
            tv.setCompoundDrawablesWithIntrinsicBounds(MainApplication.getInstance()
                    .getChanModule(getItem(position).getLeft().pageModel.chanName).getChanFavicon(), null, null,
                    null);
            tv.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };
    for (TabModel tab : MainApplication.getInstance().tabsState.tabsArray) {
        if (tab.type == TabModel.TYPE_NORMAL && tab.pageModel.type != UrlPageModel.TYPE_SEARCHPAGE) {
            SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash);
            if (page != null) {
                adapter.add(Pair.of(tab, page));
            }
        }
    }
    if (adapter.getCount() == 0) {
        for (Database.HistoryEntry entity : MainApplication.getInstance().database.getHistory()) {
            try {
                TabModel tab = new TabModel();
                tab.title = entity.title;
                tab.type = TabModel.TYPE_NORMAL;
                tab.webUrl = entity.url;
                tab.pageModel = UrlHandler.getPageModel(entity.url);
                tab.hash = ChanModels.hashUrlPageModel(tab.pageModel);
                SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash);
                if (page != null) {
                    adapter.add(Pair.of(tab, page));
                }
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
        if (adapter.getCount() == 0) {
            Toast.makeText(this, R.string.share_no_tabs, Toast.LENGTH_LONG).show();
            finish();
            return;
        }
    }
    if (PostingService.isNowPosting()) {
        Toast.makeText(this, R.string.posting_now_posting, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    selectedFile = null;
    if (intent != null) {
        Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (uri != null) {
            File file = UriFileUtils.getFile(this, uri);
            if (file != null) {
                selectedFile = file;
            }
        }
    }
    if (selectedFile == null) {
        Toast.makeText(this, R.string.postform_cannot_attach, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    setListAdapter(adapter);
}

From source file:eu.crydee.alignment.aligner.ae.MetricsOneVsOneC.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    results = HashBasedTable.create();//from ww w  . j  a v  a  2 s.co m
    keys = Lists.newArrayList(keysArray);
    methodsMetadata = Arrays.stream(Complete.class.getMethods())
            .map(m -> Pair.of(m, m.getAnnotation(Metric.class)))
            .filter(p -> p.getRight() != null && keys.contains(p.getRight().key()))
            .collect(Collectors.toMap(p -> p.getRight().key(), p -> Pair.of(p.getLeft(), p.getRight().name())));
}

From source file:com.github.steveash.guavate.Guavate.java

/**
 * Creates a stream that combines two other streams, continuing until either stream ends.
 * <p>/*from  w  w w. j  a va 2  s .co m*/
 * Each pair of input objects is combined into a {@link Pair}.
 * @param <A> the type of the first stream
 * @param <B> the type of the second stream
 * @param stream1 the first stream
 * @param stream2 the first stream
 * @return a stream of pairs, one from each stream
 */
public static <A, B> Stream<Pair<A, B>> zip(Stream<A> stream1, Stream<B> stream2) {
    return zip(stream1, stream2, (a, b) -> Pair.of(a, b));
}

From source file:mase.spec.BasicHybridExchangerDunn.java

@Override
protected Pair<MetaPopulation, MetaPopulation> findNextMerge(double[][] distanceMatrix, EvolutionState state) {
    List<BehaviourResult>[] mpBehavs = new List[metaPops.size()];
    for (int i = 0; i < metaPops.size(); i++) {
        MetaPopulation mp = metaPops.get(i);
        Individual[] inds = getElitePortion(mp.inds, (int) Math.ceil(elitePortion * popSize));
        mpBehavs[i] = new ArrayList<BehaviourResult>(mp.agents.size() * inds.length);
        for (Individual ind : inds) {
            for (Integer a : mp.agents) {
                mpBehavs[i].add(getAgentBR(ind, a));
            }/*ww  w  .j  a  v  a 2 s  . c  om*/
        }
    }

    double currentDunn = dunnIndex(distanceMatrix);
    System.out.println("Current dunn: " + currentDunn);
    Pair<MetaPopulation, MetaPopulation> next = null;

    for (int i = 0; i < metaPops.size(); i++) {
        for (int j = 0; j < metaPops.size(); j++) {
            MetaPopulation mpi = metaPops.get(i);
            MetaPopulation mpj = metaPops.get(j);
            if (i != j && mpi.age > stabilityTime && mpj.age > stabilityTime) {
                List<BehaviourResult>[] hypothesis = new List[metaPops.size() - 1];
                List<BehaviourResult> merged = new ArrayList<BehaviourResult>();
                merged.addAll(mpBehavs[i]);
                merged.addAll(mpBehavs[j]);
                int index = 0;
                hypothesis[index++] = merged;
                for (int k = 0; k < mpBehavs.length; k++) {
                    if (k != i && k != j) {
                        hypothesis[index++] = mpBehavs[k];
                    }
                }
                double[][] dists = distanceMatrix(hypothesis, state);
                double dunn = dunnIndex(dists);

                System.out.println("Hypothesis merge " + mpi + " with " + mpj + ": " + dunn);

                if (dunn > currentDunn) {
                    currentDunn = dunn;
                    next = Pair.of(mpi, mpj);
                }
            }
        }
    }
    return next;
}

From source file:com.yahoo.elide.parsers.state.RelationshipTerminalState.java

private Supplier<Pair<Integer, JsonNode>> handleRequest(StateContext state,
        BiFunction<Data<Resource>, RequestScope, Boolean> handler) {
    Data<Resource> data = state.getJsonApiDocument().getData();
    handler.apply(data, state.getRequestScope());
    return () -> Pair.of(HttpStatus.SC_NO_CONTENT, null);
}

From source file:fr.landel.utils.commons.MapUtils2Test.java

/**
 * Test method for//from w  w w.  jav a2 s. c  om
 * {@link MapUtils2#newHashMap(org.apache.commons.lang3.tuple.Pair<K,V>[])}.
 */
@SuppressWarnings("unchecked")
@Test
public void testNewHashMapPair() {
    Map<String, Long> map = MapUtils2.newHashMap(Pair.of("key1", 1L), Pair.of("key2", 2L));

    assertTrue(map instanceof HashMap);
    assertEquals(2, map.size());

    Map<String, Long> expectedMap = new HashMap<>();
    expectedMap.put("key1", 1L);
    expectedMap.put("key2", 2L);

    for (Entry<String, Long> entry : expectedMap.entrySet()) {
        assertTrue(map.containsKey(entry.getKey()));
        assertEquals(entry.getValue(), map.get(entry.getKey()));
    }

    map = MapUtils2.newHashMap();

    assertTrue(map instanceof HashMap);
    assertTrue(map.isEmpty());

    map = MapUtils2.newHashMap(new Pair[0]);

    assertTrue(map instanceof HashMap);
    assertTrue(map.isEmpty());
}

From source file:com.helion3.prism.api.parameters.ParameterRadius.java

@Override
public Optional<Pair<String, String>> processDefault(QuerySession session, Query query) {
    if (session.getCommandSource().get() instanceof Player) {
        // Default radius from config
        int defaultRadius = Prism.getConfig().getNode("defaults", "radius").getInt();

        // Player location
        Location<World> location = ((Player) session.getCommandSource().get()).getLocation();

        query.addCondition(ConditionGroup.from(location, defaultRadius));

        session.setRadius(defaultRadius);

        return Optional.of(Pair.of(aliases.get(0), "" + defaultRadius));
    }/*from w w  w . jav  a  2 s  .c  o  m*/

    return Optional.empty();
}