Skip to content

Instantly share code, notes, and snippets.

View ipapaste's full-sized avatar

ipapaste ipapaste

  • Greece, Thessaloniki
View GitHub Profile
public Result<FileDto> getFromFile(File f) {
FileDto dto = new FileDto();
Result<FileDto> result = new Result<>(dto);
result.apply(r -> r.setName(f.getName()));
result.apply(r -> r.setPath(f.getAbsolutePath()));
result.apply(r -> r.setDirectory(f.isDirectory()));
result.apply(r -> r.setSize(f.length()));
result.apply(r -> r.setModifiedAt(f.lastModified()));
result.apply(r -> {
public Result<FileDto> getFromFile(File f) {
Result<FileDto> result = new Result<>();
FileDto dto = new FileDto();
dto.setName(f.getName());
dto.setPath(f.getAbsolutePath());
dto.setDirectory(f.isDirectory());
dto.setSize(f.length());
dto.setModifiedAt(f.lastModified());
public class MyComponent {
private MyOtherComponentImpl otherComponent = Registry.get("MyOtherComponent", this);
private MyThirdComponent thirdComponent = otherComponent.getFactory(Registry.get("config"));
public MyComponent performAction()
{
if(otherComponent.isConditionOk())
{
innerAction();
public class MyComponent {
private MyOtherComponentImpl otherComponent = Registry.get("MyOtherComponent", this);
private MyThirdComponent thirdComponent = otherComponent.getFactory(Registry.get("config"));
public MyComponent performAction()
{
if(otherComponent.isConditionOk())
{
innerAction();
call(c -> service.getCars(city, c));
public static <T> Future<T> call(Consumer<AsyncCallback<T>> c) {
Tuple2<Future<T>, AsyncCallback<T>> futureCallback = AsyncUtils.<T>getTuple();
c.accept(futureCallback._2);
return futureCallback._1;
}
private static <T> Tuple2<Future<T>, AsyncCallback<T>> getTuple() {
final Tuple2<Future<T>, AsyncCallback<T>> futureCallback = AsyncUtils.make();
return futureCallback;
}
getCars(city).onSuccess(r -> {/* code here */});
public Future<List<GenericDTO>> getCars(String city) {
final Tuple2<Future<List<GenericDTO>>, AsyncCallback<List<GenericDTO>>> futureCallback = AsyncUtils.make();
rpcServiceAsync.getMediaGroups(city, futureCallback._2);
return futureCallback._1;
}
public static <T> Tuple2<Future<T>, AsyncCallback<T>> make() {
final Promise<T> promise = Promise.make();
final AsyncCallback<T> callback = new AsyncCallback<T>() {
@Override
public void onFailure(final Throwable throwable) {
promise.failure(throwable);
}
@Override
public void onSuccess(final T t) {
promise.success(t);
RPCServiceAsync service = GWT.create(RPCService.class);
service.getCars("Thessaloniki", new AsyncCallback<List<Car>>() {
public void onSuccess(List<Car> results) {
// Work done here after data is available
}
});