⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extensioncountsorter.java

📁 dump3 morpheus 0.2.9 src
💻 JAVA
字号:
/**
 * DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
 * Copyright 2005 Alexander Gr&auml;sser<BR>
 * All Rights Reserved, http://dump3.sourceforge.net/<BR>
 * <BR>
 * This file is part of DuMP3.<BR>
 * <BR>
 * DuMP3 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later version.<BR>
 * <BR>
 * DuMP3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.<BR>
 * <BR>
 * You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.za.grasser.duplicate.gui;

import net.za.grasser.duplicate.file.ExtensionCount;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

/**
 * This class sorts lists of ExtensionCount by extension or count.
 * 
 * @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
 * @version $Revision: 1.2 $
 */
public class ExtensionCountSorter extends ViewerSorter {
  /**
   * <code>EXT</code> ExtensionCountSorter -
   */
  public static final int EXT = 0;
  /**
   * <code>COUNT</code> ExtensionCountSorter -
   */
  public static final int COUNT = 1;
  /**
   * <code>ASC</code> ExtensionCountSorter -
   */
  public static final int ASC = 0;
  /**
   * <code>DESC</code> ExtensionCountSorter -
   */
  public static final int DESC = 1;
  /**
   * <code>type</code> ExtensionCountSorter -
   */
  private int type = EXT;
  /**
   * <code>direction</code> ExtensionCountSorter -
   */
  private int direction = ASC;

  /**
   * Constructor
   * 
   * @param pType
   * @param pDir
   */
  public ExtensionCountSorter(final int pType, final int pDir) {
    super();
    type = pType;
    direction = pDir;
  }

  /**
   * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
   */
  @Override
  public int compare(final Viewer viewer, final Object element1, final Object element2) {
    if (element1 instanceof ExtensionCount && element2 instanceof ExtensionCount) {
      try {
        int mult = 1;
        if (direction == DESC) {
          mult = -1;
        }
        if (type == EXT) {
          return mult * ((ExtensionCount)element1).getExtension().compareTo(((ExtensionCount)element2).getExtension());
        }
        return mult * (((ExtensionCount)element1).getCount() - ((ExtensionCount)element2).getCount());
      } catch (final ClassCastException t) {
        t.printStackTrace();
      }
    }
    return element1.toString().compareTo(element2.toString());
  }

  /**
   * @return int - Returns the direction.
   */
  public int getDirection() {
    return direction;
  }

  /**
   * @return int - Returns the type.
   */
  public int getType() {
    return type;
  }
}

⌨️ 快捷键说明

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