我有一个问题,我创建一个Foo对象的ArrayList,我重写equals方法,我不能让contains方法调用equals方法.我已经尝试重写equals和hashcode,但它仍然无法正常工作.我敢肯定有一个合乎逻辑的解释,为什么会这样,但我现在无法弄清楚我自己大声笑.我想要一种方法来查看列表是否包含指定的id.
这是一些代码:
import java.util.ArrayList;
import java.util.List;
public class Foo {
private String id;
public static void main(String... args){
Foo a = new Foo("ID1");
Foo b = new Foo("ID2");
Foo c = new Foo("ID3");
List<Foo> fooList = new ArrayList<Foo>();
fooList.add(a);
fooList.add(b);
fooList.add(c);
System.out.println(fooList.contains("ID1"));
System.out.println(fooList.contains("ID2"));
System.out.println(fooList.contains("ID5"));
}
public Foo(String id){
this.id = id;
}
@Override
public boolean equals(Object o){
if(o instanceof String){
String toCompare = (String) o;
return id.equals(toCompare);
}
return false;
}
@Override
public int hashCode(){
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:false …
我试图谷歌这个,但没有成功.如果我正在使用AUTO_ACKNOWLEDGE,并且我有一个用Java编写的消费者客户端,那么消息何时被确认?我使用的MessageListener是包含onMessage方法的.确认是onMessage在onMessage完成之前或之后还是在某个其他时间点发送回服务器的?提前感谢任何人都能提供的帮助!
所以我想弄清楚是否可以深度链接没有当前安装的应用的用户.以下是我要做的事情:1)用户在移动浏览器中点击网站上的深层链接.2)用户被带到应用程序商店安装应用程序3)安装后,用户将被带到应用程序内特定内容的深层链接.
到目前为止,我发现的最接近的是使用Android应用程序安装横幅,但这不是我正在寻找的.这甚至可能吗?
以下是页面底部附近Android App安装横幅的链接:https://medium.com/@ageitgey/everything-you-need-to-know-about-implementing-ios-and-android-mobile-deep -linking-f4348b265b49#.evsxzudwj
所以我有一个MySQL数据库,我在WebLogic的本地实例上有一个连接到该数据库的数据源.我正在尝试编写一些只需连接和查询的客户端代码.我在从数据源获取连接时遇到问题.到目前为止,这是我的代码.我正在运行WebLogic 12c.
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class ConnectionTest {
public static void main(String... args) {
ConnectionTest tCon = new ConnectionTest();
tCon.TestConnection();
}
public void TestConnection() {
Context ctx = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("java.naming.factory.initial",
"weblogic.jndi.WLInitialContextFactory");
props.put("java.naming.provider.url", "t3://localhost:7001");
props.put("java.naming.security.principal", "weblogic");
props.put("java.naming.security.credentials", "welcome1");
ctx = …Run Code Online (Sandbox Code Playgroud) 我遇到了JMS重新连接策略的问题.我不确定我是否正确地做了(很可能我不是).无论如何,我正在使用WebLogic,这是一个消费者客户端.这是我如何获得连接,并尝试添加自动重新连接.问题是它没有重新连接,并且没有例外记录.我通过启动weblogic重新创建情境,启动获得初始连接的客户端客户端,我关闭weblogic,然后重新启动weblogic,此时此消费者正在侦听的队列中的任何消息都保留在队列中而未被确认因为他们没有收到.
public void setReceiver(MessageListener listener) {
try {
Properties parm = new Properties();
parm.setProperty("java.naming.factory.initial",
"weblogic.jndi.WLInitialContextFactory");
parm.setProperty("java.naming.provider.url", URL);
parm.setProperty("java.naming.security.principal", username);
parm.setProperty("java.naming.security.credentials", password);
ctx = new InitialContext(parm);
final QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx
.lookup(conFactoryName);
connection = connectionFactory.createQueueConnection();
// TODO: 8/6/2012 Work on reconnection strategies for Consumer.
((WLConnection) connection)
.setReconnectPolicy(JMSConstants.RECONNECT_POLICY_ALL);
((WLConnection) connection).setReconnectBlockingMillis(30000L);
((WLConnection) connection).setTotalReconnectPeriodMillis(-1L);
session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queue = (Queue) ctx.lookup(queueName);
// receiver = session.createReceiver(queue);
// receiver.setMessageListener(listener);
consumer = session.createConsumer(queue);
consumer.setMessageListener(listener);
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException arg0) {
// Assume …Run Code Online (Sandbox Code Playgroud) 所以我的问题是我有一个垂直回收器视图,其中包含多行嵌套的水平回收器视图。我在嵌套的回收视图上启用了预取并将初始预取计数设置为 20(用于测试),但是,由于在外部适配器的 onBindViewHolder 中添加项目时内部回收视图适配器上的挂起更新,它不会在初始向下滚动时预取。这是我的外部适配器代码。每个“块”都是一个水平滚动视图
private class BlockAdapter(val blocks: List<Block>) : RecyclerView.Adapter<VH>() {
private val viewCreatorsByType = HashMap<Int, Block>()
override fun getItemViewType(position: Int): Int {
val block = blocks[position]
val blockKey = block.viewType.ordinal
viewCreatorsByType[blockKey] = block
return blockKey
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
val block = viewCreatorsByType[viewType]!!
return VH(block.createView(parent.context, parent))
}
override fun onBindViewHolder(holder: VH, position: Int) {
holder.index = position
holder.boundPresenter = blocks[position].presenter.apply {
attachView(holder.view)
resume()
present()
}
}
override fun onViewRecycled(holder: VH) {
holder.boundPresenter?.run { …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何方法只从文件对象创建FileInputStream对象而不在文件系统上创建实际文件?我试图做的是创建一个包含一些信息的文件对象,然后将该文件上传到其他地方.我不需要它在本地文件系统上.我知道我可以创建一个临时文件夹然后删除它,但是想知道是否有可能不这样做?
我需要:
测试将通过TeamCity启动.我创建一个TestWatcher对象来监听测试结果,这个TestWatcher包含在每个包含测试的JUnit类中.我有一个监听器,可以在整个套件完成时收听,但我不得不以编程方式添加它.由于我现在使用TeamCity来运行测试并生成结果,我相信我已经失去了这种能力.我被要求也生成一份包含TeamCity结果的PDF报告.我需要知道的是测试完成后我才能知道何时开始构建我的报告.有没有办法通过使用TestWatcher来实现这一目标?
以下是我的TestWatcher目前的样子.BaseTestResult只是一个包含测试结果的类,并将它们组织起来以便更容易打印出来.我也使用Selenium,驱动程序变量的类型为WebDriver:
@Rule
public TestWatcher watchman = new TestWatcher() {
private BaseTestResult currentTest;
private long startTime;
private long endTime;
@Override
protected void starting(Description d) {
startTime = System.currentTimeMillis();
currentTest = new BaseTestResult(d);
currentTest.setBrowser(type);
if (d.getAnnotation(TestDescription.class) != null) {
currentTest.setDescription(d.getAnnotation(
TestDescription.class).description());
}
currentTest.setSuite(d.getTestClass().getName());
}
@Override
protected void succeeded(Description d) {
currentTest.setSucceeded(true);
}
@Override
protected void failed(Throwable e, Description d) {
currentTest.setThrowable(e);
}
@Override
protected void finished(Description d) {
endTime = System.currentTimeMillis();
currentTest.setRuntime(endTime - startTime);
String fileName = …Run Code Online (Sandbox Code Playgroud) 所以我试图运行并行参数化测试.我有一个解决方案,其中相同的测试可以与提供的参数并行运行,例如说我有以下内容:
@Test
public void someTest1(){
}
@Test
public void someTest2(){
}
Run Code Online (Sandbox Code Playgroud)
我可以让someTest1()同时运行所有参数,但someTest2()仍然必须等待someTest1()在执行之前完成所有参数.我想知道是否有人知道一个解决方案能够同时运行带有所有参数的someTest1()和带有所有参数的someTest2()?我已经尝试过tempus-fugit并发测试运行器,它非常适用于未参数化的测试......
下面是我目前并行运行每个参数测试的代码.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;
/**
* Class used from the following source:
* http://jankesterblog.blogspot.com/2011/10
* /junit4-running-parallel-junit-classes.html
*
* @author Jan Kester
*
*/
public class Parallelized extends Parameterized {
private static class ThreadPoolScheduler implements RunnerScheduler {
private ExecutorService executor;
public ThreadPoolScheduler() {
String threads = System.getProperty("junit.parallel.threads", "16");
int numThreads = Integer.parseInt(threads);
executor = Executors.newFixedThreadPool(numThreads);
}
public void finished() { …Run Code Online (Sandbox Code Playgroud) 我目前有两个客户端(生产者/消费者),我试图通过JMS发送一个大文件.我成功生成并将文件发送到JMS服务器没有任何问题.问题是当我尝试使用消息时,我得到以下异常:
Aug 24, 2012 11:25:37 AM client.Client$1 onException
SEVERE: Connection to the Server has been lost, will retry in 30 seconds. weblogic.jms.common.LostServerException: java.lang.Exception: weblogic.rjvm.PeerGoneException: ; nested exception is:
weblogic.socket.MaxMessageSizeExceededException: Incoming message of size: '10000080' bytes exceeds the configured maximum of: '10000000' bytes for protocol: 't3'
<Aug 24, 2012 11:25:37 AM CDT> <Error> <Socket> <BEA-000403> <IOException occurred on socket: Socket[addr=127.0.0.1/127.0.0.1,port=7001,localport=51764]
weblogic.socket.MaxMessageSizeExceededException: Incoming message of size: '10000080' bytes exceeds the configured maximum of: '10000000' bytes for protocol: 't3'.
weblogic.socket.MaxMessageSizeExceededException: Incoming message of …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人知道AS400是否与Java 6兼容?我在网上看过,我只能找到Java 2之前的日期资料.
我想知道在FileUtils中只有静态方法有什么意义?有没有理由没有实例方法?我相信FileUtils是线程安全的(纠正我,如果我错了大声笑),但我确实有一堆线程同时使用FileUtils方法,似乎有多个实例比使用同步代码更好.是否有模仿FileUtils库的库,但不包含任何静态方法?
我在绘制JPanel时遇到问题.这就是我目前正在做的事情.我知道图像是有效的,因为我已将它写入此类的文件并获得我想要绘制的精确图像,但是当我尝试将其绘制到JPanel时,它似乎立即被删除.我试过谷歌,但已经干了.有任何想法吗?
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import utilities.Log;
public class Signature extends JFrame {
/**
*
*/
private static final long serialVersionUID = 8908413895953622794L;
private JPanel contentPane;
private JPanel panel;
private BufferedImage image;
/**
* Create the frame.
*/
private Signature() {
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 631, 338);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblDateSigned …Run Code Online (Sandbox Code Playgroud) java ×11
jms ×3
weblogic ×3
android ×2
junit ×2
selenium ×2
concurrency ×1
connection ×1
contains ×1
deep-linking ×1
equals ×1
file ×1
file-io ×1
graphics ×1
ibm-midrange ×1
io ×1
jpanel ×1
messaging ×1
mysql ×1
pdf ×1
swing ×1
weblogic12c ×1