当前位置: 首页>>代码示例>>Java>>正文


Java Box类代码示例

本文整理汇总了Java中com.diffplug.common.base.Box的典型用法代码示例。如果您正苦于以下问题:Java Box类的具体用法?Java Box怎么用?Java Box使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Box类属于com.diffplug.common.base包,在下文中一共展示了Box类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runWithCleanStack

import com.diffplug.common.base.Box; //导入依赖的package包/类
private void runWithCleanStack(Throwing.Runnable runnable) throws Throwable {
	Box.Nullable<Throwable> testError = Box.Nullable.ofNull();
	Thread thread = new Thread() {
		@Override
		public void run() {
			try {
				runnable.run();
			} catch (Throwable e) {
				testError.set(e);
			}
		}
	};
	thread.start();
	thread.join();
	if (testError.get() != null) {
		throw testError.get();
	}
}
 
开发者ID:diffplug,项目名称:durian-debug,代码行数:19,代码来源:StackDumperTest.java

示例2: javaExec

import com.diffplug.common.base.Box; //导入依赖的package包/类
/** Calls javaExec() in a way which is friendly with windows classpath limitations. */
public static ExecResult javaExec(Project project, Action<JavaExecSpec> spec) throws IOException {
	if (OS.getNative().isWindows()) {
		Box.Nullable<File> classpathJarBox = Box.Nullable.ofNull();
		ExecResult execResult = project.javaexec(execSpec -> {
			// handle the user
			spec.execute(execSpec);
			// create a jar which embeds the classpath
			File classpathJar = toJarWithClasspath(execSpec.getClasspath());
			classpathJar.deleteOnExit();
			// set the classpath to be just that one jar
			execSpec.setClasspath(project.files(classpathJar));
			// save the jar so it can be deleted later
			classpathJarBox.set(classpathJar);
		});
		// delete the jar after the task has finished
		Errors.suppress().run(() -> FileMisc.forceDelete(classpathJarBox.get()));
		return execResult;
	} else {
		return project.javaexec(spec);
	}
}
 
开发者ID:diffplug,项目名称:goomph,代码行数:23,代码来源:JavaExecWinFriendly.java

示例3: fromVolatile

import com.diffplug.common.base.Box; //导入依赖的package包/类
/**
 * Creates an `RxGetter` from the given `Observable` and `initialValue`,
 * appropriate for observables which emit values on multiple threads.
 *
 * The value returned by {@link RxGetter#get()} will be the last value emitted by
 * the observable, as recorded by a volatile field.
 */
public static <T> RxGetter<T> fromVolatile(Observable<T> observable, T initialValue) {
	Box<T> box = Box.ofVolatile(initialValue);
	Rx.subscribe(observable, box::set);
	return new RxGetter<T>() {
		@Override
		public Observable<T> asObservable() {
			return observable;
		}

		@Override
		public T get() {
			return box.get();
		}
	};
}
 
开发者ID:diffplug,项目名称:durian-rx,代码行数:23,代码来源:RxGetter.java

示例4: from

import com.diffplug.common.base.Box; //导入依赖的package包/类
/**
 * Creates an `RxGetter` from the given `Observable` and `initialValue`,
 * appropriate for observables which emit values on a single thread.
 *
 * The value returned by {@link RxGetter#get()} will be the last value emitted by
 * the observable, as recorded by a non-volatile field.
 */
public static <T> RxGetter<T> from(Observable<T> observable, T initialValue) {
	Box<T> box = Box.of(initialValue);
	Rx.subscribe(observable, box::set);
	return new RxGetter<T>() {
		@Override
		public Observable<T> asObservable() {
			return observable;
		}

		@Override
		public T get() {
			return box.get();
		}
	};
}
 
开发者ID:diffplug,项目名称:durian-rx,代码行数:23,代码来源:RxGetter.java

示例5: testLockingBehavior

import com.diffplug.common.base.Box; //导入依赖的package包/类
static void testLockingBehavior(String message, Function<String, LockBox<String>> constructor, Consumer<LockBox<String>> timed, String expectedResult) {
	LockBox<String> box = constructor.apply("1");
	Box.Nullable<Double> elapsed = Box.Nullable.of(null);
	ThreadHarness harness = new ThreadHarness();
	harness.add(() -> {
		box.modify(val -> {
			Errors.rethrow().run(() -> Thread.sleep(100));
			return val + "2";
		});
	});
	harness.add(() -> {
		LapTimer timer = LapTimer.createMs();
		timed.accept(box);
		elapsed.set(timer.lap());
	});
	harness.run();
	// make sure that the action which should have been delayed, was delayed for the proper time
	Assert.assertEquals("Wrong delay time for " + message, 0.1, elapsed.get().doubleValue(), 0.05);
	// make sure that the final result was what was expected
	Assert.assertEquals("Wrong result for " + message, expectedResult, box.get());
}
 
开发者ID:diffplug,项目名称:durian-rx,代码行数:22,代码来源:LockBoxTest.java

