mirror of https://github.com/apache/jclouds.git
Issue #830: deleted FilesList, to instead use Set<File> instead
This commit is contained in:
parent
a89905bd98
commit
50c7cf62b2
|
@ -1,147 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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 org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a list of files to be transferred (uploaded
|
||||
* or downloaded).
|
||||
* <p/>
|
||||
* <p/>
|
||||
* <p>Java class for FilesList complex type.
|
||||
* <p/>
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p/>
|
||||
* <pre>
|
||||
* <complexType name="FilesList">
|
||||
* <complexContent>
|
||||
* <extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
|
||||
* <sequence>
|
||||
* <element name="File" type="{http://www.vmware.com/vcloud/v1.5}FileType" maxOccurs="unbounded"/>
|
||||
* </sequence>
|
||||
* <anyAttribute processContents='lax' namespace='##other'/>
|
||||
* </extension>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*/
|
||||
@XmlType(name = "FilesList", propOrder = {
|
||||
"files"
|
||||
})
|
||||
public class FilesList extends ForwardingSet<File> {
|
||||
|
||||
// TODO Investigate using the same wrapper (e.g. see Tasks); can we eliminate this class?
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromFilesList(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Set<File> files = Sets.newLinkedHashSet();
|
||||
|
||||
/**
|
||||
* @see FilesList#getFiles()
|
||||
*/
|
||||
public Builder files(Iterable<File> files) {
|
||||
this.files = Sets.newLinkedHashSet(checkNotNull(files, "files"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FilesList#getFiles()
|
||||
*/
|
||||
public Builder file(File file) {
|
||||
files.add(checkNotNull(file, "file"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilesList build() {
|
||||
FilesList filesList = new FilesList(files);
|
||||
return filesList;
|
||||
}
|
||||
|
||||
public Builder fromFilesList(FilesList in) {
|
||||
return files(in.getFiles());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "File", required = true)
|
||||
private Set<File> files = Sets.newLinkedHashSet();
|
||||
|
||||
private FilesList() {
|
||||
// for JAXB
|
||||
}
|
||||
|
||||
private FilesList(Iterable<File> files) {
|
||||
this.files = ImmutableSet.copyOf(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the file property.
|
||||
*/
|
||||
public Set<File> getFiles() {
|
||||
return Collections.unmodifiableSet(this.files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
FilesList that = FilesList.class.cast(o);
|
||||
return equal(files, that.files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("")
|
||||
.add("file", files).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<File> delegate() {
|
||||
return getFiles();
|
||||
}
|
||||
}
|
|
@ -22,9 +22,11 @@ package org.jclouds.vcloud.director.v1_5.domain;
|
|||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
@ -132,13 +134,13 @@ public abstract class ResourceEntityType extends EntityType {
|
|||
}
|
||||
|
||||
public static abstract class Builder<B extends Builder<B>> extends EntityType.Builder<B> {
|
||||
private FilesList files;
|
||||
private Set<File> files;
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* @see ResourceEntityType#getFiles()
|
||||
*/
|
||||
public B files(FilesList files) {
|
||||
public B files(Set<File> files) {
|
||||
this.files = files;
|
||||
return self();
|
||||
}
|
||||
|
@ -156,8 +158,10 @@ public abstract class ResourceEntityType extends EntityType {
|
|||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Files")
|
||||
private FilesList files;
|
||||
@XmlElementWrapper(name = "Files")
|
||||
@XmlElement(name = "File")
|
||||
private Set<File> files;
|
||||
|
||||
@XmlAttribute
|
||||
private Integer status;
|
||||
|
||||
|
@ -171,11 +175,10 @@ public abstract class ResourceEntityType extends EntityType {
|
|||
// for JAXB
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value of the files property.
|
||||
*/
|
||||
public FilesList getFiles() {
|
||||
public Set<File> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,9 +71,9 @@ public class Checks {
|
|||
public static void checkResourceEntityType(ResourceEntityType resourceEntity) {
|
||||
// Check optional fields
|
||||
// NOTE status cannot be checked (TODO: doesn't status have a range of valid values?)
|
||||
FilesList files = resourceEntity.getFiles();
|
||||
if (files != null && files.getFiles() != null && !files.getFiles().isEmpty()) {
|
||||
for (File file : files.getFiles()) checkFile(file);
|
||||
Set<File> files = resourceEntity.getFiles();
|
||||
if (files != null && !files.isEmpty()) {
|
||||
for (File file : files) checkFile(file);
|
||||
}
|
||||
|
||||
// Check parent type
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.CloneMediaParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.File;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.FilesList;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Media;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
|
||||
|
@ -388,8 +387,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
|
|||
.href(URI.create("https://mycloud.greenhousedata.com/api/media/d51b0b9d-099c-499f-97f8-4fbe40ba06d7"))
|
||||
.build())
|
||||
.description("Test media generated by testCreateMedia()")
|
||||
.files(FilesList.builder()
|
||||
.file(File.builder()
|
||||
.files(ImmutableSet.of(File.builder()
|
||||
.size(0l)
|
||||
.bytesTransferred(0l)
|
||||
.name("file")
|
||||
|
@ -397,8 +395,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
|
|||
.rel("upload:default")
|
||||
.href(URI.create("https://mycloud.greenhousedata.com:443/transfer/b1fdf2d0-feff-4414-a8d1-3a8d86c4ccc5/file"))
|
||||
.build())
|
||||
.build())
|
||||
.build())
|
||||
.build()))
|
||||
.owner(owner())
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -125,9 +125,9 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
Checks.checkMediaFor(MEDIA, media);
|
||||
|
||||
assertNotNull(media.getFiles(), String.format(OBJ_FIELD_REQ, MEDIA, "files"));
|
||||
assertTrue(media.getFiles().getFiles().size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "files.size()", "1",
|
||||
media.getFiles().getFiles().size()));
|
||||
File uploadFile = getFirst(media.getFiles().getFiles(), null);
|
||||
assertTrue(media.getFiles().size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "files.size()", "1",
|
||||
media.getFiles().size()));
|
||||
File uploadFile = getFirst(media.getFiles(), null);
|
||||
assertNotNull(uploadFile, String.format(OBJ_FIELD_REQ, MEDIA, "files.first"));
|
||||
assertTrue(equal(uploadFile.getSize(), sourceMedia.getSize()), String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()",
|
||||
sourceMedia.getSize(), uploadFile.getSize()));
|
||||
|
@ -147,7 +147,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
assertEquals(task.getStatus(), "running");
|
||||
|
||||
File file = Iterables.getOnlyElement(media.getFiles().getFiles());
|
||||
File file = Iterables.getOnlyElement(media.getFiles());
|
||||
assertEquals(file.getSize(), new Long(iso.length));
|
||||
assertEquals(file.getBytesTransferred(), new Long(iso.length));
|
||||
|
||||
|
|
Loading…
Reference in New Issue