java domain_Java 满血domain

import java.util.*;public classPerson {privateString name;privateInteger age;privateString sex;/*** 兴趣爱好*/

private List hobbies = new ArrayList<>();/*** 喜欢吃的食物*/

private List foods = new ArrayList<>();/*** 个人经历*/

private Map personalHistory = new HashMap<>();publicString getName() {returnname;

}public voidsetName(String name) {if(!checkNameChese(name))throw new RuntimeException(name + "不规范!");this.name =name;

}publicInteger getAge() {returnage;

}public voidsetAge(Integer age) {if(null == age || age <=0 || age > 120)throw new RuntimeException(age + "不规范!");this.age =age;

}publicString getSex() {returnsex;

}public voidsetSex(String sex) {this.sex =sex;

}public ListgetHobbies() {returnhobbies;

}public void setHobbies(Listhobbies) {this.hobbies =hobbies;

}public ListgetFoods() {returnfoods;

}public void setFoods(Listfoods) {this.foods =foods;

}public voidaddFood(String food) {if(null ==food) {throw new RuntimeException("食物不为空!");

}for(String item : hobbies) {if(item.equals(food)) {throw new RuntimeException(food + "已填加!");

}

}

foods.add(food);

}public voiddelFood(String food) {if(null ==food) {throw new RuntimeException("食物不为空!");

}if(!hobbies.contains(food)) {throw new RuntimeException(food + "不存在!");

}

foods.remove(food);

}public voidaddHobby(String hobby) {if(null ==hobby) {throw new RuntimeException("兴趣爱好不为空!");

}for(String item : hobbies) {if(item.equals(hobby)) {throw new RuntimeException(hobby + "已填加!");

}

}

hobbies.add(hobby);

}public voiddelHobby(String hobby) {if(null ==hobby) {throw new RuntimeException("兴趣爱好不为空!");

}if(!hobbies.contains(hobby)) {throw new RuntimeException(hobby + "不存在!");

}

hobbies.remove(hobby);

}public voidaddHistory(Integer age, Object history) {if(null == age || age <=0) {throw new RuntimeException("年龄不符合规定!");

}if(null ==history) {throw new RuntimeException("个人经历不为空!");

}if(age > this.age) {throw new RuntimeException("个人经历不得大于");

}

Iterator> iterator =personalHistory.entrySet().iterator();while(iterator.hasNext()) {

Map.Entry next =iterator.next();if(next.getKey().equals(age) &&next.getValue().equals(history)) {throw new RuntimeException(age + "岁,个人经历:" + history + "已存在!");

}

}

personalHistory.put(age, history);

}public voiddelHistory(Integer age) {if(null == age || age <=0) {throw new RuntimeException("年龄不符合规定!");

}if(age > this.age) {throw new RuntimeException("个人经历不得大于");

}if(!personalHistory.containsKey(age)) {throw new RuntimeException(age + "岁,个人经历不存在!");

}

Iterator> iterator =personalHistory.entrySet().iterator();while(iterator.hasNext()) {

Map.Entry next =iterator.next();if(next.getKey().equals(age)) {

iterator.remove();

}

}

}/*** 判定输入的是否是汉字

*

*@paramc 被校验的字符

*

*@returntrue代表是汉字*/

private static boolean isChinese(charc) {

Character.UnicodeBlock ub=Character.UnicodeBlock.of(c);if (ub ==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS|| ub ==Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS|| ub ==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A|| ub ==Character.UnicodeBlock.GENERAL_PUNCTUATION|| ub ==Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION|| ub ==Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {return true;

}return false;

}/*** 校验String是否全是中文

*

*@paramname

* 被校验的字符串

*@returntrue代表全是汉字*/

private static booleancheckNameChese(String name) {boolean res = true;char[] cTemp = name.toCharArray();//转换为数组

for (int i = 0; i < name.length(); i++) {if (!isChinese(cTemp[i])) {//逐个判断是否为中文

res = false;break;

}

}returnres;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值