java

Selenium: Iterate Through Element List

纵饮孤独 提交于 2021-02-19 03:11:12
问题 I am using XPath/CSS and Selenium to locate elements on website. I want to create a method where I iterate through a list of locators (XPath / CSS) and program chooses whichever one works. In other words, it begins with locator one - if the locator is present it returns true and exists the loop. Otherwise it moves on to the next locator in list. Once it exhausts all CSS locators it moves on to XPath and so on. Currently, I am thinking of implementing this as follows: public boolean iterate

工作10年后,再看String s = new String("xyz") 创建了几个对象?

半世苍凉 提交于 2021-02-19 02:57:15
点击上方蓝色“ 方志朋 ”,选择“设为星标” 回复“ 666 ”获取独家整理的学习资料! 转自:艾小仙 这个问题相信每个学习java的同学都不陌生,作为一个经典的面试题,到现在工作这么多年了我真是认为挺操蛋的一个问题,在网上到现在你仍然可以看见很多讨论这个问题的人,其中不乏工作很多年的人都有争论,我认为还是有必要来说一说这个问题的。 从方法区说起 常量池存在于方法区,而方法区在jdk1.7版本前后改变比较大,所以还是先来说说方法区的演变。 在jdk1.7版本之前,常量池存在于方法区,方法区是堆的一个逻辑部分,他有一个名字叫做 非堆 。 1.7版本把字符串常量池放到了堆中。 而在1.8以后,则是移除了永久代,方法区概念保留,方法区的实现改为了元空间,常量池还是在堆中。 为什么要说方法区的改变,只是为了文章接下来的内容不会由于JDK的版本而产生分歧,接下来内容都会以jdk1.8版本作为基础来讨论。 String s = new String("xyz"); 先来一段代码 public class Test { public static void main (String[] args) { String s = "xyz" ; } } 接着我们javac编译代码,然后用javap来反编译,执行javap -c Test 从结果来看,ldc命令 在常量池中创建了一个"xyz"的对象

Maven - lookup dependencies at runtime

China☆狼群 提交于 2021-02-19 02:50:33
问题 I would like to be able to determine what versions I am running of a dependency at runtime as well as the version of the web application itself. Each web application I deploy is packaged with a pom.xml which I can read from, that part is trivial. The next part is parsing the pom without much effort. As the web application is running, I want to be able to understand what version I am, and what versions my dependencies are. Ideally, I would like to do something like: MavenPom pom = new MavenPom

Is there “oldline” character in Java?

偶尔善良 提交于 2021-02-19 02:47:06
问题 Is there exist the opposite to the newline '\n' character in Java which will move back to the previous line in the console? 回答1: ASCII doesn't standardize a "line starve" or reverse line feed control character. Some character based terminals/terminal emulators recognize control code sequences that move the cursor up a line; these aren't Java-specific, and depend on your OS and configuration. Here's a starting point if you're using Linux: http://www.kernel.org/doc/man-pages/online/pages/man4

Spring: unit test for class that has both field & constructor injection

好久不见. 提交于 2021-02-19 02:46:05
问题 I have below setup of classes. class Base { @Autowired private BaseService service; //No getters & setters .... } @Component class Child extends Base { private final SomeOtherService otherService; @Autowired Child(SomeOtherService otherService) { this.otherService = otherService; } } I am writing a unit test for the Child class. If I use @InjectMocks then the otherService comes out to be null. If I use, the constructor of Child class in the setup of the test, then the fields in Base class

Weird content in the clipboard after copy from Excel

◇◆丶佛笑我妖孽 提交于 2021-02-19 02:44:10
问题 I'm trying to get the content of the clipboard in my application to ensure excel compatibility, using : Clipboard clipboard = new Clipboard(Display.getDefault()); String contents = (String) clipboard.getContents(TextTransfer.getInstance()); The problem is, if I have on one column [1, 2, 3], and I select cells [1] and [3], then in the clipboard content I found 1\r\n2\r\n3\r\n instead of just 1 and 3. In other words the clipboard does not seem to handle disjointed cells. Does somebody have an

default implementation of hashcode returns different values for objects constructed the same way

╄→гoц情女王★ 提交于 2021-02-19 02:43:47
问题 Here I am writing one sample code: public class Test { private int i; private int j; public Test() { // TODO Auto-generated constructor stub } public Test(int i, int j) { this.i=i; this.j=j; } } now I am creating two objects as bellow: Test t1= new Test(4,5); Test t2 = new Test(4,5); But when i am printing t1.hashcode() and t2.hashcode() they are giving different values. But as per java's general contact they should return same value. In fact, when i am doing same thing with String or Integer

GIT学习笔记(2):时光机穿梭与远程仓库

走远了吗. 提交于 2021-02-19 02:42:55
GIT学习笔记(2):时光机穿梭与远程仓库 撤销操作 GIT如何跟踪修改   在我们 修改了代码内容后,执行了git add和git commit命令来将其交由Git进行版本控制 。我们前面举的例子是这样的,git add将文件加入暂存区(菜篮子),git commit一并提交到版本库(柜台结账)。如果我们想拿其他的菜,但是不加入篮子,Git是无法对其进行跟踪的。   比如我们队Test.java第一次修改后,执行git add命令将第一次修改版本加入了暂存区,然后又修改了Test.java,但是commit负责暂存区的修改提交了,所以第二次的修改不会被提交。      那我们该如何将第二次修改的内容提交呢?将其加入暂存区即可。add命令是将目标文件加入跟踪列表,每一次跟踪以commit为 准,也就是说你只要没有commit,不管你什么时候把这个文件add进去,最终结果是你文件最后一次修改的结果 。    说明: 简而言之,如果不用git add到暂存区,那就不会随commit提交到版本库。 撤销修改   修改最后一次提交   有时候我们提交完了才发现 漏掉了几个文件没有加,或者提交信息写错 了。想要 撤消刚才的提交操作,可以使用 --amend 选项重新提交 :   比如我们提交后,发现忘添加MyClass.java文件了,我们可以把git add MyClass.java

lmax disruptor is too slow in multi-producer mode compared to single-producer mode

本小妞迷上赌 提交于 2021-02-19 02:42:14
问题 Previously, when I use single-producer mode of disruptor, e.g. new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 2048, moranContext.getThreadPoolExecutor(), ProducerType.Single, new BlockingWaitStrategy()) the performance is good. Now I am in a situation that multiple threads would write to a single ring buffer. What I found is that ProducerType.Multi make the code several times slower than single producer mode. That poor performance is not going to be accepted by me. So should I use single

lmax disruptor is too slow in multi-producer mode compared to single-producer mode

你。 提交于 2021-02-19 02:41:53
问题 Previously, when I use single-producer mode of disruptor, e.g. new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 2048, moranContext.getThreadPoolExecutor(), ProducerType.Single, new BlockingWaitStrategy()) the performance is good. Now I am in a situation that multiple threads would write to a single ring buffer. What I found is that ProducerType.Multi make the code several times slower than single producer mode. That poor performance is not going to be accepted by me. So should I use single