@Test public void testMakeByteValue(){ Long exp = new Long(12345678901L); assertEquals(exp, GitBlitRepository.makeByteValue("123.4567.8901,23456")); assertEquals(exp, GitBlitRepository.makeByteValue("123,4567,8901.23456")); assertEquals(exp, GitBlitRepository.makeByteValue("123'4567'8901,23456")); assertEquals(exp, GitBlitRepository.makeByteValue("123'4567'8901.23456")); assertEquals(new Long(1L), GitBlitRepository.makeByteValue("1,00")); assertEquals(new Long(1L), GitBlitRepository.makeByteValue("1,00 b")); assertEquals(new Long(1024L), GitBlitRepository.makeByteValue("1,00 k")); assertEquals(new Long(1024L), GitBlitRepository.makeByteValue("1,00 kb")); assertEquals(new Long(1048576L), GitBlitRepository.makeByteValue("1,00 mb")); assertEquals(new Long(1073741824L), GitBlitRepository.makeByteValue("1,00 gb")); assertEquals(new Long(1099511627776L), GitBlitRepository.makeByteValue("1,00 tb")); assertEquals(new Long(1073741L), GitBlitRepository.makeByteValue("1,024 mb")); }
public final static Long makeByteValue(String value){ if(value == null || value.isEmpty()){ return null; } try{ String size = value; long f = 1L; size = size.trim().toLowerCase(); if(size.endsWith(" b")){ size = size.substring(0, size.length() - 2).trim(); f = 1L; }else if(size.endsWith(" k")){ size = size.substring(0, size.length() - 2).trim(); f = 1024L; }else if(size.endsWith(" kb")){ size = size.substring(0, size.length() - 3).trim(); f = 1024L; }else if(size.endsWith(" mb")){ size = size.substring(0, size.length() - 3).trim(); f = 1048576L; }else if(size.endsWith(" gb")){ size = size.substring(0, size.length() - 3).trim(); f = 1073741824L; }else if(size.endsWith(" tb")){ size = size.substring(0, size.length() - 3).trim(); f = 1099511627776L; }else{ f = 1L; } size = size.replace("'", ""); size = size.replace("´", ""); int cpos = size.lastIndexOf(","); int dpos = size.lastIndexOf("."); if(cpos != -1 || dpos != -1){ if(cpos > dpos){ size = size.replace(".", "").replaceAll(",", "."); }else if(cpos < dpos || (cpos != -1 && dpos > -1)){ size = size.replace(",", ""); } } Double val = f * Double.parseDouble(size); return val.longValue(); }catch(Exception e){ } return null; }
GitBlitRepository { public final static Long makeByteValue(String value){ if(value == null || value.isEmpty()){ return null; } try{ String size = value; long f = 1L; size = size.trim().toLowerCase(); if(size.endsWith(" b")){ size = size.substring(0, size.length() - 2).trim(); f = 1L; }else if(size.endsWith(" k")){ size = size.substring(0, size.length() - 2).trim(); f = 1024L; }else if(size.endsWith(" kb")){ size = size.substring(0, size.length() - 3).trim(); f = 1024L; }else if(size.endsWith(" mb")){ size = size.substring(0, size.length() - 3).trim(); f = 1048576L; }else if(size.endsWith(" gb")){ size = size.substring(0, size.length() - 3).trim(); f = 1073741824L; }else if(size.endsWith(" tb")){ size = size.substring(0, size.length() - 3).trim(); f = 1099511627776L; }else{ f = 1L; } size = size.replace("'", ""); size = size.replace("´", ""); int cpos = size.lastIndexOf(","); int dpos = size.lastIndexOf("."); if(cpos != -1 || dpos != -1){ if(cpos > dpos){ size = size.replace(".", "").replaceAll(",", "."); }else if(cpos < dpos || (cpos != -1 && dpos > -1)){ size = size.replace(",", ""); } } Double val = f * Double.parseDouble(size); return val.longValue(); }catch(Exception e){ } return null; } }
GitBlitRepository { public final static Long makeByteValue(String value){ if(value == null || value.isEmpty()){ return null; } try{ String size = value; long f = 1L; size = size.trim().toLowerCase(); if(size.endsWith(" b")){ size = size.substring(0, size.length() - 2).trim(); f = 1L; }else if(size.endsWith(" k")){ size = size.substring(0, size.length() - 2).trim(); f = 1024L; }else if(size.endsWith(" kb")){ size = size.substring(0, size.length() - 3).trim(); f = 1024L; }else if(size.endsWith(" mb")){ size = size.substring(0, size.length() - 3).trim(); f = 1048576L; }else if(size.endsWith(" gb")){ size = size.substring(0, size.length() - 3).trim(); f = 1073741824L; }else if(size.endsWith(" tb")){ size = size.substring(0, size.length() - 3).trim(); f = 1099511627776L; }else{ f = 1L; } size = size.replace("'", ""); size = size.replace("´", ""); int cpos = size.lastIndexOf(","); int dpos = size.lastIndexOf("."); if(cpos != -1 || dpos != -1){ if(cpos > dpos){ size = size.replace(".", "").replaceAll(",", "."); }else if(cpos < dpos || (cpos != -1 && dpos > -1)){ size = size.replace(",", ""); } } Double val = f * Double.parseDouble(size); return val.longValue(); }catch(Exception e){ } return null; } GitBlitRepository(); }
GitBlitRepository { public final static Long makeByteValue(String value){ if(value == null || value.isEmpty()){ return null; } try{ String size = value; long f = 1L; size = size.trim().toLowerCase(); if(size.endsWith(" b")){ size = size.substring(0, size.length() - 2).trim(); f = 1L; }else if(size.endsWith(" k")){ size = size.substring(0, size.length() - 2).trim(); f = 1024L; }else if(size.endsWith(" kb")){ size = size.substring(0, size.length() - 3).trim(); f = 1024L; }else if(size.endsWith(" mb")){ size = size.substring(0, size.length() - 3).trim(); f = 1048576L; }else if(size.endsWith(" gb")){ size = size.substring(0, size.length() - 3).trim(); f = 1073741824L; }else if(size.endsWith(" tb")){ size = size.substring(0, size.length() - 3).trim(); f = 1099511627776L; }else{ f = 1L; } size = size.replace("'", ""); size = size.replace("´", ""); int cpos = size.lastIndexOf(","); int dpos = size.lastIndexOf("."); if(cpos != -1 || dpos != -1){ if(cpos > dpos){ size = size.replace(".", "").replaceAll(",", "."); }else if(cpos < dpos || (cpos != -1 && dpos > -1)){ size = size.replace(",", ""); } } Double val = f * Double.parseDouble(size); return val.longValue(); }catch(Exception e){ } return null; } GitBlitRepository(); static GitBlitRepository create(String serverUrl, String gitUrl, RepositoryModel model); @Override int hashCode(); @Override boolean equals(Object obj); final static Long makeByteValue(String value); @Override String toString(); }
GitBlitRepository { public final static Long makeByteValue(String value){ if(value == null || value.isEmpty()){ return null; } try{ String size = value; long f = 1L; size = size.trim().toLowerCase(); if(size.endsWith(" b")){ size = size.substring(0, size.length() - 2).trim(); f = 1L; }else if(size.endsWith(" k")){ size = size.substring(0, size.length() - 2).trim(); f = 1024L; }else if(size.endsWith(" kb")){ size = size.substring(0, size.length() - 3).trim(); f = 1024L; }else if(size.endsWith(" mb")){ size = size.substring(0, size.length() - 3).trim(); f = 1048576L; }else if(size.endsWith(" gb")){ size = size.substring(0, size.length() - 3).trim(); f = 1073741824L; }else if(size.endsWith(" tb")){ size = size.substring(0, size.length() - 3).trim(); f = 1099511627776L; }else{ f = 1L; } size = size.replace("'", ""); size = size.replace("´", ""); int cpos = size.lastIndexOf(","); int dpos = size.lastIndexOf("."); if(cpos != -1 || dpos != -1){ if(cpos > dpos){ size = size.replace(".", "").replaceAll(",", "."); }else if(cpos < dpos || (cpos != -1 && dpos > -1)){ size = size.replace(",", ""); } } Double val = f * Double.parseDouble(size); return val.longValue(); }catch(Exception e){ } return null; } GitBlitRepository(); static GitBlitRepository create(String serverUrl, String gitUrl, RepositoryModel model); @Override int hashCode(); @Override boolean equals(Object obj); final static Long makeByteValue(String value); @Override String toString(); static final String GROUP_MAIN; public String name; public String description; public List<String> owners; public Date lastChange; public String lastChangeAuthor; public boolean hasCommits; public boolean showRemoteBranches; public boolean useIncrementalPushTags; public String incrementalPushTagPrefix; public String accessRestriction; public String authorizationControl; public boolean allowAuthenticated; public boolean isFrozen; public String federationStrategy; public List<String> federationSets; public boolean isFederated; public boolean skipSizeCalculation; public boolean skipSummaryMetrics; public String frequency; public boolean isBare; public boolean isMirror; public String origin; public String HEAD; public List<String> availableRefs; public List<String> indexedBranches; public String size; public List<String> preReceiveScripts; public List<String> postReceiveScripts; public List<String> mailingLists; public Map<String, String> customFields; public String projectPath; public boolean allowForks; public List<String> forks; public String originRepository; public boolean verifyCommitter; public String gcThreshold; public int gcPeriod; public int maxActivityCommits; public List<String> metricAuthorExclusions; transient boolean isCollectingGarbage; public Date lastGC; public String sparkleshareId; public String gitUrl; public String groupName; public String projectName; public String serverUrl; public Long byteSize; public String repoRGB; }