小编Shr*_*ani的帖子

if-else和switch语句的替代方案

我在Java中有以下代码:

public void doSomething(int i) {
    if (i == 12) {
        // order should be same
        up();
        left();
        stop();
    }
    if (i == 304) {
        // order should be same
        right();
        up();
        stop();
    }
    if (i == 962) {
        // order should be same
        down();
        left();
        up();
        stop();
    }
}
// similar code can be done using switch case statements.
// all the function can have any functionality and might not resemble to the name given to them.
Run Code Online (Sandbox Code Playgroud)

现在,如果我被要求不使用if-else和switch case语句,那么可以做些什么呢?代码可以用Java或JavaScript完成.

javascript java conditional-statements

14
推荐指数
4
解决办法
5825
查看次数

从S3存储桶下载模式匹配的条目

我有一个S3存储桶,其中存储了几个日志文件,格式为index.log.yyyy-mm-dd-01 index.log.yyyy-mm-dd-02...

yyyy for year,mm for month和dd for date.

现在我只想下载其中的一些.我看到下载整个S3存储桶?.如果我想下载整个存储桶,这篇文章的接受答案是绝对正常的,但如果我想做一些模式匹配,我该怎么办?我尝试了以下命令,但它们没有奏效:

aws s3 sync s3://mybucket/index.log.2014-08-01-* .
aws s3 sync 's3://mybucket/index.log.2014-08-01-*' .
Run Code Online (Sandbox Code Playgroud)

我还尝试使用http://fosshelp.blogspot.in/2013/06文章的POINT 7和http://s3tools.org/s3cmd-sync使用s3cmd进行下载.以下是我运行的命令:

s3cmd -c myconf.txt get --exclude '*.log.*' --include '*.2014-08-01-*' s3://mybucket/ .
s3cmd -c myconf.txt get --exclude '*.log.*' --include '*.2014-08-01-*' s3://mybucket/ .
Run Code Online (Sandbox Code Playgroud)

还有一些这样的排列.

任何人都可以告诉我为什么不发生模式匹配?或者,如果我需要使用任何其他工具.

谢谢 !!

command-line-interface amazon-s3 amazon-web-services s3cmd

13
推荐指数
1
解决办法
3239
查看次数

在HashMap中使用相同的键存储多个值

今天我接受了采访,我的面试官问我如何在HashMap中存储具有相同键的多个值?她给了我这个例子 - >如果给我一个String列表,我想将String的长度存储为键,String本身作为值存储.

我给了她以下解决方案,我将如何使用HashMap:

Map<Integer, ArrayList<String>> map = new HashMap<Integer, ArrayList<String>>();
Run Code Online (Sandbox Code Playgroud)

整数是String的长度,ArrayList将存储该特定长度的字符串.

采访者说这是使用HashMap的一种方式,但还有另一种方法我不需要ArrayList或任何其他数据结构.在采访中,我无法提出任何解决方案,现在经过足够的谷歌搜索,我仍然没有任何东西.谁能告诉我如何才能实现这个问题的解决方案?

谢谢!

java hashmap

6
推荐指数
1
解决办法
9507
查看次数

Django 表单 'autocomplete'='off' 不起作用

我看过很多关于 SO 的答案,但没有一个适合我的情况。我的模型表格如下所示:

class ChangePasswordForm(forms.Form):
    current_password = forms.CharField(
        max_length=64,
        widget=forms.PasswordInput(
            attrs={'placeholder': 'Current Password', 'autocomplete': 'off'}))

    new_password = forms.CharField(
        min_length=6,
        max_length=64,
        widget=forms.PasswordInput(
            attrs={'placeholder': 'New Password', 'autocomplete': 'off'}))

    confirm_password = forms.CharField(
        min_length=6,
        max_length=64,
        widget=forms.PasswordInput(
            attrs={'placeholder': 'Confirm New Password', 'autocomplete': 'off'}))
Run Code Online (Sandbox Code Playgroud)

current_password、new_password 和confirm_password 仍在表单上填充。我检查了 Safari 和 Google Chrome,仍然遇到同样的问题。谁能告诉我我做错了什么?

django safari google-chrome

5
推荐指数
1
解决办法
3572
查看次数