Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace abstract method with default implementation #6593

Merged
merged 3 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
package org.eclipse.che.ide.api.resources;

import static com.google.common.base.Preconditions.checkState;

import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import org.eclipse.che.api.promises.client.Promise;
Expand Down Expand Up @@ -97,7 +99,9 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#FILE
* @since 4.4.0
*/
boolean isFile();
default boolean isFile() {
return getResourceType() == FILE;
}

/**
* Casts current resource to the {@link File} if the last one's represents a file.
Expand All @@ -119,7 +123,11 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#FILE
* @since 5.1.0
*/
File asFile();
default File asFile() {
checkState(isFile(), "Current resource is not a file");

return (File) this;
}

/**
* Returns {@code true} if current represents a folder.
Expand All @@ -129,7 +137,9 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#FOLDER
* @since 4.4.0
*/
boolean isFolder();
default boolean isFolder() {
return getResourceType() == FOLDER;
}

/**
* Casts current resource to the {@link Folder} if the last one's represents a folder.
Expand All @@ -151,7 +161,11 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#FOLDER
* @since 5.1.0
*/
Folder asFolder();
default Folder asFolder() {
checkState(isFolder(), "Current resource is not a folder");

return (Folder) this;
}

/**
* Returns {@code true} if current represents a project.
Expand All @@ -161,7 +175,9 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#PROJECT
* @since 4.4.0
*/
boolean isProject();
default boolean isProject() {
return getResourceType() == PROJECT;
}

/**
* Casts current resource to the {@link Project} if the last one's represents a project.
Expand All @@ -183,7 +199,11 @@ public interface Resource extends Comparable<Resource> {
* @see Resource#PROJECT
* @since 5.1.0
*/
Project asProject();
default Project asProject() {
checkState(isProject(), "Current resource is not a project");

return (Project) this;
}

/**
* Copies resource to given {@code destination} path. Copy operation performs asynchronously and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static com.google.common.base.Optional.of;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Arrays.copyOf;
import static org.eclipse.che.ide.api.resources.marker.Marker.CREATED;
Expand All @@ -28,8 +27,6 @@
import com.google.common.base.Optional;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Folder;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.marker.Marker;
Expand All @@ -56,45 +53,6 @@ protected ResourceImpl(Path path, ResourceManager resourceManager) {
this.resourceManager = checkNotNull(resourceManager, "Null project manager occurred");
}

/** {@inheritDoc} */
@Override
public boolean isFile() {
return getResourceType() == FILE;
}

@Override
public File asFile() {
checkState(isFile(), "Current resource is not a file");

return (File) this;
}

/** {@inheritDoc} */
@Override
public boolean isFolder() {
return getResourceType() == FOLDER;
}

@Override
public Folder asFolder() {
checkState(isFolder(), "Current resource is not a folder");

return (Folder) this;
}

/** {@inheritDoc} */
@Override
public boolean isProject() {
return getResourceType() == PROJECT;
}

@Override
public Project asProject() {
checkState(isProject(), "Current resource is not a project");

return (Project) this;
}

/** {@inheritDoc} */
@Override
public Promise<Resource> copy(Path destination) {
Expand Down