我有一个java代码,以特定格式输入日期.
static Date parseDate(String userInput){
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = format.parse(userInput);
System.out.println(date);
}catch(ParseException pe){
date=null;
System.out.println("Not a valid date");
}
return date;
}
Run Code Online (Sandbox Code Playgroud)
现在我输入的2015-13-11 89:90:90是无效日期.但它Thu Jan 14 18:31:30 IST 2016作为日期返回.为什么会这样?如何让它作为日期返回null?
我已经看到了这个问题和这个博客的PAN正则表达式.[A-Z]{5}[0-9]{4}[A-Z]{1}.但我的问题比那更加广泛.
在PAN卡号中:
1) The first three letters are sequence of alphabets from AAA to zzz
2) The fourth character informs about the type of holder of the Card. Each assesse is unique:`
C — Company
P — Person
H — HUF(Hindu Undivided Family)
F — Firm
A — Association of Persons (AOP)
T — AOP (Trust)
B — Body of Individuals (BOI)
L — Local Authority
J — Artificial Judicial Person
G — Government …Run Code Online (Sandbox Code Playgroud) 我必须像这样填充一个json对象,假设它被命名为detailJSON:
{"amount": "5.00", "ac_no": "123456" }
Run Code Online (Sandbox Code Playgroud)
我是这样做的:
detailJSON.put("amount","5.00");
detailJSON.put("ac_no","123456");
Run Code Online (Sandbox Code Playgroud)
在此之后,在一些共享首选项中输入详细信息,现在我想清除此JSONObject并使用相同的detailJSON对象来存储另一个json(使用不同的键),这样:
{"amount":"6.00", "loan_no":"123456"}
Run Code Online (Sandbox Code Playgroud)
我知道有一个方法remove(),它删除了特定的键和相应的值.
这有效:
detailJSON.remove("amount");
detailJSON.remove("ac_no");
Run Code Online (Sandbox Code Playgroud)
然后使用它 -
detailJSON.put("amount","6.0");
detailJSON.put("loan_no","123456");
Run Code Online (Sandbox Code Playgroud)
现在这是一个非常简单的例子.在我正在处理的代码中,我有很多键,所以使用remove实际上增加了LOC.另外,每次删除之前我都需要检查JSONObject是否has是特定键.
有没有其他方法,我可以实现清除JSONObject?
我试过了
detailJSON=null ;
detailJSON=new JSONObject();
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我基本上是在寻找类似clear()方法的东西,如果存在的话.
我正在使用mongoDB shell with version 3.0.2
我正在尝试确保username集合中字段的唯一性约束users.
这是我给的:
db.users.ensureIndex({"username": 1},{unique: true})
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"errmsg" : "exception: E11000 duplicate key error index: mybackend.users.$username_1 dup key: { : \"rahat\" }",
"code" : 11000,
"ok" : 0
}
Run Code Online (Sandbox Code Playgroud)
然后我dropDups: true在命令中使用:
db.users.ensureIndex({"username": 1},{unique: true, dropDups: true})
Run Code Online (Sandbox Code Playgroud)
然后我也得到同样的错误:
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"errmsg" : "exception: E11000 duplicate key error index: mybackend.users.$username_1 dup key: { : \"rahat\" }",
"code" : 11000, …Run Code Online (Sandbox Code Playgroud) 是什么意思cut-off,并iteration在OpenNLP培训?或者就此而言,自然语言处理.我只需要一个外行解释这些术语.据我所知,迭代是算法重复的次数,并且截断是一个值,如果文本的值高于某个特定类别的截止值,它将被映射到该类别.我对吗?
它似乎com.android.camera.action.CROP不可靠,因为它是一个内部API,并不是每个设备都可用.但是,我发现这个库非常实用.它在我的Galaxy Nexus上运行得很好.
我真的应该考虑实施自己的解决方案吗?我使用过多冒险com.android.camera.action.CROP吗?此外,在某些设备中,它会打开谷歌+裁剪照片,之后会崩溃.
最后,有没有我可以使用的开放库可以完成同样的事情,并且可以安全地在任何Android设备上使用?
我有一个Post模型,PostSource模型.PostSource有很多帖子,帖子属于一个PostSource.
使用ActiveAdmin,在Post的Index操作中,我以这种方式显示PostSource的过滤器:
filter :post_source, label: 'Source'
filter :category, as: :select, collection: Category.order(:name).collect { |cat| [cat.name, cat.id] }
Run Code Online (Sandbox Code Playgroud)
与控制器一样:
controller do
def scoped_collection
end_of_association_chain.includes(:post_source)
end
end
Run Code Online (Sandbox Code Playgroud)
它显示源,但不按排序顺序显示.在这种情况下如何对过滤器进行排序?
我尝试在过滤器上添加可排序的顺序,但它似乎不起作用
任何人都可以建议我这个算法.
您将获得x轴上N段的起点和终点.即使在它们的边缘上,也可以通过垂直于它们的两条线来触摸这些段中的多少个?
样本输入:
3
5
2 3
1 3
1 5
3 4
4 5
5
1 2
1 3
2 3
1 4
1 5
3
1 2
3 4
5 6
Run Code Online (Sandbox Code Playgroud)
样本输出:
Case 1: 5
Case 2: 5
Case 3: 2
Run Code Online (Sandbox Code Playgroud)
说明:
约束:
1 ? N ? 10^5
0 ? a < b ? 10^9
Run Code Online (Sandbox Code Playgroud) 我有这样的哈希
trial_hash ={"key1"=>1000, "key2"=>34, "key3"=>500, "key4"=>500, "key5"=>500, "key6"=>500}
Run Code Online (Sandbox Code Playgroud)
我按照值的降序排序:
my_hash = trial_hash.sort_by{|k, v| v}.reverse
Run Code Online (Sandbox Code Playgroud)
我现在这样做了:
[["key1", 1000], ["key4", 500], ["key5", 500], ["key6", 500], ["key3", 500], ["key2", 34]]
Run Code Online (Sandbox Code Playgroud)
但我希望它在值相同时按键的升序排序.我该怎么做?
例如:以上哈希将以这种方式排序:
[["key1", 1000], ["key3", 500], ["key4", 500], ["key5", 500], ["key6", 500], ["key2", 34]]
Run Code Online (Sandbox Code Playgroud) 我有一个模型,称为Complaign,带有一些其他属性以及抱怨日期(c_date).
在ComplaignController,我有一个index视图,显示所有complaigns.从日期到日期都有一个过滤器.在过滤它时,它工作正常,并正确显示在这些日期触发的抱怨.
现在我希望将此查询的结果传递给另一个方法,比如export方法.
我想从索引视图中传递它,因为它存储在@complaigns.
这是我的索引方法:
def index
if params[:from] && params[:to]
from = params[:from].to_date
to = params[:to].to_date
@complaigns = Complaigns.where(:c_date => from..to)
else
@complaigns = Complaigns.all
end
end
Run Code Online (Sandbox Code Playgroud)
在索引视图中,这是我写的
<%= link_to "Export", {:controller => "complaigns", :action => "export", :complaigns => @complaigns}%>
Run Code Online (Sandbox Code Playgroud)
这是导出方法
def export
@complaigns = params[:complaigns]
end
Run Code Online (Sandbox Code Playgroud)
现在,在导出视图中,当我执行以下操作时:
@complaigns.each,我得到这个错误 -
undefined method `each' for "#<Complaign::ActiveRecord_Relation:0x00000003cfb4c8>":String
Run Code Online (Sandbox Code Playgroud)
现在,这是因为,我认为,没有任何方法each在String类.有什么办法,我可以在方法中将String转换为Complaign类型,export或者在索引视图中传递它时,将其作为Complaign对象而不是String传递?有没有其他方法这样做?
android ×2
java ×2
ruby ×2
sorting ×2
activeadmin ×1
algorithm ×1
date ×1
graph-theory ×1
hash ×1
json ×1
mongodb ×1
opennlp ×1
overlapping ×1
regex ×1
text-mining ×1