示例#1
0
 @Transient
 public String getWorkage() {
   if (this.dob != null) {
     Calendar c = Calendar.getInstance();
     if (this.firstworktime == null) c.setTime(new Date());
     else c.setTime(firstworktime);
     Calendar cnow = Calendar.getInstance();
     cnow.setTime(new Date());
     Period p = new Period(c.getTimeInMillis(), cnow.getTimeInMillis(), PeriodType.yearMonthDay());
     Integer yearint = p.getYears();
     Integer monthint = p.getMonths();
     Integer dayint = p.getDays();
     return yearint.toString() + "年" + monthint.toString() + "月" + dayint.toString() + "日";
   } else return "";
 }
示例#2
0
  @Transient
  public String getAge() {
    if (this.dob != null) {
      Calendar c = Calendar.getInstance();
      c.setTime(this.dob);
      Calendar cnow = Calendar.getInstance();
      cnow.setTime(new Date());

      Period p = new Period(c.getTimeInMillis(), cnow.getTimeInMillis(), PeriodType.yearMonthDay());
      Integer yearint = p.getYears();
      Integer monthint = p.getMonths();
      Integer dayint = p.getDays();

      //			Integer yearint = cnow.get(Calendar.YEAR) - c.get(Calendar.YEAR);
      //			if(cnow.get(Calendar.DAY_OF_YEAR) < c.get(Calendar.DAY_OF_YEAR))
      //				yearint--;
      //			Integer monthint = (cnow.get(Calendar.MONTH) - c.get(Calendar.MONTH) + 12)%12;
      //			Integer dayint  = (cnow.get(Calendar.DAY_OF_MONTH) - c.get(Calendar.DAY_OF_MONTH)+30)%30;
      return yearint.toString() + "岁" + monthint.toString() + "月" + dayint.toString() + "日";
    } else return "";
  }
示例#3
0
 private String epocToSimpleDate(long epoc) {
   Period diff = new Period(epoc, System.currentTimeMillis(), PeriodType.standard());
   PeriodType type;
   if (diff.getMonths() > 0) {
     type = PeriodType.yearMonthDay();
   } else if (diff.getWeeks() > 0) {
     type = PeriodType.yearWeekDay();
   } else if (diff.getDays() > 0) {
     type = PeriodType.dayTime().withSecondsRemoved().withMillisRemoved().withMinutesRemoved();
   } else if (diff.getMinutes() > 0) {
     type = PeriodType.time().withMillisRemoved().withSecondsRemoved();
   } else {
     type = PeriodType.time().withMillisRemoved();
   }
   return PeriodFormat.getDefault().print(new Period(epoc, System.currentTimeMillis(), type));
 }
示例#4
0
 public Duration getWidth() {
   int millis = new Period(low, high, PeriodType.millis()).getMillis();
   return new Duration(millis);
 }
 private String getPrintableTtl(long ttl) {
   return PERIOD_FORMATTER.print(new Period(ttl).normalizedStandard(PeriodType.dayTime()));
 }
示例#6
0
/** @author OldDragon2A */
public class Timer extends JFrame implements ActionListener {
  private static final long serialVersionUID = -5610732114416563838L;
  public static Launcher launcher;
  protected static PeriodFormatter format_full =
      new PeriodFormatterBuilder()
          .printZeroIfSupported()
          .minimumPrintedDigits(1)
          .appendHours()
          .appendSeparator(":")
          .minimumPrintedDigits(2)
          .appendMinutes()
          .appendSeparator(":")
          .appendSeconds()
          .appendSeparator(".")
          .minimumPrintedDigits(3)
          .appendMillis()
          .toFormatter();
  protected static PeriodFormatter format_short =
      new PeriodFormatterBuilder()
          .minimumPrintedDigits(1)
          .appendHours()
          .appendSeparatorIfFieldsBefore(":")
          .minimumPrintedDigits(2)
          .appendMinutes()
          .appendSeparatorIfFieldsBefore(":")
          .printZeroIfSupported()
          .appendSeconds()
          .appendSeparator(".")
          .minimumPrintedDigits(3)
          .appendMillis()
          .toFormatter();
  protected static PeriodType period_type = PeriodType.time();
  static final Color transparent = new Color(0, 0, 0, 0);

