convert

How do I convert from List<?> to List<T> in Java using generics?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Java, how do I convert List<?> to List<T> using a general purpose method so that I can replace patterns like the following with a single method call: List untypedList = new ArrayList(); // or returned from a legacy method List<Integer> typedList = new ArrayList<Integer>(); for (Object item: untypedList) typedList.add((Integer)item); Note that the above code does not generate any type-safety warnings and, ideally, your solution shouldn't generate any such warnings, either. Will the following solution work provided that list Class<L> has a

Convert a string to a byte array in PowerShell version 2

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What I'm trying to do is use SHA1 UTF-8 encryption and then base64 encoding and on a password string value. However, I needed to do the encryption first, then the encoding, but I did it the other way around. Here is the code: # Create Input Data $enc = [ system . Text . Encoding ]:: UTF8 $string1 = "This is a string to hash" $data1 = $enc . GetBytes ( $string1 ) # Create a New SHA1 Crypto Provider $sha = New - Object System . Security . Cryptography . SHA1CryptoServiceProvider $ # Now hash and display results $result1 = $sha .

Convert Map to Bundle in android

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there an easy way to convert a Map to a Bundle in android without explicit iteration? Why? Firebase returns a Map for Notification getData() . I need to pass the data to an intent. Formerly GCM gave me a bundle, so I didn't need to worry about this. 回答1: I guess a good old fashioned for loop is the easiest way: Bundle bundle = new Bundle(); for (Map.Entry<String, String> entry : getData().entrySet()) { bundle.putString(entry.getKey(), entry.getValue()); } 回答2: Came across this same issue with firebase messaging and created a kotlin

Scala convert List[Int] to a java.util.List[java.lang.Integer]

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a good way in Scala to convert between a List[Int] to a java.util.List[java.lang.Integer]? I'm interfacing with Java (Thrift). JavaConversions supports List --> java.util.List, and implicits exist between Int --> java.lang.Integer, but from what I can tell I would still need an extra pass to manually do the conversion. val y = List(1) val z: java.util.List[Integer] = asList(y) map { (x: Int) => x : java.lang.Integer } 回答1: Apparently you need both conversions. However, you can group them in a single implicit conversion: implicit def

convert string to memory stream - Memory stream is not expandable?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i was trying to write a string to a memory stream, but failed with the error message: Memory stream is not expandable. the line of code that produces this problem: context.Response.Filter = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(myPage)); anyone have a workaround/fix for that? stacktrace: [NotSupportedException: Memory stream is not expandable.] System.IO.MemoryStream.set_Capacity(Int32 value) +9385744 System.IO.MemoryStream.EnsureCapacity(Int32 value) +50 System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32

Issue with calcuating compass bearing between two GPS coordinates

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my webapp, have a JSON data response from a database query that includes the lat/long coordinates of 1 to n locations. I want to calculate the bearing from the data[i] location to the current position. I've been adapting the code here , but the bearing returned is incorrect. //starting lat/long along with converting lat to rads var endLat = toRad(location.lat()); var endLong = location.lng(); //loop over response, calculate new headings for links and add link to array for(var i=0; i<data.length; i++){ //this link's lat/long coordinates,

Is there a way to convert the coordinate system after a change to Landscape Orientation?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In a view-based iPhone OS application, I change the orientation from the initial portrait orientation to a landscape orientation (UIInterfaceOrientationLandscapeRight). But now the x,y origin (0,0) is in the lower-left corner (instead of the usual upper-left) and each time I want to do something that involves coordinates I must re-calculate to compensate for the new coordinate system. I have also noticed that my views within the new coordinate system are not behaving normally at times. So, Is there a way to convert the coordinate system ONCE

How to convert an MD5 hash to a string and use it as a file name

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am taking the MD5 hash of an image file and I want to use the hash as a filename. How do I convert the hash to a string that is valid filename? EDIT: toString() just gives "System.Byte[]" 回答1: How about this: string filename = BitConverter . ToString ( yourMD5ByteArray ); If you prefer a shorter filename without hyphens then you can just use: string filename = BitConverter . ToString ( yourMD5ByteArray ). Replace ( "-" , string . Empty ); 回答2: System.Convert.ToBase64String As a commenter pointed out -- normal base 64 encoding can

Convert a two byte UInt8 array to a UInt16 in Swift

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: With Swift I want to convert bytes from a uint8_t array to an integer. "C" Example: char bytes[2] = {0x01, 0x02}; NSData *data = [NSData dataWithBytes:bytes length:2]; NSLog(@"data: %@", data); // data: uint16_t value2 = *(uint16_t *)data.bytes; NSLog(@"value2: %i", value2); // value2: 513 Swift Attempt: let bytes:[UInt8] = [0x01, 0x02] println("bytes: \(bytes)") // bytes: [1, 2] let data = NSData(bytes: bytes, length: 2) println("data: \(data)") // data: let integer1 = *data.bytes // This fails let integer2 = *data.bytes as UInt16 // This

python csv reader - convert string to int on the for line when iterating

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm interested in not having to write map the int function to the tuple of strings where I currently have it. See the last part of my example: import os import csv filepath = os.path.normpath("c:/temp/test.csv") individualFile = open(filepath,'rb') dialect = csv.Sniffer().sniff(individualFile.read(1000)) individualFile.seek(0) reader = csv.reader(individualFile,dialect) names = reader.next() print names def buildTree(arityList): if arityList == []: return 0 else: tree = {} for i in xrange(arityList[0][0],arityList[0][1]+1): tree[i] =