當前位置: 首頁>>代碼示例>>Java>>正文


Java Pair類代碼示例

本文整理匯總了Java中org.javatuples.Pair的典型用法代碼示例。如果您正苦於以下問題:Java Pair類的具體用法?Java Pair怎麽用?Java Pair使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Pair類屬於org.javatuples包,在下文中一共展示了Pair類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: zipMaps

import org.javatuples.Pair; //導入依賴的package包/類
public static <T, S> Observable<Map<T, S>> zipMaps(final Map<T, Observable<S>> tasks) {

        Objects.requireNonNull(tasks, "tasks is null");

        return Observable.combineLatest(
            tasks.entrySet()
                .stream()
                .map(entry -> Observable.combineLatest(
                    Observable.just(entry.getKey()),
                    entry.getValue(),
                    Pair::with))
                .collect(ImmutableList.toImmutableList()),
            xs -> Arrays.stream(xs)
                .map(x -> (Pair<T, S>)x)
                .collect(ImmutableMap.toImmutableMap(Pair::getValue0, Pair::getValue1)));
    }
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:17,代碼來源:MoreObservables.java

示例2: BlackDuckIoMapper

import org.javatuples.Pair; //導入依賴的package包/類
private BlackDuckIoMapper(BlackDuckIoMapper.Builder builder) {
    // Configure the graph topology
    List<GraphInitializer> initializers = builder.registries.stream()
            .flatMap(registry -> registry.find(BlackDuckIo.class, GraphInitializer.class).stream())
            .map(Pair::getValue1).collect(toList());

    onGraphTopology = gt -> {
        initializers.forEach(i -> gt.addInitializer(i::initialize));
        builder.onGraphTopology.ifPresent(c -> c.accept(gt));
    };

    // Configure the graph mapper
    List<DatatypeRegistration> datatypes = builder.registries.stream()
            .flatMap(registry -> registry.find(BlackDuckIo.class, DatatypeRegistration.class).stream())
            .map(Pair::getValue1).collect(toList());
    Optional<MultiValueCollectorRegistration> multiValueCollector = builder.registries.stream()
            .flatMap(registry -> registry.find(BlackDuckIo.class, MultiValueCollectorRegistration.class).stream())
            .map(Pair::getValue1).findAny();

    onGraphMapper = gm -> {
        datatypes.forEach(d -> gm.addDatatype(d.iri(), d.handler()));
        multiValueCollector.ifPresent(m -> gm.multiValueCollector(m.collector()));
        builder.onGraphMapper.ifPresent(c -> c.accept(gm));
    };
}
 
開發者ID:blackducksoftware,項目名稱:bdio,代碼行數:26,代碼來源:BlackDuckIoMapper.java

示例3: merge1

import org.javatuples.Pair; //導入依賴的package包/類
@Test
public void merge1() throws Exception {

    final Process<Integer, String> a = Process.of(Observable.just(
        Either.left(1), Either.left(2), Either.left(3), Either.right("A")));

    final Process<Integer, String> b = Process.of(Observable.just(
        Either.left(7), Either.left(8), Either.left(9), Either.right("B")));

    final CountDownLatch latch = new CountDownLatch(2);

    Process.merge(a, b).result().subscribe(result -> {
        assertEquals(Pair.with("A", "B"), result);
        latch.countDown();
    });

    Process.merge(a, b).states().subscribe(next -> {}, error -> {}, latch::countDown);

    latch.await(5000L, TimeUnit.MILLISECONDS);
}
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:21,代碼來源:ProcessTest.java

示例4: isComplete2

import org.javatuples.Pair; //導入依賴的package包/類
@Test
public void isComplete2() throws Exception {

    final ResolvedDependencies a = ResolvedDependencies.of(ImmutableMap.of(
        RecipeIdentifier.of("org", "project"),
        Pair.with(
            SemanticVersion.of(1),
            RecipeVersion.of(
                Either.left(GitCommit.of("https://github.com/magicco/magiclib/commit", "b0215d5")),
                Optional.of("my-magic-lib"),
                DependencyGroup.of(ImmutableMap.of(
                    RecipeIdentifier.of("megacorp", "json"), AnySemanticVersion.of())),
                Optional.empty()))));

    assertFalse(a.isComplete());
}
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:17,代碼來源:ResolvedDependenciesTest.java

示例5: show

import org.javatuples.Pair; //導入依賴的package包/類
/**
 * Constructs and displays dialog based on the FXML at the specified URL
 * 
 * @param url
 *            the location of the FXML file, relative to the
 *            {@code sic.nmsu.javafx} package
 * @param stateInit
 *            a consumer used to configure the controller before FXML injection
 * @return
 */
