Search in sources :

Example 86 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class FileWatcher method handleFileOperations.

@Inject
private void handleFileOperations(EventBus eventBus) {
    eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {

        @Override
        public void onResourceChanged(ResourceChangedEvent event) {
            if (event.getDelta().getKind() != REMOVED) {
                return;
            }
            if ((event.getDelta().getFlags() & DERIVED) == 0) {
                return;
            }
            final Resource resource = event.getDelta().getResource();
            final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
            if (srcFolder.isPresent()) {
                reparseAllOpenedFiles();
            }
        }
    });
    eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {

        @Override
        public void onActivePartChanged(ActivePartChangedEvent event) {
            if (event.getActivePart() instanceof TextEditor) {
                if (editor2reconcile.contains(event.getActivePart())) {
                    reParseEditor((TextEditor) event.getActivePart());
                }
            }
        }
    });
}
Also used : ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Optional(com.google.common.base.Optional) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) Inject(com.google.inject.Inject)

Example 87 with Optional

use of com.google.common.base.Optional in project druid by druid-io.

the class DimFilterUtilsTest method assertFilterResult.

private void assertFilterResult(DimFilter filter, Iterable<ShardSpec> input, Set<ShardSpec> expected) {
    Set<ShardSpec> result = DimFilterUtils.filterShards(filter, input, CONVERTER);
    Assert.assertEquals(expected, result);
    Map<String, Optional<RangeSet<String>>> dimensionRangeMap = Maps.newHashMap();
    result = Sets.newHashSet();
    for (ShardSpec shard : input) {
        result.addAll(DimFilterUtils.filterShards(filter, ImmutableList.of(shard), CONVERTER, dimensionRangeMap));
    }
    Assert.assertEquals(expected, result);
}
Also used : Optional(com.google.common.base.Optional) ShardSpec(io.druid.timeline.partition.ShardSpec)

Example 88 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class ResourceManager method getRemoteResources.

Promise<Resource[]> getRemoteResources(final Container container, final int depth, boolean includeFiles) {
    checkArgument(depth > -2, "Invalid depth");
    if (depth == DEPTH_ZERO) {
        return promises.resolve(NO_RESOURCES);
    }
    int depthToReload = depth;
    final Optional<Resource[]> descendants = store.getAll(container.getLocation());
    if (depthToReload != -1 && descendants.isPresent()) {
        for (Resource resource : descendants.get()) {
            if (resource.getLocation().segmentCount() - container.getLocation().segmentCount() > depth) {
                depthToReload = resource.getLocation().segmentCount() - container.getLocation().segmentCount();
            }
        }
    }
    return ps.getTree(container.getLocation(), depthToReload, includeFiles).then(new Function<TreeElement, Resource[]>() {

        @Override
        public Resource[] apply(TreeElement tree) throws FunctionException {
            class Visitor implements ResourceVisitor {

                Resource[] resources;

                //size of total items
                private int size = 0;

                //step to increase resource array
                private int incStep = 50;

                private Visitor() {
                    this.resources = NO_RESOURCES;
                }

                @Override
                public void visit(Resource resource) {
                    if (resource.getResourceType() == PROJECT) {
                        final Optional<ProjectConfigDto> optionalConfig = findProjectConfigDto(resource.getLocation());
                        if (optionalConfig.isPresent()) {
                            final Optional<ProblemProjectMarker> optionalMarker = getProblemMarker(optionalConfig.get());
                            if (optionalMarker.isPresent()) {
                                resource.addMarker(optionalMarker.get());
                            }
                        }
                    }
                    if (size > resources.length - 1) {
                        //check load factor and increase resource array
                        resources = copyOf(resources, resources.length + incStep);
                    }
                    resources[size++] = resource;
                }
            }
            final Visitor visitor = new Visitor();
            traverse(tree, visitor);
            return copyOf(visitor.resources, visitor.size);
        }
    }).then(new Function<Resource[], Resource[]>() {

        @Override
        public Resource[] apply(Resource[] reloaded) throws FunctionException {
            Resource[] result = new Resource[0];
            if (descendants.isPresent()) {
                Resource[] outdated = descendants.get();
                final Resource[] removed = removeAll(outdated, reloaded, false);
                for (Resource resource : removed) {
                    store.dispose(resource.getLocation(), false);
                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, REMOVED)));
                }
                final Resource[] updated = removeAll(outdated, reloaded, true);
                for (Resource resource : updated) {
                    store.register(resource);
                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, UPDATED)));
                    final Optional<Resource> registered = store.getResource(resource.getLocation());
                    if (registered.isPresent()) {
                        result = Arrays.add(result, registered.get());
                    }
                }
                final Resource[] added = removeAll(reloaded, outdated, false);
                for (Resource resource : added) {
                    store.register(resource);
                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
                    final Optional<Resource> registered = store.getResource(resource.getLocation());
                    if (registered.isPresent()) {
                        result = Arrays.add(result, registered.get());
                    }
                }
            } else {
                for (Resource resource : reloaded) {
                    store.register(resource);
                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
                    final Optional<Resource> registered = store.getResource(resource.getLocation());
                    if (registered.isPresent()) {
                        result = Arrays.add(result, registered.get());
                    }
                }
            }
            return result;
        }
    });
}
Also used : Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) ProblemProjectMarker(org.eclipse.che.ide.api.resources.Project.ProblemProjectMarker) FunctionException(org.eclipse.che.api.promises.client.FunctionException) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Function(org.eclipse.che.api.promises.client.Function) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 89 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class ResourceManager method findResource.

