Package br.com.objectos.way.gdrive

Source Code of br.com.objectos.way.gdrive.GDirectoryFolder

/*
* 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 mario.marques@objectos.com.br (Mario Marques Junior)
*/
class GDirectoryFolder implements GDirectory {

  private final DriveExec exec;
  private final String id;
  private final File file;
  private From from;
  private String title;

  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<GFile> listFiles() {
    Iterator<File> iterator;
    iterator = exec.iterateFilesOf(file);

    Iterator<GFile> files;
    files = Iterators.transform(iterator, new ToGFile(exec));

    return ImmutableList.copyOf(files);
  }

  @Override
  public GDirectory mkdir(String name) {
    File dir = exec.mkdir(file, name);
    return new GDirectoryFolder(exec, dir);
  }

  @Override
  public GDirectory write(java.io.File from) {
    this.from = From.of(from);
    this.title = from.getName();
    return this;
  }

  @Override
  public GDirectory writeStream(InputStream from, String title) {
    this.from = From.of(from);
    this.title = title;
    return this;
  }

  @Override
  public GFile as(MimeType mimeType) {
    File res = exec.write(file, from, title, mimeType);
    return new GFileBuilder(exec, res).build();
  }

  @Override
  public GObserver observe() {
    return new GObserverPojo(exec, file);
  }

  @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;
    }
  }

}
TOP

Related Classes of br.com.objectos.way.gdrive.GDirectoryFolder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.