Code Duplication    Length = 44-48 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/framework/time/tn/TemporalNetwork.java 2 locations

@@ 331-378 (lines=48) @@
328
	 * @return
329
	 * @throws InconsistentTpValueException
330
	 */
331
	public final TimePoint addTimePoint(long at) 
332
			throws InconsistentTpValueException, InconsistentDistanceConstraintException {
333
		
334
		// check desired value
335
		if (at < this.origin || at > this.horizon) {
336
			// inconsistent value
337
			throw new InconsistentTpValueException("TimePoint value (= " + at +") out of the domain [origin= " + this.origin + ", horizon= " + this.horizon);
338
		}
339
		
340
		// create a time point or use a previous created one
341
		TimePoint tp = null;
342
		// extract the first element
343
		Iterator<TimePoint> it = this.recyclePoints.iterator();
344
		// check recycled time points first
345
		if (it.hasNext()) {
346
			// extract next time point
347
			tp = it.next();
348
			// set bounds
349
			tp.setDomLb(at);
350
			tp.setDomUb(at);
351
			// remove time point from the underlying set
352
			it.remove();
353
		}
354
		else {
355
			
356
			// create time point
357
			tp = new TimePoint(COUNTER.getAndIncrement(), at, at);
358
		}
359
		
360
		// add time point to the network
361
		this.doAddTimePoint(tp);
362
363
		// create notification
364
		AddTimePointTemporalNetworkNotification info = TemporalNetworkNotificationFactory.createNotification(TemporalNetworkNotificationTypes.ADD_TP);
365
		info.addTimePoint(tp);
366
		
367
		
368
		// check observers
369
		synchronized (this.observers) {
370
			// notify observers
371
			for (TemporalNetworkObserver obs : this.observers) {
372
				// do notify
373
				obs.notify(info);
374
			}
375
		}
376
377
		// return new time point
378
		return tp;
379
	}
380
	
381
	/**
@@ 389-432 (lines=44) @@
386
	 * @throws InconsistentTpValueException
387
	 * @throws InconsistentDistanceConstraintException
388
	 */
389
	public final TimePoint addTimePoint(long lb, long ub) 
390
			throws InconsistentTpValueException, InconsistentDistanceConstraintException
391
	{
392
		// check domain
393
		if (lb > ub || lb < this.origin || ub > this.horizon) {
394
			// inconsistent value
395
			throw new InconsistentTpValueException("TimePoint (lb= " + lb +", ub= " + ub + ") is inconsistent or it is out of the domain [origin= " + this.origin + ", horizon= " + this.horizon);
396
		}
397
		
398
		// create a time point or use a previous created one
399
		TimePoint tp = null;
400
		// extract the first element
401
		Iterator<TimePoint> it = this.recyclePoints.iterator();
402
		// check recycled time points first
403
		if (it.hasNext()) {
404
			// extract next time point
405
			tp = it.next();
406
			// set desired bounds
407
			tp.setDomLb(lb);
408
			tp.setDomUb(ub);
409
			// remove time point from the set
410
			it.remove();
411
		}
412
		else {
413
			// create time point
414
			tp = new TimePoint(COUNTER.getAndIncrement(), lb, ub);
415
		}
416
		
417
		// add time point to the network
418
		this.doAddTimePoint(tp);
419
		// create notification
420
		AddTimePointTemporalNetworkNotification info = TemporalNetworkNotificationFactory.createNotification(TemporalNetworkNotificationTypes.ADD_TP);
421
		info.addTimePoint(tp);
422
		
423
		// check observers
424
		synchronized (this.observers) {
425
			// notify observers
426
			for (TemporalNetworkObserver obs : this.observers) {
427
				obs.notify(info);
428
			}
429
		}
430
431
		// return new time point
432
		return tp;
433
	}
434
	
435
	/**