Skip to content

Commit

Permalink
dcache-vehicles: remove deprecated type conversions + refactor compar…
Browse files Browse the repository at this point in the history
…ison

Motivation:
Modification:
Replace deprecated Long(String) with static factory method valueOf(String).
Refactored manual int and long comparisons: use standard library versions.

Result:
Less deprecated code, improved readability.

Target: master
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/12983
Acked-by: Albert Rossi
  • Loading branch information
lemora authored and alrossi committed Apr 15, 2021
1 parent a43129d commit 960f310
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Expand Up @@ -53,8 +53,8 @@ public CacheStatistics(String pnfsString) {
try {
_totalAccesses = Integer.parseInt(st.nextToken());
_accessTime = Long.parseLong(st.nextToken());
_score = new Float(st.nextToken());
_halfLife = new Float(st.nextToken());
_score = Float.valueOf(st.nextToken());
_halfLife = Float.valueOf(st.nextToken());
} catch (Exception e){
throw new IllegalArgumentException(pnfsString);
}
Expand Down Expand Up @@ -149,14 +149,11 @@ public int compareTo(CacheStatistics other ){
//
//XXX this needs to use the half-life algorithm
//
if (_totalAccesses == other.getTotalAccesses()){
return _accessTime>other.getAccessTime()?-1:_accessTime==other.getAccessTime()?0:1;
// return (new Long(_accessTime)).compareTo(new Long(other.getAccessTime()));
} else {
return _totalAccesses>other.getTotalAccesses()?
-1:_totalAccesses==other.getTotalAccesses()?0:1;
// return (new Integer(_totalAccesses)).compareTo(new Integer(other.getTotalAccesses()));
}
if (_totalAccesses == other.getTotalAccesses()){
return Long.compare(other.getAccessTime(), _accessTime);
} else {
return Integer.compare(other.getTotalAccesses(), _totalAccesses);
}
}

public static void main(String[] args){
Expand Down
Expand Up @@ -123,7 +123,7 @@ public void testObject()
testObject(msg,
111222333444.5,
true, 5,
true, new Long("987654321987654321").longValue(),
true, Long.valueOf("987654321987654321").longValue(),
true, 30);


Expand All @@ -138,7 +138,7 @@ true, new Long("987654321987654321").longValue(),
testObject(msg,
111222333444.5,
true, 5,
true, new Long("987654321987654321").longValue(),
true, Long.valueOf("987654321987654321").longValue(),
true, 30);


Expand Down Expand Up @@ -166,7 +166,7 @@ true, new Long("987654321987654321").longValue(),
testObject(msg,
111222333444.5,
true, 5,
true, new Long("987654321987654321").longValue(),
true, Long.valueOf("987654321987654321").longValue(),
false, 0);


Expand Down

0 comments on commit 960f310

Please sign in to comment.