Code Duplication    Length = 100-102 lines in 2 locations

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

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