package com.perforce.spark.browse;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.perforce.p4java.core.file.IFileSize;
import com.perforce.p4java.core.file.IFileSpec;
public class BrowseFile {
private final String name;
private final String link;
private final String date;
private final int size;
public BrowseFile(IFileSpec spec, IFileSize size) {
String file = spec.getDepotPathString();
Path path = Paths.get(file);
this.name = path.getFileName().toString();
this.link = toBasePath(file);
this.date = spec.getDate().toString();
this.size = size.getFileSize();
}
private static String toBasePath(String depot) {
List<String> parts = new ArrayList<>();
parts.addAll(Arrays.asList(depot.split("/")));
parts.remove(0);
parts.remove(0);
String path = String.join("/", parts);
path = "/view/" + path;
return path;
}
public String getName() {
return name;
}
public String getLink() {
return link;
}
public String getDate() {
return date;
}
public String getSize() {
if (size <= 0) {
return "0";
}
String[] units = new String[] { "", "K", "M", "G", "T", "P" };
int i = (int) (Math.log10(size) / Math.log10(1024));
double n = size / Math.pow(1024, i);
String fmt = new DecimalFormat("#,##0.#").format(n);
return fmt + " " + units[i] + "Bytes";
}
public String toString() {
return getName() + " (" + getLink() + ")";
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
14863 |
Paul Allen |
Change File/Dir browse to support extended options |
|
|
//guest/paul_allen/p4am/src/main/java/com/perforce/spark/browse/BrowseItem.java |
#1
|
14226 |
Paul Allen |
Tidy up Browse elements over to micro MVC model |
|
|