  public DateTime started;
  public ArrayList<TimeSpan> times = new ArrayList<TimeSpan>();
  public Period period = new Period(0);
  public int update_speed = 250;
  public boolean was_visible = false;

  /** Controls */
  protected JPanel panel = new JPanel();

  protected JLabel total = new JLabel();
  protected JLabel time = new JLabel();
  protected JPopupMenu popup = new JPopupMenu();
  protected JMenuItem miToggle = createMenuItem("Start", this, "toggle", 's');
  protected JMenuItem miAdjust = createMenuItem("Adjust", this, "adjust", 'a');
  protected JMenuItem miForeground = createMenuItem("Foreground", this, "foreground", 'f');
  protected JMenuItem miBackground = createMenuItem("Background", this, "background", 'b');
  protected JMenuItem miTransparent = createMenuItem("Transparent", this, "transparent", 't');
  protected JMenuItem miDelete = createMenuItem("Delete", this, "delete", 'd');

  protected javax.swing.Timer timer;
  protected MousePopupListener popup_listener = new MousePopupListener();

  public Timer() {
    setBackground(Timer.transparent);
    setSize(new Dimension(300, 100));
    setLocationRelativeTo(null);
    panel.setBackground(Color.white);
    setContentPane(new AlphaContainer(panel));
    setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();

    c.insets = new Insets(5, 5, 5, 5);
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    total.setText("0000:00:00.000");
    total.setHorizontalAlignment(JLabel.RIGHT);
    Font font = total.getFont().deriveFont((float) 20);
    total.setFont(font);
    add(total, c);

    c.insets = new Insets(0, 5, 5, 5);
    c.gridy = 1;
    time.setText("0000:00:00.000");
    time.setHorizontalAlignment(JLabel.RIGHT);
    time.setFont(font);
    add(time, c);

    popup.add(miToggle);
    popup.add(miAdjust);
    popup.add(miForeground);
    popup.add(miBackground);
    popup.add(miTransparent);
    popup.add(miDelete);
    addMouseListener(popup_listener);

    timer = new javax.swing.Timer(this.update_speed, this);
    timer.setActionCommand("tick");
    if (started != null) {
      timer.start();
    }
  }

  public Timer(Element timer) {
    this();

    setTitle(timer.getChildTextNormalize("title"));
    String started = timer.getChildTextNormalize("started");
    this.started = started.isEmpty() ? null : DateTime.parse(started);
    if (this.started != null) {
      this.timer.start();
    }
    period = Period.parse(timer.getChildTextNormalize("total"));

    update_speed = Integer.parseInt(timer.getChildTextNormalize("speed"), 10);
    this.timer.setDelay(update_speed);
    if (this.started != null) {
      this.timer.start();
    }

    setLocation(
        Integer.parseInt(timer.getChildTextNormalize("x"), 10),
        Integer.parseInt(timer.getChildTextNormalize("y"), 10));
    setSize(
        Integer.parseInt(timer.getChildTextNormalize("width"), 10),
        Integer.parseInt(timer.getChildTextNormalize("height"), 10));

    Color foreground =
        new Color((int) Long.parseLong(timer.getChildTextNormalize("foreground"), 16), true);
    total.setForeground(foreground);
    time.setForeground(foreground);
    Color background =
        new Color((int) Long.parseLong(timer.getChildTextNormalize("background"), 16), true);
    panel.setBackground(background);

    Element times = timer.getChild("times");
    for (Element ts : times.getChildren()) {
      this.times.add(new TimeSpan(ts));
    }

    updateTimes();
    setVisible(Boolean.parseBoolean(timer.getChildText("visible")));
  }