public static <R, C extends FXDialogController<R>> R show(String url, Consumer<C> stateInit) {
	final Pair<Parent, C> result = FXController.get(url, stateInit);
	final Parent view = result.getValue0();
	final C ctrl = result.getValue1();

	final Dialog<R> dialog = new Dialog<>();
	dialog.titleProperty().bind(ctrl.title);

	final DialogPane dialogPane = dialog.getDialogPane();
	dialogPane.setContent(view);
	dialogPane.getButtonTypes().add(ButtonType.CLOSE);

	final Stage window = (Stage) dialogPane.getScene().getWindow();
	window.getIcons().add(new Image("images/recipe_icon.png"));

	final Node closeButton = dialogPane.lookupButton(ButtonType.CLOSE);
	closeButton.managedProperty().bind(closeButton.visibleProperty());
	closeButton.setVisible(false);

	ctrl.dialog = dialog;
	ctrl.dialog.showAndWait();

	return ctrl.result;
}
 
開發者ID:NMSU-SIC-Club,項目名稱:JavaFX_Tutorial,代碼行數:35,代碼來源:FXDialogController.java

示例6: get

import org.javatuples.Pair; //導入依賴的package包/類
/**
 * Create the view and controller associated with the provided FXML URL
 * 
 * @param url
 *            the location of the FXML file, relative to the
 *            {@code sic.nmsu.javafx} package
 * @param stateInit
 *            a consumer used to configure the controller before FXML injection
 * @return the initialized view and controller
 */
public static <C extends FXController> Pair<Parent, C> get(String url, Consumer<C> stateInit) {
	FXMLLoader loader = new FXMLLoader(App.class.getResource(url));
	loader.setControllerFactory(ctrlClass -> {
		@SuppressWarnings("unchecked")
		C ctrl = (C) Resolver.resolve(ctrlClass);
		if (stateInit != null)
			stateInit.accept(ctrl);
		return ctrl;
	});

	try {
		loader.load();
	} catch (IOException e) {
		logger.error(e.getMessage());
		e.printStackTrace();
		return null;
	}

	return new Pair<Parent, C>(loader.getRoot(), loader.getController());
}
 
開發者ID:NMSU-SIC-Club,項目名稱:JavaFX_Tutorial,代碼行數:31,代碼來源:FXController.java

示例7: process

import org.javatuples.Pair; //導入依賴的package包/類
@Override
public Observable<Event> process(Event e) {
    switch (e.sender) {
        case Event.MARKUP_CONTROLLER:
            switch (e.descriptor) {
                case MarkupController.REMOVE_HIGHLIGHTS:
                    return removeHighlight((Markup) e.data);
                case MarkupController.CHANGE_HIGHLIGHT_COLOR:
                    return changeHighlightColor((Markup) e.data);
                case MarkupController.SET_CURSOR:
                    return setCursorPosition((Bounds) e.data);
                case MarkupController.FILE_SELECTED:
                    return fileSelected((Pair<String, List<Markup>>) e.data);
                default:
                    throw new RuntimeException("Bad Custom Tag!");
            }
        default:
            throw new RuntimeException("Bad Sender!");
    }
}
 
開發者ID:LouisJenkinsCS,項目名稱:Code-Glosser,代碼行數:21,代碼來源:MarkupView.java

示例8: SVMRandomGaussian

import org.javatuples.Pair; //導入依賴的package包/類
/**
 * Convert an ArrayList of histograms into a matrix of svm_nodes that can be passed into the svm library
 * This is done in parallel. This library can also be instantiated multiple times in parallel
 *
 * @param histograms The ArrayList of histograms that we're 
 * @param threadCount The number of threads to use to perform the computation
 * @param D The number of random fourier features
 * @param sigmak A measure of the bandwidth of the RBF kernel; gammak = 1/(2*sigmak^2)
 * @param 
 * @param threadCount if svm_type is svm_parameter.PRECOMPUTED, use this many threads to apply kernel. Otherwise ignore value
 */
public SVMRandomGaussian(ArrayList<Pair<Integer, GenericPoint<Integer>>> histograms, int D, 
						 double gammak, boolean sine, int threadCount) {
	_threadCount = threadCount;
	_threadArray = new Thread[_threadCount];
	_histograms = histograms;
	_D = D;
	_sine = sine;
	_n = _histograms.get(0).getValue1().getDimensions();
	_retNode = new svm_node[histograms.size()][];
	_retNodeRowCache = new HashMap<GenericPoint<Integer>,Integer>();
	
	_gff = new GaussianRandomFeatures(_D, _n, gammak, sine);
	if (_sine) _D *= 2;
	
	for (svm_node[] svmNodeArr : _retNode)
		svmNodeArr = null;

	_retNodeLock = new ReentrantLock();

	for (int i = 0; i < _threadCount; i++) {
		_threadArray[i] = new Thread(new SVMRandomGaussian(_retNodeLock, _retNode, _histograms, _retNodeRowCache, _D, _n, _gff));
		_threadArray[i].start();
	}   
}
 
