我想将任何枚举值传递给实用程序类中的方法,并获取相同枚举类型的另一个枚举值.像这样的东西:
public class XMLUtils {
public static Enum<?> getEnumAttribute(Element element, String name,
Enum<?> defaultValue) {
if (element.hasAttribute(name)) {
String valueName = element.getAttribute(name);
// search for value
for (Enum<?> value: defaultValue.getClass().getEnumConstants())
if (value.toString().equalsIgnoreCase(valueName))
return value;
}
// not found, return default value
return defaultValue;
}
}
Run Code Online (Sandbox Code Playgroud)
使用方法getEnumAttribute():
// simple enum
public enum EUploadMethod {
INSERT, UPDATE, DELETE
}
// read enum value from XML config file
EUploadMethod method = XMLUtils.getEnumAttribute(element, "method",
EUploadMethod.INSERT);
Run Code Online (Sandbox Code Playgroud)
这段代码功能齐全,Eclipse编译并运行它没有警告或错误,它就像一个魅力.
但是当我通过Maven2从命令行清理和编译项目时,它会因为 …
在我正在开发的系统中,我需要以下列格式识别youtube链接
[youtube] youtube url [/ youtube]
目前我到达了这个正则表达式:
#\[youtube\]http://www.youtube\.(.*)/watch\?v=([a-zA-Z0-9_-]*)\[\/youtube\]#s
Run Code Online (Sandbox Code Playgroud)
但是这种模式无法识别网址
[youtube] http://www.youtube.com/watch?v=s3wXkv1VW54&feature=fvst[/youtube]
注意feature = fvst.
有人可以帮我识别所有可能的youtube网址吗?
我们可以像这样使用SQL:
SELECT * FROM student WITH(NOLOCK);
Run Code Online (Sandbox Code Playgroud)
如何在不使用LINQ to SQL的情况下实现这一点TransactionScope?
我有一个类似爬虫的软件,在阅读和解析特定网页后填充表格.我用Java编写它(使用Hibernate).我已经有了实体和其他逻辑.
我想在网页中显示这些表格,网页最终会有所改进,可能会有注册/登录屏幕,还有很多其他内容.
我的问题是我应该使用一个用Java之外的语言编写的简单Web框架,比如Django,还是应该坚持使用Java并重用我已经拥有的那些实体和逻辑?
如果我使用另一种语言,我预计我需要复制一些我在Java部分已有的逻辑,这意味着更有可能发生错误.
我问这个的原因是,当我尝试用Java编写一个简单的Web应用程序时,使用框架真的很难,当我切换到另一种语言,因此框架(当时的CakePHP),一切顺利.我认为使用Java会使事情复杂化.
现在我想分开观点和逻辑.
如果你通过分享你的经验和想法来表达一些建议,我将很高兴.
哪个更有效率
if(!var_name)
Run Code Online (Sandbox Code Playgroud)
要么
if(var_name == NULL)
Run Code Online (Sandbox Code Playgroud) 我正在为以下问题寻找一种近似算法 - 我有一个未加权的无向图,带有周期,并希望找到从给定节点开始的最长路径.我认为速度超过性能(因此O(n ^ 5)算法可能是一种过度杀伤力).
这不是作业(我发誓!)或与工作有关,但我会感谢您提供的任何提示.
我遇到了这个问题
select datepart(ww, '20100208')
Run Code Online (Sandbox Code Playgroud)
在第7周在SQL Server 2000中返回结果.但是根据ISO 8601规范,08.02.2010应该是第6周!这导致交货周计算出现问题.
我该怎么做才能获得符合ISO 8601的周数值?
有人after_commit在Rails中实现了一个钩子吗?在更新/创建/等提交后,我不是在寻找基于模型的模型,我希望能够动态定义仅在当前(最顶层)事务通过时才会执行的块:
def remove_file
current_transaction.after_commit do
FileUtils.rm(file_path)
end
end
Run Code Online (Sandbox Code Playgroud)
不知道是否已经实现了,如果它将在rails 3.0中?
我对内联汇编程序有疑问.可以在同一个函数中从内联汇编程序调用另一个汇编程序子程序吗?例如:
void FindValidPID(unsigned int &Pid)
{
__asm
{
sub esp, 20h
mov eax, Pid
add eax,eax
call sub123 ; another assm subroutine
mov Pid, eax
add esp, 20h
}
}
Run Code Online (Sandbox Code Playgroud)
在哪里,以及如何编写子程序sub123?
干杯,
托马斯
我在Ubuntu g ++版本4.4.3中编译的c ++问题中遇到此问题.我不知道要包含的标题来解决这个问题..谢谢
centro_medico.cpp: In constructor ‘Centro_medico::Centro_medico(char*, char*, int, int, float)’:
centro_medico.cpp:5: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘Centro_medico& Centro_medico::operator=(const Centro_medico&)’:
centro_medico.cpp:26: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘bool Centro_medico::quitar_medico(int)’:
centro_medico.cpp:92: …Run Code Online (Sandbox Code Playgroud) c++ ×3
java ×2
sql ×2
transactions ×2
.net ×1
algorithm ×1
assembly ×1
c ×1
datetime ×1
deprecated ×1
eclipse ×1
generics ×1
graph ×1
javac ×1
linq-to-sql ×1
path ×1
php ×1
preg-match ×1
regex ×1
sql-server ×1
youtube ×1