我有一个解析数据流的类.每个数据块称为a Box.Boxes 有很多种.我希望Parser每种类型的盒子都有不同的颜色.所以基本上我需要一个Registry或类似的东西,让我为每个提取正确的解析器Box.这是我的问题的简化版本:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GenericsTest {
class Box {
private String data;
public String getData() {
return data;
}
}
class BoxA extends Box {
private String adata;
BoxA( String adata ) {
this.adata = adata;
}
public String getAData() {
return adata;
}
}
class BoxB extends Box {
private String bdata;
BoxB( String bdata ) {
this.bdata = bdata;
} …Run Code Online (Sandbox Code Playgroud) 我最近需要签出一个apache项目来做一些事实调查/调试(特别是maven-surefire-plugin,看看这个问题).与大多数其他apache项目一样,这是一个maven多模块项目.所以,在eclipse中,我打开SVN Repositories browswer,添加一个新的存储库,找到项目和right-click->Checkout....在向导中,我单击Checkout as a project in the workspace并键入项目的名称.
我有这个项目,现在我需要让eclipse知道它的maven项目,所以right-click->Configure->Convert to Maven Project.现在,父项目是一个maven项目.我可以right-click->Run As->Maven Build,它的工作原理.但是,所有模块都只是文件夹.Eclipse不知道源代码的位置,也不知道源代码的位置.在单个模块项目中,它将自动设置源文件夹,构建文件夹和其他配置.此外,如果您从头开始创建一个多模块项目,首先要创建父项目,然后,当您向其添加模块时,它们每个都显示为eclipse中的单个项目,其中物理目录位于父项目下默认maven构建过程所需的文件夹.
现在,知道在创建新项目时它是如何完成的,我可以File->New->Project...选择General->Project给项目命名(我将其与模块名称相匹配),取消选中Use default location并设置Location:到父项目文件夹内部模块的路径.点击后Finish,为每个其他模块重复这个过程,我有一些看起来类似于我期望的东西.我现在需要以与父项目相同的方式将每个单独的模块转换为maven模块.太棒了,他们都是maven项目,对吧?
然后我打开它们,并且没有设置源文件夹.
唉...然后我去每个项目,把它打开,然后放在src文件夹I上right-click->Build Path->Use as Source Folder.泡沫,冲洗,重复......一旦完成所有项目,它看起来和感觉就像我从头开始这个项目.事情的功能.
我的问题是,这真的很难吗?我错过了一条捷径吗?如果Configure->Convert to Maven Project父母pom意识到它是一个多模块项目并且为我完成了所有工作,那会不会有意义?对于apache项目来说,这是一个非常痛苦的过程,因为它们似乎都有很多很多模块......任何人都知道更好的过程吗?
简而言之,如何在webflow视图jsp中使用EL获取完整的查询字符串?这就是我想要做的:
<span class="forgot-password">
<a href="forgotPasswordRequest?<%=request.getQueryString() %>">
<spring:message code="screen.welcome.link.forgotPassword" />
</a>
</span>
Run Code Online (Sandbox Code Playgroud)
除了我想使用EL而不是scriptlet <%=request.getQueryString() %>.使用任何单个参数似乎很容易${param.someParameterName},但我想要整个事情.更具体地说,我使用CAS作为SSO提供商.为了进行身份验证,应用程序会使用包含参数的查询字符串将其登录名重定向到CAS,该参数service是成功进行身份验证后要返回的URL.像这样的东西:
?service=http%3A%2F%2Fmysite.com%3A9080%2Fwelcome
Run Code Online (Sandbox Code Playgroud)
我的CAS登录页面有一个忘记密码webflow的链接.我需要将该服务参数传播到其他Web流.所以我可以这样做:
<span class="forgot-password">
<a href="forgotPasswordRequest?service=${param.service}">
<spring:message code="screen.welcome.link.forgotPassword" />
</a>
</span>
Run Code Online (Sandbox Code Playgroud)
但后来我失去了所有的网址转义.此外,如果将来还有其他要保留的参数,它们也会丢失.
这个小脚本目前有效,但它很难看,我不喜欢在我的演示文稿中使用代码(因为这是真正的java代码),尽管它很简单.EL肯定是一个更优雅的解决方案.
我探讨了spring文档中列出的所有特殊EL变量,但仍无法找到获取完整queryString的方法.
-------------------------------- UPDATE ----------------- ---------------
好吧,所以我正在制定一些理由......结果是ExternalContext界面有一个getNativeRequest()实际的HttpServletRequest对象.从那里我可以得到完整的查询字符串:
externalContext.getNativeRequest().getQueryString()
Run Code Online (Sandbox Code Playgroud)
所以现在我假设因为有一个名为externalContext 的特殊EL变量,我会这样做:
${externalContext.nativeRequest.queryString}
Run Code Online (Sandbox Code Playgroud)
对?错误!事实证明externalContext,JSP页面中没有该变量.谁知道为什么?但是,还有flowRequestScope,JSP可用并且有一个getExternalContext方法,所以现在我可以这样做:
${flowRequestScope.externalContext.nativeRequest.queryString}
Run Code Online (Sandbox Code Playgroud)
很酷,有效......但为什么有必要呢?为什么只有一些特殊的EL变量被推送到JSP页面,为什么它们中的一些变化(viewScope似乎它的所有值都被提升到root级别,因此viewScope.commandName在JSP中被引用为$ {commandName} EL)?我必须错过WebFlow工作方式的基本内容.有人能指出我正确的方向吗?
我有一个接受InputStream(二进制数据)并将其序列化为XML的方法.为此,它使用base64编码器封装流,Reader并将其转换为字符数据.但是,由于InputStream作为一个参数传递,我认为关闭流是一个有害的副作用,而合同Reader.close()说它会这样做.如果我不关闭阅读器,编译器警告我,我有一个
资源泄漏:读者永远不会关闭
所以,我可以@SuppressWarnings( "resource" )在读者声明中添加一个,但这是正确的做法吗?我错过了什么吗?
这是实际的代码:
/**
* Writes base64 encoded text read from the binary stream.
*
* @param binaryStream
* The binary stream to write from
* @return <code>this</code> XmlWriter (for chaining)
* @throws IOException
*/
public XmlWriter binary( InputStream binaryStream ) throws IOException {
Reader reader = new InputStreamReader(
new Base64InputStream( binaryStream, true, base64LineLength, base64LineSeparator.getBytes( charset ) ) );
int bufferSize = 2048;
int charsRead;
char[] buffer …Run Code Online (Sandbox Code Playgroud) ClientBase的 C# 定义是:
public abstract class ClientBase<TChannel> : ICommunicationObject,
IDisposable
where TChannel : class
Run Code Online (Sandbox Code Playgroud)
这清楚地表明了class对TChannel类型的约束。据我所知,这意味着在声明自己的类时不能使用泛型的接口类型。因此,鉴于如此声明的服务:
public IMyService
...
public MyService : IMyService
...
Run Code Online (Sandbox Code Playgroud)
这应该有效:
public MyServiceClient : ClientBase<MyService>
Run Code Online (Sandbox Code Playgroud)
这应该不是:
public MyServiceClient : ClientBase<IMyService>
Run Code Online (Sandbox Code Playgroud)
但显然我不理解,因为该示例显示了以下声明:
public partial class SampleServiceClient :
System.ServiceModel.ClientBase<ISampleService>, ISampleService
Run Code Online (Sandbox Code Playgroud)
更重要的是,我试图抽象身份验证,并使用实用程序方法正确关闭客户端:
public TResult WithClient<TInterface, T, TResult>(T service,
Func<TInterface, TResult> callback)
where T : ClientBase<TInterface>, TInterface
{
service.ClientCredentials.UserName.UserName = userName;
service.ClientCredentials.UserName.Password = password;
try
{
var result = callback(service);
service.Close();
return …Run Code Online (Sandbox Code Playgroud) 可能重复:
在Java中实现接口时降低可见性
我必须遗漏一些明显的东西,但我得到了:
无法降低继承方法的可见性
我不知道怎么做.这是我的界面:
interface QueryBuilderPart {
StringBuilder toStringBuilder();
}
Run Code Online (Sandbox Code Playgroud)
这是我的实施:
public class Stupid implements QueryBuilderPart {
@Override
StringBuilder toStringBuilder() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
类和实现都在同一个包中.有任何想法吗?
我刚刚完成了围棋之旅,并开始了树行者练习。其明显的递归,但关闭通道是在最终弹出调用堆栈后的特殊情况。无论如何,我最终实现了它:
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
var walker func(t *tree.Tree, ch chan int)
walker = func(t *tree.Tree, ch chan int) {
if (t.Left != nil) {
walker(t.Left, ch)
}
ch <- t.Value
if (t.Right != nil) {
walker(t.Right, ch)
}
}
walker(t, ch)
close(ch)
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我去的印象是,他们宁愿避免说的事情,如果他们可以,这样的声明var walker的定义似乎之前关闭。也许我错过了一些允许函数在没有声明的情况下引用自身的细节?如果可以的话会好一点:
// Walk walks the tree t sending all values
// …Run Code Online (Sandbox Code Playgroud) 据我所知,我正在使用两种不同的方法来做同一件事:
const https = require("https");
const axios = require("axios");
let httpsAgent = new https.Agent({rejectUnauthorized: false});
axios.get(`https://${hostname}:${port}${path}`, {httpsAgent})
.then((data) => { console.log("axios success: " + data.substr(0, 100)); })
.catch((error) => { console.log("axios error: " + error); });
let data = "";
https.get({ hostname, path, port, agent: httpsAgent },
(response) => {
response.on("data", (chunk) => { data += chunk; });
response.on("end", () => { console.log("https success: " + data.substr(0, 100)); });
})
.on("error", (error) => { console.log("https error: " + error); }); …Run Code Online (Sandbox Code Playgroud) 我很难过.我这样宣布我的一套:
private Set<Long> applicationIds;
Run Code Online (Sandbox Code Playgroud)
然后我像这样填充它:
public void setApplicationIds( Set<Long> applicationIds ) {
this.applicationIds = new TreeSet<Long>( applicationIds );
this.applications = null;
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用它:
public List<Application> getApplications() {
if ( applications == null ) {
applications = new ArrayList<Application>();
if ( applicationIds != null ) {
for ( Application application : availableApplications ) {
if ( applicationIds.contains( Long.valueOf( application.getId() ) ) ) {
applications.add( application );
}
}
}
}
return applications;
}
Run Code Online (Sandbox Code Playgroud)
我最终得到了这个:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long …Run Code Online (Sandbox Code Playgroud) java ×5
generics ×3
axios ×1
c# ×1
eclipse ×1
go ×1
https ×1
inputstream ×1
interface ×1
javascript ×1
jsf-2 ×1
maven ×1
multi-module ×1
node-https ×1
node.js ×1
spring ×1
spring-mvc ×1
type-safety ×1
updatemodel ×1
vcs-checkout ×1
wcf ×1