Skip to content

Commit a299f48

Browse files
committed
Clean code
1 parent 7e4d002 commit a299f48

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

library/src/com/nostra13/universalimageloader/cache/disc/LimitedDiscCache.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
/**
3030
* Abstract disc cache limited by some parameter. If cache exceeds specified limit then file with the most oldest last
3131
* usage date will be deleted.
32-
*
32+
*
3333
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3434
* @since 1.0.0
3535
* @see BaseDiscCache
3636
* @see FileNameGenerator
3737
*/
3838
public abstract class LimitedDiscCache extends BaseDiscCache {
3939

40-
private static final int INVALID_READ_SIZE = -1;
40+
private static final int INVALID_SIZE = -1;
4141

4242
private final AtomicInteger cacheSize;
4343

@@ -93,7 +93,7 @@ public void put(String key, File file) {
9393

9494
while (curCacheSize + valueSize > sizeLimit) {
9595
int freedSize = removeNext();
96-
if (freedSize == INVALID_READ_SIZE ) break; // cache is empty (have nothing to delete)
96+
if (freedSize == INVALID_SIZE) break; // cache is empty (have nothing to delete)
9797
curCacheSize = cacheSize.addAndGet(-freedSize);
9898
}
9999
cacheSize.addAndGet(valueSize);
@@ -124,7 +124,7 @@ public void clear() {
124124
/** Remove next file and returns it's size */
125125
private int removeNext() {
126126
if (lastUsageDates.isEmpty()) {
127-
return INVALID_READ_SIZE;
127+
return INVALID_SIZE;
128128
}
129129
Long oldestUsage = null;
130130
File mostLongUsedFile = null;
@@ -144,15 +144,16 @@ private int removeNext() {
144144
}
145145
}
146146

147-
int fileSize = getSize(mostLongUsedFile);
148-
149-
if (!mostLongUsedFile.exists()) {
150-
lastUsageDates.remove(mostLongUsedFile);
151-
return 0;
152-
}
153-
154-
if ( mostLongUsedFile.delete()) {
155-
lastUsageDates.remove(mostLongUsedFile);
147+
int fileSize = 0;
148+
if (mostLongUsedFile != null) {
149+
if (mostLongUsedFile.exists()) {
150+
fileSize = getSize(mostLongUsedFile);
151+
if (mostLongUsedFile.delete()) {
152+
lastUsageDates.remove(mostLongUsedFile);
153+
}
154+
} else {
155+
lastUsageDates.remove(mostLongUsedFile);
156+
}
156157
}
157158
return fileSize;
158159
}

0 commit comments

Comments
 (0)