Package: DbgpRequest

DbgpRequest

nameinstructionbranchcomplexitylinemethod
DbgpRequest(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
DbgpRequest(String, boolean)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
addOption(String, Object)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
addOption(String, int)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 35 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getCommand()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getData()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOption(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPacketAsString()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hasOption(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isAsync()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
optionCount()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setData(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
toString()
M: 55 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
writeTo(OutputStream)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.core.dbgp;
23:
24: import java.io.IOException;
25: import java.io.OutputStream;
26: import java.util.HashMap;
27: import java.util.Iterator;
28: import java.util.Map;
29: import java.util.Map.Entry;
30:
31: import org.overture.ide.debug.core.dbgp.internal.utils.Base64Helper;
32: import org.overture.ide.debug.utils.StrUtils;
33:
34: public class DbgpRequest implements IDbgpRawPacket
35: {
36:         private final Map<String, String> options;
37:
38:         private final String command;
39:         private final boolean async;
40:
41:         private String data;
42:
43:         public DbgpRequest(String command)
44:         {
45:                 this(command, false);
46:         }
47:
48:         public DbgpRequest(String command, boolean async)
49:         {
50:                 this.command = command;
51:                 this.async = async;
52:                 this.options = new HashMap<String, String>();
53:         }
54:
55:         public String getCommand()
56:         {
57:                 return command;
58:         }
59:
60:         public void addOption(String optionNmae, int optionValue)
61:         {
62:                 addOption(optionNmae, new Integer(optionValue));
63:         }
64:
65:         public void addOption(String optionName, Object optionValue)
66:         {
67:•                if (optionValue == null)
68:                 {
69:                         throw new IllegalArgumentException();
70:                 }
71:
72:                 options.put(optionName, optionValue.toString());
73:         }
74:
75:         public String getOption(String optionName)
76:         {
77:                 return (String) options.get(optionName);
78:         }
79:
80:         public boolean hasOption(String optionName)
81:         {
82:                 return options.containsKey(optionName);
83:         }
84:
85:         public int optionCount()
86:         {
87:                 return options.size();
88:         }
89:
90:         public void setData(String data)
91:         {
92:                 this.data = data;
93:         }
94:
95:         public String getData()
96:         {
97:                 return this.data;
98:         }
99:
100:         public String toString()
101:         {
102:                 StringBuffer sb = new StringBuffer(command);
103:
104:                 Iterator<Entry<String, String>> it = options.entrySet().iterator();
105:
106:•                while (it.hasNext())
107:                 {
108:                         Entry<String, String> entry = it.next();
109:
110:                         sb.append(' ');
111:                         sb.append(entry.getKey());
112:                         sb.append(' ');
113:                         sb.append(entry.getValue());
114:                 }
115:
116:•                if (data != null)
117:                 {
118:                         sb.append(" -- "); //$NON-NLS-1$
119:                         sb.append(Base64Helper.encodeString(data));
120:                 }
121:
122:                 return sb.toString();
123:         }
124:
125:         public boolean equals(Object o)
126:         {
127:•                if (o instanceof DbgpRequest)
128:                 {
129:                         DbgpRequest request = (DbgpRequest) o;
130:
131:•                        return command.equals(request.command) && async == request.async
132:•                                        && options.equals(request.options)
133:•                                        && StrUtils.equals(data, request.data);
134:                 }
135:
136:                 return false;
137:         }
138:
139:         /**
140:          * @return the async
141:          */
142:         public boolean isAsync()
143:         {
144:                 return async;
145:         }
146:
147:         public void writeTo(OutputStream output) throws IOException
148:         {
149:                 // TODO optimize - send directly to stream without string
150:                 output.write(toString().getBytes("ASCII")); //$NON-NLS-1$
151:         }
152:
153:         public String getPacketAsString()
154:         {
155:                 return toString();
156:         }
157: }