/******************************* Copyright notice ******************************* Copyright (C)2002 by Andrei Loskutov <loskutov@gmx.de>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ package adiag.model; import java.util.Comparator; /** * VComparator compare versions by change number (at first) * or version number, if change number is not available, and take notice to * the sequence of (currently hard coded order of TUI Infotec) branches, * i.e. entw->itest->kdtest->prod * @author Andrei Loskutov */ public class VersionComparator implements Comparator { /** first branch path for branch sort order */ public static String path1 = "/entw/"; /** second branchh path for branch sort order */ public static String path2 = "/itest/"; /** third branchh path for branch sort order */ public static String path3 = "/kdtest/"; /** fourth branchh path for branch sort order */ public static String path4 = "/prod/"; /** flag to use branch path's for sort operation */ public static boolean sort_custom_paths = true; /** * VComparator default construktor. */ public VersionComparator() { super(); } /** * VComparator compare versions by change number (at first) * or version number, if change number is not available, and take notice to * the sequence of (currently hard coded order of TUI Infotec) branches, * i.e. entw->itest->kdtest->prod * @return -1, 0, 1 if the first version younger, same or older is * @see java.util.Comparator# * @param o1 first version * @param o2 second version */ public int compare(Object o1, Object o2) { if(o1 ==null || o2 == null){ return (o1 ==null && o2 == null)? 0 : o1 ==null? 1 : -1; } Version v1 = (Version)o1; Version v2 = (Version)o2; int x = v1.getChange(); x = v1.isChangeNumOk() ? x : -1; int y = v2.getChange(); y = v2.isChangeNumOk() ? y : -1; if((x == -1 || y == -1) || (x == y)){ // change number not available or same // different paths if(v1.getPath() != null && !v1.getPath().equals(v2.getPath())){ int test = 0; if(sort_custom_paths){ test = checkPaths(v1.getPath(), v2.getPath()); } if(test != 0){ return test; } if(x==y) { return 0; // cannot decide... } return x == -1 ? 1 : -1; // unknown will be older!... } else { // same path, use only version number x = v1.getVersNumber(); y = v2.getVersNumber(); } } if(x<y) return -1; if(x==y) return 0; if(x>y) return 1; return 0; } /** * See return description * @param p1 first path * @param p2 second path * @return -1, 0, 1 if the first path has layout position before, at the same * place or after the second path . * Currently it is like TUI order: entw->itest->kdtest->prod and * will not work properly with other paths. */ private int checkPaths(String p1, String p2){ // what is the first path? if(p1.indexOf(path1) >=0){ p1 = path1; } else if(p1.indexOf(path2) >=0){ p1 = path2; } else if(p1.indexOf(path3) >=0){ p1 = path3; } else if(p1.indexOf(path4) >=0){ p1 = path4; } else { // don't match and we don't know what we should do return 0; } // what is the second path? if(p2.indexOf(path1) >=0){ p2 = path1; } else if(p2.indexOf(path2) >=0){ p2 = path2; } else if(p2.indexOf(path3) >=0){ p2 = path3; } else if(p2.indexOf(path4) >=0){ p2 = path4; } else { return 0; } // quick and dirty, work only on entw->itest->kdtest->prod char x = p1.charAt(1); char y = p2.charAt(1); if(x<y) return -1; if(x==y) return 0; if(x>y) return 1; return 0; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#1 | 2222 | andrei_loskutov |
#13.10.2002 22:16 Revision 1.2.1 1) Documentation task is finished... Yes!!! 2) New feature: copy P4 depot path 3) Some small fixes to menu shortkeys belongs ctrl + c and ctrl + d 4) Clipboard fix because of JDK 1.2 - 1.3 bug 5) Smallest refactoring on some methods. 6) Html help updated |