idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
30,100 | static void eventuallyThrowException ( List < Throwable > _suppressedExceptions ) { if ( _suppressedExceptions . isEmpty ( ) ) { return ; } Throwable _error = null ; for ( Throwable t : _suppressedExceptions ) { if ( t instanceof Error ) { _error = t ; break ; } if ( t instanceof ExecutionException && t . getCause ( ) instanceof Error ) { _error = t . getCause ( ) ; break ; } } String _text = "Exception(s) during shutdown" ; if ( _suppressedExceptions . size ( ) > 1 ) { _text = " (" + ( _suppressedExceptions . size ( ) - 1 ) + " more suppressed exceptions)" ; } if ( _error != null ) { throw new CacheInternalError ( _text , _error ) ; } throw new CacheException ( _text , _suppressedExceptions . get ( 0 ) ) ; } | During the shutdown of the cache manager multiple exceptions can happen from various caches . The list of exceptions gets examined to throw one exception . | 202 | 26 |
30,101 | private String getManagerId ( ) { return "name='" + name + "', objectId=" + Integer . toString ( System . identityHashCode ( this ) , 36 ) + ", classloaderId=" + Integer . toString ( System . identityHashCode ( classLoader ) , 36 ) + ", default=" + defaultManager ; } | Relevant information to id a manager . Since there could be multiple cache managers for each class loader better | 71 | 20 |
30,102 | public boolean checkAndSwitchProcessingState ( int ps0 , int ps ) { long rt = refreshTimeAndState ; long _expect = withState ( rt , ps0 ) ; long _update = withState ( rt , ps ) ; return STATE_UPDATER . compareAndSet ( this , _expect , _update ) ; } | Check and switch the processing state atomically . | 76 | 9 |
30,103 | private PiggyBack existingPiggyBackForInserting ( ) { Object _misc = misc ; if ( _misc instanceof SimpleTimerTask ) { return new TaskPiggyBack ( ( SimpleTimerTask ) _misc , null ) ; } return ( PiggyBack ) _misc ; } | We want to add a new piggy back . Check for timer task and convert it to piggy back . | 62 | 22 |
30,104 | public void resetSuppressedLoadExceptionInformation ( ) { LoadExceptionPiggyBack inf = getPiggyBack ( LoadExceptionPiggyBack . class ) ; if ( inf != null ) { inf . info = null ; } } | If the entry carries information about a suppressed exception clear it . | 50 | 12 |
30,105 | public Entry < K , V > lookup ( K key , int _hash , int _keyValue ) { OptimisticLock [ ] _locks = locks ; int si = _hash & LOCK_MASK ; OptimisticLock l = _locks [ si ] ; long _stamp = l . tryOptimisticRead ( ) ; Entry < K , V > [ ] tab = entries ; if ( tab == null ) { throw new CacheClosedException ( cache ) ; } Entry < K , V > e ; int n = tab . length ; int _mask = n - 1 ; int idx = _hash & ( _mask ) ; e = tab [ idx ] ; while ( e != null ) { if ( e . hashCode == _keyValue && keyObjIsEqual ( key , e ) ) { return e ; } e = e . another ; } if ( l . validate ( _stamp ) ) { return null ; } _stamp = l . readLock ( ) ; try { tab = entries ; if ( tab == null ) { throw new CacheClosedException ( cache ) ; } n = tab . length ; _mask = n - 1 ; idx = _hash & ( _mask ) ; e = tab [ idx ] ; while ( e != null ) { if ( e . hashCode == _keyValue && ( keyObjIsEqual ( key , e ) ) ) { return e ; } e = e . another ; } return null ; } finally { l . unlockRead ( _stamp ) ; } } | Lookup the entry in the hash table and return it . First tries an optimistic read . | 328 | 18 |
30,106 | public Entry < K , V > insertWithinLock ( Entry < K , V > e , int _hash , int _keyValue ) { K key = e . getKeyObj ( ) ; int si = _hash & LOCK_MASK ; Entry < K , V > f ; Object ek ; Entry < K , V > [ ] tab = entries ; if ( tab == null ) { throw new CacheClosedException ( cache ) ; } int n = tab . length , _mask = n - 1 , idx = _hash & ( _mask ) ; f = tab [ idx ] ; while ( f != null ) { if ( f . hashCode == _keyValue && ( ( ek = f . getKeyObj ( ) ) == key || ( ek . equals ( key ) ) ) ) { return f ; } f = f . another ; } e . another = tab [ idx ] ; tab [ idx ] = e ; segmentSize [ si ] . incrementAndGet ( ) ; return e ; } | Insert an entry . Checks if an entry already exists . | 218 | 11 |
30,107 | public boolean remove ( Entry < K , V > e ) { int _hash = modifiedHashCode ( e . hashCode ) ; OptimisticLock [ ] _locks = locks ; int si = _hash & LOCK_MASK ; OptimisticLock l = _locks [ si ] ; long _stamp = l . writeLock ( ) ; try { Entry < K , V > f ; Entry < K , V > [ ] tab = entries ; if ( tab == null ) { throw new CacheClosedException ( cache ) ; } int n = tab . length , _mask = n - 1 , idx = _hash & ( _mask ) ; f = tab [ idx ] ; if ( f == e ) { tab [ idx ] = f . another ; segmentSize [ si ] . decrementAndGet ( ) ; return true ; } while ( f != null ) { Entry < K , V > _another = f . another ; if ( _another == e ) { f . another = _another . another ; segmentSize [ si ] . decrementAndGet ( ) ; return true ; } f = _another ; } } finally { l . unlockWrite ( _stamp ) ; } return false ; } | Remove existing entry from the hash . | 257 | 7 |
30,108 | private void eventuallyExpand ( int _segmentIndex ) { long [ ] _stamps = lockAll ( ) ; try { long _size = segmentSize [ _segmentIndex ] . get ( ) ; if ( _size <= segmentMaxFill ) { return ; } rehash ( ) ; } finally { unlockAll ( _stamps ) ; } } | Acquire all segment locks and rehash if really needed . | 75 | 12 |
30,109 | private long [ ] lockAll ( ) { OptimisticLock [ ] _locks = locks ; int sn = _locks . length ; long [ ] _stamps = new long [ locks . length ] ; for ( int i = 0 ; i < sn ; i ++ ) { OptimisticLock l = _locks [ i ] ; _stamps [ i ] = l . writeLock ( ) ; } return _stamps ; } | Acquire all segment locks and return an array with the lock stamps . | 89 | 14 |
30,110 | private void unlockAll ( long [ ] _stamps ) { OptimisticLock [ ] _locks = locks ; int sn = _locks . length ; for ( int i = 0 ; i < sn ; i ++ ) { _locks [ i ] . unlockWrite ( _stamps [ i ] ) ; } } | Release the all segment locks . | 65 | 6 |
30,111 | @ SuppressWarnings ( "unchecked" ) void rehash ( ) { Entry < K , V > [ ] src = entries ; if ( src == null ) { throw new CacheClosedException ( cache ) ; } int i , sl = src . length , n = sl * 2 , _mask = n - 1 , idx ; Entry < K , V > [ ] tab = new Entry [ n ] ; long _count = 0 ; Entry _next , e ; for ( i = 0 ; i < sl ; i ++ ) { e = src [ i ] ; while ( e != null ) { _count ++ ; _next = e . another ; idx = modifiedHashCode ( e . hashCode ) & _mask ; e . another = tab [ idx ] ; tab [ idx ] = e ; e = _next ; } } entries = tab ; calcMaxFill ( ) ; } | Double the hash table size and rehash the entries . Assumes total lock . | 192 | 16 |
30,112 | public < T > T runTotalLocked ( Job < T > j ) { long [ ] _stamps = lockAll ( ) ; try { return j . call ( ) ; } finally { unlockAll ( _stamps ) ; } } | Lock all segments and run the job . | 51 | 8 |
30,113 | public long calcEntryCount ( ) { long _count = 0 ; for ( Entry e : entries ) { while ( e != null ) { _count ++ ; e = e . another ; } } return _count ; } | Count the entries in the hash table by scanning through the hash table . This is used for integrity checks . | 46 | 21 |
30,114 | private static JCacheJmxSupport findJCacheJmxSupportInstance ( ) { for ( CacheLifeCycleListener l : CacheManagerImpl . getCacheLifeCycleListeners ( ) ) { if ( l instanceof JCacheJmxSupport ) { return ( JCacheJmxSupport ) l ; } } throw new LinkageError ( "JCacheJmxSupport not loaded" ) ; } | The JMX support is already created via the serviceloader | 83 | 13 |
30,115 | public Cache resolveCacheWrapper ( org . cache2k . Cache _c2kCache ) { synchronized ( getLockObject ( ) ) { return c2k2jCache . get ( _c2kCache ) ; } } | Return the JCache wrapper for a c2k cache . | 49 | 12 |
30,116 | @ Override protected void removeFromReplacementList ( Entry e ) { if ( e . isHot ( ) ) { hotHits += e . hitCnt ; handHot = Entry . removeFromCyclicList ( handHot , e ) ; hotSize -- ; } else { coldHits += e . hitCnt ; handCold = Entry . removeFromCyclicList ( handCold , e ) ; coldSize -- ; } } | Remove expire or eviction of an entry happens . Remove the entry from the replacement list data structure . | 94 | 19 |
30,117 | @ Override protected Entry findEvictionCandidate ( Entry _previous ) { coldRunCnt ++ ; Entry _hand = handCold ; int _scanCnt = 1 ; if ( _hand == null ) { _hand = refillFromHot ( _hand ) ; } if ( _hand . hitCnt > 0 ) { _hand = refillFromHot ( _hand ) ; do { _scanCnt ++ ; coldHits += _hand . hitCnt ; _hand . hitCnt = 0 ; Entry e = _hand ; _hand = Entry . removeFromCyclicList ( e ) ; coldSize -- ; e . setHot ( true ) ; hotSize ++ ; handHot = Entry . insertIntoTailCyclicList ( handHot , e ) ; } while ( _hand != null && _hand . hitCnt > 0 ) ; } if ( _hand == null ) { _hand = refillFromHot ( _hand ) ; } coldScanCnt += _scanCnt ; handCold = _hand . next ; return _hand ; } | Runs cold hand an in turn hot hand to find eviction candidate . | 229 | 14 |
30,118 | @ Override public Hash2 < Integer , V > createHashTable ( ) { return new Hash2 < Integer , V > ( this ) { @ Override protected int modifiedHashCode ( final int hc ) { return IntHeapCache . this . modifiedHash ( hc ) ; } @ Override protected boolean keyObjIsEqual ( final Integer key , final Entry e ) { return true ; } } ; } | Modified hash table implementation . Rehash needs to calculate the correct hash code again . | 88 | 17 |
30,119 | @ SuppressWarnings ( "unchecked" ) public static < V > LoadDetail < V > wrapRefreshedTime ( V value , long refreshedTimeInMillis ) { return new RefreshedTimeWrapper < V > ( value , refreshedTimeInMillis ) ; } | Wraps a loaded value to add the refreshed value . | 62 | 11 |
30,120 | private void registerExtensions ( ) { Iterator < Cache2kExtensionProvider > it = ServiceLoader . load ( Cache2kExtensionProvider . class , CacheManager . class . getClassLoader ( ) ) . iterator ( ) ; while ( it . hasNext ( ) ) { try { it . next ( ) . registerCache2kExtension ( ) ; } catch ( ServiceConfigurationError ex ) { Log . getLog ( CacheManager . class . getName ( ) ) . debug ( "Error loading cache2k extension" , ex ) ; } } } | ignore load errors so we can remove the serverSide or the xmlConfiguration code and cache2k core still works | 119 | 22 |
30,121 | void removeManager ( CacheManager cm ) { synchronized ( getLockObject ( ) ) { Map < String , CacheManager > _name2managers = loader2name2manager . get ( cm . getClassLoader ( ) ) ; _name2managers = new HashMap < String , CacheManager > ( _name2managers ) ; Object _removed = _name2managers . remove ( cm . getName ( ) ) ; Map < ClassLoader , Map < String , CacheManager > > _copy = new WeakHashMap < ClassLoader , Map < String , CacheManager > > ( loader2name2manager ) ; _copy . put ( cm . getClassLoader ( ) , _name2managers ) ; loader2name2manager = _copy ; if ( cm . isDefaultManager ( ) ) { Map < ClassLoader , String > _defaultNameCopy = new WeakHashMap < ClassLoader , String > ( loader2defaultName ) ; _defaultNameCopy . remove ( cm . getClassLoader ( ) ) ; loader2defaultName = _defaultNameCopy ; } } } | Called from the manager after a close . Removes the manager from the known managers . | 230 | 18 |
30,122 | private void loadAllWithAsyncLoader ( final CacheOperationCompletionListener _listener , final Set < K > _keysToLoad ) { final AtomicInteger _countDown = new AtomicInteger ( _keysToLoad . size ( ) ) ; EntryAction . ActionCompletedCallback cb = new EntryAction . ActionCompletedCallback ( ) { @ Override public void entryActionCompleted ( final EntryAction ea ) { int v = _countDown . decrementAndGet ( ) ; if ( v == 0 ) { _listener . onCompleted ( ) ; return ; } } } ; for ( K k : _keysToLoad ) { final K key = k ; executeAsync ( key , null , SPEC . GET , cb ) ; } } | Load the keys into the cache via the async path . The key set must always be non empty . The completion listener is called when all keys are loaded . | 155 | 31 |
30,123 | @ Override public Map < K , V > peekAll ( final Iterable < ? extends K > keys ) { Map < K , CacheEntry < K , V > > map = new HashMap < K , CacheEntry < K , V > > ( ) ; for ( K k : keys ) { CacheEntry < K , V > e = execute ( k , SPEC . peekEntry ( k ) ) ; if ( e != null ) { map . put ( k , e ) ; } } return heapCache . convertCacheEntry2ValueMap ( map ) ; } | We need to deal with possible null values and exceptions . This is a simple placeholder implementation that covers it all by working on the entry . | 118 | 27 |
30,124 | @ Override public void onEvictionFromHeap ( final Entry < K , V > e ) { CacheEntry < K , V > _currentEntry = heapCache . returnCacheEntry ( e ) ; if ( syncEntryEvictedListeners != null ) { for ( CacheEntryEvictedListener < K , V > l : syncEntryEvictedListeners ) { l . onEntryEvicted ( this , _currentEntry ) ; } } } | Nothing done here . Will notify the storage about eviction in some future version . | 94 | 15 |
30,125 | public static long mixTimeSpanAndPointInTime ( long loadTime , long refreshAfter , long pointInTime ) { long _refreshTime = loadTime + refreshAfter ; if ( _refreshTime < 0 ) { _refreshTime = ETERNAL ; } if ( pointInTime == ETERNAL ) { return _refreshTime ; } if ( pointInTime > _refreshTime ) { return _refreshTime ; } long _absPointInTime = Math . abs ( pointInTime ) ; if ( _absPointInTime <= _refreshTime ) { return pointInTime ; } long _pointInTimeMinusDelta = _absPointInTime - refreshAfter ; if ( _pointInTimeMinusDelta < _refreshTime ) { return _pointInTimeMinusDelta ; } return _refreshTime ; } | Combine a refresh time span and an expiry at a specified point in time . | 182 | 17 |
30,126 | private static Object getLockObject ( Object key ) { int hc = key . hashCode ( ) ; return KEY_LOCKS [ hc & KEY_LOCKS_MASK ] ; } | Simulate locking by key use the hash code to spread and avoid lock contention . The additional locking we introduce here is currently run synchronously inside the entry mutation operation . | 41 | 33 |
30,127 | public void queue ( final AsyncEvent < K > _event ) { final K key = _event . getKey ( ) ; synchronized ( getLockObject ( key ) ) { Queue < AsyncEvent < K >> q = keyQueue . get ( key ) ; if ( q != null ) { q . add ( _event ) ; return ; } q = new LinkedList < AsyncEvent < K > > ( ) ; keyQueue . put ( key , q ) ; } Runnable r = new Runnable ( ) { @ Override public void run ( ) { runMoreOrStop ( _event ) ; } } ; executor . execute ( r ) ; } | Immediately executes an event with the provided executor . If an event is already executing for the identical key queue the event and execute the event with FIFO scheme preserving the order of the arrival . | 144 | 40 |
30,128 | public void runMoreOrStop ( AsyncEvent < K > _event ) { for ( ; ; ) { try { _event . execute ( ) ; } catch ( Throwable t ) { cache . getLog ( ) . warn ( "Async event exception" , t ) ; } final K key = _event . getKey ( ) ; synchronized ( getLockObject ( key ) ) { Queue < AsyncEvent < K >> q = keyQueue . get ( key ) ; if ( q . isEmpty ( ) ) { keyQueue . remove ( key ) ; return ; } _event = q . remove ( ) ; } } } | Run as long there is still an event for the key . | 133 | 12 |
30,129 | @ Override public Iterable < K > keys ( ) { return new Iterable < K > ( ) { @ Override public Iterator < K > iterator ( ) { final Iterator < CacheEntry < K , V > > it = BaseCache . this . iterator ( ) ; return new Iterator < K > ( ) { @ Override public boolean hasNext ( ) { return it . hasNext ( ) ; } @ Override public K next ( ) { return it . next ( ) . getKey ( ) ; } @ Override public void remove ( ) { throw new UnsupportedOperationException ( ) ; } } ; } } ; } | Key iteration on top of normal iterator . | 135 | 8 |
30,130 | public void setCacheConfig ( final Cache2kConfiguration c ) { valueType = c . getValueType ( ) ; keyType = c . getKeyType ( ) ; if ( name != null ) { throw new IllegalStateException ( "already configured" ) ; } setName ( c . getName ( ) ) ; setFeatureBit ( KEEP_AFTER_EXPIRED , c . isKeepDataAfterExpired ( ) ) ; setFeatureBit ( REJECT_NULL_VALUES , ! c . isPermitNullValues ( ) ) ; setFeatureBit ( BACKGROUND_REFRESH , c . isRefreshAhead ( ) ) ; setFeatureBit ( UPDATE_TIME_NEEDED , c . isRecordRefreshedTime ( ) ) ; setFeatureBit ( RECORD_REFRESH_TIME , c . isRecordRefreshedTime ( ) ) ; metrics = TUNABLE . commonMetricsFactory . create ( new CommonMetricsFactory . Parameters ( ) { @ Override public boolean isDisabled ( ) { return c . isDisableStatistics ( ) ; } @ Override public boolean isPrecise ( ) { return false ; } } ) ; if ( c . getLoaderExecutor ( ) != null ) { loaderExecutor = createCustomization ( ( CustomizationSupplier < Executor > ) c . getLoaderExecutor ( ) ) ; } else { if ( c . getLoaderThreadCount ( ) > 0 ) { loaderExecutor = provideDefaultLoaderExecutor ( c . getLoaderThreadCount ( ) ) ; } } if ( c . getPrefetchExecutor ( ) != null ) { prefetchExecutor = createCustomization ( ( CustomizationSupplier < Executor > ) c . getPrefetchExecutor ( ) ) ; } } | called from CacheBuilder | 379 | 4 |
30,131 | public void setName ( String n ) { if ( n == null ) { n = this . getClass ( ) . getSimpleName ( ) + "#" + cacheCnt ++ ; } name = n ; } | Set the name and configure a logging used within cache construction . | 45 | 12 |
30,132 | protected CacheEntry < K , V > returnEntry ( final ExaminationEntry < K , V > e ) { if ( e == null ) { return null ; } return returnCacheEntry ( e ) ; } | Wrap entry in a separate object instance . We can return the entry directly however we lock on the entry object . | 42 | 23 |
30,133 | protected final void putValue ( final Entry e , final V _value ) { if ( ! isUpdateTimeNeeded ( ) ) { insertOrUpdateAndCalculateExpiry ( e , _value , 0 , 0 , 0 , INSERT_STAT_PUT ) ; } else { long t = clock . millis ( ) ; insertOrUpdateAndCalculateExpiry ( e , _value , t , t , t , INSERT_STAT_PUT ) ; } } | Update the value directly within entry lock . Since we did not start entry processing we do not need to notify any waiting threads . | 103 | 25 |
30,134 | protected boolean replace ( final K key , final boolean _compare , final V _oldValue , final V _newValue ) { Entry e = lookupEntry ( key ) ; if ( e == null ) { metrics . peekMiss ( ) ; return false ; } synchronized ( e ) { e . waitForProcessing ( ) ; if ( e . isGone ( ) || ! e . hasFreshData ( clock ) ) { return false ; } if ( _compare && ! e . equalsValue ( _oldValue ) ) { return false ; } putValue ( e , _newValue ) ; } return true ; } | replace if value matches . if value not matches return the existing entry or the dummy entry . | 130 | 18 |
30,135 | final protected Entry < K , V > peekEntryInternal ( K key ) { int hc = modifiedHash ( key . hashCode ( ) ) ; return peekEntryInternal ( key , hc , extractIntKeyValue ( key , hc ) ) ; } | Return the entry if it is in the cache without invoking the cache source . | 54 | 15 |
30,136 | @ Override public boolean removeIfEquals ( K key , V _value ) { Entry e = lookupEntry ( key ) ; if ( e == null ) { metrics . peekMiss ( ) ; return false ; } synchronized ( e ) { e . waitForProcessing ( ) ; if ( e . isGone ( ) ) { metrics . peekMiss ( ) ; return false ; } boolean f = e . hasFreshData ( clock ) ; if ( f ) { if ( ! e . equalsValue ( _value ) ) { return false ; } } else { metrics . peekHitNotFresh ( ) ; return false ; } removeEntry ( e ) ; return f ; } } | Remove the object from the cache . | 142 | 7 |
30,137 | protected void loadAndReplace ( K key ) { Entry e ; for ( ; ; ) { e = lookupOrNewEntry ( key ) ; synchronized ( e ) { e . waitForProcessing ( ) ; if ( e . isGone ( ) ) { metrics . goneSpin ( ) ; continue ; } e . startProcessing ( Entry . ProcessingState . LOAD ) ; break ; } } boolean _finished = false ; try { load ( e ) ; _finished = true ; } finally { e . ensureAbort ( _finished ) ; } } | Always fetch the value from the source . That is a copy of getEntryInternal without freshness checks . | 118 | 21 |
30,138 | private void checkForHashCodeChange ( Entry < K , V > e ) { K key = extractKeyObj ( e ) ; if ( extractIntKeyValue ( key , modifiedHash ( key . hashCode ( ) ) ) != e . hashCode ) { if ( keyMutationCnt == 0 ) { getLog ( ) . warn ( "Key mismatch! Key hashcode changed! keyClass=" + e . getKey ( ) . getClass ( ) . getName ( ) ) ; String s ; try { s = e . getKey ( ) . toString ( ) ; if ( s != null ) { getLog ( ) . warn ( "Key mismatch! key.toString(): " + s ) ; } } catch ( Throwable t ) { getLog ( ) . warn ( "Key mismatch! key.toString() threw exception" , t ) ; } } keyMutationCnt ++ ; } } | Check whether the key was modified during the stay of the entry in the cache . We only need to check this when the entry is removed since we expect that if the key has changed the stored hash code in the cache will not match any more and the item is evicted very fast . | 193 | 57 |
30,139 | private boolean entryInRefreshProbationAccessed ( final Entry < K , V > e , final long now ) { long nrt = e . getRefreshProbationNextRefreshTime ( ) ; if ( nrt > now ) { reviveRefreshedEntry ( e , nrt ) ; return true ; } return false ; } | Entry was refreshed before reset timer and make entry visible again . | 73 | 12 |
30,140 | private void resiliencePolicyException ( final Entry < K , V > e , final long t0 , final long t , Throwable _exception ) { ExceptionWrapper < K > _value = new ExceptionWrapper ( extractKeyObj ( e ) , _exception , t0 , e ) ; insert ( e , ( V ) _value , t0 , t , t0 , INSERT_STAT_LOAD , 0 ) ; } | Exception from the resilience policy . We have two exceptions now . One from the loader or the expiry policy one from the resilience policy . We propagate the more severe one from the resilience policy . | 91 | 38 |
30,141 | private void refreshEntry ( final Entry < K , V > e ) { synchronized ( e ) { e . waitForProcessing ( ) ; if ( e . isGone ( ) ) { return ; } e . startProcessing ( Entry . ProcessingState . REFRESH ) ; } boolean _finished = false ; try { load ( e ) ; _finished = true ; } catch ( CacheClosedException ignore ) { } catch ( Throwable ex ) { logAndCountInternalException ( "Refresh exception" , ex ) ; try { synchronized ( e ) { expireEntry ( e ) ; } } catch ( CacheClosedException ignore ) { } } finally { e . ensureAbort ( _finished ) ; } } | Executed in loader thread . Load the entry again . After the load we copy the entry to the refresh hash and expire it in the main hash . The entry needs to stay in the main hash during the load to block out concurrent reads . | 151 | 48 |
30,142 | private void expireAndRemoveEventually ( final Entry e ) { if ( isKeepAfterExpired ( ) || e . isProcessing ( ) ) { metrics . expiredKept ( ) ; } else { removeEntry ( e ) ; } } | Remove expired from heap and increment statistics . The entry is not removed when there is processing going on in parallel . | 50 | 22 |
30,143 | public Map < K , V > getAll ( final Iterable < ? extends K > _inputKeys ) { Map < K , ExaminationEntry < K , V > > map = new HashMap < K , ExaminationEntry < K , V > > ( ) ; for ( K k : _inputKeys ) { Entry < K , V > e = getEntryInternal ( k ) ; if ( e != null ) { map . put ( extractKeyObj ( e ) , ReadOnlyCacheEntry . of ( e ) ) ; } } return convertValueMap ( map ) ; } | JSR107 bulk interface . The behaviour is compatible to the JSR107 TCK . We also need to be compatible to the exception handling policy which says that the exception is to be thrown when most specific . So exceptions are only thrown when the value which has produced an exception is requested from the map . | 119 | 61 |
30,144 | public final void checkIntegrity ( ) { executeWithGlobalLock ( new Job < Void > ( ) { @ Override public Void call ( ) { IntegrityState is = getIntegrityState ( ) ; if ( is . getStateFlags ( ) > 0 ) { throw new Error ( "cache2k integrity error: " + is . getStateDescriptor ( ) + ", " + is . getFailingChecks ( ) + ", " + generateInfoUnderLock ( HeapCache . this , clock . millis ( ) ) . toString ( ) ) ; } return null ; } } ) ; } | Check internal data structures and throw and exception if something is wrong used for unit testing | 128 | 16 |
30,145 | @ Override public boolean add ( final CustomizationSupplier < T > entry ) { if ( list . contains ( entry ) ) { throw new IllegalArgumentException ( "duplicate entry" ) ; } return list . add ( entry ) ; } | Adds a customization to the collection . | 53 | 7 |
30,146 | public static OptimisticLock newOptimistic ( ) { if ( optimisticLockImplementation == null ) { initializeOptimisticLock ( ) ; } try { return optimisticLockImplementation . newInstance ( ) ; } catch ( Exception ex ) { throw new Error ( ex ) ; } } | Returns a new lock implementation depending on the platform support . | 60 | 11 |
30,147 | private Entry < K , V > returnEntry ( final Entry < K , V > e ) { touchEntry ( e . getKey ( ) ) ; return e ; } | Entry is accessed update expiry if needed . | 35 | 9 |
30,148 | private V returnValue ( K key , V _value ) { if ( _value != null ) { Duration d = expiryPolicy . getExpiryForAccess ( ) ; if ( d != null ) { c2kCache . expireAt ( key , calculateExpiry ( d ) ) ; } return _value ; } return null ; } | Entry was accessed update expiry if value is non null . | 73 | 12 |
30,149 | public Map < K , V > loadAll ( Iterable < ? extends K > keys , Executor executor ) throws Exception { throw new UnsupportedOperationException ( ) ; } | Loads multiple values to the cache . | 37 | 8 |
30,150 | private void setupTypes ( ) { if ( ! cache2kConfigurationWasProvided ) { cache2kConfiguration . setKeyType ( config . getKeyType ( ) ) ; cache2kConfiguration . setValueType ( config . getValueType ( ) ) ; } else { if ( cache2kConfiguration . getKeyType ( ) == null ) { cache2kConfiguration . setKeyType ( config . getKeyType ( ) ) ; } if ( cache2kConfiguration . getValueType ( ) == null ) { cache2kConfiguration . setValueType ( config . getValueType ( ) ) ; } } keyType = cache2kConfiguration . getKeyType ( ) ; valueType = cache2kConfiguration . getValueType ( ) ; if ( ! config . getKeyType ( ) . equals ( Object . class ) && ! config . getKeyType ( ) . equals ( keyType . getType ( ) ) ) { throw new IllegalArgumentException ( "Key type mismatch between JCache and cache2k configuration" ) ; } if ( ! config . getValueType ( ) . equals ( Object . class ) && ! config . getValueType ( ) . equals ( valueType . getType ( ) ) ) { throw new IllegalArgumentException ( "Value type mismatch between JCache and cache2k configuration" ) ; } } | If there is a cache2k configuration we take the types from there . | 282 | 15 |
30,151 | private void setupExceptionPropagator ( ) { if ( cache2kConfiguration . getExceptionPropagator ( ) != null ) { return ; } cache2kConfiguration . setExceptionPropagator ( new CustomizationReferenceSupplier < ExceptionPropagator < K > > ( new ExceptionPropagator < K > ( ) { @ Override public RuntimeException propagateException ( Object key , final ExceptionInformation exceptionInformation ) { return new CacheLoaderException ( "propagate previous loader exception" , exceptionInformation . getException ( ) ) ; } } ) ) ; } | If an exception propagator is configured take this one otherwise go with default that is providing JCache compatible behavior . | 117 | 22 |
30,152 | private void setupCacheThrough ( ) { if ( config . getCacheLoaderFactory ( ) != null ) { final CacheLoader < K , V > clf = config . getCacheLoaderFactory ( ) . create ( ) ; cache2kConfiguration . setAdvancedLoader ( new CustomizationReferenceSupplier < AdvancedCacheLoader < K , V > > ( new CloseableLoader ( ) { @ Override public void close ( ) throws IOException { if ( clf instanceof Closeable ) { ( ( Closeable ) clf ) . close ( ) ; } } @ Override public V load ( final K key , final long currentTime , final CacheEntry < K , V > currentEntry ) { return clf . load ( key ) ; } } ) ) ; } if ( config . getCacheWriterFactory ( ) != null ) { final javax . cache . integration . CacheWriter < ? super K , ? super V > cw = config . getCacheWriterFactory ( ) . create ( ) ; cache2kConfiguration . setWriter ( new CustomizationReferenceSupplier < CacheWriter < K , V > > ( new CloseableWriter ( ) { @ Override public void write ( final K key , final V value ) { Cache . Entry < K , V > ce = new Cache . Entry < K , V > ( ) { @ Override public K getKey ( ) { return key ; } @ Override public V getValue ( ) { return value ; } @ Override public < T > T unwrap ( Class < T > clazz ) { throw new UnsupportedOperationException ( "unwrap entry not supported" ) ; } } ; cw . write ( ce ) ; } @ Override public void delete ( final Object key ) { cw . delete ( key ) ; } @ Override public void close ( ) throws IOException { if ( cw instanceof Closeable ) { ( ( Closeable ) cw ) . close ( ) ; } } } ) ) ; } } | Configure loader and writer . | 417 | 6 |
30,153 | @ SuppressWarnings ( "unchecked" ) @ Override public SpringCache2kCache getCache ( final String name ) { return name2cache . computeIfAbsent ( name , n -> { if ( ! allowUnknownCache && ! configuredCacheNames . contains ( n ) ) { throw new IllegalArgumentException ( "Cache configuration missing for: " + n ) ; } return buildAndWrap ( Cache2kBuilder . forUnknownTypes ( ) . manager ( manager ) . name ( n ) ) ; } ) ; } | Returns an existing cache or retrieves and wraps a cache from cache2k . | 113 | 16 |
30,154 | @ Override public Collection < String > getCacheNames ( ) { Set < String > cacheNames = new HashSet <> ( ) ; for ( org . cache2k . Cache < ? , ? > cache : manager . getActiveCaches ( ) ) { cacheNames . add ( cache . getName ( ) ) ; } cacheNames . addAll ( configuredCacheNames ) ; return Collections . unmodifiableSet ( cacheNames ) ; } | Get a list of known caches . Depending on the configuration caches may be created dynamically without providing a configuration for a specific cache name . Because of this combine the known names from configuration and activated caches . | 93 | 39 |
30,155 | @ SuppressWarnings ( "unchecked" ) @ Override public < C extends Configuration < K , T > > C getConfiguration ( Class < C > clazz ) { final C c = cache . getConfiguration ( clazz ) ; if ( c instanceof CompleteConfiguration ) { final CompleteConfiguration < K , T > cc = ( CompleteConfiguration < K , T > ) c ; return ( C ) new CompleteConfiguration < K , T > ( ) { @ Override public Iterable < CacheEntryListenerConfiguration < K , T > > getCacheEntryListenerConfigurations ( ) { return cc . getCacheEntryListenerConfigurations ( ) ; } @ Override public boolean isReadThrough ( ) { return cc . isReadThrough ( ) ; } @ Override public boolean isWriteThrough ( ) { return cc . isWriteThrough ( ) ; } @ Override public boolean isStatisticsEnabled ( ) { return cc . isStatisticsEnabled ( ) ; } @ Override public boolean isManagementEnabled ( ) { return cc . isManagementEnabled ( ) ; } @ Override public Factory < CacheLoader < K , T > > getCacheLoaderFactory ( ) { return cc . getCacheLoaderFactory ( ) ; } @ Override public Factory < CacheWriter < ? super K , ? super T > > getCacheWriterFactory ( ) { return cc . getCacheWriterFactory ( ) ; } @ Override public Factory < ExpiryPolicy > getExpiryPolicyFactory ( ) { return cc . getExpiryPolicyFactory ( ) ; } @ Override public Class < K > getKeyType ( ) { return cc . getKeyType ( ) ; } @ Override public Class < T > getValueType ( ) { return cc . getValueType ( ) ; } @ Override public boolean isStoreByValue ( ) { return true ; } } ; } else if ( c instanceof Configuration ) { return ( C ) new Configuration < K , T > ( ) { @ Override public Class < K > getKeyType ( ) { return c . getKeyType ( ) ; } @ Override public Class < T > getValueType ( ) { return c . getValueType ( ) ; } @ Override public boolean isStoreByValue ( ) { return true ; } } ; } return c ; } | Delegates to the wrapped cache . Wrap configuration and return true on store by value | 481 | 16 |
30,156 | public static < K , V > Cache2kConfiguration < K , V > of ( CacheType < K > keyType , CacheType < V > valueType ) { Cache2kConfiguration < K , V > c = new Cache2kConfiguration < K , V > ( ) ; c . setKeyType ( keyType ) ; c . setValueType ( valueType ) ; return c ; } | Construct a config instance setting the type parameters and returning a proper generic type . | 83 | 15 |
30,157 | public CustomizationCollection < CacheEntryOperationListener < K , V > > getListeners ( ) { if ( listeners == null ) { listeners = new DefaultCustomizationCollection < CacheEntryOperationListener < K , V > > ( ) ; } return listeners ; } | A set of listeners . Listeners added in this collection will be executed in a synchronous mode meaning further processing for an entry will stall until a registered listener is executed . The expiry will be always executed asynchronously . | 54 | 45 |
30,158 | public static synchronized void reload ( ) { map = new HashMap < Class < ? > , Object > ( ) ; customProperties = loadFile ( CUSTOM_TUNING_FILE_NAME ) ; defaultProperties = loadFile ( DEFAULT_TUNING_FILE_NAME ) ; } | Reload the tunable configuration from the system properties and the configuration file . | 64 | 15 |
30,159 | @ SuppressWarnings ( "unchecked" ) public synchronized static < T extends TunableConstants > T get ( Properties p , Class < T > c ) { T cfg = getDefault ( c ) ; if ( p != null && p . containsKey ( TUNE_MARKER ) && p . containsKey ( cfg . getClass ( ) . getName ( ) + ".tuning" ) ) { cfg = ( T ) cfg . clone ( ) ; apply ( p , cfg ) ; } return cfg ; } | Provide tuning object with initialized information from the properties file . | 117 | 12 |
30,160 | public boolean add ( ConfigurationSection section ) { if ( section instanceof SingletonConfigurationSection ) { if ( getSection ( section . getClass ( ) ) != null ) { throw new IllegalArgumentException ( "Section of same type already inserted: " + section . getClass ( ) . getName ( ) ) ; } } return sections . add ( section ) ; } | Add a new configuration section to the container . | 77 | 9 |
30,161 | @ SuppressWarnings ( "unchecked" ) public < T extends ConfigurationSection > T getSection ( Class < T > sectionType ) { for ( ConfigurationSection s : sections ) { if ( sectionType . equals ( s . getClass ( ) ) ) { return ( T ) s ; } } return null ; } | Retrieve a single section from the container . | 68 | 9 |
30,162 | void deliverAsyncEvent ( final EntryEvent < K , V > _event ) { if ( asyncListenerByType . get ( _event . getEventType ( ) ) . isEmpty ( ) ) { return ; } List < Listener < K , V > > _listeners = new ArrayList < Listener < K , V > > ( asyncListenerByType . get ( _event . getEventType ( ) ) ) ; if ( _listeners . isEmpty ( ) ) { return ; } K key = _event . getKey ( ) ; synchronized ( getLockObject ( key ) ) { Queue < EntryEvent < K , V > > q = keyQueue . get ( key ) ; if ( q != null ) { q . add ( _event ) ; return ; } q = new LinkedList < EntryEvent < K , V > > ( ) ; keyQueue . put ( key , q ) ; } runAllListenersInParallel ( _event , _listeners ) ; } | If listeners are registered for this event type run the listeners or queue the event if already something is happening for this key . | 211 | 24 |
30,163 | void runAllListenersInParallel ( final EntryEvent < K , V > _event , List < Listener < K , V > > _listeners ) { final AtomicInteger _countDown = new AtomicInteger ( _listeners . size ( ) ) ; for ( final Listener < K , V > l : _listeners ) { Runnable r = new Runnable ( ) { @ Override public void run ( ) { try { l . fire ( _event ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; } int _done = _countDown . decrementAndGet ( ) ; if ( _done == 0 ) { runMoreOnKeyQueueOrStop ( _event . getKey ( ) ) ; } } } ; executor . execute ( r ) ; } } | Pass on runnables to the executor for all listeners . After each event is handled within the listener we check whether the event is processed by all listeners by decrementing a countdown . In case the event is processed completely we check whether more is queued up for this key meanwhile . | 175 | 58 |
30,164 | void runMoreOnKeyQueueOrStop ( K key ) { EntryEvent < K , V > _event ; synchronized ( getLockObject ( key ) ) { Queue < EntryEvent < K , V > > q = keyQueue . get ( key ) ; if ( q . isEmpty ( ) ) { keyQueue . remove ( key ) ; return ; } _event = q . remove ( ) ; } List < Listener < K , V > > _listeners = new ArrayList < Listener < K , V > > ( asyncListenerByType . get ( _event . getEventType ( ) ) ) ; if ( _listeners . isEmpty ( ) ) { runMoreOnKeyQueueOrStop ( key ) ; return ; } runAllListenersInParallel ( _event , _listeners ) ; } | Check the event queue for this key and process the next event . If no more events are present remove the queue . | 173 | 23 |
30,165 | private long calculateWeight ( final Entry e , final Object v ) { long _weight ; if ( v instanceof ExceptionWrapper ) { _weight = 1 ; } else { _weight = weigher . weigh ( e . getKey ( ) , v ) ; } if ( _weight < 0 ) { throw new IllegalArgumentException ( "weight must be positive." ) ; } return _weight ; } | Exceptions have the minimum weight . | 85 | 7 |
30,166 | @ Override public void updateWeight ( final Entry e ) { if ( ! isWeigherPresent ( ) ) { return ; } Entry [ ] _evictionChunk = null ; synchronized ( lock ) { updateWeightInLock ( e ) ; _evictionChunk = fillEvictionChunk ( ) ; } evictChunk ( _evictionChunk ) ; int _processCount = 1 ; while ( isEvictionNeeded ( ) && _processCount > 0 ) { synchronized ( lock ) { _evictionChunk = fillEvictionChunk ( ) ; } _processCount = evictChunk ( _evictionChunk ) ; } } | Update the weight in the entry and update the weight calculation in this eviction segment . Since the weight limit might be reached try to evict until within limits again . | 139 | 31 |
30,167 | Entry [ ] reuseChunkArray ( ) { Entry [ ] ea = evictChunkReuse ; if ( ea != null ) { evictChunkReuse = null ; } else { ea = new Entry [ chunkSize ] ; } return ea ; } | Safe GC overhead by reusing the chunk array . | 57 | 10 |
30,168 | @ SuppressWarnings ( "unchecked" ) private void configureViaSettersDirect ( HeapCache < K , V > c ) { if ( config . getLoader ( ) != null ) { Object obj = c . createCustomization ( config . getLoader ( ) ) ; if ( obj instanceof CacheLoader ) { final CacheLoader < K , V > _loader = ( CacheLoader ) obj ; c . setAdvancedLoader ( new AdvancedCacheLoader < K , V > ( ) { @ Override public V load ( final K key , final long currentTime , final CacheEntry < K , V > currentEntry ) throws Exception { return _loader . load ( key ) ; } } ) ; } else { final FunctionalCacheLoader < K , V > _loader = ( FunctionalCacheLoader ) obj ; c . setAdvancedLoader ( new AdvancedCacheLoader < K , V > ( ) { @ Override public V load ( final K key , final long currentTime , final CacheEntry < K , V > currentEntry ) throws Exception { return _loader . load ( key ) ; } } ) ; } } if ( config . getAdvancedLoader ( ) != null ) { final AdvancedCacheLoader < K , V > _loader = c . createCustomization ( config . getAdvancedLoader ( ) ) ; AdvancedCacheLoader < K , V > _wrappedLoader = new WrappedAdvancedCacheLoader < K , V > ( c , _loader ) ; c . setAdvancedLoader ( _wrappedLoader ) ; } if ( config . getExceptionPropagator ( ) != null ) { c . setExceptionPropagator ( c . createCustomization ( config . getExceptionPropagator ( ) ) ) ; } c . setCacheConfig ( config ) ; } | The generic wiring code is not working on android . Explicitly call the wiring methods . | 368 | 17 |
30,169 | private Eviction constructEviction ( HeapCache hc , HeapCacheListener l , Cache2kConfiguration config ) { final boolean _strictEviction = config . isStrictEviction ( ) ; final int _availableProcessors = Runtime . getRuntime ( ) . availableProcessors ( ) ; final boolean _boostConcurrency = config . isBoostConcurrency ( ) ; final long _maximumWeight = config . getMaximumWeight ( ) ; long _entryCapacity = config . getEntryCapacity ( ) ; if ( _entryCapacity < 0 && _maximumWeight < 0 ) { _entryCapacity = 2000 ; } final int _segmentCountOverride = HeapCache . TUNABLE . segmentCountOverride ; int _segmentCount = determineSegmentCount ( _strictEviction , _availableProcessors , _boostConcurrency , _entryCapacity , _segmentCountOverride ) ; Eviction [ ] _segments = new Eviction [ _segmentCount ] ; long _maxSize = determineMaxSize ( _entryCapacity , _segmentCount ) ; long _maxWeight = determineMaxWeight ( _maximumWeight , _segmentCount ) ; final Weigher _weigher = ( Weigher ) hc . createCustomization ( config . getWeigher ( ) ) ; for ( int i = 0 ; i < _segments . length ; i ++ ) { Eviction ev = new ClockProPlusEviction ( hc , l , _maxSize , _weigher , _maxWeight ) ; _segments [ i ] = ev ; } if ( _segmentCount == 1 ) { return _segments [ 0 ] ; } return new SegmentedEviction ( _segments ) ; } | Construct segmented or queued eviction . For the moment hard coded . If capacity is at least 1000 we use 2 segments if 2 or more CPUs are available . Segmenting the eviction only improves for lots of concurrent inserts or evictions there is no effect on read performance . | 373 | 55 |
30,170 | public void setTitle ( final String TITLE ) { if ( null == title ) { _title = TITLE ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { title . set ( TITLE ) ; } } | Defines the title of the clock . The title could be used to show for example the current city or timezone | 48 | 23 |
30,171 | public void setText ( final String TEXT ) { if ( null == text ) { _text = TEXT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { text . set ( TEXT ) ; } } | Define the text for the clock . This text could be used for additional information . | 45 | 17 |
30,172 | public void setSectionsVisible ( final boolean VISIBLE ) { if ( null == sectionsVisible ) { _sectionsVisible = VISIBLE ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { sectionsVisible . set ( VISIBLE ) ; } } | Defines if the sections should be drawn in the clock . | 58 | 12 |
30,173 | public void setHighlightSections ( final boolean HIGHLIGHT ) { if ( null == highlightSections ) { _highlightSections = HIGHLIGHT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { highlightSections . set ( HIGHLIGHT ) ; } } | Defines if sections should be highlighted in case they contain the current time . | 68 | 15 |
30,174 | public void setAreas ( final List < TimeSection > AREAS ) { areas . setAll ( AREAS ) ; Collections . sort ( areas , new TimeSectionComparator ( ) ) ; fireUpdateEvent ( SECTION_EVENT ) ; } | Sets the areas to the given list of TimeSection objects . The sections will be used to colorize areas with a special meaning . Areas in the Medusa library usually are more eye - catching than Sections . | 51 | 42 |
30,175 | public void addArea ( final TimeSection AREA ) { if ( null == AREA ) return ; areas . add ( AREA ) ; Collections . sort ( areas , new TimeSectionComparator ( ) ) ; fireUpdateEvent ( SECTION_EVENT ) ; } | Adds the given TimeSection to the list of areas . Areas in the Medusa library usually are more eye - catching than Sections . | 55 | 26 |
30,176 | public void removeArea ( final TimeSection AREA ) { if ( null == AREA ) return ; areas . remove ( AREA ) ; Collections . sort ( areas , new TimeSectionComparator ( ) ) ; fireUpdateEvent ( SECTION_EVENT ) ; } | Removes the given TimeSection from the list of areas . Areas in the Medusa library usually are more eye - catching than Sections . | 55 | 27 |
30,177 | public void setAreasVisible ( final boolean VISIBLE ) { if ( null == areasVisible ) { _areasVisible = VISIBLE ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { areasVisible . set ( VISIBLE ) ; } } | Defines if the areas should be drawn in the clock . | 58 | 12 |
30,178 | public void setHighlightAreas ( final boolean HIGHLIGHT ) { if ( null == highlightAreas ) { _highlightAreas = HIGHLIGHT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { highlightAreas . set ( HIGHLIGHT ) ; } } | Defines if areas should be highlighted in case they contain the current time . | 64 | 15 |
30,179 | public void setTitleVisible ( final boolean VISIBLE ) { if ( null == titleVisible ) { _titleVisible = VISIBLE ; fireUpdateEvent ( VISIBILITY_EVENT ) ; } else { titleVisible . set ( VISIBLE ) ; } } | Defines if the title of the clock will be drawn . | 57 | 12 |
30,180 | public void setBackgroundPaint ( final Paint PAINT ) { if ( null == backgroundPaint ) { _backgroundPaint = PAINT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { backgroundPaint . set ( PAINT ) ; } } | Defines the Paint object that will be used to fill the clock background . This is usally a Color object . | 56 | 23 |
30,181 | public void setBorderPaint ( final Paint PAINT ) { if ( null == borderPaint ) { _borderPaint = PAINT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { borderPaint . set ( PAINT ) ; } } | Defines the Paint object that will be used to draw the border of the clock . Usually this is a Color object . | 56 | 24 |
30,182 | public void setBorderWidth ( final double WIDTH ) { if ( null == borderWidth ) { _borderWidth = Helper . clamp ( 0.0 , 50.0 , WIDTH ) ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { borderWidth . set ( WIDTH ) ; } } | Defines the width in pixels that will be used to draw the border of the clock . The value will be clamped between 0 and 50 pixels . | 69 | 30 |
30,183 | public void setForegroundPaint ( final Paint PAINT ) { if ( null == foregroundPaint ) { _foregroundPaint = PAINT ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { foregroundPaint . set ( PAINT ) ; } } | Defines the Paint object that will be used to fill the foreground of the clock . This could be used to visualize glass effects etc . and is only rarely used . | 58 | 33 |
30,184 | public void setTitleColor ( final Color COLOR ) { if ( null == titleColor ) { _titleColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { titleColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the title of the clock | 52 | 16 |
30,185 | public void setTextColor ( final Color COLOR ) { if ( null == textColor ) { _textColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { textColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the text of the clock . | 51 | 17 |
30,186 | public void setDateColor ( final Color COLOR ) { if ( null == dateColor ) { _dateColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { dateColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the date of the clock | 52 | 16 |
30,187 | public void setMinuteTickMarkColor ( final Color COLOR ) { if ( null == minuteTickMarkColor ) { _minuteTickMarkColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { minuteTickMarkColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the minute tickmarks of the clock . | 65 | 19 |
30,188 | public void setTickLabelColor ( final Color COLOR ) { if ( null == tickLabelColor ) { _tickLabelColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { tickLabelColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the ticklabels of the clock . | 57 | 19 |
30,189 | public void setTickLabelsVisible ( final boolean VISIBLE ) { if ( null == tickLabelsVisible ) { _tickLabelsVisible = VISIBLE ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { tickLabelsVisible . set ( VISIBLE ) ; } } | Defines if the ticklabels will be drawn . | 65 | 11 |
30,190 | public void setSecondColor ( final Color COLOR ) { if ( null == secondColor ) { _secondColor = COLOR ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { secondColor . set ( COLOR ) ; } } | Defines the color that will be used to colorize the second hand of the clock | 52 | 17 |
30,191 | public void setLcdCrystalEnabled ( final boolean ENABLED ) { if ( null == lcdCrystalEnabled ) { _lcdCrystalEnabled = ENABLED ; fireUpdateEvent ( VISIBILITY_EVENT ) ; } else { lcdCrystalEnabled . set ( ENABLED ) ; } } | Defines if the crystal effect of the LCD display will be drawn . This feature could decrease the performance if you run it on embedded devices because it will calculate a bitmap image where each pixel will be calculated . | 67 | 42 |
30,192 | public void setShadowsEnabled ( final boolean ENABLED ) { if ( null == shadowsEnabled ) { _shadowsEnabled = ENABLED ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { shadowsEnabled . set ( ENABLED ) ; } } | Defines if effects like shadows will be drawn . | 60 | 10 |
30,193 | public void setLocale ( final Locale LOCALE ) { if ( null == locale ) { _locale = LOCALE ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { locale . set ( LOCALE ) ; } } | Defines the Locale that will be used to format the date in some ClockSkins . | 51 | 19 |
30,194 | public void setCustomFont ( final Font FONT ) { if ( null == customFont ) { _customFont = FONT ; fireUpdateEvent ( RESIZE_EVENT ) ; } else { customFont . set ( FONT ) ; } } | Defines the custom font that can be used to render all text elements . To enable the custom font one has to set customFontEnabled = true | 52 | 29 |
30,195 | private void checkAlarms ( final ZonedDateTime TIME ) { alarmsToRemove . clear ( ) ; for ( Alarm alarm : alarms ) { final ZonedDateTime ALARM_TIME = alarm . getTime ( ) ; switch ( alarm . getRepetition ( ) ) { case ONCE : if ( TIME . isAfter ( ALARM_TIME ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } alarmsToRemove . add ( alarm ) ; } break ; case HALF_HOURLY : if ( ( ALARM_TIME . getMinute ( ) == TIME . getMinute ( ) || ALARM_TIME . plusMinutes ( 30 ) . getMinute ( ) == TIME . getMinute ( ) ) && ALARM_TIME . getSecond ( ) == TIME . getSecond ( ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; case HOURLY : if ( ALARM_TIME . getMinute ( ) == TIME . getMinute ( ) && ALARM_TIME . getSecond ( ) == TIME . getSecond ( ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; case DAILY : if ( ALARM_TIME . getHour ( ) == TIME . getHour ( ) && ALARM_TIME . getMinute ( ) == TIME . getMinute ( ) && ALARM_TIME . getSecond ( ) == TIME . getSecond ( ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; case WEEKLY : if ( ALARM_TIME . getDayOfWeek ( ) == TIME . getDayOfWeek ( ) && ALARM_TIME . getHour ( ) == TIME . getHour ( ) && ALARM_TIME . getMinute ( ) == TIME . getMinute ( ) && ALARM_TIME . getSecond ( ) == TIME . getSecond ( ) ) { if ( alarm . isArmed ( ) ) { fireAlarmEvent ( new AlarmEvent ( Clock . this , alarm ) ) ; alarm . executeCommand ( ) ; } } break ; } } for ( Alarm alarm : alarmsToRemove ) { removeAlarm ( alarm ) ; } } | Calling this method will check the current time against all Alarm objects in alarms . The Alarm object will fire events in case the time is after the alarm time . | 568 | 33 |
30,196 | public void setMinValue ( final double VALUE ) { if ( Status . RUNNING == timeline . getStatus ( ) ) { timeline . jumpTo ( Duration . ONE ) ; } if ( null == minValue ) { if ( VALUE > getMaxValue ( ) ) { setMaxValue ( VALUE ) ; } _minValue = Helper . clamp ( - Double . MAX_VALUE , getMaxValue ( ) , VALUE ) ; setRange ( getMaxValue ( ) - _minValue ) ; if ( Double . compare ( originalMinValue , - Double . MAX_VALUE ) == 0 ) originalMinValue = _minValue ; if ( isStartFromZero ( ) && _minValue < 0 ) setValue ( 0 ) ; if ( Double . compare ( originalThreshold , getThreshold ( ) ) < 0 ) { setThreshold ( Helper . clamp ( _minValue , getMaxValue ( ) , originalThreshold ) ) ; } updateFormatString ( ) ; fireUpdateEvent ( RECALC_EVENT ) ; if ( ! valueProperty ( ) . isBound ( ) ) Gauge . this . setValue ( Helper . clamp ( getMinValue ( ) , getMaxValue ( ) , Gauge . this . getValue ( ) ) ) ; } else { minValue . set ( VALUE ) ; } } | Sets the minimum value of the gauge scale to the given value | 284 | 13 |
30,197 | public void setSubTitle ( final String SUBTITLE ) { if ( null == subTitle ) { _subTitle = SUBTITLE ; fireUpdateEvent ( VISIBILITY_EVENT ) ; fireUpdateEvent ( REDRAW_EVENT ) ; } else { subTitle . set ( SUBTITLE ) ; } } | Sets the subtitle of the gauge . This subtitle will usually only be visible if it is not empty . | 67 | 21 |
30,198 | public void setAreas ( final List < Section > AREAS ) { areas . setAll ( AREAS ) ; Collections . sort ( areas , new SectionComparator ( ) ) ; fireUpdateEvent ( SECTION_EVENT ) ; } | Sets the sections to the given list of Section objects . The sections will be used to colorize areas with a special meaning such as the red area in a rpm gauge . Areas in the Medusa library usually are more eye - catching than Sections . | 49 | 50 |
30,199 | public void addArea ( final Section AREA ) { if ( null == AREA ) return ; areas . add ( AREA ) ; Collections . sort ( areas , new SectionComparator ( ) ) ; fireUpdateEvent ( SECTION_EVENT ) ; } | Adds the given Section to the list of areas . Areas in the Medusa library usually are more eye - catching than Sections . | 53 | 25 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.