示例6: testDisposableEar

import com.diffplug.common.base.Box; //导入依赖的package包/类
@Test
public void testDisposableEar() {
	InteractiveTest.testCoat("Non-interactive, will pass itself", cmp -> {
		Shell underTest = new Shell(cmp.getShell(), SWT.NONE);
		DisposableEar ear = SwtRx.disposableEar(underTest);
		Assert.assertFalse(ear.isDisposed());

		Box<Boolean> hasBeenDisposed = Box.of(false);
		ear.runWhenDisposed(() -> hasBeenDisposed.set(true));

		Assert.assertFalse(hasBeenDisposed.get());
		underTest.dispose();
		Assert.assertTrue(hasBeenDisposed.get());
		Assert.assertTrue(ear.isDisposed());

		Box<Boolean> alreadyDisposed = Box.of(false);
		ear.runWhenDisposed(() -> alreadyDisposed.set(true));
		Assert.assertTrue(alreadyDisposed.get());

		InteractiveTest.closeAndPass(cmp);
	});
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:23,代码来源:SwtRxTest.java

示例7: scheduleCancelWorks

import com.diffplug.common.base.Box; //导入依赖的package包/类
@Test
public void scheduleCancelWorks() throws InterruptedException, ExecutionException {
	testOffUiThread(() -> {
		Box<Boolean> hasRun = Box.of(false);
		ScheduledFuture<?> future = SwtExec.async().schedule(() -> {
			hasRun.set(true);
		}, 100, TimeUnit.MILLISECONDS);
		Thread.sleep(10);
		future.cancel(true);
		Thread.sleep(200);
		try {
			future.get();
			Assert.fail();
		} catch (CancellationException e) {
			// we got the cancellation we expected
		}
		Assert.assertEquals(true, future.isCancelled());
		Assert.assertEquals(true, future.isDone());
		Assert.assertEquals(false, hasRun.get());
	});
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:22,代码来源:SwtExecSchedulingTest.java

示例8: scheduleFixedRate

import com.diffplug.common.base.Box; //导入依赖的package包/类
@Test
public void scheduleFixedRate() throws InterruptedException, ExecutionException {
	testOffUiThread(() -> {
		Box.Int count = Box.Int.of(0);
		ScheduledFuture<?> future = SwtExec.async().scheduleAtFixedRate(() -> {
			count.set(count.getAsInt() + 1);
			// block UI thread for 400ms - very bad
			Errors.rethrow().run(() -> Thread.sleep(400));
		}, 500, 500, TimeUnit.MILLISECONDS);
		Thread.sleep(2250);
		// increment every 500ms for 2250ms, it should tick 4 times
		Assertions.assertThat(count.getAsInt()).isEqualTo(4);
		future.cancel(true);
		Thread.sleep(1000);
		Assertions.assertThat(count.getAsInt()).isEqualTo(4);
	});
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:18,代码来源:SwtExecSchedulingTest.java

示例9: scheduleFixedDelay

import com.diffplug.common.base.Box; //导入依赖的package包/类
@Test
public void scheduleFixedDelay() throws InterruptedException, ExecutionException {
	testOffUiThread(() -> {
		Box.Int count = Box.Int.of(0);
		ScheduledFuture<?> future = SwtExec.async().scheduleWithFixedDelay(() -> {
			// block UI thread for 400ms - very bad
			Errors.rethrow().run(() -> Thread.sleep(400));
			count.set(count.getAsInt() + 1);
		}, 500, 500, TimeUnit.MILLISECONDS);
		Thread.sleep(2250);
		// increment every 500ms and burn 400ms for 2250ms, it should tick twice
		Assertions.assertThat(count.getAsInt()).isEqualTo(2);
		future.cancel(true);
		Thread.sleep(1000);
		Assertions.assertThat(count.getAsInt()).isEqualTo(2);
	});
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:18,代码来源:SwtExecSchedulingTest.java

示例10: Running

import com.diffplug.common.base.Box; //导入依赖的package包/类
private Running() throws Exception {
	Box.Nullable<BundleContext> context = Box.Nullable.ofNull();
	Main main = new Main() {
		@SuppressFBWarnings(value = "DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED", justification = "splashHandler is a thread rather than a runnable.  Almost definitely a small bug, " +
				"but there's a lot of small bugs in the copy-pasted launcher code.  It's battle-tested, FWIW.")
		@Override
		protected void invokeFramework(String[] passThruArgs, URL[] bootPath) throws Exception {
			context.set(EclipseStarter.startup(passThruArgs, splashHandler));
		}
	};
	main.basicRun(eclipseIni.getLinesAsArray());
	this.bundleContext = Objects.requireNonNull(context.get());
}
 
开发者ID:diffplug,项目名称:goomph,代码行数:14,代码来源:EclipseIniLauncher.java

示例11: testEquals

import com.diffplug.common.base.Box; //导入依赖的package包/类
public void testEquals() {
	List<List<Object>> allGroups = new ArrayList<>();
	Box<List<Object>> currentGroup = Box.of(new ArrayList<>());
	API api = new API() {
		@Override
		public void areDifferentThan() {
			currentGroup.modify(current -> {
				// create two instances, and add them to the group
				current.add(create());
				current.add(create());
				// create two instances using a serialization roundtrip, and add them to the group
				current.add(reserialize(create()));
				current.add(reserialize(create()));
				// add this group to the list of all groups
				allGroups.add(current);
				// and return a new blank group for the next call
				return new ArrayList<>();
			});
		}
	};
	try {
		setupTest(api);
	} catch (Exception e) {
		throw new AssertionError("Error during setupTest", e);
	}
	List<Object> lastGroup = currentGroup.get();
	if (!lastGroup.isEmpty()) {
		throw new IllegalArgumentException("Looks like you forgot to make a final call to 'areDifferentThan()'.");
	}
	EqualsTester tester = new EqualsTester();
	for (List<Object> step : allGroups) {
		tester.addEqualityGroup(step.toArray());
	}
	tester.testEquals();
}
 
开发者ID:diffplug,项目名称:spotless,代码行数:36,代码来源:SerializableEqualityTester.java

示例12: modify

import com.diffplug.common.base.Box; //导入依赖的package包/类
/** Shortcut for doing a set() on the result of a get(). */
@Override
public R modify(Function<? super R, ? extends R> mutator) {
	Box.Nullable<R> result = Box.Nullable.ofNull();
	delegate.modify(input -> {
		R unmappedResult = mutator.apply(converter.convertNonNull(input));
		result.set(unmappedResult);
		return converter.revertNonNull(unmappedResult);
	});
	return result.get();
}
 
开发者ID:diffplug,项目名称:durian-rx,代码行数:12,代码来源:MappedImp.java

示例13: settable

import com.diffplug.common.base.Box; //导入依赖的package包/类
@Test
public void settable() {
	DisposableEar.Settable ear = DisposableEar.settable();
	Assert.assertFalse(ear.isDisposed());

	Box<Boolean> hasBeenDisposed = Box.of(false);
	ear.runWhenDisposed(() -> hasBeenDisposed.set(true));

	Assert.assertFalse(hasBeenDisposed.get());
	ear.dispose();
	Assert.assertTrue(hasBeenDisposed.get());
	Assert.assertTrue(ear.isDisposed());

	assertDisposedBehavior(ear);
}
 
开发者ID:diffplug,项目名称:durian-rx,代码行数:16,代码来源:DisposableEarTest.java

示例14: setResult

import com.diffplug.common.base.Box; //导入依赖的package包/类
private static void setResult(Control ctl, Optional<Throwable> result) {
	SwtExec.async().guardOn(ctl).execute(() -> {
		Shell shell = ctl.getShell();
		Box<Optional<Throwable>> resultBox = shellToResult.remove(shell);
		Objects.requireNonNull(resultBox, "No test shell for control.");
		resultBox.set(result);
		shell.dispose();
	});
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:10,代码来源:InteractiveTest.java

示例15: openInstructions

import com.diffplug.common.base.Box; //导入依赖的package包/类
/** Opens the instructions dialog. */
private static Shell openInstructions(Shell underTest, String instructions, Box<Optional<Throwable>> result) {
	Shell instructionsShell = Shells.builder(SWT.TITLE | SWT.BORDER, cmp -> {
		Layouts.setGrid(cmp).numColumns(3);

		// show the instructions
		Text text = new Text(cmp, SWT.WRAP);
		Layouts.setGridData(text).horizontalSpan(3).grabAll();
		text.setEditable(false);
		text.setText(instructions);

		// pass / fail buttons
		Layouts.newGridPlaceholder(cmp).grabHorizontal();

		Consumer<Boolean> buttonCreator = isPass -> {
			Button btn = new Button(cmp, SWT.PUSH);
			btn.setText(isPass ? "PASS" : "FAIL");
			btn.addListener(SWT.Selection, e -> {
				result.set(isPass ? Optional.empty() : Optional.of(new FailedByUser(instructions)));
				cmp.getShell().dispose();
			});
			Layouts.setGridData(btn).widthHint(SwtMisc.defaultButtonWidth());
		};
		buttonCreator.accept(true);
		buttonCreator.accept(false);
	})
			.setTitle("PASS / FAIL")
			.setSize(SwtMisc.scaleByFontHeight(18, 0))
			.openOn(underTest);

	// put the instructions to the right of the dialog under test 
	Rectangle instructionsBounds = instructionsShell.getBounds();
	Rectangle underTestBounds = underTest.getBounds();
	instructionsBounds.x = underTestBounds.x + underTestBounds.width + HORIZONTAL_SEP;
	instructionsBounds.y = underTestBounds.y;
	instructionsShell.setBounds(instructionsBounds);

	// return the value
	return instructionsShell;
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:41,代码来源:InteractiveTest.java


注:本文中的com.diffplug.common.base.Box类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。