Skip to content

Commit

Permalink
Issue #7540, code observations were fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Sep 11, 2017
1 parent 221d340 commit d359555
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,43 @@ public Object setValue(final String iName, final Object iValue) {
return config.put(iName, iValue);
}

public <T> T getValue(final OGlobalConfiguration iConfig) {
public Object getValue(final OGlobalConfiguration iConfig) {
if (config != null && config.containsKey(iConfig.getKey()))
return (T) config.get(iConfig.getKey());
return config.get(iConfig.getKey());
return iConfig.getValue();
}

/**
* @param config Global configuration parameter.
*
* @return Value of configuration parameter stored in this context as enumeration if such one exists, otherwise value stored in passed in
* {@link OGlobalConfiguration} instance.
*
* @throws ClassCastException if stored value can not be casted and parsed from string to passed in enumeration class.
* @throws IllegalArgumentException if value associated with configuration parameter is a string bug can not be converted to
* instance of passed in enumeration class.
*/
public <T extends Enum<T>> T getValueAsEnum(final OGlobalConfiguration config, Class<T> enumType) {
final Object value;
if (this.config != null && this.config.containsKey(config.getKey())) {
value = this.config.get(config.getKey());
} else {
value = config.getValue();
}

if (value == null)
return null;

if (enumType.isAssignableFrom(value.getClass())) {
return enumType.cast(value);
} else if (value instanceof String) {
final String presentation = value.toString();
return Enum.valueOf(enumType, presentation);
} else {
throw new ClassCastException("Value " + value + " can not be cast to enumeration " + enumType.getSimpleName());
}
}

@SuppressWarnings("unchecked")
public <T> T getValue(final String iName, final T iDefaultValue) {
if (config != null && config.containsKey(iName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.index.engine.OHashTableIndexEngine;
import com.orientechnologies.orient.core.index.engine.OSBTreeIndexEngine;
import com.orientechnologies.orient.core.storage.OChecksumMode;
import com.orientechnologies.orient.core.storage.cache.OReadCache;
import com.orientechnologies.orient.core.storage.cache.local.OWOWCache;
import com.orientechnologies.orient.core.storage.cache.local.twoq.O2QCache;
Expand Down Expand Up @@ -67,8 +68,7 @@
public class OLocalPaginatedStorage extends OAbstractPaginatedStorage {

private static final String[] ALL_FILE_EXTENSIONS = { ".ocf", ".pls", ".pcl", ".oda", ".odh", ".otx", ".ocs", ".oef", ".oem",
".oet",
".fl", ODiskWriteAheadLog.WAL_SEGMENT_EXTENSION, ODiskWriteAheadLog.MASTER_RECORD_EXTENSION,
".oet", ".fl", ODiskWriteAheadLog.WAL_SEGMENT_EXTENSION, ODiskWriteAheadLog.MASTER_RECORD_EXTENSION,
OHashTableIndexEngine.BUCKET_FILE_EXTENSION, OHashTableIndexEngine.METADATA_FILE_EXTENSION,
OHashTableIndexEngine.TREE_FILE_EXTENSION, OHashTableIndexEngine.NULL_BUCKET_FILE_EXTENSION,
OClusterPositionMap.DEF_EXTENSION, OSBTreeIndexEngine.DATA_FILE_EXTENSION, OWOWCache.NAME_ID_MAP_EXTENSION,
Expand Down Expand Up @@ -493,7 +493,8 @@ protected void initWalAndDiskCache(OContextConfiguration contextConfiguration) t

final OWOWCache wowCache = new OWOWCache(OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger() * ONE_KB,
OByteBufferPool.instance(), writeAheadLog, OGlobalConfiguration.DISK_WRITE_CACHE_PAGE_FLUSH_INTERVAL.getValueAsInteger(),
writeCacheSize, this, true, files, getId(), contextConfiguration.getValue(OGlobalConfiguration.STORAGE_CHECKSUM_MODE));
writeCacheSize, this, true, files, getId(),
contextConfiguration.getValueAsEnum(OGlobalConfiguration.STORAGE_CHECKSUM_MODE, OChecksumMode.class));

wowCache.addLowDiskSpaceListener(this);
wowCache.loadRegisteredFiles();
Expand Down

0 comments on commit d359555

Please sign in to comment.