더북(TheBook)

이제 iloveyouboss의 핵심 클래스인 Profile을 살펴봅니다.

iloveyouboss_06/src/iloveyouboss/Profile.java

01     package iloveyouboss;
02
03 import java.util.*; 04
05 public class Profile { 06 private Map<String, Answer> answers = new HashMap<>(); 07 private int score; 08 private String name; 09
10 public Profile(String name) { 11 this.name = name; 12 } 13
14 public String getName() { 15 return name; 16 } 17
18 public void add(Answer answer) { 19 answers.put(answer.getQuestionText(), answer); 20 } 21
22 public boolean matches(Criteria criteria) { 23 score = 0; 24
25 boolean kill = false; 26 boolean anyMatches = false; 27 for (Criterion criterion: criteria) { 28 Answer answer = answers.get( 29 criterion.getAnswer().getQuestionText()); 30 boolean match = 31 criterion.getWeight() == Weight.DontCare || 32 answer.match(criterion.getAnswer()); 33
34 if (!match && criterion.getWeight() == Weight.MustMatch) { 35 kill = true; 36 } 37 if (match) { 38 score += criterion.getWeight().getValue(); 39 } 40 anyMatches |= match; 41 } 42 if (kill) 43 return false; 44 return anyMatches; 45 } 46
47 public int score() { 48 return score; 49 } 50 }

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.