HashOjbect之HashObjectMap(5)

private abstract class HashIterator implements Iterator<T> {
BaseHashObject next; // next entry to return
int expectedModCount; // For fast-fail
int index; // current slot
BaseHashObject current; // current entry

HashIterator() {
expectedModCount = modCount;
if (size > 0) { // advance to first entry
BaseHashObject[] t = table;
while (index < t.length && (next = t[index++]) == null)
;
}
}

public final boolean hasNext() {
return next != null;
}

final T nextObject() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
BaseHashObject e = next;
if (e == null)
throw new NoSuchElementException();

if ((next = e.getNext()) == null) {
BaseHashObject[] t = table;
while (index < t.length && (next = t[index++]) == null)
;
}
current = e;
return (T)e;
}

public void remove() {
if (current == null)
throw new IllegalStateException();
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
BaseHashObject k = current;
current = null;
HashObjectMap.this.remove(k);
expectedModCount = modCount;
}

}

public Collection<T> objects() {
return new Objects();
}

private final class Objects extends AbstractCollection<T> {
public Iterator<T> iterator() {
return newObjectIterator();
}
public int size() {
return size;
}
public boolean contains(BaseHashObject o) {
return containsObject(o);
}
public void clear() {
HashObjectMap.this.clear();
}
}
public void putAll(Collection<BaseHashObject> objects) {
int numKeysToBeAdded = objects.size();
if (numKeysToBeAdded == 0)
return;

/*
* Expand the map if the map if the number of mappings to be added
* is greater than or equal to threshold. This is conservative; the
* obvious condition is (m.size() + size) >= threshold, but this
* condition could result in a map with twice the appropriate capacity,
* if the keys to be added overlap with the keys already in this map.
* By using the conservative calculation, we subject ourself
* to at most one extra resize.
*/
if (numKeysToBeAdded > threshold) {
int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1);
if (targetCapacity > MAXIMUM_CAPACITY)
targetCapacity = MAXIMUM_CAPACITY;
int newCapacity = table.length;
while (newCapacity < targetCapacity)
newCapacity <<= 1;
if (newCapacity > table.length)
resize(newCapacity);
}

for (Iterator<BaseHashObject> i = objects.iterator(); i.hasNext(); ) {
put(i.next());
}
}
}
资源下载链接为: https://pan.quark.cn/s/7cc20f916fe3 以下是对“js做的期末项目”的介绍:这是一个以童话为主题的前端开发作品,通过一系列功能实现,打造出了一个互动性强且视觉效果吸引人的用户界面,充分展现了作者对JavaScript语言的掌握程度。在项目中,作者运用了诸多JavaScript知识点。首先是DOM操作,JavaScript与HTML文档对象模型(DOM)紧密相连,可动态地创建、修改或删除页面元素,像document.getElementById()、document.querySelector()或document.querySelectorAll()等方法,就可能被用于选择和操作DOM节点。其次,为实现用户交互,例如轮播图切换等功能,addEventListener()函数被用来添加事件监听器,涵盖点击、滑动等事件,事件处理函数则依据用户行为执行相应逻辑。再者,JavaScript能够改变元素的CSS样式,通过element.style.property = value的方式,实现诸如轮播图过渡动画、照片墙图片淡入淡出等动态效果。在处理照片墙等涉及集合数据的场景时,数组的遍历方法,如forEach()、for...of循环或map()等,可能会被用到,以便显示或操作多个元素。闭包(Closure)在项目中也发挥了作用,它常用于封装私有变量和函数,保障数据安全,同时实现一些特定功能,像计时器控制等。为了实现自动轮播等功能,setTimeout()或setInterval()函数被用来定期执行任务,比如切换图片。在控制程序流程方面,if...else、switch语句以及逻辑运算符&&、||、!不可或缺,它们依据条件执行不同的代码块。函数是JavaScript的重要组成部分,项目中可能定义了多个函数,包括初始化页面、处理用户输入
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值