package com.google.sps.data;

import com.google.sps.data.ChromeOSDevice;
import java.util.ArrayList;
import java.util.List;

/*
 * Class representing response to `list Chrome OS Devices` request.
 * See https://developers.google.com/admin-sdk/directory/v1/reference/chromeosdevices/list
 */
public final class ListDeviceResponse {

  private final String kind;
  private final List<ChromeOSDevice> chromeosdevices;
  private final String nextPageToken;
  private final String etag;

  public ListDeviceResponse(String kind, List<ChromeOSDevice> chromeosdevices, String nextPageToken, String etag) {
    this.kind = kind;
    this.chromeosdevices = getDeviceListCopy(chromeosdevices);
    this.nextPageToken = nextPageToken;
    this.etag = etag;
  }
  
  public boolean hasNextPageToken() {
      return nextPageToken != null;
  }

  public String getNextPageToken() {
      return nextPageToken;
  }

  public List<ChromeOSDevice> getDeviceListCopy(List<ChromeOSDevice> original) {
    final List<ChromeOSDevice> devices = new ArrayList<>();
    for (final ChromeOSDevice device : original) {
      devices.add(device.copy());
    }
    return devices;
  }

  public List<ChromeOSDevice> getDevices() {
    return getDeviceListCopy(chromeosdevices);
  }
}

@@ -743,18 +743,16 @@
 ag;%0A  %7D%0A
-  
 %0A  publi
@@ -1034,16 +1034,72 @@
 st%3C%3E();%0A
+    if (original == null) %7B%0A      return devices;%0A    %7D%0A
     for 

Fix null pointer exception when user has 0 devices associated with account