Gitee 更新日志

在现如今的互联网应用中,手机号码已经完全取代电子邮件成为了用户注册账号的唯一标识。而随着移动网络的高速发展,各种前缀的手机号码不断推出,如何验证有效的手机号码就是程序员必须关注的功能点,你说重要吧? 好像没那么重要,你说不重要吧? 一旦程序出错,用户注册不了那就是大事!

所以你怎么看下面这段验证手机号码是否正确的代码呢?

public String validatePhone(String phoneStr) {
  if (phoneStr != null) {
	if (phoneStr.length() == 11) {
	  if (isNumeric(phoneStr)) {
		if (phoneStr.startsWith("130") || phoneStr.startsWith("131") || phoneStr.startsWith("132")
			|| phoneStr.startsWith("134") || phoneStr.startsWith("135") || phoneStr.startsWith("136")
			|| phoneStr.startsWith("137") || phoneStr.startsWith("138") || phoneStr.startsWith("139")
			|| phoneStr.startsWith("140") || phoneStr.startsWith("141") || phoneStr.startsWith("142")
			|| phoneStr.startsWith("144") || phoneStr.startsWith("145") || phoneStr.startsWith("146")
			|| phoneStr.startsWith("147") || phoneStr.startsWith("148") || phoneStr.startsWith("149")
			|| phoneStr.startsWith("150") || phoneStr.startsWith("151") || phoneStr.startsWith("152")
			|| phoneStr.startsWith("154") || phoneStr.startsWith("155") || phoneStr.startsWith("156")
			|| phoneStr.startsWith("157") || phoneStr.startsWith("158") || phoneStr.startsWith("159")
			|| phoneStr.startsWith("170") || phoneStr.startsWith("171") || phoneStr.startsWith("172")
			|| phoneStr.startsWith("174") || phoneStr.startsWith("175") || phoneStr.startsWith("176")
			|| phoneStr.startsWith("177") || phoneStr.startsWith("178") || phoneStr.startsWith("179")
			|| phoneStr.startsWith("180") || phoneStr.startsWith("181") || phoneStr.startsWith("182")
			|| phoneStr.startsWith("184") || phoneStr.startsWith("185") || phoneStr.startsWith("186")
			|| phoneStr.startsWith("187") || phoneStr.startsWith("188") || phoneStr.startsWith("189")) {
			return "手机号正确";
		  } else {
			return "手机号规则错误";
		  }
		} else {
		  return "手机号必须为数字";
		}
	} else {
		return "手机号长度必须为11位";
	}
  } else {
	return "手机号不能为空";
  }
}

逻辑好像没有问题,但是真的好啰嗦啊!!!

那么你有更好的方法吗?

请移步下面链接发表评论,领取奖品:

https://gitee.com/oschina/bullshit-codes/blob/master/java/PhoneRuleValidate.java

码云 6 周年,我们正在征集各种坑爹代码,很多奖品等你来拿

详细的参与方法请看  https://gitee.com/oschina/bullshit-codes

------ 分割线 ------

其他坑爹代码吐槽:

码云的用户群中关于码云企业版集成度不高的、使用体验不一致的吐槽,一直不绝于耳,特别是企业版中的仓库页面需要跳到企业外打开的问题。后来可能大家吐啊吐啊,也就习惯了。但是我们坚决不能忍受这样的吐槽,已经解决了不少吐槽的人,开个玩笑,别当真。

所以年初的时候我们就把企业版集成仓库页面的改造列为今年重点任务之一。仓库页面是整个码云系统最为复杂也是功能点最为繁多的部分,它同时还承担着开源项目和社区交互的重担。

我们花了很大精力准备了几个月的时间,现在终于迎来了码云六周年系列更新的第三弹 —— 企业版代码仓库页面集成。

码云 6 周年的其他更新系列:

  1. 码云六周年系列更新第一弹 —— 企业知识库管理改版
  2. 码云六周年系列更新第二弹 —— Git 只读文件支持

企业版全面集成代码仓库页面。如下图所示:

1. 企业版仓库的概览页面

2. 企业版仓库的代码浏览页面

这次更新我们重写了企业版代码仓库页面,将原有独立的仓库页面的所有功能集成到企业工作台内,用户的所有关于企业内的操作都可以在企业工作台内完成。

同时我们依然保留了独立的仓库页面,特别是企业的开源仓库。

由于牵扯仓库操作的功能点特别多,目前该更新还处于公测阶段,尚有个别功能点没有完全集成(如仓库的任务和 PR)。

欢迎大家体验。使用过程中有任何问题欢迎随时吐槽,我们会及时予以处理。

码云企业版体验地址:https://gitee.com/enterprises

Stream 作为 Java 8 的一大亮点,它与 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念。Java 8 中的 Stream 是对集合(Collection)对象功能的增强,它专注于对集合对象进行各种非常便利、高效的聚合操作(aggregate operation),或者大批量数据操作 (bulk data operation)。Stream API 借助于同样新出现的 Lambda 表达式,极大的提高编程效率和程序可读性。

图 1.  流管道 (Stream Pipeline) 的构成

那么 Java 8 的 Stream 到底是王者,还是个巨坑,这完全取决于你是怎么玩的?

