我有以下列表 -
val A = List(("A","B","C","D"),("A1","B1","C1","D1"),("A2","B2","C2","D2"))
Run Code Online (Sandbox Code Playgroud)
和
val B = List(("P","Q","R","S","T"),("P1","Q1","R1","S1","T1"),("P2","Q2","R2","S2","T2"),("P3","Q3","R3","S3","T3"))
Run Code Online (Sandbox Code Playgroud)
我想将列表A的第一个元素与列表B的第一个元素合并,依此类推.这里列表A有3个元素,B有4个.我想在合并时考虑列表A中的元素数量.
输出如下
val combineList = List(("A","B","C","D","P","Q","R","S","T"),("A1","B1","C1","D1","P1","Q1","R1","S1","T1"),
("A2","B2","C2","D2","P2","Q2","R2","S2","T2"))
Run Code Online (Sandbox Code Playgroud) 我正在使用scala和play框架.我想在我的应用程序中使用播放安全授权.
以前我使用java在项目中实现它并播放如下:
public class Secured extends Security.Authenticator {
private static String EMAIL = "Email";
private static String U_COOKIE = "ucookie";
public String getUsername(Context ctx) {
String decodedText = null;
String CHARSET = "ISO-8859-1";
Cookies cookies = play.mvc.Controller.request().cookies();
try {
Cookie emailCookie = cookies.get(EMAIL);
Cookie uCookie = cookies.get(U_COOKIE);
if (uCookie !=null && uCookie.value() != null) {
String userId = uCookie.value();
}
if (emailCookie != null && emailCookie.value() != null) {
String email = emailCookie.value();
try {
decodedText = new String(Base64.decodeBase64(email.getBytes(CHARSET)));
} …Run Code Online (Sandbox Code Playgroud) 我有两个清单
val firstList = List(("A","B",12),("P","Q",13),("L","M",21))
val secondList = List(("A",11),("P",34),("L",43))
Run Code Online (Sandbox Code Playgroud)
我想要输出如下
val outPutList = List(("P","Q",13,34),("L","M",21,43))
Run Code Online (Sandbox Code Playgroud)
我想比较firstList的第三个成员和secondList的第二个元素.这意味着 - 我想检查第二个列表值secondList.map(_.2)是否大于第一个列表firstList.map(_.3)
有一个 shell 脚本正在更新日志文件。
我想在写入日志文件时逐行显示日志(而不是一次显示整个文件)。
写入文件工作正常,但我在读取文件时遇到问题,因为它一次显示整个文件。
这是我的阅读代码:
String nmapstatusfile = runMT.instdir+"/logs/nmapout."+customer+".log";
String nmapcommand=runMT.instdir+"/bin/doscan.sh "+nmapoutfile+" "
+IPRange+" "+nmapstatusfile+" "+nmapdonefile;
System.out.println("nmapcommand is .. "+nmapcommand);
Runtime r = Runtime.getRuntime();
Process pr = r.exec(nmapcommand);
RandomAccessFile raf =null;
try {
System.out.println(nmapstatusfile);
System.out.println("Reading a file");
raf = new RandomAccessFile(nmapstatusfile, "r");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // read from input file
System.out.println("Will print file contents line by line...");
long pos = 0;
raf.seek(pos);
String line =null;
while ((line = raf.readLine())!= null) …Run Code Online (Sandbox Code Playgroud) 我有以下列表 -
List((name1,A1,176980), (name2,A2,0), (name3,A3,1948), (name4,A4,95676))
Run Code Online (Sandbox Code Playgroud)
从上面的列表中我想分别创建单独的列表元素列表,如element1,element2和element3.
我想要单独的清单,如 -
List(name1,name2,name3,name4)
List(A1,A2,A3,A4)
List(176980,0,1948,95676)
Run Code Online (Sandbox Code Playgroud)
如何使用scala获取上面的列表???
我有以下列表:
List(List(vmnic4), List(vmnic5))
Run Code Online (Sandbox Code Playgroud)
我想把它改成
List(vmnic4,vmnic5)
Run Code Online (Sandbox Code Playgroud)
我如何使用scala?
我正在使用 R 和 Java 来显示预测。
我有5小时的数据。我想从四个小时的数据(相对于日期的内存)预测第 5 小时的数据。通过使用 4 小时的数据,我正在创建新集合并将第 5 小时的预测数据插入到新集合中。但我收到以下错误:
The Exception is eval failed, request status: error code: 127
org.rosuda.REngine.Rserve.RserveException: eval failed, request status: error code: 127
at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:233)
at scheduler.scheduler.predictions.getPredictionsofData(predictions.java:45)
at pack.GetCollectionMultithreaded.getPredictionAndInsert(GetCollectionMultithreaded.java:386)
at pack.GetCollectionMultithreaded.runCustomerListAndPredictionEvery5Min(GetCollectionMultithreaded.java:155)
at pack.GetCollectionMultithreaded.main(GetCollectionMultithreaded.java:103)
Run Code Online (Sandbox Code Playgroud)
这是代码:
public class predictions {
public void getPredictionsofData(DB dbObj){
FileInputStream fis = null;
DBCollection network_device_realtime = dbObj.getCollection("mycollectionname");
DBObject return_dobject = null;
// For Network device1 realtime
try{
List<String> listOfIps = network_device_realtime.distinct("hostId");
RConnection c = new RConnection(Rhost,Rport);
c.eval("library(RMongo)");
c.eval("library(plyr)");
c.eval("library(randomForest)");
c.eval(" …Run Code Online (Sandbox Code Playgroud) 我试图通过MongoDB使用C# driver(最新驱动程序版本 2.0.1.27)获得一些结果。
这就是我如何称呼 mongo :
public static async Task < List < MomLogModel >> MomLogAr(MomLogArModel arama) {
var asd = Builders < MomLogModel > .Filter.Where(a => a.SipID == arama.SipID);
asd = asd & Builders < MomLogModel > .Filter.Where(a => a._id == arama._id);
var donucek = await mongoContex.MomLog.Find(asd).ToListAsync().ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)
这是 MomLogModel 的类:
public class MomLogModel {
[BsonRepresentation(BsonType.ObjectId)]
public string _id {
get;
set;
}
[BsonElement("g")]
public BsonDocument gelen {
get;
set;
}
[BsonElement("t")]
public DateTime YaratTarih …Run Code Online (Sandbox Code Playgroud) public class SubClass {
public bool isValid {
get;
set;
}
}
public class MainClass {
public List < SubClass > SubClasses {
get;
set;
}
}
MainClass m = new MainClass() {
Name = "Mohsen", SubClasses = new List < SubClass > (new SubClass[] {
new SubClass() {
IsValid = true
}
})
};
MongoMainClassCollection.Save < MainClass > (m);
Run Code Online (Sandbox Code Playgroud)
问题是所有子类 ID 的默认值都为零。
每当我保存 MainClass 时,我希望 MongoDB 为任何 SubClass 分配一个唯一的 ID。
有没有办法配置 MongoDB 来做到这一点?
我有以下两个清单 -
val list1 = List(("192.168.0.1","A"),("192.168.0.2","B"),("192.168.0.3","C"))
val list2 = List(("192.168.0.104",2), ("192.168.0.119",2), ("205.251.0.185",24), ("192.168.0.1",153))
Run Code Online (Sandbox Code Playgroud)
我想匹配两个列表的第一个值,如下所示:
outputList = List(("192.168.0.1","A",153))
Run Code Online (Sandbox Code Playgroud)
目前我正在使用以下来获得输出 -
list1.map{
ajson =>
val findHost = list2.filter(_._1.contains(ajson._1.trim))
if(findHost.nonEmpty) {
(ajson._1,ajson._2,findHost.head._2)
} else ("NA","NA",0)
}.filterNot(p => p._1.equals("NA") || p._2.equals("NA"))
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
我也试过了
(list1 ::: list2).groupBy(_._1).map{.......}
Run Code Online (Sandbox Code Playgroud)
但它给出了list1中的所有元素.
任何人都可以帮助我获得预期的输出吗?