SS-Lab3 IntervalSet Interface设计

一、顶层(基本)接口 IntervalSet Interface

该接口对 labelinterval 的对应关系不做要求,仅定义 IntervalSet 应具有基本方法

  • insert() : 向 IntervalSet 中插入一个时间段 interval
/**
 * @method insert
 * @param1 start of interval
 * @param2 end of interval
 * @param3 label of interval
 * @function
 * 		insert an interval of (start, end, label) into the IntervalSet
 * */
public void insert(long start, long end, L label);
  • labels() : 返回 IntervalSet 中的所有时间段 interval 的标签 label 的集合
/**
 * @method labels
 * @return	
 * 		a set of all the labels in the IntervalSet
 * */
public Set<L> labels();
  • intervalsCount() : 返回 *IntervalSet* 中的时间段 interval 总数
/**
 * @method intervalsCount
 * @return
 * 		the count of the intervals in the IntervalSet
 * */
public int intervalsCount();
  • remove : 从 IntervalSet 中移除属于某个标签 label 的所有时间段 interval
/**
 * @method remove
 * @param label to be removed
 * @return	
 * 		true if this label is in the IntervalSet and remove it successfully
 * 		false if not and do nothing
 * */
public boolean remove(L label);
  • minIntervalStart : 返回 IntervalSet 中具有的最小的开始时间
/**
 * @method minIntervalStart
 * @return
 * 		the min start of intervals in the IntervalSet
 * 
 * */
public long minIntervalStart();
  • maxIntervalEnd : 返回 IntervalSet 中具有的最大的结束时间
/**
 * @method maxIntervalEnd
 * @return
 * 		the max end of intervals in the IntervalSet
 * 
 * */
public long maxIntervalEnd();

二、基于标签可对应时间段数量分类的实现类

CommonIntervalSet 一个标签只能对应一个时间段

该类增加的方法

  • start : 返回标签 label 对应的时间段 interval 的开始时间
/**
 * @method start
 * @param label of interval
 * @return 
 * 		start of this label
 * 		-1 if this label not exists
 * */
public long start(L label);
  • end : 返回标签 label 对应的时间段 interval 的结束时间
/**
 * @method end
 * @param label of interval
 * @return 
 * 		end of this label
 * 		-1 if this label not exists
 * */
public long end(L label);

MultiIntervalSet 一个标签可以对应多个时间段

该类增加的方法

  • isSelfOverlapped : 判断即将被标记为属于标签 label 的时间段 interval,是否和该标签 label 的其他时间段 intervals 存在重合
/**
 * @method isSelfOverlapped
 * @param1 start of interval
 * @param2 end of interval
 * @param3 label of interval
 * @return
 * 		true if the new interval is overlapped with other intervals of this label
 * 		false if not
 * */
public boolean isSelfOverlapped(long start, long end, L label);
  • intervals : 返回以开始时间升序排列的,属于一个标签 label 的所有时间段 intervals
/**
 * @method intervals
 * @param the label to get intervals
 * @return 
 * 		a list of intervals of this label sorted by the start of intervals
 * 		null if this label is not in the labels
 * */
public CommonIntervalSet<Integer> intervals(L label);

猜你喜欢

转载自blog.csdn.net/weixin_39578432/article/details/118395069