  protected JMenuItem createMenuItem(
      String text, ActionListener listener, String command, char mnemonic) {
    JMenuItem mi = new JMenuItem();
    mi.setText(text);
    mi.addActionListener(listener);
    mi.setActionCommand(command);
    mi.setMnemonic(mnemonic);
    return mi;
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("tick")) {
      updateTimes();
    } else if (e.getActionCommand().equals("toggle")) {
      actionToggle();
    } else if (e.getActionCommand().equals("adjust")) {
      actionAdjustment();
    } else if (e.getActionCommand().equals("foreground")) {
      actionForeground();
    } else if (e.getActionCommand().equals("background")) {
      actionBackground();
    } else if (e.getActionCommand().equals("transparent")) {
      actionTransparent();
    } else if (e.getActionCommand().equals("delete")) {
      actionDelete();
    }
  }

  protected void updateTimes() {
    Period current = started == null ? new Period(0) : new Period(started, new DateTime());
    total.setText(Timer.format_full.print(period.plus(current).normalizedStandard(period_type)));
    time.setText(Timer.format_short.print(current.normalizedStandard(period_type)));
  }

  protected void actionToggle() {
    if (started == null) {
      miToggle.setText("Stop");
      started = new DateTime();
      timer.start();
    } else {
      miToggle.setText("Start");
      DateTime end = new DateTime();
      TimeSpan ts = new TimeSpan(started, end);
      times.add(ts);
      period = period.plus(ts.getPeriod()).normalizedStandard();
      started = null;
      timer.stop();
      updateTimes();
    }
  }

  protected void actionAdjustment() {
    String result =
        (String) JOptionPane.showInputDialog(this, "Enter an adjustment", "0 00:00:00.000");
    if (result != null && !result.isEmpty()) {
      try {
        Period adjustment = format_short.parsePeriod(result);
        DateTime start = new DateTime();
        DateTime end = start.plus(adjustment);
        TimeSpan ts = new TimeSpan(start, end);
        times.add(ts);
        period = period.plus(adjustment);
        updateTimes();
      } catch (IllegalArgumentException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
      }
    }
  }

  protected void actionForeground() {
    Color color = JColorChooser.showDialog(this, "Foreground", panel.getForeground());
    if (color != null) {
      total.setForeground(color);
      time.setForeground(color);
    }
  }

  protected void actionBackground() {
    Color color = JColorChooser.showDialog(this, "Background", panel.getBackground());
    if (color != null) {
      panel.setBackground(color);
    }
  }

  protected void actionTransparent() {
    dispose();
    panel.setBackground(Timer.transparent);
    setVisible(true);
  }

  protected void actionDelete() {
    int result =
        JOptionPane.showConfirmDialog(
            this,
            "Are you sure?",
            "Delete Timer: " + getTitle(),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE);
    if (result == JOptionPane.YES_OPTION) {
      setVisible(false);
      Timer.launcher.timers.remove(this);
      Timer.launcher.combobox.removeItem(this);
    }
  }

  public Element toXML() {
    Element result = new Element("timer");

    XMLUtil.createElement("title", getTitle(), result);
    XMLUtil.createElement("started", started == null ? "" : started.toString(), result);
    XMLUtil.createElement("total", period.toString(), result);
    XMLUtil.createElement("speed", update_speed, result);

    XMLUtil.createElement("x", getX(), result);
    XMLUtil.createElement("y", getY(), result);
    XMLUtil.createElement("width", getWidth(), result);
    XMLUtil.createElement("height", getHeight(), result);

    XMLUtil.createElement(
        "foreground", String.format("%08x", total.getForeground().getRGB()), result);
    XMLUtil.createElement(
        "background", String.format("%08x", panel.getBackground().getRGB()), result);

    XMLUtil.createElement("visible", isVisible(), result);

    Element times = new Element("times");
    for (TimeSpan ts : this.times) {
      times.addContent(ts.toXML());
    }
    result.addContent(times);
    return result;
  }

  class MousePopupListener extends MouseAdapter implements Serializable {
    private static final long serialVersionUID = -1112142857364855862L;

    public void mousePressed(MouseEvent e) {
      checkPopup(e);
    }

    public void mouseClicked(MouseEvent e) {
      checkPopup(e);
    }

    public void mouseReleased(MouseEvent e) {
      checkPopup(e);
    }

    private void checkPopup(MouseEvent e) {
      if (e.isPopupTrigger()) {
        popup.show((Component) e.getSource(), e.getX(), e.getY());
      }
    }
  }
}
示例#7
0
public class ExampleLoader {

