update dev300-m58
[ooovba.git] / solenv / bin / modules / installer / sorter.pm
blob6dc1485c79a2cb6b22f5bf131dc79e32175774f2
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: sorter.pm,v $
11 # $Revision: 1.6 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::sorter;
34 #########################################
35 # Sorting an array of hashes
36 #########################################
38 sub sorting_array_of_hashes
40 my ($arrayref, $sortkey) = @_;
42 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
44 my $onehashunder = ${$arrayref}[$i];
45 my $sortvalueunder = $onehashunder->{$sortkey};
47 for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
49 my $onehashover = ${$arrayref}[$j];
50 my $sortvalueover = $onehashover->{$sortkey};
52 if ( $sortvalueunder gt $sortvalueover)
54 ${$arrayref}[$i] = $onehashover;
55 ${$arrayref}[$j] = $onehashunder;
57 $onehashunder = $onehashover;
58 $sortvalueunder = $sortvalueover;
64 ######################################################
65 # Sorting an array of hashes with a numerical value
66 ######################################################
68 sub sort_array_of_hashes_numerically
70 my ($arrayref, $sortkey) = @_;
72 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
74 my $onehashunder = ${$arrayref}[$i];
75 my $sortvalueunder = $onehashunder->{$sortkey};
77 for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
79 my $onehashover = ${$arrayref}[$j];
80 my $sortvalueover = $onehashover->{$sortkey};
82 if ( $sortvalueunder > $sortvalueover)
84 ${$arrayref}[$i] = $onehashover;
85 ${$arrayref}[$j] = $onehashunder;
87 $onehashunder = $onehashover;
88 $sortvalueunder = $sortvalueover;
94 #########################################
95 # Sorting an array of of strings
96 #########################################
98 sub sorting_array_of_strings
100 my ($arrayref) = @_;
102 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
104 my $onestringunder = ${$arrayref}[$i];
106 for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
108 my $onestringover = ${$arrayref}[$j];
110 if ( $onestringunder gt $onestringover)
112 ${$arrayref}[$i] = $onestringover;
113 ${$arrayref}[$j] = $onestringunder;
114 $onestringunder = $onestringover;