/*
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * 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 com.google.gcloud.storage;

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

import java.util.Iterator;
import java.util.Objects;

/**
 * Implementation of a paginated list of Google Cloud storage {@code Blob}.
 */
public class BlobListResult implements ListResult<Blob> {

  private final ListResult<BlobInfo> infoList;
  private final Storage storage;

  private class BlobListIterator implements Iterator<Blob> {

    private final Iterator<BlobInfo> blobInfoIterator;

    public BlobListIterator() {
      this.blobInfoIterator = infoList.iterator();
    }

    @Override
    public boolean hasNext() {
      return blobInfoIterator.hasNext();
    }

    @Override
    public Blob next() {
      return new Blob(storage, blobInfoIterator.next());
    }

    @Override
    public void remove() {
      blobInfoIterator.remove();
    }
  }

  public BlobListResult(Storage storage, ListResult<BlobInfo> infoList) {
    this.storage = checkNotNull(storage);
    this.infoList = checkNotNull(infoList);
  }

  @Override
  public String nextPageCursor() {
    return infoList.nextPageCursor();
  }

  @Override
  public ListResult<Blob> nextPage() {
    ListResult<BlobInfo> nextPageInfoList = infoList.nextPage();
    if (nextPageInfoList == null) {
      return null;
    }
    return new BlobListResult(storage, nextPageInfoList);
  }

  @Override
  public Iterator<Blob> iterator() {
    return new BlobListIterator();
  }

  @Override
  public int hashCode() {
    return Objects.hash(infoList);
  }

  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof BlobListResult)) {
      return false;
    }
    BlobListResult other = (BlobListResult) obj;
    return Objects.equals(infoList, other.infoList);
  }
}

@@ -714,16 +714,101 @@
 tNull;%0A%0A
+import com.google.common.base.Function;%0Aimport com.google.common.collect.Iterators;%0A%0A
 import j
@@ -826,16 +826,16 @@
 erator;%0A
-
 import j
@@ -1081,497 +1081,8 @@
 e;%0A%0A
-  private class BlobListIterator implements Iterator%3CBlob%3E %7B%0A%0A    private final Iterator%3CBlobInfo%3E blobInfoIterator;%0A%0A    public BlobListIterator() %7B%0A      this.blobInfoIterator = infoList.iterator();%0A    %7D%0A%0A    @Override%0A    public boolean hasNext() %7B%0A      return blobInfoIterator.hasNext();%0A    %7D%0A%0A    @Override%0A    public Blob next() %7B%0A      return new Blob(storage, blobInfoIterator.next());%0A    %7D%0A%0A    @Override%0A    public void remove() %7B%0A      blobInfoIterator.remove();%0A    %7D%0A  %7D%0A%0A
   pu
@@ -1636,29 +1636,192 @@
 urn 
-new BlobListIterator(
+Iterators.transform(infoList.iterator(), new Function%3CBlobInfo, Blob%3E() %7B%0A      @Override%0A      public Blob apply(BlobInfo info) %7B%0A        return new Blob(storage, info);%0A      %7D%0A    %7D
 );%0A 

Use transform in BlobListResult