  private static final Logger LOGGER = LoggerFactory.getLogger(ExampleLoader.class);
  private static final String STAGE_SKILL_SPEC_PATH =
      "src/main/resources/ProjectStageSkillSpecification.txt";
  private static final String TEAMS_EMPLOYEES_SPEC_PATH =
      "src/main/resources/TeamPersonalSpecification.txt";
  private static final int NAME_COL_INDEX = 1;
  private static final int HOURS_COL_INDEX = 2;
  private static final int FIRST_SKILL_COL_INDEX = 6;
  private static final String EPICS_SPEC_PATH = "src/main/resources/EpicsSpecification.txt";
  private static final int EPIC_ID_COL_INDEX = 0;
  private static final int EPIC_TITLE_COL_INDEX = 1;
  private static final int STORY_ID_COL_INDEX = 3;
  private static final int STORY_TITLE_COL_INDEX = 4;
  private static final PeriodType DEFAULT_WORKLOAD_TIMEUNIT = PeriodType.days();
  private static final int STORY_PREDS_COL_INDEX = 5;

  public static void main(String[] args) throws IOException {
    FileInputStream inputStream = new FileInputStream(STAGE_SKILL_SPEC_PATH);
    try {
      List<String> projectStageAndSkillsString = IOUtils.readLines(inputStream);
      String skillString = projectStageAndSkillsString.get(1);
      List<IProjectStageSkill> skills =
          Collections.unmodifiableList(extractProjectStageSkills(skillString));
      //			System.out.println(Joiner.on(",").join(skills));

      String stageString = projectStageAndSkillsString.get(0);
      List<IProjectStage> stages = extractProjectStages(stageString, skills);
      //			System.out.println(Joiner.on(",").join(stages));

      List<String> teamsEmployeesStrings =
          IOUtils.readLines(new FileInputStream(TEAMS_EMPLOYEES_SPEC_PATH));
      List<ITeam> teams = extractTeamsList(teamsEmployeesStrings, skills);
      //	    	System.out.println(Joiner.on(",").join(teams));

      List<String> epicsStrings = IOUtils.readLines(new FileInputStream(EPICS_SPEC_PATH));
      Map<IEpic, Map<IStory, Set<String>>> epicsToStoryPredsMap =
          extractEpicsToStoryPredsMap(epicsStrings, stages, skills);
      Set<IEpic> epics = epicsToStoryPredsMap.keySet();
      //			System.out.println(Joiner.on(",").join(epics));

      Set<IStoryRelation> storyRelations =
          extractStoryRelations(epicsToStoryPredsMap.values(), epics);
      BusinessDomainModel domainModel =
          new BusinessDomainModel(Sets.newHashSet(teams), stages, epics, storyRelations);

      IRoadmapProblem problem = BusinessModelToRmppTransformer.createRoadmapProblem(domainModel);
      RmppConstructionAlgorithm algo = new RmppConstructionAlgorithm();
      IRoadmapSchedule construct = algo.construct(problem);
      System.out.println(construct);
      System.out.println("makespan: " + construct.getMakeSpan());
    } finally {
      inputStream.close();
    }
  }

  private static Set<IStoryRelation> extractStoryRelations(
      Collection<Map<IStory, Set<String>>> values, Set<IEpic> epics) {
    Set<IStoryRelation> storyRelations = Sets.newHashSet();
    Map<IStory, Set<String>> storyToPredStringMap = mergeMaps(values);
    for (Entry<IStory, Set<String>> predecessorEntry : storyToPredStringMap.entrySet()) {
      IStory story = predecessorEntry.getKey();
      for (String predCode : predecessorEntry.getValue()) {
        if (predCode.isEmpty()) {
          continue;
        }
        Set<IStory> predecessors =
            getPredecessorsForId(predCode, storyToPredStringMap.keySet(), epics);
        for (IStory predecessor : predecessors) {
          IStoryRelation relation = new PredecessorRelation(predecessor, story);
          storyRelations.add(relation);
        }
      }
    }
    return storyRelations;
  }

