我研究Java是通过值传递对象引用,并且为了制作对象的本地副本,我可以做clone()或copy-constructor.我还查看了深/浅副本以及stackoverflow上的几个帖子.
现在我看一下例子:
List<String> list = new ArrayList<String>();
String one = "one"
list.add(one);
Run Code Online (Sandbox Code Playgroud)
我读过的文章很少提到ArrayList实现了cloneable,但是如果type是List not ArrayList并且没有实现cloneable,那么它并没有真正说明如何制作"list"的本地副本.
如果"list"是ArrayList的类型,我可以调用clone().
ArrayList<String> list = new ArrayList<String();
list.clone();
Run Code Online (Sandbox Code Playgroud)
但如果type是List,我不能.
我应该只使用下面的复制构造函数来制作本地副本吗?复制"列表"的最佳方法是什么?
List<String> tmpList = new ArrayList<String>(list);
Run Code Online (Sandbox Code Playgroud) 我正在尝试编译ActionFactory.java文件,该文件导入我的一个包RegisterAction.java
这是文件结构:
/com/masatosan/actions/register/RegisterAction.java
/com/masatosan/redirector/ActionFactory.java
根据ANT输出,我认为ANT找不到在ActionFactory.java中导入的RegisterAction.java
当我在控制台上手动运行javac时它会成功编译,所以这必须是ANT没有看到的一些类路径设置.
我知道我可以在ANT_HOME/lib中添加一些jar但在我的情况下,ANT似乎无法找到ActionRegister.java,而不是jar或其他东西.任何人都可以帮我找出问题所在吗?
ANT脚本
<project name="CompileMasatosan" default="main"
basedir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan">
<description>
masatosan compiler
</description>
<!-- this invokes all targets -->
<target name="main" depends="compileAll" />
<!-- properties -->
<property name="srcMasatosan"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan" />
<property name="dest"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes" />
<property name="redirectorSrc" location="${srcMasatosan}\redirector" />
<!-- complie -->
<target name="compileAll">
<javac target="1.5" source="1.5" srcdir="${redirectorSrc}" destdir="${dest}" />
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
环境变量
ANT_HOME=C:\apache-ant-1.8.1-bin\apache-ant-1.8.1
CLASSPATH=C:\Program Files\Java\jre6\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib;C:\Program Files\Java\jre6\bin;C:\P
rogram Files\Apache Software Foundation\Tomcat 6.0\lib\mail.jar;C:\Program …Run Code Online (Sandbox Code Playgroud) 我有parent window (opener)和child (popup)
---------- --------------
| | | |
| parent | -----> opens popup | child |
| | | |
----------- --------------
Run Code Online (Sandbox Code Playgroud)
比方说,在父页面中,我有js函数 hello()
为了让子窗口关闭时调用父级的hello()并传递参数,我可以这样做,
window.close();
window.opener.hello(someArgument);
Run Code Online (Sandbox Code Playgroud)
这将关闭窗口并调用parent的hello();
但是如果我不想在子页面中使用代码window.opener.hello()呢?我的意思是我希望代码只在父页面中
我能想到的一件事是:
有些父母知道孩子何时关闭(事件监听器???在js中不确定)但在这种情况下如何接收参数?(即从孩子那里得到的一些数据)
我正在使用JPA toplink-essential和SQL Server 2008
我的目标是获取将要插入表中的数据的自动增量主键值.我知道在JDBC中,有getInsertedId()方法,它给你自动增加主id的id(但是在执行insert语句之后)
在JPA中,我发现@GenratedValue annotation可以做到这一点.
@Entity
@Table(name = "tableOne")
public class TableOne implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "tableId")
private Integer tableId;
Run Code Online (Sandbox Code Playgroud)
现在,如果我运行下面的代码,它应该给我自动增加的id 但它返回NULL ...
EntityManager em = EmProvider.getInstance().getEntityManagerFactory().createEntityManager();
EntityTransaction txn = em.getTransaction();
txn.begin();
TableOne parent = new TableOne();
em.persist(parent); //here I assume that id is pre-generated for me.
System.out.println(parent.getTableId()); //this returns NULL :(
Run Code Online (Sandbox Code Playgroud) My PC (client)
OS windows7 32bit
Tortoise SVN ver 1.7.5
Run Code Online (Sandbox Code Playgroud)
我已经能够SVN更新到存储库,几个月后,我的同事试图检查整个项目(Web应用程序)并有svn错误.
我尝试了相同的,创建新文件夹并检查我的项目,然后我得到:
REPORT of '/svnrepos/!svn/vcc/default': Could not read status line: Secure
connection truncated (https://foobar.jp)
Run Code Online (Sandbox Code Playgroud)
我svn cleanup按照网上几个没有效果的人的建议做了.
似乎每次错误都不同.我也得到:
REPORT of '/svnrepos/!svn/vcc/default': Could not read response body: Secure
Run Code Online (Sandbox Code Playgroud)
和
REPORT of '/svnrepos/!svn/vcc/default': Could not read chunk delimiter: Secure
Run Code Online (Sandbox Code Playgroud)
还有人说存储库中可能存在损坏的文件.我逐个删除每个文件,看看是否有特定文件导致此错误,没有特定文件导致此错误.
我还更新了我的最新Tortoise SVN版本1.7.5.
我正在尝试签出的文件大小约为30 MB,这根本不大.
我完成了所有我能想到的但仍然无法解决这个问题.以前有人会遇到这个吗?
看似简单的问题,但我真的很厌倦数学和网上的几个例子,我搜索似乎不适合我.(结果只返回与输入相同的值等)
例如..但它在C中不是Java Round to Next .05 in C.
所以我的目标是我有%.1f格式float或者double或者big decimal想要将它四舍五入到最接近的.5
example:
1.3 --> 1.5
5.5 --> 5.5
2.4 --> 2.5
3.6 --> 4.0
7.9 --> 8.0
Run Code Online (Sandbox Code Playgroud)
我尝试了以下示例,但没有工作:(下面只输出1.3这是原始值.我希望它是1.5
public class tmp {
public static void main(String[] args) {
double foo = 1.3;
double mid = 20 * foo;
System.out.println("mid " + mid);
double out = Math.ceil(mid);
System.out.println("out after ceil " + out);
System.out.printf("%.1f\n", out/20.0);
}
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以将Selenium与包含WebBrowser对象的C#Windows窗体一起使用.
我正在使用selenium,我可以使用Selenium脚本记录创建测试用例; 我只想确定是否可以导出C#代码并让它们都在C#环境中运行.我感谢任何想法或解释.
更新 我得到了Selenium打开包含WebBrowser组件的WinForm的观点.但是从那里我的测试将不会执行.看起来它不懂selenium命令.我没有看到任何错误消息被抛出.嗯
事情是winformWithWebBrowserTest打开带有webbrowser的winForm的.exe.但没有任何反应.下面的代码是启动.exe的代码
测试代码(Selenium命令)
namespace ClassLibrary1
{
class Class2
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium
("localhost", 4444, "*custom C:\\Users\\m-tak\\Documents\\Visual Studio 2010\\Projects\\winformWithWebBrowserTest\\winformWithWebBrowserTest\\bin\\Release\\winformWithWebBrowserTest.exe", "http://www.livemocha.com");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
selenium.Stop();
}
[Test]
public void TheUntitledTest()
{
//nothing here gets executed :(
Console.WriteLine("foobar front");
selenium.Open("/");
Console.WriteLine("foobar");
selenium.WaitForPageToLoad("30000");
selenium.Open("/users/logout");
selenium.Open("/users/login");
}
}
}
Run Code Online (Sandbox Code Playgroud)
.可执行程序
namespace WindowsFormsApplication1
{
public partial class Form1 : Form …Run Code Online (Sandbox Code Playgroud) 在下面的查询中,我查看了在给定日期范围内调用的第 80 个百分位中的一个 API (foo/bar1) 持续时间,以便我可以查看是否存在任何峰值或降级。(下图)
let dataset = requests
| where name == "GET foo/bar1"
and timestamp between(datetime("2020-10-15") .. datetime('2020-10-28'));
dataset
| summarize loadTime = round(percentile(duration, 80)) by format_datetime(timestamp, 'yyyy-MM-dd')
| order by timestamp desc
Run Code Online (Sandbox Code Playgroud)
我面临的挑战是可能有多个 API(我的环境中大约有 150 个),我也希望获得这些 API 的第 80 个百分位数,但很难做到这一点,甚至很难做到。
我花了半天的时间试图找出这个,最后我得到了解决方案.但是,我觉得这可以用更简单的方式完成.我认为这段代码不是真的可读.
问题:从字符串中查找第一个非重复字符.
$ string ="abbcabz"
在这种情况下,函数应输出"c".
我使用连接而不是$input[index_to_remove] = ''
从给定字符串中删除字符的原因是因为如果我这样做,它实际上只留下空单元格,以便我的返回值$ input [0]不会返回我想要返回的字符.
例如,
$str = "abc";
$str[0] = '';
echo $str;
Run Code Online (Sandbox Code Playgroud)
这将输出"bc"
但实际上,如果我测试,
var_dump($str);
Run Code Online (Sandbox Code Playgroud)
它会给我:
string(3) "bc"
Run Code Online (Sandbox Code Playgroud)
这是我的意图:
Given: input
while first char exists in substring of input {
get index_to_remove
input = chars left of index_to_remove . chars right of index_to_remove
if dupe of first char is not found from substring
remove first char from input
}
return first char of input
Run Code Online (Sandbox Code Playgroud)
码:
function find_first_non_repetitive2($input) {
while(strpos(substr($input, 1), …Run Code Online (Sandbox Code Playgroud) 我试图根据内容设置每个项目的宽度,但到目前为止我已经将宽度一直设置为可用空间。flex: 0 0 auto 似乎并不能解决问题。我究竟做错了什么?
目标是根据内容大小设置宽度。
[Hello]
[Hello world]
Run Code Online (Sandbox Code Playgroud)
现在
[Hello ]
[Hello world ]
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/v6cgLjbd/8/
<span class='box'>
<span class='item'>Hello</span>
<span class='item'>Hello World</span>
<span class='item'>Hello lOOOOONG text</span>
</span>
.box {
height: 200px;
width: auto;
border: 1px solid red;
display: flex;
flex-direction: column;
}
.item {
background-color: gray;
flex: 0 0 auto;
width: auto;
}
Run Code Online (Sandbox Code Playgroud)