private Promise<Optional<Resource>> findResource(final Path absolutePath, boolean quiet) {
    //search resource in local cache
    final Optional<Resource> optionalCachedResource = store.getResource(absolutePath);
    if (optionalCachedResource.isPresent()) {
        return promises.resolve(optionalCachedResource);
    }
    //request from server
    final Path projectPath = Path.valueOf(absolutePath.segment(0)).makeAbsolute();
    final Optional<Resource> optProject = store.getResource(projectPath);
    final boolean isPresent = optProject.isPresent();
    checkState(isPresent || quiet, "Resource with path '" + projectPath + "' doesn't exists");
    if (!isPresent) {
        return promises.resolve(Optional.<Resource>absent());
    }
    final Resource project = optProject.get();
    checkState(project.getResourceType() == PROJECT, "Resource with path '" + projectPath + "' isn't a project");
    final int seekDepth = absolutePath.segmentCount() - 1;
    return getRemoteResources((Container) project, seekDepth, true).then(new Function<Resource[], Optional<Resource>>() {

        @Override
        public Optional<Resource> apply(Resource[] resources) throws FunctionException {
            for (Resource resource : resources) {
                if (absolutePath.equals(resource.getLocation())) {
                    return of(resource);
                }
            }
            return absent();
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException)

Example 90 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class FullTextSearchPresenter method search.

@Override
public void search(final String text) {
    final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
    appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {

        @Override
        public void apply(Optional<Container> optionalContainer) throws OperationException {
            if (!optionalContainer.isPresent()) {
                view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
                return;
            }
            final Container container = optionalContainer.get();
            container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {

                @Override
                public void apply(Resource[] result) throws OperationException {
                    view.close();
                    findResultPresenter.handleResponse(result, text);
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Optional (com.google.common.base.Optional)159 RevFeature (org.locationtech.geogig.api.RevFeature)42 Test (org.junit.Test)38 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 ImmutableList (com.google.common.collect.ImmutableList)24 List (java.util.List)24 File (java.io.File)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)20 ArrayList (java.util.ArrayList)18 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)18 Function (com.google.common.base.Function)17 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)17 ObjectId (org.locationtech.geogig.api.ObjectId)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 Resource (org.eclipse.che.ide.api.resources.Resource)15 AddOp (org.locationtech.geogig.api.porcelain.AddOp)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 RevObject (org.locationtech.geogig.api.RevObject)13 NodeRef (org.locationtech.geogig.api.NodeRef)12 Feature (org.opengis.feature.Feature)12