null

Groovy String concatenation with null checks

独自空忆成欢 提交于 2019-12-23 08:38:07
问题 Is there a better way to do this? Note: part1 , part2 and part3 are string variables defined elsewhere (they can be null). def list = [part1, part2, part3] list.removeAll([null]) def ans = list.join() The desired result is a concatenated string with null values left out. 回答1: You can do this: def ans = [part1, part2, part3].findAll({it != null}).join() You might be able to shrink the closure down to just {it} depending on how your list items will evaluate according to Groovy Truth, but this

Drowning in a Sea of Nulls

只愿长相守 提交于 2019-12-23 08:26:57
问题 An application I inherited tracks lab test results performed on material samples. Data is stored in a single table (tblSampleData) with a primary key of SampleID and 235 columns representing potential test results. The problem is that only a few tests are performed per sample, so each row contains over 200 nulls. Actually, there is a second similar table (tblSampleData2) with another 215 primarily null columns and a primary key of SampleID. The two tables have a one-to-one relationship and

How do I identify an empty NSData Object that appears as empty brackets?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 08:12:32
问题 I am dealing with a corruption issue in Game Kit's GKTurnBasedMatch class (see this thread) which sometimes results in an invalid game state, with corrupted matchData. So as a workaround, I'm creating a way out a way to identify these invalid matches so I can deal with them appropriately. The corrupted matchData seems like a good way to do this. However, so far I've been unable to identify them. When I do this: // "match" is an existing GKTurnBasedMatch object NSLog(@"match data is: %@",

TypeError: must be string without null bytes, not str

六月ゝ 毕业季﹏ 提交于 2019-12-23 07:48:32
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

TypeError: must be string without null bytes, not str

旧巷老猫 提交于 2019-12-23 07:48:26
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

Regex.MatchData returning null: why not Option[String]?

人盡茶涼 提交于 2019-12-23 07:39:00
问题 Is there any particular reason why Regex.MatchData.group(i: Int): java.lang.String returns null rather than Option[String]? Is there a "Scala Way" to handle nulls in Scala? 回答1: It returns null because it is a shallow interface over the Java library. I think it sucks too, and I have been bitten by it. If you get a value that may be null, you can write Option(value) on Scala 2.8 and it will become either None or Some(value) . That doesn't work with pattern matching, but you can write your own

Are keySet entries of a WeakHashMap never null?

六眼飞鱼酱① 提交于 2019-12-23 07:29:12
问题 If I iterate over the key set of a WeakHashMap, do I need to check for null values? WeakHashMap<MyObject, WeakReference<MyObject>> hm = new WeakHashMap<MyObject, WeakReference<MyObject>>(); for ( MyObject item : hm.keySet() ) { if ( item != null ) { // <- Is this test necessary? // Do something... } } In other words, can elements of the WeakHashMap be collected while I am iterating over them? EDIT For the sake of this question, one can assume that no null entries is added in the hash map. 回答1

Splat on a hash

最后都变了- 提交于 2019-12-23 07:26:38
问题 A splat on a hash converts it into an array. [*{foo: :bar}] # => [[:foo, :bar]] Is there some hidden mechanism (such as implicit class cast) going on here, or is it a built-in primitive feature? Besides an array, are nil and hash the only things that disappear/change with the splat operator under Ruby 1.9? 回答1: A splat will attempt an explicit conversion of an object to an Array. To do this, it will send to_a and expect an Array as a result. class Foo def to_a [1,2,3] end end a, b, c = *Foo

basic_string::_M_construct null not valid after constructing subvector of strings

£可爱£侵袭症+ 提交于 2019-12-23 07:03:10
问题 My code is supposed to read in a text file and have multiple threads look through different chunks of lines for the longest palindrome. The size of the chunk (how many lines) is determined by a variable number of threads passed in as an argument. The original text file is stored in an std::vector where each index of the vector corresponds to the original file. When I pass the subvector chunk to findPalindome(), I get a 'C++ basic_string::_M_construct null not valid' and I can't figure out why

basic_string::_M_construct null not valid after constructing subvector of strings

左心房为你撑大大i 提交于 2019-12-23 07:02:04
问题 My code is supposed to read in a text file and have multiple threads look through different chunks of lines for the longest palindrome. The size of the chunk (how many lines) is determined by a variable number of threads passed in as an argument. The original text file is stored in an std::vector where each index of the vector corresponds to the original file. When I pass the subvector chunk to findPalindome(), I get a 'C++ basic_string::_M_construct null not valid' and I can't figure out why