Ignore:
Timestamp:
09/24/15 10:59:05 (9 years ago)
Author:
sherbold
Message:
  • formatted code and added copyrights
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/decentApp/FileWatcher.java

    r32 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.decentApp; 
    216 
     
    822 *  
    923 * @author Philip Makedonski 
    10  * 
     24 *  
    1125 */ 
    1226public abstract class FileWatcher extends TimerTask { 
    13         // Last timestamp 
    14         private long timeStamp; 
    15          
    16         // File to watch 
    17         private File file; 
     27    // Last timestamp 
     28    private long timeStamp; 
    1829 
    19         /** 
    20          * Constructor 
    21          * @param file 
    22          */ 
    23         public FileWatcher(File file) { 
    24                 this.file = file; 
    25                 this.timeStamp = file.lastModified(); 
    26         } 
     30    // File to watch 
     31    private File file; 
    2732 
    28         /** 
    29          * Watches a file and executes the onChange Method 
    30          * if a file is changed 
    31          */ 
    32         public final void run() { 
    33                 long timeStamp = file.lastModified(); 
     33    /** 
     34     * Constructor 
     35     *  
     36     * @param file 
     37     */ 
     38    public FileWatcher(File file) { 
     39        this.file = file; 
     40        this.timeStamp = file.lastModified(); 
     41    } 
    3442 
    35                 if (this.timeStamp != timeStamp) { 
    36                         this.timeStamp = timeStamp; 
    37                         onChange(file); 
    38                 } 
    39         } 
     43    /** 
     44     * Watches a file and executes the onChange Method if a file is changed 
     45     */ 
     46    public final void run() { 
     47        long timeStamp = file.lastModified(); 
    4048 
    41         protected abstract void onChange(File file); 
     49        if (this.timeStamp != timeStamp) { 
     50            this.timeStamp = timeStamp; 
     51            onChange(file); 
     52        } 
     53    } 
     54 
     55    protected abstract void onChange(File file); 
    4256} 
Note: See TracChangeset for help on using the changeset viewer.