  private static Set<IStory> getPredecessorsForId(
      String predCode, Set<IStory> stories, Set<IEpic> epics) {
    for (IEpic epic : epics) {
      if (epic.getId().equals(predCode)) {
        return epic.getStories();
      }
    }
    for (IStory story : stories) {
      if (story.getId().equals(predCode)) {
        return Sets.newHashSet(story);
      }
    }
    throw new RuntimeException();
  }

  private static <K, V> Map<K, V> mergeMaps(Collection<Map<K, V>> maps) {
    Map<K, V> merged = Maps.newHashMap();
    for (Map<K, V> map : maps) {
      merged.putAll(map);
    }
    return merged;
  }

  private static Map<IEpic, Map<IStory, Set<String>>> extractEpicsToStoryPredsMap(
      List<String> epicsStrings, List<IProjectStage> stages, List<IProjectStageSkill> skillList) {
    Map<IEpic, Map<IStory, Set<String>>> epicsToStoryMap = Maps.newHashMap();
    Map<IStory, Set<String>> storyToPredIdMap = Maps.newHashMap();
    String epicTitle = null;
    String epicId = null;
    for (String storyString : epicsStrings) {
      if (Strings.isNullOrEmpty(storyString.trim())) {
        continue;
      }
      LOGGER.debug("create story for string: {}", storyString);
      Iterable<String> strings = Splitter.on('\t').split(storyString);
      List<String> words = Lists.newArrayList(strings);
      if (!words.get(0).isEmpty()) {
        if (epicTitle != null) {
          IEpic epic = new Epic(epicId, epicTitle, storyToPredIdMap.keySet());
          epicsToStoryMap.put(epic, storyToPredIdMap);
        }
        storyToPredIdMap = Maps.newHashMap();
        epicId = words.get(EPIC_ID_COL_INDEX);
        epicTitle = words.get(EPIC_TITLE_COL_INDEX);
      }
      Entry<IStory, Set<String>> storyToPredIdsEntry =
          extractStoryAndPredecessorIds(words, stages, skillList);
      storyToPredIdMap.put(storyToPredIdsEntry.getKey(), storyToPredIdsEntry.getValue());
    }
    // TODO last epic is missing
    return epicsToStoryMap;
  }

  private static Entry<IStory, Set<String>> extractStoryAndPredecessorIds(
      List<String> words, List<IProjectStage> stages, List<IProjectStageSkill> skills) {
    String id = words.get(STORY_ID_COL_INDEX);
    String title = words.get(STORY_TITLE_COL_INDEX);
    CharSequence predString = words.get(STORY_PREDS_COL_INDEX);
    Iterable<String> predecessors = Splitter.on(", ").split(predString);
    Set<String> predecessorCodes = Sets.newHashSet(predecessors);
    LinkedHashMap<IProjectStage, Map<IProjectStageSkill, IWorkLoad>> stageToWorkLoadMap =
        extractSkillToWorkLoadMapList(words, stages, skills);
    IStory story = new Story(id, title, stageToWorkLoadMap);
    LOGGER.debug(
        "created story {} with predecessor strings {}",
        story,
        Joiner.on(",").join(predecessorCodes));
    return new AbstractMap.SimpleEntry<IStory, Set<String>>(story, predecessorCodes);
  }

