如何声明其键可以包含任何枚举的Map?
例如,我有两个enum水果和蔬菜.
如何声明地图哪里的键可以是水果和蔬菜,但只有枚举,而不是对象?
我的意思是,像
Map<???, String> myMap...
Run Code Online (Sandbox Code Playgroud) 这在技术上是一个代码挑战.有人问我一个有趣的问题,在接受记者采访时,我希望能为一些有识之士为最佳答案我可以想出是O(2N ^ 2) - N平方类别,但仍然非常强力.
假设你有一个M大小为N的矩阵(数组数组(int[][]))
1 2 4 3 1
0 5 3 7 7
5 8 9 2 8
6 7 0 8 9
Run Code Online (Sandbox Code Playgroud)
如果单元格包含零,则将整个行和列设置为零.
结果如下:
0 2 0 3 1
0 0 0 0 0
0 8 0 2 8
0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
最快和/或最好的方法是什么?
我自己的答案是迭代整个数组,跟踪行和列的归零,然后将它们归零.
public void zeroOut(int[][] myArray){
ArrayList<Integer> rowsToZero = new....
ArrayList<Integer> columnsToZero = new....
for(int i=0; i<myArray.length; i++){ // record which rows and columns will be zeroed
for(int j=0; j<myArray[i].length; …Run Code Online (Sandbox Code Playgroud) 我有一个Spring应用程序.登录后,我正在调用getUserByEmail()方法.
我只需要用户和角色数据.基于角色我将显示不同的视图,每个视图具有不同的数据并且需要User的不同子实体.
好像我必须使用不同的子实体调用getUserByEmail().
这是涉及实体的部分代码:
EntityGraph(value = "withAddresses", type = EntityGraphType.FETCH)
public class User{
public firstName;
public lastName;
@OneToMany(fetch = FetchType.LAZY)
public List<Address> addresses
@OneToMany(fetch = FetchType.LAZY)
public List<Order> orders;
}
public userRepository extend jPaRepository(User.class,Long){
@EntityGraph(name="withAdresses")
getUserByEmail(String email)
/* if possible */
@EntityGraph(name="withOrder")
getUserByEmail(String email)
}
Run Code Online (Sandbox Code Playgroud)
是否可以有两个具有相同查询名称的User对象图?因为我需要不同视图的不同数据.
此外,当切换到新视图(弹簧控制器中的新调用)时,先前视图中的事务将被关闭,我必须进行新调用以与用户具有不同的数据.我不明白如果你不在同一个事务服务方法中,fetch lazy如何有用,除非我没有遗漏任何东西.
例如,如果我需要"orderWiew.html"中的订单数据,则延迟加载订单不会有帮助我必须另外完全调用相同的用户数据和其他订单数据
我正在研究Luhn的测试问题,我想用一维数组构建程序.我初始化了一个16位数组,但我希望能够根据用户输入的位数初始化数组.
//create scanner object
Scanner input = new Scanner(System.in);
//declare variable
long [] cc_num = new long[16];
//get input
System.out.print("Enter 15 or 16-digit credit card number: ");
//long cc_num = input.nextLong();
for (int i = 0; i < cc_num.length; i++) {
cc_num[i] = input.nextLong();
}
Run Code Online (Sandbox Code Playgroud)
如何根据输入的长度初始化数组(请求15或16)
我想的范围减少arr到一个do ... while循环,所以一旦退出循环,可以销毁.
如果我宣布arr 内的do while循环,我得到的错误:
符号无法找到
我可以在循环之前声明它,但是arr即使我不再需要它,我仍然会在内存中保持膨胀.
//int[] arr = {0}; // this works, but the scope is outside the loop
do {
int[] arr = {0}; // causes "cannot find symbol" on `while` line
arr = evolve(arr); // modifies array, saves relevant results elsewhere
} while (arr.length < 9999);
Run Code Online (Sandbox Code Playgroud)
处理这种情况的正确方法是什么?
在阅读了很多"生成字符串排列"的帖子之后,我尝试用Java编写它.1)将第一个字符开始与组合中剩余的字符进行交换.
但是当我尝试使用递归实现它时,它只给了我一个长度为3的字符串的字符串:(.
public static void main(String[] args) {
char a[]= "123".toCharArray();
printPermutation(a,0);
}
private static void printPermutation(char[] a, int i) {
if(i==a.length-1)
System.out.println(new String(a));
else{
for(int x=i+1;x<a.length;x++)
{
swap(a,i,x);
printPermutation(a,x );
swap(a,i,x);
}
}
}
private static void swap(char[] a, int i, int x) {
char t=a[i];
a[i]=a[x];
a[x]=t;
}
Run Code Online (Sandbox Code Playgroud)
我期待打印6个字符串.
预期:123,132,213,231,312,321
Spring启动应用程序启动,tomcat运行,然后在最终死亡之前抛出错误.
运行我的应用程序给我这个Autowired错误:
2016-07-29 02:18:24.737 ERROR 44715 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSecurityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private myapp.MyUserDetailsService myapp.WebSecurityConfig.userDetailsService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [myapp.MyUserDetailsService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
Run Code Online (Sandbox Code Playgroud)
我的安全配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends …Run Code Online (Sandbox Code Playgroud) 我现在几个小时都在努力解决这个问题,但我找不到出路,问题是:
我编写了一个程序,使用itext版本7(以及很多版本)生成一个pdf文件以及一些统计信息,每个事情都是正确的,但是当我的pdf应该包含一些阿拉伯字符串时,它们只是从左到右出现,没有重要的是我尝试过(改变字体,使用通用编码,将字符串放在表格的单元格内,使用画布,......)我无法使它们正常显示.这是我用来显示阿拉伯字符串的一段代码:
PdfFont fArabic=PdfFontFactory.createFont(ARABICFONT,PdfEncodings.IDENTITY_H, true);
final String ARABIC = "\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645";
document.add(new Paragraph(ARABIC).setFont(fArabic).setBaseDirection(BaseDirection.RIGHT_TO_LEFT));
Run Code Online (Sandbox Code Playgroud)
注意:我认为itext 5版本也许可以解决它,但正如我所说,我无法撤消我写的代码,特别是我有它的第三个统计库,而且项目已经很晚了.我只想要一个使用itext的解决方案7版.
java ×8
algorithm ×2
arrays ×2
spring ×2
collections ×1
do-while ×1
enums ×1
generics ×1
itext ×1
itext7 ×1
jpa ×1
loops ×1
matrix ×1
pdf ×1
recursion ×1
scope ×1
spring-boot ×1
spring-data ×1
spring-ioc ×1
string ×1