zipmodificationtimecomparator.java

来自「Ftp服务1.0」· Java 代码 · 共 44 行

JAVA
44
字号
package ranab.jar;

import java.util.Date;
import java.util.zip.ZipEntry;

/**
 * Compare two zip entries based on the file name.
 *
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public 
class ZipModificationTimeComparator extends ZipComparator  {
    
    public int compare(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        Date dt1 = new Date(z1.getTime());
        Date dt2 = new Date(z2.getTime());
        return dt1.compareTo(dt2);
    }
    
    public boolean equals(Object o1, Object o2)  {
        if (!(o1 instanceof java.util.zip.ZipEntry && o1 instanceof java.util.zip.ZipEntry))  {
            throw new IllegalArgumentException("Not a ZipEntry object."); 
        }
        
        ZipEntry z1 = (ZipEntry)o1;
        ZipEntry z2 = (ZipEntry)o2;
        return z1.getTime() == z2.getTime();
    }
    
    
    /**
     * get header name
     */
     public String getHeaderName()  {
         return "Modification Time";
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?