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

« back to all changes in this revision

Viewing changes to src/org/jcsp/net/settings/LinkProfiles.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
//  JCSP ("CSP for Java") Libraries                                 //
 
4
//  Copyright (C) 1996-2008 Peter Welch and Paul Austin.            //
 
5
//                2001-2004 Quickstone Technologies Limited.        //
 
6
//                                                                  //
 
7
//  This library is free software; you can redistribute it and/or   //
 
8
//  modify it under the terms of the GNU Lesser General Public      //
 
9
//  License as published by the Free Software Foundation; either    //
 
10
//  version 2.1 of the License, or (at your option) any later       //
 
11
//  version.                                                        //
 
12
//                                                                  //
 
13
//  This library is distributed in the hope that it will be         //
 
14
//  useful, but WITHOUT ANY WARRANTY; without even the implied      //
 
15
//  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR         //
 
16
//  PURPOSE. See the GNU Lesser General Public License for more     //
 
17
//  details.                                                        //
 
18
//                                                                  //
 
19
//  You should have received a copy of the GNU Lesser General       //
 
20
//  Public License along with this library; if not, write to the    //
 
21
//  Free Software Foundation, Inc., 59 Temple Place, Suite 330,     //
 
22
//  Boston, MA 02111-1307, USA.                                     //
 
23
//                                                                  //
 
24
//  Author contact: P.H.Welch@kent.ac.uk                             //
 
25
//                                                                  //
 
26
//                                                                  //
 
27
//////////////////////////////////////////////////////////////////////
 
28
 
 
29
package org.jcsp.net.settings;
 
30
 
 
31
import java.util.*;
 
32
import org.jcsp.net.*;
 
33
 
 
34
/**
 
35
 * Used internally within the JCSP network infrastructure to represent a set of link profiles.
 
36
 *
 
37
 * @author Quickstone Technologies Limited
 
38
 */
 
39
public class LinkProfiles
 
40
{
 
41
   public void addProfile(LinkProfile p)
 
42
   {
 
43
      if(p != null)
 
44
      {
 
45
         if(!profiles.contains(p) && !profileNameMap.containsKey(p.getName()))
 
46
         {
 
47
            profiles.put(p, p);
 
48
            profileNameMap.put(p.getName(), p);
 
49
            lastProfile = p;
 
50
         }
 
51
         else
 
52
            throw new LinkProfileAlreadyExistsException("Already have a profile named " + p.getName());
 
53
      }
 
54
      else
 
55
         Node.err.log(this, "Error: Null profile");
 
56
   }
 
57
   
 
58
   public void removeProfile(LinkProfile p)
 
59
   {
 
60
      if(profiles.contains(p))
 
61
      {
 
62
         profiles.remove(p);
 
63
         profileNameMap.remove(p.getName());
 
64
      }
 
65
   }
 
66
   
 
67
   public LinkProfile getProfile(String name)
 
68
   {
 
69
      return (LinkProfile) profileNameMap.get(name);
 
70
   }
 
71
   
 
72
   public LinkProfile[] getProfiles()
 
73
   {
 
74
      LinkProfile[] toReturn = new LinkProfile[profiles.size()];
 
75
      return (LinkProfile[])profiles.keySet().toArray(toReturn);
 
76
   }
 
77
   
 
78
   public LinkProfile getLastProfile()
 
79
   {
 
80
      return lastProfile;
 
81
   }
 
82
   
 
83
   public String toString()
 
84
   {
 
85
      StringBuffer sb = new StringBuffer();
 
86
      sb.append("<LinkProfiles>\n");
 
87
      LinkProfile[] profiles = getProfiles();
 
88
      for(int i=0; i<profiles.length; i++)
 
89
         sb.append(JCSPConfig.tabIn(profiles[i].toString())).append("\n");
 
90
      sb.append("</LinkProfiles>");
 
91
      return sb.toString();
 
92
   }
 
93
   
 
94
   private Hashtable profiles = new Hashtable();
 
95
   private Hashtable profileNameMap = new Hashtable();
 
96
   private LinkProfile lastProfile = null;
 
97
   
 
98
   static class LinkProfileAlreadyExistsException extends RuntimeException
 
99
   {
 
100
      private LinkProfileAlreadyExistsException(String msg)
 
101
      {
 
102
         super(msg);
 
103
      }
 
104
   }
 
105
}
 
 
b'\\ No newline at end of file'