3 The file is used to provide all kinds of sorting method
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.frameworkwizard
.common
;
18 import java
.util
.Vector
;
20 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
21 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsIdentification
;
22 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsVector
;
23 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassIdentification
;
24 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassVector
;
25 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedIdentification
;
26 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedVector
;
27 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdIdentification
;
28 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdVector
;
29 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Ppis
.PpisIdentification
;
30 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Ppis
.PpisVector
;
31 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsIdentification
;
32 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsVector
;
33 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
34 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
39 Sort all elements in the vector as the specific sort type
41 @param v The vector need to be sorted
42 @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending
45 public static void sortVectorString(Vector
<String
> v
, int mode
) {
47 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
48 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
49 if ((v
.get(indexJ
).compareTo(v
.get(indexI
)) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
50 || (v
.get(indexI
).compareTo(v
.get(indexJ
)) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
51 String temp
= v
.get(indexI
);
52 v
.setElementAt(v
.get(indexJ
), indexI
);
53 v
.setElementAt(temp
, indexJ
);
61 Sort all elements of vector and return sorted sequence
63 @param v The vector need to be sorted
64 @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending
65 @return Vector<Integer> The sorted sequence
68 public static Vector
<Integer
> getVectorSortSequence(Vector
<String
> v
, int mode
) {
69 Vector
<Integer
> vSequence
= new Vector
<Integer
>();
74 for (int index
= 0; index
< v
.size(); index
++) {
75 vSequence
.addElement(index
);
80 // sort and get new sequence
82 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
83 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
84 if ((v
.get(indexJ
).compareTo(v
.get(indexI
)) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
85 || (v
.get(indexI
).compareTo(v
.get(indexJ
)) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
89 String tempStr
= v
.get(indexI
);
90 v
.setElementAt(v
.get(indexJ
), indexI
);
91 v
.setElementAt(tempStr
, indexJ
);
96 int tempInt
= vSequence
.get(indexI
);
97 vSequence
.setElementAt(vSequence
.get(indexJ
), indexI
);
98 vSequence
.setElementAt(tempInt
, indexJ
);
107 Sort all elements of vector as input sequence
109 @param v The vector need to be sorted
110 @param vSequence The sort sequence should be followed
113 public static void sortVectorString(Vector
<String
> v
, Vector
<Integer
> vSequence
) {
114 if (v
!= null && vSequence
!= null && v
.size() == vSequence
.size()) {
115 Vector
<String
> tempV
= new Vector
<String
>();
116 for (int index
= 0; index
< v
.size(); index
++) {
117 tempV
.addElement(v
.get(index
));
119 for (int index
= 0; index
< v
.size(); index
++) {
120 v
.setElementAt(tempV
.get(vSequence
.get(index
)), index
);
132 public static void sortModules(Vector
<ModuleIdentification
> v
, int mode
) {
137 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
138 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
139 if ((v
.get(indexJ
).getName().compareTo(v
.get(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
140 || (v
.get(indexI
).getName().compareTo(v
.get(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
141 ModuleIdentification temp
= v
.get(indexI
);
142 v
.setElementAt(v
.get(indexJ
), indexI
);
143 v
.setElementAt(temp
, indexJ
);
157 public static void sortPackages(Vector
<PackageIdentification
> v
, int mode
) {
162 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
163 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
164 if ((v
.get(indexJ
).getName().compareTo(v
.get(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
165 || (v
.get(indexI
).getName().compareTo(v
.get(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
166 PackageIdentification temp
= v
.get(indexI
);
167 v
.setElementAt(v
.get(indexJ
), indexI
);
168 v
.setElementAt(temp
, indexJ
);
182 public static void sortPlatforms(Vector
<PlatformIdentification
> v
, int mode
) {
187 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
188 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
189 if ((v
.get(indexJ
).getName().compareTo(v
.get(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
190 || (v
.get(indexI
).getName().compareTo(v
.get(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
191 PlatformIdentification temp
= v
.get(indexI
);
192 v
.setElementAt(v
.get(indexJ
), indexI
);
193 v
.setElementAt(temp
, indexJ
);
207 public static void sortPcds(PcdVector v
, int mode
) {
212 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
213 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
214 if ((v
.getPcd(indexJ
).getName().compareTo(v
.getPcd(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
215 || (v
.getPcd(indexI
).getName().compareTo(v
.getPcd(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
216 PcdIdentification temp
= v
.getPcd(indexI
);
217 v
.setPcd(v
.getPcd(indexJ
), indexI
);
218 v
.setPcd(temp
, indexJ
);
232 public static void sortPpis(PpisVector v
, int mode
) {
237 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
238 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
239 if ((v
.getPpis(indexJ
).getName().compareTo(v
.getPpis(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
240 || (v
.getPpis(indexI
).getName().compareTo(v
.getPpis(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
241 PpisIdentification temp
= v
.getPpis(indexI
);
242 v
.setPpis(v
.getPpis(indexJ
), indexI
);
243 v
.setPpis(temp
, indexJ
);
251 Sort all protocol entries
257 public static void sortProtocols(ProtocolsVector v
, int mode
) {
262 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
263 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
264 if ((v
.getProtocols(indexJ
).getName().compareTo(v
.getProtocols(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
265 || (v
.getProtocols(indexI
).getName().compareTo(v
.getProtocols(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
266 ProtocolsIdentification temp
= v
.getProtocols(indexI
);
267 v
.setProtocols(v
.getProtocols(indexJ
), indexI
);
268 v
.setProtocols(temp
, indexJ
);
276 Sort all guid entries
282 public static void sortGuids(GuidsVector v
, int mode
) {
287 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
288 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
289 if ((v
.getGuids(indexJ
).getName().compareTo(v
.getGuids(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
290 || (v
.getGuids(indexI
).getName().compareTo(v
.getGuids(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
291 GuidsIdentification temp
= v
.getGuids(indexI
);
292 v
.setGuids(v
.getGuids(indexJ
), indexI
);
293 v
.setGuids(temp
, indexJ
);
301 Sort all pcd coded entries
307 public static void sortPcdCodeds(PcdCodedVector v
, int mode
) {
312 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
313 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
314 if ((v
.getPcdCoded(indexJ
).getName().compareTo(v
.getPcdCoded(indexI
).getName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
315 || (v
.getPcdCoded(indexI
).getName().compareTo(v
.getPcdCoded(indexJ
).getName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
316 PcdCodedIdentification temp
= v
.getPcdCoded(indexI
);
317 v
.setPcdCoded(v
.getPcdCoded(indexJ
), indexI
);
318 v
.setPcdCoded(temp
, indexJ
);
326 Sort all pcd coded entries
332 public static void sortLibraryClass(LibraryClassVector v
, int mode
) {
337 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
338 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
339 if ((v
.getLibraryClass(indexJ
).getLibraryClassName().compareTo(
340 v
.getLibraryClass(indexI
)
341 .getLibraryClassName()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
342 || (v
.getLibraryClass(indexI
).getLibraryClassName().compareTo(
343 v
.getLibraryClass(indexJ
)
344 .getLibraryClassName()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
345 LibraryClassIdentification temp
= v
.getLibraryClass(indexI
);
346 v
.setLibraryClass(v
.getLibraryClass(indexJ
), indexI
);
347 v
.setLibraryClass(temp
, indexJ
);
355 Sort all objects of a vector based on the object's "toString"
361 public static void sortObjectVector(Vector
<Object
> v
, int mode
) {
366 for (int indexI
= 0; indexI
< v
.size(); indexI
++) {
367 for (int indexJ
= indexI
+ 1; indexJ
< v
.size(); indexJ
++) {
368 if ((v
.get(indexJ
).toString().compareTo(v
.get(indexI
).toString()) < 0 && mode
== DataType
.SORT_TYPE_ASCENDING
)
369 || (v
.get(indexI
).toString().compareTo(v
.get(indexJ
).toString()) < 0 && mode
== DataType
.SORT_TYPE_DESCENDING
)) {
370 Object temp
= v
.get(indexI
);
371 v
.setElementAt(v
.get(indexJ
), indexI
);
372 v
.setElementAt(temp
, indexJ
);