開發者ID:dpinney,項目名稱:essence,代碼行數:36,代碼來源:SVMRandomGaussian.java

示例9: tryDrainNextWaiting

import org.javatuples.Pair; //導入依賴的package包/類
/**
 * Completes the next waiting future if there is one.
 */
private synchronized void tryDrainNextWaiting(final boolean force) {
    // need to peek because the number of available items needs to be >= the expected size for that future. if not
    // it needs to keep waiting
    final Pair<CompletableFuture<List<Result>>, Integer> nextWaiting = waiting.peek();
    if (nextWaiting != null && (force || (resultLinkedBlockingQueue.size() >= nextWaiting.getValue1() || readComplete.isDone()))) {
        final int items = nextWaiting.getValue1();
        final CompletableFuture<List<Result>> future = nextWaiting.getValue0();
        final List<Result> results = new ArrayList<>(items);
        resultLinkedBlockingQueue.drainTo(results, items);

        // it's important to check for error here because a future may have already been queued in "waiting" prior
        // to the first response back from the server. if that happens, any "waiting" futures should be completed
        // exceptionally otherwise it will look like success.
        if (null == error.get())
            future.complete(results);
        else
            future.completeExceptionally(error.get());

        waiting.remove(nextWaiting);
    }
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:25,代碼來源:ResultQueue.java

示例10: featureString

import org.javatuples.Pair; //導入依賴的package包/類
public static String featureString(final Graph.Features features) {
    final StringBuilder sb = new StringBuilder("FEATURES");
    final Predicate<Method> supportMethods = (m) -> m.getModifiers() == Modifier.PUBLIC && m.getName().startsWith(featuresStartWith) && !m.getName().equals(featuresStartWith);
    sb.append(LINE_SEPARATOR);

    Stream.of(Pair.with(Graph.Features.GraphFeatures.class, features.graph()),
            Pair.with(Graph.Features.VariableFeatures.class, features.graph().variables()),
            Pair.with(Graph.Features.VertexFeatures.class, features.vertex()),
            Pair.with(Graph.Features.VertexPropertyFeatures.class, features.vertex().properties()),
            Pair.with(Graph.Features.EdgeFeatures.class, features.edge()),
            Pair.with(Graph.Features.EdgePropertyFeatures.class, features.edge().properties())).forEach(p -> {
        printFeatureTitle(p.getValue0(), sb);
        Stream.of(p.getValue0().getMethods())
                .filter(supportMethods)
                .map(createTransform(p.getValue1()))
                .forEach(sb::append);
    });

    return sb.toString();
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:21,代碼來源:StringFactory.java

示例11: create

import org.javatuples.Pair; //導入依賴的package包/類
/**
 * Creates a {@code GryoMapper}.
 */
public GryoMapper create() {
    // consult the registry if provided and inject registry entries as custom classes.
    registries.forEach(registry -> {
        final List<Pair<Class, Object>> serializers = registry.find(GryoIo.class);
        serializers.forEach(p -> {
            if (null == p.getValue1())
                addCustom(p.getValue0());
            else if (p.getValue1() instanceof Serializer)
                addCustom(p.getValue0(), (Serializer) p.getValue1());
            else if (p.getValue1() instanceof Function)
                addCustom(p.getValue0(), (Function<Kryo, Serializer>) p.getValue1());
            else
                throw new IllegalStateException(String.format(
                        "Unexpected value provided by %s for serializable class %s - expected a parameter in [null, %s implementation or Function<%s, %s>], but received %s",
                        registry.getClass().getSimpleName(), p.getValue0().getClass().getCanonicalName(),
                        Serializer.class.getName(), Kryo.class.getSimpleName(),
                        Serializer.class.getSimpleName(), p.getValue1()));
        });
    });

    return new GryoMapper(this);
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:26,代碼來源:GryoMapper.java

示例12: ser

import org.javatuples.Pair; //導入依賴的package包/類
public void ser(final TraversalExplanation te, final JsonGenerator jsonGenerator) throws IOException {
    final Map<String, Object> m = new HashMap<>();
    m.put(GraphSONTokens.ORIGINAL, getStepsAsList(te.getOriginalTraversal()));

    final List<Pair<TraversalStrategy, Traversal.Admin<?,?>>> strategyTraversals = te.getStrategyTraversals();

    final List<Map<String,Object>> intermediates = new ArrayList<>();
    for (final Pair<TraversalStrategy, Traversal.Admin<?, ?>> pair : strategyTraversals) {
        final Map<String,Object> intermediate = new HashMap<>();
        intermediate.put(GraphSONTokens.STRATEGY, pair.getValue0().toString());
        intermediate.put(GraphSONTokens.CATEGORY, pair.getValue0().getTraversalCategory().getSimpleName());
        intermediate.put(GraphSONTokens.TRAVERSAL, getStepsAsList(pair.getValue1()));
        intermediates.add(intermediate);
    }
    m.put(GraphSONTokens.INTERMEDIATE, intermediates);

    if (strategyTraversals.isEmpty())
        m.put(GraphSONTokens.FINAL, getStepsAsList(te.getOriginalTraversal()));
    else
        m.put(GraphSONTokens.FINAL, getStepsAsList(strategyTraversals.get(strategyTraversals.size() - 1).getValue1()));

    jsonGenerator.writeObject(m);
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:24,代碼來源:GraphSONSerializers.java

示例13: apply

import org.javatuples.Pair; //導入依賴的package包/類
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES, TraversalHelper.getRootTraversal(traversal)))
        return;
    final Collection<Pair<VertexStep, Step>> stepsToReplace = new ArrayList<>();
    Step prev = null;
    for (final Step curr : traversal.getSteps()) {
        if (isOptimizable(prev, curr)) {
            stepsToReplace.add(Pair.with((VertexStep) prev, curr));
        }
        prev = curr;
    }
    if (!stepsToReplace.isEmpty()) {
        for (final Pair<VertexStep, Step> pair : stepsToReplace) {
            optimizeSteps(traversal, pair.getValue0(), pair.getValue1());
        }
    }
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:19,代碼來源:IncidentToAdjacentStrategy.java

示例14: shouldFindRegisteredClassesByIoImplementation

import org.javatuples.Pair; //導入依賴的package包/類
@Test
public void shouldFindRegisteredClassesByIoImplementation() {
    // note that this is a non-standard usage of IoRegistry strictly for testing purposes - refer to javadocs
    // for proper usage
    final FakeIoRegistry registry = new FakeIoRegistry();
    registry.register(GryoIo.class, Long.class, "test");
    registry.register(GryoIo.class, Integer.class, 1);
    registry.register(GryoIo.class, String.class, 1L);
    registry.register(GraphSONIo.class, Short.class, 100);

    final List<Pair<Class, Object>> foundGryo = registry.find(GryoIo.class);
    assertEquals(3, foundGryo.size());
    assertEquals("test", foundGryo.get(0).getValue1());
    assertEquals(String.class, foundGryo.get(2).getValue0());
    assertEquals(1L, foundGryo.get(2).getValue1());
    assertEquals(Long.class, foundGryo.get(0).getValue0());
    assertEquals(1, foundGryo.get(1).getValue1());
    assertEquals(Integer.class, foundGryo.get(1).getValue0());

    final List<Pair<Class, Object>> foundGraphSON = registry.find(GraphSONIo.class);
    assertEquals(1, foundGraphSON.size());
    assertEquals(100, foundGraphSON.get(0).getValue1());
    assertEquals(Short.class, foundGraphSON.get(0).getValue0());
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:25,代碼來源:IoRegistryTest.java

示例15: shouldFindRegisteredClassesByIoImplementationAndSerializer

import org.javatuples.Pair; //導入依賴的package包/類
@Test
public void shouldFindRegisteredClassesByIoImplementationAndSerializer() {
    // note that this is a non-standard usage of IoRegistry strictly for testing purposes - refer to javadocs
    // for proper usage
    final FakeIoRegistry registry = new FakeIoRegistry();
    registry.register(GryoIo.class, Long.class, "test");
    registry.register(GryoIo.class, Integer.class, 1);
    registry.register(GryoIo.class, String.class, 1L);
    registry.register(GraphSONIo.class, Short.class, 100);

    final List<Pair<Class, Number>> foundGryo = registry.find(GryoIo.class, Number.class);
    assertEquals(2, foundGryo.size());
    assertEquals(String.class, foundGryo.get(1).getValue0());
    assertEquals(1L, foundGryo.get(1).getValue1());
    assertEquals(1, foundGryo.get(0).getValue1());
    assertEquals(Integer.class, foundGryo.get(0).getValue0());

    final List<Pair<Class, Date>> foundGraphSON = registry.find(GraphSONIo.class, Date.class);
    assertEquals(0, foundGraphSON.size());
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:21,代碼來源:IoRegistryTest.java


注:本文中的org.javatuples.Pair類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。