Code Duplication    Length = 100-102 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/executive/pdb/ExecutivePlanDataBase.java 2 locations

@@ 291-392 (lines=102) @@
288
			}
289
			
290
			// check observations
291
			for (TimelineProtocolDescriptor tl : plan.getObservations()) {
292
				
293
				// setup node arrays
294
				ExecutionNode[] list = new ExecutionNode[tl.getTokens().size()];
295
				// list index
296
				int counter = 0;
297
				// create an execution node for each token
298
				for (TokenProtocolDescriptor token : tl.getTokens()) {
299
					// check predicate
300
					if (!token.getPredicate().toLowerCase().equals("unallocated")) {
301
						
302
						// get token's bound
303
						long[] start = token.getStartTimeBounds();
304
						long[] end = token.getEndTimeBounds();
305
						long[] duration = token.getDurationBounds();
306
						
307
						// check controllability type
308
						// set default controllability type
309
						ControllabilityType controllability = null;
310
						// check specific type
311
						if (tl.isExternal()) {
312
							
313
							// uncontrollable 
314
							controllability = ControllabilityType.UNCONTROLLABLE;
315
							
316
						} else if (token.getPredicate().startsWith("_")) {
317
							
318
							// partially controllable token
319
							controllability = ControllabilityType.PARTIALLY_CONTROLLABLE;
320
							
321
						} else {
322
							
323
							// controllable token
324
							controllability = ControllabilityType.CONTROLLABLE;
325
						}
326
						
327
						// set parameter information
328
						String signature = token.getPredicate();
329
						String[] paramValues = new String[token.getParameters().size()];
330
						ParameterType[] paramTypes = new ParameterType[token.getParameters().size()];
331
						for (int index = 0; index < token.getParameters().size(); index++) {
332
							
333
							// get parameter
334
							ParameterDescriptor param= token.getParameter(index);
335
							// check type
336
							if (param.getType().equals(ParameterTypeDescriptor.NUMERIC)) {
337
								// set t							ype
338
								paramTypes[index] = ParameterType.NUMERIC_PARAMETER_TYPE;
339
								// set value
340
								paramValues[index] = Long.toString(param.getBounds()[0]);
341
								
342
							} else {
343
								
344
								// enumeration
345
								paramTypes[index] = ParameterType.ENUMERATION_PARAMETER_TYPE;
346
								// set value
347
								paramValues[index] = param.getValues()[0];
348
							}
349
						}
350
						
351
						// create a node
352
						ExecutionNode node = this.createNode(tl.getComponent(), tl.getName(), 
353
								signature, paramTypes, paramValues, 
354
								start, end, duration, controllability, token.getStartExecutionState());
355
						
356
						// add node
357
						this.addNode(node);
358
						// add entry to the dictionary
359
						dictionary.put(token, node);
360
						
361
						// add node to list
362
						list[counter] = node;
363
						counter++;
364
					}
365
					
366
				}
367
				
368
				// link subsequent nodes
369
				for (int pos = 0; pos < list.length; pos++) {
370
					
371
					// check first node
372
					if (pos == 0) {
373
						
374
						// first node of the timeline
375
						ExecutionNode first = list[pos];
376
						// set next node
377
						first.setNext(list[pos+1]);
378
						
379
					} else if (pos == list.length - 1) {
380
						// last node of the timeline
381
						ExecutionNode last = list[pos];
382
						// set previous ndoe
383
						last.setPrev(list[pos-1]);
384
						
385
					} else {
386
						
387
						// intermediate node
388
						ExecutionNode i = list[pos];
389
						// set prev
390
						i.setPrev(list[pos-1]);
391
						// set next
392
						i.setNext(list[pos+1]);
393
					}
394
				}
395
			}
@@ 185-284 (lines=100) @@
182
			// map token descriptor to nodes
183
			Map<TokenProtocolDescriptor, ExecutionNode> dictionary = new HashMap<>();
184
			// check time-lines
185
			for (TimelineProtocolDescriptor tl : plan.getTimelines()) {
186
				
187
				// setup node arrays
188
				ExecutionNode[] list = new ExecutionNode[tl.getTokens().size()];
189
				// list index
190
				int counter = 0;
191
				// create an execution node for each token
192
				for (TokenProtocolDescriptor token : tl.getTokens()) {
193
					// check predicate
194
					if (!token.getPredicate().toLowerCase().equals("unallocated")) {
195
						
196
						// get token's bound
197
						long[] start = token.getStartTimeBounds();
198
						long[] end = token.getEndTimeBounds();
199
						long[] duration = token.getDurationBounds();
200
						
201
						// set default controllability type
202
						ControllabilityType controllability = null;
203
						// check specific type
204
						if (tl.isExternal()) {
205
							// uncontrollable 
206
							controllability = ControllabilityType.UNCONTROLLABLE;
207
							
208
						} else if (token.getPredicate().startsWith("_")) {
209
							// partially controllable token
210
							controllability = ControllabilityType.PARTIALLY_CONTROLLABLE;
211
							
212
						} else {
213
							// controllable
214
							controllability = ControllabilityType.CONTROLLABLE; 
215
						}
216
						
217
						// set parameter information
218
						String signature = token.getPredicate();
219
						String[] paramValues = new String[token.getParameters().size()];
220
						ParameterType[] paramTypes = new ParameterType[token.getParameters().size()];
221
						for (int index = 0; index < token.getParameters().size(); index++) {
222
							
223
							// get parameter
224
							ParameterDescriptor param= token.getParameter(index);
225
							// check type
226
							if (param.getType().equals(ParameterTypeDescriptor.NUMERIC)) 
227
							{
228
								// set type
229
								paramTypes[index] = ParameterType.NUMERIC_PARAMETER_TYPE;
230
								// set value
231
								paramValues[index] = Long.toString(param.getBounds()[0]); 
232
							}
233
							else 
234
							{
235
								// enumeration
236
								paramTypes[index] = ParameterType.ENUMERATION_PARAMETER_TYPE;
237
								// set value
238
								paramValues[index] = param.getValues()[0];
239
							}
240
						}
241
						
242
						// create a node
243
						ExecutionNode node = this.createNode(tl.getComponent(), tl.getName(), 
244
								signature, paramTypes, paramValues, 
245
								start, end, duration, controllability, token.getStartExecutionState());
246
						
247
						// add node
248
						this.addNode(node);
249
						// add entry to the dictionary
250
						dictionary.put(token, node);
251
						
252
						// add node to list
253
						list[counter] = node;
254
						counter++;
255
					}
256
				}
257
				
258
				// link subsequent nodes
259
				if (list.length > 1)  {
260
					for (int pos = 0; pos < list.length; pos++) {
261
						
262
						// check first node
263
						if (pos == 0) {
264
						
265
							// first node of the timeline
266
							ExecutionNode first = list[pos];
267
							// set next node
268
							first.setNext(list[pos+1]);
269
							
270
						} else if (pos == list.length - 1) {
271
							
272
							// last node of the timeline
273
							ExecutionNode last = list[pos];
274
							// set previous node
275
							last.setPrev(list[pos-1]);
276
							
277
						} else {
278
							
279
							// intermediate node
280
							ExecutionNode i = list[pos];
281
							// set previous
282
							i.setPrev(list[pos-1]);
283
							// set next
284
							i.setNext(list[pos+1]);
285
						}
286
					}
287
				}