  private static LinkedHashMap<IProjectStage, Map<IProjectStageSkill, IWorkLoad>>
      extractSkillToWorkLoadMapList(
          List<String> words, List<IProjectStage> stages, List<IProjectStageSkill> skillsList) {
    LinkedHashMap<IProjectStage, Map<IProjectStageSkill, IWorkLoad>> stageToWorkLoadMap =
        Maps.newLinkedHashMap();
    LinkedHashMap<IProjectStage, List<String>> estimationStringMap =
        extractEstimationStringMap(words, stages);
    Map<IProjectStage, List<IProjectStageSkill>> stageToSkillMap =
        extractStageToSkillMap(stages, skillsList);
    for (Entry<IProjectStage, List<String>> estimationStringEntry :
        estimationStringMap.entrySet()) {
      Map<IProjectStageSkill, IWorkLoad> workLoadMap = Maps.newHashMap();
      IProjectStage stage = estimationStringEntry.getKey();
      List<String> estimationStrings = estimationStringEntry.getValue();
      List<IProjectStageSkill> stageSkillList = stageToSkillMap.get(stage);
      for (int i = 0; i < stageSkillList.size(); i++) {
        String estimationString = estimationStrings.get(i);
        IProjectStageSkill skill = stageSkillList.get(i);
        if (estimationString == null || estimationString.trim().isEmpty()) {
          continue;
        }
        Float estimation = Float.parseFloat(estimationString.replace(',', '.'));
        IWorkLoad load = new WorkLoad(estimation, DEFAULT_WORKLOAD_TIMEUNIT);
        workLoadMap.put(skill, load);
      }
      stageToWorkLoadMap.put(stage, workLoadMap);
    }
    return stageToWorkLoadMap;
  }

  private static Map<IProjectStage, List<IProjectStageSkill>> extractStageToSkillMap(
      List<IProjectStage> stages, List<IProjectStageSkill> skillsList) {
    Map<IProjectStage, List<IProjectStageSkill>> stageToSkillListMap = Maps.newHashMap();
    LinkedList<IProjectStageSkill> skillListCopy = Lists.newLinkedList(skillsList);
    for (IProjectStage stage : stages) {
      Set<IProjectStageSkill> skillSet = stage.getProjectStageSkills();
      List<IProjectStageSkill> entryList = Lists.newLinkedList();
      while (skillSet.contains(skillListCopy.peekFirst())) {
        entryList.add(skillListCopy.pollFirst());
      }
      stageToSkillListMap.put(stage, entryList);
    }
    return stageToSkillListMap;
  }

  private static LinkedHashMap<IProjectStage, List<String>> extractEstimationStringMap(
      List<String> words, List<IProjectStage> stages) {
    LinkedHashMap<IProjectStage, List<String>> estimationStringMap = Maps.newLinkedHashMap();
    LinkedList<String> wordsCopy = Lists.newLinkedList(words);
    for (int i = 1; i <= stages.size(); i++) {
      IProjectStage stage = stages.get(stages.size() - i);
      int stageSkillCount = stage.getProjectStageSkills().size();
      int estimationCount = stageSkillCount + 1;
      LinkedList<String> entryList = Lists.newLinkedList();
      for (int j = 0; j < estimationCount; j++) {
        String word = wordsCopy.pollLast();
        entryList.addFirst(word);
      }
      estimationStringMap.put(stage, entryList);
      wordsCopy.pollLast();
    }
    return estimationStringMap;
  }

  private static List<ITeam> extractTeamsList(
      List<String> teamsEmployeesStrings, List<IProjectStageSkill> skills) {
    List<ITeam> teams = Lists.newArrayList();
    Set<IEmployee> employees = Sets.newHashSet();
    String teamName = null;
    for (String employeeString : teamsEmployeesStrings) {
      if (Strings.isNullOrEmpty(employeeString.trim())) {
        continue;
      }
      LOGGER.debug("create employee for string: {}", employeeString);
      Iterable<String> strings = Splitter.on('\t').split(employeeString);
      List<String> words = Lists.newArrayList(strings);
      if (!words.get(0).isEmpty()) {
        if (teamName != null) {
          ITeam team = new Team(teamName, employees);
          teams.add(team);
        }
        employees = Sets.newHashSet();
        teamName = words.get(0);
      }
      IEmployee employee = extractEmployee(words, skills);
      employees.add(employee);
    }
    return teams;
  }

