null

返回null或空集合更好吗?

╄→尐↘猪︶ㄣ 提交于 2020-02-26 13:58:21
这是一个普遍的问题(但是我正在使用C#),最好的方法是什么(最佳实践),对于以集合为返回类型的方法,您是否返回null或空集合? #1楼 我想在这里举例说明。 在这里考虑一个案例。 int totalValue = MySession.ListCustomerAccounts() .FindAll(ac => ac.AccountHead.AccountHeadID == accountHead.AccountHeadID) .Sum(account => account.AccountValue); 在这里考虑我正在使用的功能.. 1. ListCustomerAccounts() // User Defined 2. FindAll() // Pre-defined Library Function 我可以轻松地使用 ListCustomerAccount 和 FindAll 代替。 int totalValue = 0; List<CustomerAccounts> custAccounts = ListCustomerAccounts(); if(custAccounts !=null ){ List<CustomerAccounts> custAccountsFiltered = custAccounts.FindAll(ac => ac.AccountHead

未 二叉搜索树与双向链表

走远了吗. 提交于 2020-02-26 13:26:58
输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 /** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ ///??????????????????????????????? public class Solution { TreeNode head = null; TreeNode realHead = null; public TreeNode Convert(TreeNode pRootOfTree) { ConvertSub(pRootOfTree); return realHead; } private void ConvertSub(TreeNode pRootOfTree) { if(pRootOfTree==null) return; ConvertSub(pRootOfTree.left); if (head == null) { head = pRootOfTree; realHead = pRootOfTree; } else { head.right = pRootOfTree;

两个链表的第一个公共结点

旧巷老猫 提交于 2020-02-25 15:51:11
题目描述: 输入两个链表,找出它们的第一个公共结点。(注意因为传入数据是链表,所以错误测试数据的提示是用其他方式显示的,保证传入数据是正确的) 代码描述: /* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode FindFirstCommonNode ( ListNode pHead1 , ListNode pHead2 ) { if ( pHead1 == null || pHead2 == null ) { return null ; } ListNode p1 = pHead1 ; ListNode p2 = pHead2 ; while ( p1 != p2 ) { p1 = p1 . next ; p2 = p2 . next ; if ( p1 != p2 ) { //若其中某个链表的指针已经遍历为null,则把该指针指向另一链表的头结点,较长链表也到null时也指正指向另一链表头结点。如此一来两个链表的遍历就是同步状态,继续遍历还是没有共同节点的话,最后结果就是同是指向两个链表的尾部null,循环结束。 if ( p1 == null ) p1 =

Issues in log4net with dynamic filenaming in RollingFileAppender

强颜欢笑 提交于 2020-02-22 06:17:26
问题 I have 3 appenders in my config file for creating 3 different types of logs. I am using dynamic naming of file in each of the 3 appenders by setting the global context properties. In some cases, i need to set the log file name dynamically for just 1 appender. When i set the file name for just 1 appender, it creates another file named "null" with no data in addition to the actual logfile whose name has been set dynamically . I have created the config file as shown. <appender name=

Spark DataFrame的空值形式和空值和非空值之间的相互转换

我的未来我决定 提交于 2020-02-21 22:51:41
1.空值替换为其他值 建df时的空值表示形式为:null null val df = Seq("a", null, "c", "b").toDF("col1") df.show() var df4 = df.na.fill(value="qqq",Array[String]("col1")) df4.show() df: org.apache.spark.sql.DataFrame = [col1: string] +----+ |col1| +----+ | a| |null| | c| | b| +----+ df4: org.apache.spark.sql.DataFrame = [col1: string] +----+ |col1| +----+ | a| | qqq| | c| | b| +----+ 2.其他值转换为空值 此时的空值形式为 “null” val df2 = df.withColumn("col1", regexp_replace(col("col1"), "NullNone", "null")) df2.show() df2: org.apache.spark.sql.DataFrame = [col1: string] +----+ |col1| +----+ | a| |null| | c| | b| +----+ val df3 = df2

POJ 3468 A Simple Problem with Integers splay

孤街浪徒 提交于 2020-02-19 01:45:48
题意:给你一个数列,区间更新和区间询问 解题思路:splay指针版撸的,4700 ms险过 解题代码: 1 // File Name: spoj3468.cpp 2 // Author: darkdream 3 // Created Time: 2014年11月05日 星期三 19时40分26秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bitset> 12 #include<algorithm> 13 #include<functional> 14 #include<numeric> 15 #include<utility> 16 #include<sstream> 17 #include<iostream> 18 #include<iomanip> 19 #include<cstdio> 20 #include<cmath> 21 #include<cstdlib> 22 #include<cstring> 23 #include<ctime> 24 #define LL long long 25 #define maxn 100010 26 using namespace std;

Postgres excludes NULL in WHERE id != int query

我是研究僧i 提交于 2020-02-13 04:36:49
问题 I came up against a strange problem in Postgres yesterday when trying to filter out user ids from a stats table. When we did, for example, user_id != 24 , postgres excluded the rows where user_id is NULL as well. I created the following test code which shows the same results. CREATE TEMPORARY TABLE test1 ( id int DEFAULT NULL ); INSERT INTO test1 (id) VALUES (1), (2), (3), (4), (5), (2), (4), (6), (4), (7), (5), (9), (5), (3), (6), (4), (3), (7), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL)

Postgres excludes NULL in WHERE id != int query

风流意气都作罢 提交于 2020-02-13 04:35:09
问题 I came up against a strange problem in Postgres yesterday when trying to filter out user ids from a stats table. When we did, for example, user_id != 24 , postgres excluded the rows where user_id is NULL as well. I created the following test code which shows the same results. CREATE TEMPORARY TABLE test1 ( id int DEFAULT NULL ); INSERT INTO test1 (id) VALUES (1), (2), (3), (4), (5), (2), (4), (6), (4), (7), (5), (9), (5), (3), (6), (4), (3), (7), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL)

验证手机号的工具类

♀尐吖头ヾ 提交于 2020-02-12 12:15:23
public class PhoneUtil { /** * 手机号验证 * * @param str * @return 验证通过返回true */ public static boolean isMobileNo(String str) { Pattern p = null; Matcher m = null; boolean b = false; p = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$"); // 验证手机号 m = p.matcher(str); b = m.matches(); return b; } /** * 电话号码验证 * * @param str * @return 验证通过返回true */ public static boolean isPhone(String str) { Pattern p1 = null, p2 = null; Matcher m = null; boolean b = false; p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的 p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的 if (str.length() > 9) { m =

约束

亡梦爱人 提交于 2020-02-12 00:40:09
主键约束 能够唯一确定一张表中的一条记录,也就是我们通过给某一字段添加约束,就可以使得该字段不重复且不为空 mysql> use test Database changed mysql> create table user( -> id int primary key, -> name varchar(20) -> ); Query OK, 0 rows affected (0.14 sec) mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | pet | | user | +----------------+ 2 rows in set (0.00 sec) mysql> describe user; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(20) | YES | | NULL | | +-----