+++ /dev/null
-/** @file\r
- \r
- The file is used to provide all kinds of sorting method \r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- \r
- **/\r
-\r
-package org.tianocore.frameworkwizard.common;\r
-\r
-import java.util.Vector;\r
-\r
-import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.Guids.GuidsIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.Guids.GuidsVector;\r
-import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassVector;\r
-import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdCodedIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdCodedVector;\r
-import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;\r
-import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisVector;\r
-import org.tianocore.frameworkwizard.module.Identifications.Protocols.ProtocolsIdentification;\r
-import org.tianocore.frameworkwizard.module.Identifications.Protocols.ProtocolsVector;\r
-import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
-import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r
-\r
-public class Sort {\r
-\r
- /**\r
- Sort all elements in the vector as the specific sort type\r
- \r
- @param v The vector need to be sorted\r
- @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending\r
-\r
- **/\r
- public static void sortVectorString(Vector<String> v, int mode) {\r
- if (v != null) {\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).compareTo(v.get(indexI)) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).compareTo(v.get(indexJ)) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- String temp = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all elements of vector and return sorted sequence\r
- \r
- @param v The vector need to be sorted\r
- @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending\r
- @return Vector<Integer> The sorted sequence\r
- \r
- **/\r
- public static Vector<Integer> getVectorSortSequence(Vector<String> v, int mode) {\r
- Vector<Integer> vSequence = new Vector<Integer>();\r
- //\r
- // Init sequence\r
- //\r
- if (v != null) {\r
- for (int index = 0; index < v.size(); index++) {\r
- vSequence.addElement(index);\r
- }\r
- }\r
-\r
- //\r
- // sort and get new sequence\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).compareTo(v.get(indexI)) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).compareTo(v.get(indexJ)) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- //\r
- // Swap strings\r
- //\r
- String tempStr = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(tempStr, indexJ);\r
-\r
- //\r
- // Swap sequences\r
- //\r
- int tempInt = vSequence.get(indexI);\r
- vSequence.setElementAt(vSequence.get(indexJ), indexI);\r
- vSequence.setElementAt(tempInt, indexJ);\r
- }\r
- }\r
- }\r
-\r
- return vSequence;\r
- }\r
-\r
- /**\r
- Sort all elements of vector as input sequence\r
- \r
- @param v The vector need to be sorted\r
- @param vSequence The sort sequence should be followed\r
- \r
- **/\r
- public static void sortVectorString(Vector<String> v, Vector<Integer> vSequence) {\r
- if (v != null && vSequence != null && v.size() == vSequence.size()) {\r
- Vector<String> tempV = new Vector<String>();\r
- for (int index = 0; index < v.size(); index++) {\r
- tempV.addElement(v.get(index));\r
- }\r
- for (int index = 0; index < v.size(); index++) {\r
- v.setElementAt(tempV.get(vSequence.get(index)), index);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all modules\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortModules(Vector<ModuleIdentification> v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- ModuleIdentification temp = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all packages\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortPackages(Vector<PackageIdentification> v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- PackageIdentification temp = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all platforms\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortPlatforms(Vector<PlatformIdentification> v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- PlatformIdentification temp = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all pcd entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortPcds(PcdVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getPcd(indexJ).getName().compareTo(v.getPcd(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getPcd(indexI).getName().compareTo(v.getPcd(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- PcdIdentification temp = v.getPcd(indexI);\r
- v.setPcd(v.getPcd(indexJ), indexI);\r
- v.setPcd(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all ppi entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortPpis(PpisVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getPpis(indexJ).getName().compareTo(v.getPpis(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getPpis(indexI).getName().compareTo(v.getPpis(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- PpisIdentification temp = v.getPpis(indexI);\r
- v.setPpis(v.getPpis(indexJ), indexI);\r
- v.setPpis(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all protocol entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortProtocols(ProtocolsVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getProtocols(indexJ).getName().compareTo(v.getProtocols(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getProtocols(indexI).getName().compareTo(v.getProtocols(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- ProtocolsIdentification temp = v.getProtocols(indexI);\r
- v.setProtocols(v.getProtocols(indexJ), indexI);\r
- v.setProtocols(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all guid entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortGuids(GuidsVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getGuids(indexJ).getName().compareTo(v.getGuids(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getGuids(indexI).getName().compareTo(v.getGuids(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- GuidsIdentification temp = v.getGuids(indexI);\r
- v.setGuids(v.getGuids(indexJ), indexI);\r
- v.setGuids(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all pcd coded entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortPcdCodeds(PcdCodedVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getPcdCoded(indexJ).getName().compareTo(v.getPcdCoded(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getPcdCoded(indexI).getName().compareTo(v.getPcdCoded(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- PcdCodedIdentification temp = v.getPcdCoded(indexI);\r
- v.setPcdCoded(v.getPcdCoded(indexJ), indexI);\r
- v.setPcdCoded(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all pcd coded entries\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortLibraryClass(LibraryClassVector v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.getLibraryClass(indexJ).getLibraryClassName().compareTo(\r
- v.getLibraryClass(indexI)\r
- .getLibraryClassName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.getLibraryClass(indexI).getLibraryClassName().compareTo(\r
- v.getLibraryClass(indexJ)\r
- .getLibraryClassName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- LibraryClassIdentification temp = v.getLibraryClass(indexI);\r
- v.setLibraryClass(v.getLibraryClass(indexJ), indexI);\r
- v.setLibraryClass(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- Sort all objects of a vector based on the object's "toString"\r
- \r
- @param v\r
- @param mode\r
- \r
- **/\r
- public static void sortObjectVector(Vector<Object> v, int mode) {\r
- if (v != null) {\r
- //\r
- // sort by name\r
- //\r
- for (int indexI = 0; indexI < v.size(); indexI++) {\r
- for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) {\r
- if ((v.get(indexJ).toString().compareTo(v.get(indexI).toString()) < 0 && mode == DataType.SORT_TYPE_ASCENDING)\r
- || (v.get(indexI).toString().compareTo(v.get(indexJ).toString()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) {\r
- Object temp = v.get(indexI);\r
- v.setElementAt(v.get(indexJ), indexI);\r
- v.setElementAt(temp, indexJ);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-}\r