我正在学习使用套装.我的问题是:集合不包含重复项.当我们尝试插入重复项时,它不会抛出任何错误并自动删除重复项.在插入集合之前检查每个值是否存在是否是一个好习惯?或者可以执行类似下面的代码?我认为Java会在内部进行检查.contains(value).你怎么看?
考虑到有n个元素进入集合,两种情况下的Big O复杂度是多少?
import java.util.HashSet;
import java.util.Set;
public class DuplicateTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Set<Integer> mySet = new HashSet<Integer>();
mySet.add(10);
mySet.add(20);
mySet.add(30);
mySet.add(40);
mySet.add(50);
mySet.add(50);
mySet.add(50);
mySet.add(50);
mySet.add(50);
mySet.add(50);
System.out.println("Contents of the Hash Set :"+mySet);
}
}
Run Code Online (Sandbox Code Playgroud) 作为spring注释的新手,我需要澄清下面的代码.
@PostFilter("hasPermission(filterObject, 'READ') or hasRole('ROLE_ADMIN')")
public List<User> getUsers(String orderByInsertionDate,
Integer numberDaysToLookBack) throws AppException
Run Code Online (Sandbox Code Playgroud)
;
所以这意味着getUsers返回的用户列表将只包含那些"READ"对调用对象具有完全访问权限或者调用对象具有角色的元素"ROLE_ADMIN".谢谢.
我想获得一个存储库或文件列表,其中存储库中包含的文件内容与我在搜索中指定的关键字匹配。我尝试使用https GET请求进行简单搜索,但是如果未指定存储库或组织名称,则似乎无法进行搜索。我收到以下错误。
https://api.github.com/search/code?q=authorization+in:file
{
"message": "Validation Failed",
"errors": [
{
"message": "Must include at least one user, organization, or repository",
"resource": "Search",
"field": "q",
"code": "invalid"
}
],
"documentation_url": "https://developer.github.com/v3/search/#search-code"
}
Run Code Online (Sandbox Code Playgroud)
我了解没有存储库或组织名称的搜索将占用大量资源。有什么解决方法吗?我以为既然能够通过在线搜索获得结果,那么我应该能够使用git search api达到相同的效果。
所以基本上我想模拟以下内容:
https://github.com/search?utf8=%E2%9C%93&q=authorization&type=Code&ref=searchresults
我是春天安全的新手.我怎么解释这个?
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI')")
OpetussuunnitelmaDto addOpetussuunnitelma(OpetussuunnitelmaDto opetussuunnitelmaDto);
Run Code Online (Sandbox Code Playgroud)
来自权限评估程序的哪种方法会被调用?我想在这种情况下会调用带有三个参数的那个.它正在检查当前用户是否对类型目标''opetussuunnitelma'具有'LUONTI'权限.我对吗?我们不能只包括"null"并且只传递两个参数.我读到没有提供第一个参数(Authentication对象).
+public class PermissionEvaluator implements org.springframework.security.access.PermissionEvaluator {
+
+ @Override
+ public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
+ LOG.error(" *** ei toteutettu *** ");
+ return true;
+ }
+
+ @Override
+ public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
+ LOG.error(" *** ei toteutettu *** ");
+ return true;
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(PermissionEvaluator.class);
+}
Run Code Online (Sandbox Code Playgroud) 我对为什么有人会使用@PreAuthorize("denyAll")一种方法感到有些困惑。根据 spring 安全文档,它始终评估为 false。
如果我们不打算允许访问特定的方法,那么保留这样的方法又有什么意义呢?为什么不注释掉呢?还是仍然可以从同一个类中访问它?
我试图了解在什么情况下会出现这样的要求。
我有这个要求.根据函数中传递的参数数量,我需要在地图中创建许多条目.假设我有一个函数myfunc1(a,b,c),我需要一个带有键的地图,如"a","b"和"c",我可以为每个键设置多个值.但问题是我事先不知道,这些键会有多少值.当值到达时,我需要将它们添加到与映射中的匹配键对应的值列表中.我如何在javascript中执行此操作?我找到了如下的静态答案.但我想动态地这样做.我们可以使用推送方法吗?
var map = {};
map["country1"] = ["state1", "state2"];
map["country2"] = ["state1", "state2"];
Run Code Online (Sandbox Code Playgroud) 我读过这篇stackoverflow帖子 @Secured和@PreAuthorize在spring security 3中的区别是什么? 但是,我还不清楚两者在安全方面有什么大不同?与@Secured相比,在什么情况下我们应该选择@PreAuthorize?
我试图根据单词之间的空格分割输入句子.它没有按预期工作.
public static void main(String[] args) {
Scanner scaninput=new Scanner(System.in);
String inputSentence = scaninput.next();
String[] result=inputSentence.split("-");
// for(String iter:result) {
// System.out.println("iter:"+iter);
// }
System.out.println("result.length: "+result.length);
for (int count=0;count<result.length;count++) {
System.out.println("==");
System.out.println(result[count]);
}
}
Run Code Online (Sandbox Code Playgroud)
当我在split中使用" - "时,它给出了下面的输出:
fsfdsfsd-second-third
result.length: 3
==
fsfdsfsd
==
second
==
third
Run Code Online (Sandbox Code Playgroud)
当我用空格""替换" - "时,它给出了下面的输出.
first second third
result.length: 1
==
first
Run Code Online (Sandbox Code Playgroud)
关于这里有什么问题的任何建议?我已经提到了stackoverflow post 如何按空格分割字符串,但它不起作用.
使用split("\\s+")提供此输出:
first second third
result.length: 1
==
first
Run Code Online (Sandbox Code Playgroud) 我试图使用递归解决二进制间隙问题.它可以很容易地解决而无需递归.但我想通过递归来解决这个问题.下面的程序将整数作为输入并找到二进制间隙.
例:
input= 9, Binary form = 1001, Answer = 2
input=37, Binary form = 100101, Answer = 2
Run Code Online (Sandbox Code Playgroud)
它找到二进制表示中两个1之间出现的最大零数.
我想在O(logn)中解决这个问题.现在,下面的程序只计算零的总数并给出输出3而不是2.如何更正此输出以获得正确的输出?
class BinaryGap {
public int solution(int N){
return solution(N, false, 0);
}
public int solution(int N, boolean prevFlag, int memo) {
if(N<2)
return 0;
int remainder = N%2 ;
if(prevFlag){
if(remainder == 0){
memo = 1 + solution(N/2, prevFlag, memo);
} else {
int newGap = solution(N/2, prevFlag, memo);
if(newGap > memo)
memo = newGap;
}
} else { …Run Code Online (Sandbox Code Playgroud) 我想选择所有标签<td class='blob-code blob-code-addition'> and <td class='blob-code blob-code-deletion'>.所以我试图or在两个谓词之间包含条件.这是行不通的.但是,如果我只包括其中两个类中的一个.这里有什么问题?语法有问题.
By getChanges = By.xpath("//td[@class='blob-code blob-code-addition'] or //td[@class='blob-code blob-code-deletion']");
Run Code Online (Sandbox Code Playgroud) 作为Spring安全框架的新手,我想知道为什么我们使用@PreAuthorize("permitAll()")方法?文档说permitAll总是评估为true.(http://docs.spring.io/spring-security/site/docs/3.0.x/reference/el-access.html)
另外,我有以下代码更改.开发人员从permitAll()更改为特定权限检查.这里的含义是什么?由于我不太确定permitAll()如何工作,我无法判断代码更改背后的逻辑.在我看来,开发人员添加了特定的权限检查,并将null作为身份验证对象传递.有人可以解释显式传递null作为身份验证对象的影响吗?未经身份验证的用户是否具有访问权限,如果他们对目标对象具有此特定的"LUONTI"权限 - 'opetussuunnitelma'?
- @PreAuthorize("permitAll()")
+ @PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI')")
OpetussuunnitelmaDto addOpetussuunnitelma(OpetussuunnitelmaDto opetussuunnitelmaDto);
Run Code Online (Sandbox Code Playgroud)
谢谢.任何帮助非常感谢!
java security annotations spring-security spring-annotations
我想了解以下行为:
def test
puts "In Method"
end
test
#=> In Method
test {puts "In Block" }
#=> In Method
Run Code Online (Sandbox Code Playgroud)
我的解释是,这test是一种方法,我{puts "In Block"}作为一个参数传递给这个方法.由于该方法不使用参数,因此它将打印默认值"In Method".这样对吗?
我们如何区分块和方法调用?可能test {puts "In Block"}也被解释为一个块?是yield执行代码块的唯一方法吗?
我正在尝试将ISO 8601日期字符串转换为纪元时间.我该如何处理负面日期?以下代码是否正确?我应该使用其他东西而不是简单的日期格式库吗?负日期适用于BC.
String formatString = "yyyy-MM-dd'T'hh:mm:ssX";
SimpleDateFormat formatter = new SimpleDateFormat(formatString);
Date date = formatter.parse("-2017-01-04T12:30:00+05:00");
System.out.println(date.getTime()/1000);
Answer: -125818806600L
Run Code Online (Sandbox Code Playgroud) java ×10
spring ×4
annotations ×3
security ×3
algorithm ×1
big-o ×1
binary ×1
codeblocks ×1
date ×1
dictionary ×1
github ×1
github-api ×1
iso8601 ×1
javascript ×1
node.js ×1
performance ×1
recursion ×1
ruby ×1
selenium ×1
set ×1
web-scraping ×1
xpath ×1
yield ×1