在这篇文章中,我们将为您详细介绍count的内容,并且讨论关于与量角器中的长度的相关问题。此外,我们还会涉及一些关于Android:ListView中的getCount()和getChildCount
在这篇文章中,我们将为您详细介绍count的内容,并且讨论关于与量角器中的长度的相关问题。此外,我们还会涉及一些关于Android:ListView中的getCount()和getChildCount()之间的区别、Angular:量角器 – count()没有解析并导致超时、Collectors.summingInt()与mapToInt()sum()、Collectors.summingInt()与mapToInt()。sum()的知识,以帮助您更全面地了解这个主题。
本文目录一览:- count()与量角器中的长度(量角器chn是什么意思的缩写)
- Android:ListView中的getCount()和getChildCount()之间的区别
- Angular:量角器 – count()没有解析并导致超时
- Collectors.summingInt()与mapToInt()sum()
- Collectors.summingInt()与mapToInt()。sum()
count()与量角器中的长度(量角器chn是什么意思的缩写)
根据文档,有两种方法可以获取ElementArrayFinder
(element.all()
调用结果)内部有多少个元素:
$$(".myclass").length
,记录在这里:
…该数组
length
等于length
由找到的元素的ElementArrayFinder
,每个结果代表对该元素执行操作的结果。
$$(".myclass").count()
,记录在这里:
计算表示的元素数量
ElementArrayFinder
。
这两种方法有什么区别,应首选哪一种?
答案1
小编典典$$(".myclass").length
需要解决诺言以正确获取元素的长度。
// WORK$$(".myclass").then(function(items){ items.length;});// DOES NOT WORK$$(".myclass").length;
$$(".myclass").count()
一个包装器,$$(''.myclass'').length
它本身就是一个承诺,不需要解决承诺,例如.length
$$(".myclass").count();
哪一个应该是首选?
除非在进行定位$$(".myclass")
和.then(function(items){...})
参与时有一些复杂的业务,否则items.length
它将提供更好的性能。
否则$$(".myclass").count()
应始终使用。
Android:ListView中的getCount()和getChildCount()之间的区别
有什么区别getCount()
和getChildCount()
在ListView
?
答案1
小编典典getCount()
返回您适配器中项目的数量(列表中的总数),getChildCount()
是一种ViewGroup
返回子视图数量的方法。ListView
主动重用视图,因此,如果您的列表中有1000个项目,getCount()
则返回1000,getChildCount()
大约是10左右…
Angular:量角器 – count()没有解析并导致超时
carousel.po.ts
import { browser,element,by,Key } from 'protractor'; export class CarouselDemoPage { navigateto() { return browser.get('/design/carousel'); } getCarouselComponent(index: number) { return element.all(by.css('cfc-carousel')).get(index); } getCarouselIndicators(index: number) { return this.getCarouselComponent(index).element(by.css('.indicators')).all(by.repeater('item in items')); } }
我的spec文件:
import { CarouselDemoPage } from './carousel.po'; describe('Carousel component',() => { let page: CarouselDemoPage; beforeEach(() => { page = new CarouselDemoPage(); page.navigateto(); }); it('At least one carousel component should exist',() => { expect<any>(page.getCarouselComponent(0)).tobedefined(); }); it('Check correct number of indicators displayed',() => { expect<any>(page.getCarouselIndicators(0).count()).toEqual(4); }); });
我有最新的或接近最新的至少包
“@angular/core”: “^5.0.0-beta.7”,
“jasmine-core”: “~2.8.0”,
“protractor”: “~5.1.2”
第一次测试运行正常,第二次测试结束时间
1)轮播组件检查显示的正确指示器数量
– 失败:超时等待异步Angular任务在20秒后完成.这可能是因为当前页面不是Angular应用程序.有关详细信息,请参阅常见问题解答:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
在等待带定位符的元素时 – Locator:By(css selector,cfc-custom-select)
放弃
我在ngAfterViewInit()中有setTimeout
这里:
ngAfterViewInit() { // Needs the timeout to avoid the "expression has changed" bug setTimeout(() => { this.items = this.viewItems.toArray().concat(this.contentItems.toArray()); this.totalItems = this.items.length; this._first = this.items[0]; this._last = this.items[this.totalItems - 1]; this._setItemsOrder(this.currentFrame); this._setInterval(); },0); }
因此,我尝试了
browser.ignoreSynchronization = true;
和
browser.driver.sleep(50);
和
browser.waitForAngular();
但后来我把数量计算为0
所以经过一些调试后我发现我的轮播组件中的setInterval会破坏测试
我应该使用browser.ignoreSynchronization = true; ??
有任何想法吗?
browser.ignoreSynchronization = true;
我稍微修改了我的getCarouselIndicators函数
成为:
getCarouselIndicators(index: number) { browser.ignoreSynchronization = true; return this.getCarouselComponent(index).all(by.css('.indicators li')); }
现在测试解决并完美运行!
Collectors.summingInt()与mapToInt()sum()
如何解决Collectors.summingInt()与mapToInt()sum()?
您正在看两个否则不同的用例的交集。使用mapToInt(…)
可使您IntStream
在终端操作之前链接其他操作。相反,Collectors.summingInt(…)
可以与其他收集器组合,例如用作收集器中的下游收集groupingBy
器。对于这些用例,毫无疑问要使用哪个。
在您的特殊情况下,当您不链接更多操作或不首先与收集器打交道时,这两种方法之间没有根本区别。尽管如此,使用更具可读性的方法还是有道理的。通常,当流上存在预定义的操作时,您就不会使用收集器。collect(Collectors.reducing(…))
只要可以使用就不会使用.reduce(…)
,是吗?
不仅被mapToInt(mapFunc).sum()
短路,而且还遵循通常的从左到右的顺序进行概念上的处理,首先转换为anint
,然后将这些int
s
相加。我认为这证明了选择这种替代方案是合理的.collect(Collectors.summingInt(mapFunc))
。
解决方法
当您想对流中的整数值求和时,有两种主要方法:
ToIntFunction<...> mapFunc = ...
int sum = stream().collect(Collectors.summingInt(mapFunc))
int sum = stream().mapToInt(mapFunc).sum()
第一个涉及对返回的整数装箱并将其取消装箱,但是第二个步骤涉及额外的步骤。
哪个更有效/更清晰?
Collectors.summingInt()与mapToInt()。sum()
当您想对流中的整数值求和时,有两种主要方法:
ToIntFunction<...> mapFunc = ...int sum = stream().collect(Collectors.summingInt(mapFunc))int sum = stream().mapToInt(mapFunc).sum()
第一个涉及对返回的整数装箱并将其取消装箱,但是第二个步骤涉及额外的步骤。
哪个更有效/更清晰?
答案1
小编典典您正在看两个否则不同的用例的交集。使用mapToInt(…)
可使您IntStream
在终端操作之前链接其他操作。相反,Collectors.summingInt(…)
可以与其他收集器组合,例如用作收集器中的下游收集groupingBy
器。对于这些用例,毫无疑问要使用哪个。
在您的特殊情况下,当您不链接更多操作或不首先与收集器打交道时,这两种方法之间没有根本区别。尽管如此,使用更具可读性的方法还是有道理的。通常,当流上存在预定义的操作时,您就不会使用收集器。collect(Collectors.reducing(…))
只要可以使用就不会使用.reduce(…)
,是吗?
不仅被mapToInt(mapFunc).sum()
短路,而且还遵循通常的从左到右的顺序进行概念上的处理,首先转换为anint
,然后将这些int
s
相加。我认为这证明了选择这种替代方案是合理的.collect(Collectors.summingInt(mapFunc))
。
我们今天的关于count和与量角器中的长度的分享已经告一段落,感谢您的关注,如果您想了解更多关于Android:ListView中的getCount()和getChildCount()之间的区别、Angular:量角器 – count()没有解析并导致超时、Collectors.summingInt()与mapToInt()sum()、Collectors.summingInt()与mapToInt()。sum()的相关信息,请在本站查询。
本文标签: