EN · DE · RU · FR · ES

#668: WeekHolder.java

projectforge-business/src/main/java/org/projectforge/framework/calendar/WeekHolder.java Type: Java · Role: Calendar · Source: projectforge-business/src/main/java/org/projectforge/framework/calendar/WeekHolder.java 111 lines · 57 code · 36 comments · 18 blank
Source code file at projectforge-business/src/main/java/org/projectforge/framework/calendar/WeekHolder.java containing Java code for the Calendar layer.

Code Structure

Package: org.projectforge.framework.calendar

Classes: WeekHolder

Implements: Serializable

Methods (6): getWeekOfYear, getFirstDayDate, getLastDayDate, addObject, getObject, toString

Fields (2): serialVersionUID, weekOfYear

Imports: 6 packages

Source Code (abridged)

package org.projectforge.framework.calendar;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.projectforge.framework.time.PFDay;

import java.io.Serializable;
import java.time.Month;
import java.util.HashMap;
import java.util.Map;


/**
 * @author Kai Reinhard (k.reinhard@micromata.de)
 */
public class WeekHolder implements Serializable {
  private static final long serialVersionUID = -3895513078248004222L;

  private PFDay[] days;

  private int weekOfYear;

  private Map<String, Object> objects;

  public WeekHolder(PFDay date) {
    final Month month = date.getMonth();
    weekOfYear = date.getWeekOfYear();
    days = new PFDay[7];
    PFDay day = date.getBeginOfWeek();
    // Process week
    for (int i = 0; i < 7; i++) {
      if (day.getMonth() != month) {
        // TODO: Mark this day as day from the previous or next month:
        //day.setMarker(true);
      }
      days[i] = day;
      day = day.plusDays(1);
    }
  }


  public int getWeekOfYear() {
    return weekOfYear;
  }

  public PFDay[] getDays() {
    return days;
  }

  public PFDay getFirstDayDate() {
    return days[0];
  }

  public PFDay getLastDayDate() {
    return days[days.length - 1];
  }

  /**
   * For storing additional objects to a week. This is used by the date selector for showing the user's total working time.
   */
  public void addObject(String key, Object value) {
    if (this.objects == null) {
      this.objects = new HashMap<>();
    }
    this.objects.put(key, value);
  }

  /**
   * Used for getting e. g. the user total working time at this week.
   *
   * @return the stored objects to this day or null, if not exist.
   */
  public Object getObject(String key) {
    if (this.objects == null) {
      return null;
    }
    return this.objects.get(key);
  }

  public Map<String, Object> getObjects() {
    return this.objects;
  }

  public String toString() {
    ToStringBuilder tos = new ToStringBuilder(this);
    tos.append("days", getDays());
    return tos.toString();
  }
}

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
5f7ef41b8 Copyright 2021 -> 2022