You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CacheMap.java 925B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer;
  5. import java.util.LinkedHashMap;
  6. import java.util.Map;
  7. /**
  8. * CacheMap extends LinkedHashMap, adding the possibility to adjust maximum
  9. * number of items. In SQLContainer this is used for RowItem -cache. Cache size
  10. * will be two times the page length parameter of the container.
  11. */
  12. class CacheMap<K, V> extends LinkedHashMap<K, V> {
  13. private static final long serialVersionUID = 679999766473555231L;
  14. private int cacheLimit = SQLContainer.CACHE_RATIO
  15. * SQLContainer.DEFAULT_PAGE_LENGTH;
  16. @Override
  17. protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
  18. return size() > cacheLimit;
  19. }
  20. void setCacheLimit(int limit) {
  21. cacheLimit = limit > 0 ? limit : SQLContainer.DEFAULT_PAGE_LENGTH;
  22. }
  23. int getCacheLimit() {
  24. return cacheLimit;
  25. }
  26. }