~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar-ptb/src/org/herac/tuxguitar/io/ptb/base/PTSection.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.io.ptb.base;
 
2
 
 
3
import java.util.ArrayList;
 
4
import java.util.Iterator;
 
5
import java.util.List;
 
6
 
 
7
public class PTSection {
 
8
        
 
9
        private int number;
 
10
        private int staffs;
 
11
        private List positions;
 
12
        
 
13
        public PTSection(int number){
 
14
                this.number = number;
 
15
                this.positions = new ArrayList();
 
16
        }
 
17
        
 
18
        public int getNumber(){
 
19
                return this.number;
 
20
        }
 
21
        
 
22
        public int getStaffs() {
 
23
                return this.staffs;
 
24
        }
 
25
        
 
26
        public void setStaffs(int staffs) {
 
27
                this.staffs = staffs;
 
28
        }
 
29
        
 
30
        public List getPositions(){
 
31
                return this.positions;
 
32
        }
 
33
        
 
34
        public PTPosition getPosition(int position){
 
35
                Iterator it = getPositions().iterator();
 
36
                while(it.hasNext()){
 
37
                        PTPosition p = (PTPosition)it.next();
 
38
                        if(p.getPosition() == position){
 
39
                                return p;
 
40
                        }
 
41
                }
 
42
                PTPosition p = new PTPosition(position);
 
43
                getPositions().add(p);
 
44
                return p;
 
45
        }
 
46
        
 
47
        public int getNextPositionNumber(){
 
48
                int next = 0;
 
49
                Iterator it = getPositions().iterator();
 
50
                while(it.hasNext()){
 
51
                        PTPosition p = (PTPosition)it.next();
 
52
                        next = Math.max(next, (p.getPosition() + 1) );
 
53
                }
 
54
                return next;
 
55
        }
 
56
        
 
57
        public void sort(){
 
58
                int count = getPositions().size();
 
59
                for(int i = 0;i < count;i++){
 
60
                        PTPosition minimun = null;
 
61
                        for(int j = i;j < count;j++){
 
62
                                PTPosition position = (PTPosition)getPositions().get(j);
 
63
                                if(minimun == null || position.getPosition() < minimun.getPosition()){
 
64
                                        minimun = position;
 
65
                                }
 
66
                        }
 
67
                        getPositions().remove(minimun);
 
68
                        getPositions().add(i,minimun);
 
69
                }
 
70
        }
 
71
}