
br.com.objectos.way.gdrive.GDirectoryFolder Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.way.gdrive;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import com.google.api.services.drive.model.File;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
/**
* @author [email protected] (Mario Marques Junior)
*/
class GDirectoryFolder implements GDirectory {
private final DriveExec exec;
private final String id;
private final File file;
public GDirectoryFolder(DriveExec exec, File file) {
this.exec = exec;
this.file = file;
id = file.getId();
}
@Override
public String getId() {
return id;
}
@Override
public String getName() {
return file.getTitle();
}
@Override
public List listFiles() {
Iterator iterator;
iterator = exec.iterateFilesOf(file);
Iterator files;
files = Iterators.transform(iterator, new ToGFile(exec));
return ImmutableList.copyOf(files);
}
@Override
public GFile getFile(String fileId) {
File file = exec.getFile(fileId);
return new ToGFile(exec).apply(file);
}
@Override
public GDirectory mkdir(String name) {
File dir = exec.mkdir(file, name);
return new GDirectoryFolder(exec, dir);
}
@Override
public WriteWrapper write(java.io.File from) {
return new WriteWrapperBuilder()
.exec(exec)
.file(file)
.from(From.of(from))
.title(from.getName())
.build();
}
@Override
public WriteWrapper writeStream(InputStream from, String title) {
return new WriteWrapperBuilder()
.exec(exec)
.file(file)
.from(From.of(from))
.title(title)
.build();
}
@Override
public GObserver observe() {
return new GObserverPojo(exec, file);
}
@Override
public void trash() {
exec.trash(id);
}
@Override
public void untrash() {
exec.untrash(id);
}
@Override
public final int hashCode() {
return Objects.hashCode(id);
}
@Override
public final boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (obj instanceof GDirectoryFolder) {
final GDirectoryFolder that = (GDirectoryFolder) obj;
return Objects.equal(this.id, that.id);
} else {
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy