~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/org/jcsp/net2/NetConnectionLocation.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * 
 
3
 */
 
4
package org.jcsp.net2;
 
5
 
 
6
import java.io.Serializable;
 
7
 
 
8
/**
 
9
 * @author Kevin
 
10
 */
 
11
public final class NetConnectionLocation
 
12
    extends NetLocation
 
13
    implements Serializable
 
14
{
 
15
    /**
 
16
     * The SUID representing this class
 
17
     */
 
18
    private static final long serialVersionUID = 1L;
 
19
 
 
20
    /**
 
21
     * The NodeID portion of the location
 
22
     */
 
23
    private final NodeID nodeID;
 
24
 
 
25
    /**
 
26
     * The vconnn portion of the location
 
27
     */
 
28
    private final int vconnn;
 
29
 
 
30
    /**
 
31
     * Creates a new NetConnectionLocation
 
32
     * 
 
33
     * @param aNodeID
 
34
     *            The NodeID part of the location
 
35
     * @param aVConnN
 
36
     *            The vconnn part of the location
 
37
     */
 
38
    public NetConnectionLocation(NodeID aNodeID, int aVConnN)
 
39
    {
 
40
        this.nodeID = aNodeID;
 
41
        this.vconnn = aVConnN;
 
42
    }
 
43
 
 
44
    /**
 
45
     * Gets the NodeID part of the location
 
46
     * 
 
47
     * @return The NodeID part of the NetConnectionLocation
 
48
     */
 
49
    public NodeID getNodeID()
 
50
    {
 
51
        return this.nodeID;
 
52
    }
 
53
 
 
54
    /**
 
55
     * Gets the NodeAddress part of the location
 
56
     * 
 
57
     * @return The NodeAddress part of the NetConnectionLocation
 
58
     */
 
59
    public NodeAddress getNodeAddress()
 
60
    {
 
61
        return this.nodeID.getNodeAddress();
 
62
    }
 
63
 
 
64
    /**
 
65
     * Gets the vconnn part of the location
 
66
     * 
 
67
     * @return The VConnN part of the NetConnectionLocation
 
68
     */
 
69
    public int getVConnN()
 
70
    {
 
71
        return this.vconnn;
 
72
    }
 
73
 
 
74
    /**
 
75
     * Converts the NetConnectionLocation object into a string representation of the form nconnl://[NodeID]/[VConnN]
 
76
     * 
 
77
     * @return The String form of the NetConnectionLocation
 
78
     */
 
79
    public String toString()
 
80
    {
 
81
        return "nconnl://" + this.nodeID.toString() + "/" + this.vconnn;
 
82
    }
 
83
 
 
84
    /**
 
85
     * Converts the string form of a NetConnectionLocation back into its object form
 
86
     * 
 
87
     * @param str
 
88
     *            The string representation of a NetConnectionLocation
 
89
     * @return A new NetConnectionLocation created from the String representation
 
90
     */
 
91
    public static NetConnectionLocation parse(String str)
 
92
    {
 
93
        if (str.equalsIgnoreCase("null"))
 
94
            return null;
 
95
        if (str.startsWith("nconnl://"))
 
96
        {
 
97
            String toParse = str.substring(6);
 
98
            String[] addressBits = toParse.split("/");
 
99
            NodeID nodeID = NodeID.parse(addressBits[0]);
 
100
            int vcn = Integer.parseInt(addressBits[1]);
 
101
            return new NetConnectionLocation(nodeID, vcn);
 
102
        }
 
103
        throw new IllegalArgumentException("String is not a string form of a NetConnectionLocation");
 
104
    }
 
105
}