  private static IEmployee extractEmployee(List<String> words, List<IProjectStageSkill> skills) {
    String name = words.get(NAME_COL_INDEX);
    int hoursPerWeek = Integer.parseInt(words.get(HOURS_COL_INDEX));
    Map<IProjectStageSkill, SkillLevel> skillMap = extractSkillMap(words, skills);
    IEmployee employee = new Employee(name, hoursPerWeek, skillMap);
    LOGGER.debug("created employee: {}", employee);
    return employee;
  }

  private static Map<IProjectStageSkill, SkillLevel> extractSkillMap(
      List<String> words, List<IProjectStageSkill> skills) {
    Map<IProjectStageSkill, SkillLevel> skillsMap = Maps.newHashMap();
    List<String> skillEvaluations = words.subList(FIRST_SKILL_COL_INDEX, words.size());
    for (int i = 0; i < skills.size(); i++) {
      String evaluation = skillEvaluations.get(i);
      if (Strings.isNullOrEmpty(evaluation)) {
        continue;
      }
      IProjectStageSkill skill = skills.get(i);
      SkillLevel level = SkillLevel.parse(evaluation);
      skillsMap.put(skill, level);
    }
    return skillsMap;
  }

  private static List<IProjectStage> extractProjectStages(
      String stageString, List<IProjectStageSkill> skills) {
    LinkedHashMap<String, Integer> stageNameToSkillCountMap =
        createStageNameToSkillCountMap(stageString);
    List<IProjectStage> stages = createStages(stageNameToSkillCountMap, skills);
    return stages;
  }

  private static List<IProjectStage> createStages(
      LinkedHashMap<String, Integer> stageNameToSkillCountMap, List<IProjectStageSkill> skills) {
    LOGGER.debug(
        "create project stages for stageNameToSkillCountMap {} and skill list {}",
        Joiner.on(",").join(stageNameToSkillCountMap.entrySet()),
        Joiner.on(",").join(skills));
    List<IProjectStage> stages = Lists.newArrayList();

    List<IProjectStageSkill> copy = Lists.newArrayList(skills);
    for (Entry<String, Integer> entry : stageNameToSkillCountMap.entrySet()) {
      String name = entry.getKey();
      int skillCount = entry.getValue();
      Set<IProjectStageSkill> stageSkills = getAndRemoveNextSkills(copy, skillCount);
      IProjectStage stage = new ProjectStage(stageSkills, name);
      stages.add(stage);
    }
    LOGGER.debug("created project stages: {}", Joiner.on(",").join(stages));
    return stages;
  }

  private static Set<IProjectStageSkill> getAndRemoveNextSkills(
      List<IProjectStageSkill> skills, int skillCount) {
    Set<IProjectStageSkill> nextSkills = Sets.newHashSet();
    for (int i = 0; i < skillCount; i++) {
      IProjectStageSkill skill = skills.remove(0);
      nextSkills.add(skill);
    }
    return nextSkills;
  }

  private static LinkedHashMap<String, Integer> createStageNameToSkillCountMap(String stageString) {
    LOGGER.debug("create stage to skill count map for string {}", stageString);
    List<String> stageNames = extractStageNames(stageString);
    List<String> stageNamesAndTabs = extractStageNamesWithTabs(stageNames, stageString);
    LinkedHashMap<String, Integer> nameToCountMap = Maps.newLinkedHashMap();
    for (int i = 0; i < stageNames.size(); i++) {
      String stageName = stageNames.get(i);
      String stageAndTabs = stageNamesAndTabs.get(i);
      int count = CharMatcher.is('\t').countIn(stageAndTabs) - 1;
      nameToCountMap.put(stageName, count);
    }
    return nameToCountMap;
  }

  private static List<String> extractStageNamesWithTabs(
      List<String> stageNames, String stageString) {
    List<String> namesWithTabs = Lists.newArrayList();
    for (int i = 0; i < stageNames.size() - 1; i++) {
      String thisStage = stageNames.get(i);
      String nextStage = stageNames.get(i + 1);
      int indexThisStage = stageString.indexOf(thisStage);
      int indexNextStage = stageString.indexOf(nextStage);
      String string = stageString.substring(indexThisStage, indexNextStage);
      namesWithTabs.add(string);
    }
    int lastStageIndex = stageString.indexOf(stageNames.get(stageNames.size() - 1));
    String last = stageString.substring(lastStageIndex);
    namesWithTabs.add(last);
    return namesWithTabs;
  }

