我如何计算javascript知道周数和年份的日期?对于2013年5月16日获得的第20周和2013年,我正在尝试:
Date.prototype.dayofYear = function() {
var d = new Date(this.getFullYear(), 0, 0);
return Math.floor((enter code here this - d) / 8.64e + 7);
}
Run Code Online (Sandbox Code Playgroud) 假设我有两个数组:
int ArrayA [] = {5,17,150,230,285};
int ArrayB [] = {7,11,57,110,230,250};
两个数组都是排序的,可以是任何大小.我正在寻找一种有效的算法来查找数组是否包含它们之间的任何重复元素.我只想要一个真/假答案,我不关心共享哪个元素或多少元素.
天真的解决方案是循环遍历ArrayA中的每个项目,并在ArrayB中对其进行二进制搜索.我相信这种复杂性是O(m*log n).
因为两个数组都是排序的,所以似乎应该有一个更有效的算法.
我还想要一个通用的解决方案,它不假设数组包含数字(即解决方案也适用于字符串).但是,比较运算符定义良好,两个数组都从最小到最大排序.
我试图复制我的春季网络应用程序 的resource-ref属性来配置JNDI.web.xmlWebApplicationInitializer
我该怎么做:
<resource-ref>
<description>Connection Pool</description>
<res-ref-name>jdbc/LocalCheddar</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
在java配置而不是xml?
我正在努力解决Java中泛型的这个方面.希望有人可以帮我看看方法.
我有一个包含对象列表的类.这段代码有效,但我想摆脱演员表.我怎样才能使这更通用?
public class Executor {
List<BaseRequest<BaseObj>> mRequests = new ArrayList<BaseRequest<BaseObj>>();
public Executor() {
}
@SuppressWarnings("unchecked")
public <T extends BaseObj> void add(final BaseRequest<T> request) {
mRequests.add((BaseRequest<BaseObj>) request);
}
public void execute() {
for (BaseRequest<BaseObj> r : mRequests) {
// DO SOMETHING WITH r
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring-Jersey3,并且无法弄清楚如何使用Spring bean对RESTFul API进行单元测试
调节器
package com.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.service.DataSource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("test")
@Component
public class SpringController {
@Autowired
private DataSource datasource;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getHello() {
return new String(datasource.load());
}
}
Run Code Online (Sandbox Code Playgroud)
服务接口
package com.service;
public interface DataSource {
public String load();
}
Run Code Online (Sandbox Code Playgroud)
服务实施
package com.service;
import org.springframework.stereotype.Repository;
@Repository
public class DataSourceImpl implements DataSource {
@Override
public String load() {
return "Hello";
}
}
Run Code Online (Sandbox Code Playgroud)
ResourceRegister.java(泽西资源注册)
package com.component;
import org.glassfish.jersey.server.ResourceConfig;
import com.controller.SpringController; …Run Code Online (Sandbox Code Playgroud) 在我的页面上,我有一个按钮,用于打开弹出窗口中的项目列表.当我在列表中选择1项时,我想将项目的ID传递给我的第一页的后台.可能吗?它试图用它做a4j:jsFunction,a4j:param但它不起作用.
这是我的代码:
第1页:
<a4j:jsFunction name="renderGuarantor" render="guarantor" actionListener="#{prospectDetail.setNewGuarantor}">
<a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}" />
</a4j:jsFunction>
Run Code Online (Sandbox Code Playgroud)
popuppage:
<h:outputLink value="" onclick="window.opener.renderGuarantor(#{applicant.deposit_id});window.close();">
<h:graphicImage style="padding:0 1px; border:0" value="${path.staticRootUrl}images/confirm.gif" alt="${msg.applicantslist_select}" title="${msg.applicantslist_select}"/>
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
这是第一页的支持bean代码
private Integer newGuarantorId;
public void setNewGuarantor() {
guarantor = newGuarantorId;
}
public Integer getNewGuarantorId() {
return newGuarantorId;
}
public void setNewGuarantorId(Integer newGuarantorId) {
this.newGuarantorId = newGuarantorId;
}
Run Code Online (Sandbox Code Playgroud)
在弹出窗口中选择时,我的backingbean中的方法被调用,但是newGuarantorId为null并且setNewGuarantorId从不被调用.
我的问题有解决方案吗?
我正在尝试在Photoshop中构建类似Liquify过滤器的东西.我一直在阅读图像失真代码,但我正在努力找出会产生类似效果的内容.我能找到的最接近的参考是Gimp中的iWarp过滤器,但其代码根本没有评论.
我也看过像ImageMagick这样的地方,但他们在这方面没有任何东西
任何指针或算法描述都将非常感激.
由于某种原因,只为数组中的最终值赋值......为什么会这样?
public void openFrameScores() {
int x = 0;
int y = 0;
int total = 0;
for(int i = 0; i < framesToBowl; i++) {
scores = new int[2][framesToBowl];
x = (int)(Math.random() * 9);
if(x == 0) y = (int)(Math.random() * 9);
else y = (int)(Math.random() * (9 - x));
scores[0][i] = x;
scores[1][i] = y;
}
for(int i = 0; i < framesToBowl; i++) {
total = total + scores[0][i] + scores[1][i];
System.out.println("Frame: " + i + ", …Run Code Online (Sandbox Code Playgroud) java ×3
algorithm ×2
spring ×2
ajax ×1
ajax4jsf ×1
arrays ×1
config ×1
generics ×1
javascript ×1
jersey ×1
jersey-2.0 ×1
jsf ×1
jsf-2 ×1
junit ×1
math ×1
richfaces ×1
servlet-3.0 ×1
unit-testing ×1