Code Duplication    Length = 44-47 lines in 2 locations

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

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