summaryrefslogtreecommitdiff
path: root/comms/rxtx/files/patch-src-gnu-io-CommPortEnumerator.java
blob: 7ba631e273b25cebc57bb20896b643515d2fe619 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--- src/gnu/io/CommPortEnumerator.java.orig	2007-04-26 05:26:05 UTC
+++ src/gnu/io/CommPortEnumerator.java
@@ -69,50 +69,79 @@ import java.util.Enumeration;
 class CommPortEnumerator implements Enumeration
 {
 	private CommPortIdentifier index;
-	private final static boolean debug = false;
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
 	static
 	{
-		if (debug)
-			System.out.println("CommPortEnumerator:{}");
+		if (debug) System.out.println("CommPortEnumerator:Static{}");
 	}
 
 	CommPortEnumerator()
 	{
 	}
-/*------------------------------------------------------------------------------
-        nextElement()
-        accept:
-        perform:
-        return:
-        exceptions:
-        comments:
-------------------------------------------------------------------------------*/
+
 	public Object nextElement()
 	{
-		if(debug) System.out.println("CommPortEnumerator:nextElement()");
+		if (debug) System.out.println("CommPortEnumerator:nextElement()");
+		
 		synchronized (CommPortIdentifier.Sync)
 		{
-			if(index != null) index = index.next;
-			else index=CommPortIdentifier.CommPortIndex;
+			if(index != null)
+			{
+				index = index.next;
+			}
+			else
+			{
+				index=CommPortIdentifier.CommPortIndex;
+			}
+			if (debug) System.out.println(" CommPortEnumerator:nextElement(" + index + ")");
 			return(index);
 		}
 	}
-/*------------------------------------------------------------------------------
-        hasMoreElements()
-        accept:
-        perform:
-        return:
-        exceptions:
-        comments:
-------------------------------------------------------------------------------*/
+
 	public boolean hasMoreElements()
 	{
-		if(debug) System.out.println("CommPortEnumerator:hasMoreElements() " + CommPortIdentifier.CommPortIndex == null ? false : true );
+		if (debug) System.out.println("CommPortEnumerator:hasMoreElements()");
+		
+		if (CommPortIdentifier.CommPortIndex == null)
+		{
+			 if (debug) System.out.println(" ComPortIndex is null...");
+		}
+		else
+		{
+			if (debug) System.out.println(" ComPortIndex is not null...");
+		}
+		
 		synchronized (CommPortIdentifier.Sync)
 		{
-			if(index != null) return index.next == null ? false : true;
-			else return CommPortIdentifier.CommPortIndex == null ?
-				false : true;
+			if (debug) System.out.println(" Syncronised");
+			if(index != null) 
+			{
+				if (debug) System.out.println(" Valid index");
+				if (index.next == null)
+				{
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(Next index is null - false)");
+					return false;
+				}
+				else
+				{
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(Next index is not null - true)");
+					return true;
+				}
+			}
+			else 
+			{
+				if (debug) System.out.println(" Index is not valid");
+				if (CommPortIdentifier.CommPortIndex == null)
+				{
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(CommPortIdentifier.CommPortIndex is null - false)");
+					return false;
+				}
+				else
+				{
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(CommPortIdentifier.CommPortIndex is not null - true)");
+					return true;
+				}
+			}
 		}
 	}
 }