1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.channel.model;
17
18 import org.kuali.common.util.Assert;
19
20 import com.google.common.base.Optional;
21
22 public final class RemoteFile {
23
24 private final String absolutePath;
25 private final Optional<Integer> groupId;
26 private final Optional<Integer> userId;
27 private final Optional<Integer> permissions;
28 private final Optional<Long> size;
29 private final boolean directory;
30 private final Optional<Status> status;
31
32 public static class Builder {
33
34
35 private final String absolutePath;
36
37
38 private Optional<Integer> groupId = Optional.absent();
39 private Optional<Integer> userId = Optional.absent();
40 private Optional<Integer> permissions = Optional.absent();
41 private Optional<Long> size = Optional.absent();
42 private boolean directory = false;
43 private Optional<Status> status = Optional.absent();
44
45 public Builder(String absolutePath) {
46 this.absolutePath = absolutePath;
47 }
48
49 public Builder clone(RemoteFile other) {
50 this.groupId = other.groupId;
51 this.userId = other.userId;
52 this.permissions = other.permissions;
53 this.size = other.size;
54 this.directory = other.directory;
55 this.status = other.status;
56 return this;
57 }
58
59 public Builder groupId(int groupId) {
60 this.groupId = Optional.of(groupId);
61 return this;
62 }
63
64 public Builder userId(int userId) {
65 this.userId = Optional.of(userId);
66 return this;
67 }
68
69 public Builder permissions(int permissions) {
70 this.permissions = Optional.of(permissions);
71 return this;
72 }
73
74 public Builder size(long size) {
75 this.size = Optional.of(size);
76 return this;
77 }
78
79 public Builder directory(boolean directory) {
80 this.directory = directory;
81 return this;
82 }
83
84 public Builder status(Status status) {
85 this.status = Optional.of(status);
86 return this;
87 }
88
89 public RemoteFile build() {
90 Assert.noBlanks(absolutePath);
91 Assert.noNulls(groupId, userId, permissions, size, directory, status);
92 if (size.isPresent()) {
93 Assert.notNegative(size.get());
94 }
95 return new RemoteFile(this);
96 }
97
98 }
99
100 private RemoteFile(Builder builder) {
101 this.absolutePath = builder.absolutePath;
102 this.groupId = builder.groupId;
103 this.userId = builder.userId;
104 this.permissions = builder.permissions;
105 this.size = builder.size;
106 this.directory = builder.directory;
107 this.status = builder.status;
108 }
109
110 public String getAbsolutePath() {
111 return absolutePath;
112 }
113
114 public Optional<Integer> getGroupId() {
115 return groupId;
116 }
117
118 public Optional<Integer> getUserId() {
119 return userId;
120 }
121
122 public Optional<Integer> getPermissions() {
123 return permissions;
124 }
125
126 public Optional<Long> getSize() {
127 return size;
128 }
129
130 public boolean isDirectory() {
131 return directory;
132 }
133
134 public Optional<Status> getStatus() {
135 return status;
136 }
137
138 }