Conversation
| @@ -1,50 +1,165 @@ | |||
| package ru.mipt.java2016.homework.g596.proskurina.task2; | |||
There was a problem hiding this comment.
Лучше перенеси новое в .task3, в .task2 оставь всё, как оно было во втором задании
| private InputStream readBuffer = null; | ||
| private OutputStream writeBuffer = null; | ||
|
|
||
| private long currentPositionInStream = 0; |
There was a problem hiding this comment.
В java по умолчанию поля инициализируются именно так
| this.keySerialiser = keySerialiser; | ||
| this.valueSerialiser = valueSerialiser; | ||
| private Long currentPositionInValuesFile = new Long(0); | ||
| private final Integer lock = 42; |
There was a problem hiding this comment.
Вот такой Integer очень опасно использовать как лок
| try { | ||
| String inputData = file.read(fileName); | ||
| private LoadingCache<K, V> cacheValues = CacheBuilder.newBuilder() | ||
| .maximumSize(42) |
There was a problem hiding this comment.
Выноси такие константы как static final поля
| public int size() { | ||
| checkIfFileIsOpen(); | ||
| return map.size(); | ||
| synchronized (lock) { |
There was a problem hiding this comment.
У тебя получается однопоточная реализация этого метода: одновременно только один поток может узнавать размер. С ReadWriteLock можно быстрее
| int bytesNumber = ByteBuffer.wrap(bytesNumberArray).getInt(); | ||
| byte[] bytesArray = new byte[bytesNumber]; | ||
| int bytesArraySize = readBuffer.read(bytesArray, 0, bytesNumber); | ||
| //addToCalc(bytes); |
There was a problem hiding this comment.
Не бросай закомментированный код в репозитории. Ему так грустно и одиноко от этого
| valuesFile.close(); | ||
| valuesFile.delete(); | ||
| newValuesFile.rename(directoryPath + "valuesFile.db"); | ||
| newValuesFile.close(); |
There was a problem hiding this comment.
FileWorker же Closeable. Используй try-with-resources и тогда close() вызовется автоматически и при любых неожиданностях
| writeToFileDeleteKeySet(); | ||
| deleteKeyFile.close(); | ||
| keyPositionFile.close(); | ||
| valuesFile.close(); |
There was a problem hiding this comment.
Повторяются строчки
deleteKeyFile.close();
keyPositionFile.close();тут и в rebuild. Почему бы их просто не вынести из if?
|
|
||
| @Override | ||
| public boolean exists(K key) { | ||
| wlock.lock(); |
There was a problem hiding this comment.
А почему тут wlock?
И в readKeys
No description provided.