  private static List<String> extractStageNames(String stageString) {
    List<String> stageNames = Lists.newArrayList();
    StringTokenizer tokenizer = new StringTokenizer(stageString, "\t");
    while (tokenizer.hasMoreElements()) {
      String next = tokenizer.nextToken();
      stageNames.add(next);
    }
    return stageNames;
  }

  private static List<IProjectStageSkill> extractProjectStageSkills(String skillString) {
    StringTokenizer tokenizer = new StringTokenizer(skillString, "\t");
    List<IProjectStageSkill> skills = Lists.newArrayList();
    while (tokenizer.hasMoreElements()) {
      String name = tokenizer.nextToken();
      IProjectStageSkill skill = new ProjectStageSkill(name);
      skills.add(skill);
    }
    return skills;
  }
}
示例#8
0
        // when dialog box is closed, below method will be called.
        @Override
        public void onDateSet(
            DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {

          year = selectedYear;
          month = selectedMonth;
          day = selectedDay;

          // Show selected date
          expDate.setText(
              new StringBuilder()
                  .append(day)
                  .append("-")
                  .append(month + 1)
                  .append("-")
                  .append(year));

          StringBuilder sDate;
          StringBuilder eDate;

          eDate =
              new StringBuilder()
                  .append(year)
                  .append("-")
                  .append(month + 1)
                  .append("-")
                  .append(day);

          if (edDate.getText().toString().trim().length() == 0) {
            edDate.setText(
                new StringBuilder()
                    .append(day)
                    .append("-")
                    .append(month + 1)
                    .append("-")
                    .append(year));
            sDate =
                new StringBuilder()
                    .append(year)
                    .append("-")
                    .append(month + 1)
                    .append("-")
                    .append(day);
          } else {
            String tempDate = edDate.getText().toString();

            int tempdays =
                Integer.valueOf(tempDate.substring(0, edDate.getText().toString().indexOf("-")));
            int tempmonth =
                Integer.valueOf(
                    tempDate.substring(
                        edDate.getText().toString().indexOf("-") + 1,
                        edDate.getText().toString().lastIndexOf("-")));
            int tempyear =
                Integer.valueOf(
                    tempDate.substring(
                        edDate.getText().toString().lastIndexOf("-") + 1, edDate.length()));

            sDate =
                new StringBuilder()
                    .append(tempyear)
                    .append("-")
                    .append(tempmonth)
                    .append("-")
                    .append(tempdays);
          }

          LocalDate startDate = new LocalDate(sDate.toString().trim());
          LocalDate endDate = new LocalDate(eDate.toString().trim());

          Period period = new Period(startDate, endDate, PeriodType.months());
          Log.e("############## dif", "" + period.getMonths());

          if (period.getMonths() <= 0) {
            edTerm.setText("0");
          } else {
            edTerm.setText("" + period.getMonths());
          }
        }
示例#9
0
 public int getAge() {
   LocalDate today = new LocalDate();
   Period period = new Period(this.dateOfBirth, today, PeriodType.years());
   return period.getYears();
 }
 private DateDiscreteDomain(
     DurationFieldType iterationFieldType, DateTimeFieldType roundFloorFieldType) {
   this.iterationFieldType = iterationFieldType;
   this.roundFieldType = roundFloorFieldType;
   this.periodType = PeriodType.forFields(new DurationFieldType[] {iterationFieldType});
 }
示例#11
0
 public void testSetInto_Object() throws Exception {
   MutablePeriod m = new MutablePeriod(PeriodType.millis());
   NullConverter.INSTANCE.setInto(m, null, null);
   assertEquals(0L, m.getMillis());
 }
示例#12
0
 // -----------------------------------------------------------------------
 public void testGetPeriodType_Object() throws Exception {
   assertEquals(PeriodType.standard(), NullConverter.INSTANCE.getPeriodType(null));
 }