我不得不说,下面代码是我从业 20 年(说谁呢,谁从业 20 年,我今年 19  岁!!!)看过最牛逼的 Stream 的用法:

Optional.of(req)
        .map(e -> e.clueUid)
        .map(id -> {
            final ClueExample example = new ClueExample();
            example.createCriteria()
                    .andClueUidEqualTo(id)
                    .andDeletedEqualTo(false)
                    .andReceivedEqualTo(false)
                    .andCreateTimeGreaterThan(now - cluetime);
            example.setOrderByClause("create_time asc");
            return example;
        })  // 获取该被邀请人所有未过期且未被领取的线索的线索
        .map(clueMapper::selectByExample)
        .filter(StringUtil::isNotEmpty)
        .ifPresent(clues -> {
                    final ClueResp clueResp = Optional.of(req)
                            .filter(c -> {
                                c.count = clues.size();
                                return true;
                            })
                            .map(this::awardValue)
                            .orElseThrow(() -> ExceptionUtil.createParamException("参数错误"));
                    final Integer specialId = req.getIsHead()
                            ? clues.get(0).getId()
                            : clues.get(clues.size() - 1).getId();
                    clues.stream()
                            .peek(clue -> {
                                final AwardConfig awardConfigclone = Optional.of(awardConfig)
                                        .map(JSONUtil::obj2Json)
                                        .map(json -> JSONUtil.json2Obj(json, AwardConfig.class))
                                        .orElseGet(AwardConfig::new);
                                awardConfigclone.setMoney(
                                        Optional.of(clue.getId())
                                                .filter(specialId::equals)
                                                .map(e -> clueResp.specialReward.longValue())
                                                .orElse(clueResp.otherAverageReward.longValue())
                                );
                                eventActionService.assembleAward(
                                        awardConfigclone,
                                        clue.getAdviserUid(),
                                        clue.getAdviserUid(),
                                        clue.getClueUid(),
                                        eventAction,
                                        new PasMessageParam(),
                                        clue.getId(),
                                        AwardRelationType.Clud.code()
                                );
                            })
                            .forEach(clue -> {
                                clue.setOrderNo(req.orderNo);
                                clue.setCommodityName(req.commodityName);
                                clue.setOrderAmount(req.orderAmount);
                                clue.setReceived(true);
                                clue.setModifyTime(now);
                                clueMapper.updateByPrimaryKeySelective(clue);
                            });
                }
        );

Java 就是这么一门神奇的语言,任何水平的人都能写出可以运行的代码,但是一看代码便知水平高低。

但是这样的 Stream 代码你一定一口老谈不吐不快,请移步下面链接发表评论,领取奖品:

https://gitee.com/oschina/bullshit-codes/blob/master/java/NBStream.java

码云 6 周年,我们正在征集各种坑爹代码,很多奖品等你来拿

详细的参与方法请看  https://gitee.com/oschina/bullshit-codes

------ 分割线 ------

其他坑爹代码吐槽:

玩 Java 的人,刚开始会被各种异常虐,空指针应该是最常见的。多玩两年就开始玩异常,各种奇葩异常玩法层出不穷。

你觉得下面这种异常的定义妥吗?

public class CommandException extends BaseException {

	private static final long serialVersionUID = -6354513454371927970L;
	
	public static CommandException PARAM_NULL= new CommandException("Command_assemble_01", "Parameter is Needed But Empty");
	public static CommandException DEVID_NULL = new CommandException("Command_assemble_02", "DevId Cannot Be Null");
	public static CommandException MDCODE_NULL = new CommandException("Command_assemble_03", "Model Code Cannot Be Empty");
	public static CommandException ORDER_NULL = new CommandException("Command_assemble_04", "Order Cannot Be Empty");
	public static CommandException TYPE_NULL = new CommandException("Command_assemble_05", "Upstream / Downstream Type Cannot Be Empty");
	public static CommandException MENUID_NULL = new CommandException("Command_assemble_06", "Menu Id Cannot Be Null");
	public static CommandException CTRLTYPE_NOT_RANGE= new CommandException("Command_assemble_07", "Ctrltype Cannot Be Recognized, Which is not in Range");
	public static CommandException CMD_NULL = new CommandException("Command_analyze_01", "CMD Cannot Be Null");
	public static CommandException PAYLOAD_NULL = new CommandException("Command_analyze_02", "Payload Cannot Be Null");
	public static CommandException FRAMEWORK_FAILED= new CommandException("Command_analyze_03", "Framework Failed to be Checked");
	public static CommandException CHECK_FAILED= new CommandException("Command_analyze_04", "Command Failed to be Checked");
	public static CommandException CONFIGURE_NOT_EXIST = new CommandException("Command_error_1001", "Configure is not Exist");
	public static CommandException REDIS_ERROR = new CommandException("Command_error_1002", "Cache Command in Redis Error", true);
	
	public CommandException() {
		super();
	}

如果不妥,有什么问题呢? 

请到下面链接发表评论,领取奖品:

https://gitee.com/oschina/bullshit-codes/blob/master/java/BadException.java

码云 6 周年,我们正在征集各种坑爹代码,很多奖品等你来拿

详细的参与方法请看  https://gitee.com/oschina/bullshit-codes

------ 分割线 ------

其他坑爹代码吐槽: