| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JodaWorkingWeek |
|
| 1.1428571428571428;1.143 |
| 1 | /* | |
| 2 | * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit. | |
| 3 | * | |
| 4 | * Based in London, we are world leaders in the design and development | |
| 5 | * of bespoke applications for the securities financing markets. | |
| 6 | * | |
| 7 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> | |
| 8 | * ___ _ _ _ _ _ | |
| 9 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 10 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 11 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 12 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 13 | * |__/ | |
| 14 | * | |
| 15 | * www.ObjectLab.co.uk | |
| 16 | * | |
| 17 | * $Id: JodaWorkingWeek.java 334 2010-03-30 11:06:50Z marchy $ | |
| 18 | * | |
| 19 | * Copyright 2006 the original author or authors. | |
| 20 | * | |
| 21 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 22 | * use this file except in compliance with the License. You may obtain a copy of | |
| 23 | * the License at | |
| 24 | * | |
| 25 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 26 | * | |
| 27 | * Unless required by applicable law or agreed to in writing, software | |
| 28 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
| 29 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
| 30 | * License for the specific language governing permissions and limitations under | |
| 31 | * the License. | |
| 32 | */ | |
| 33 | package net.objectlab.kit.datecalc.joda; | |
| 34 | ||
| 35 | import net.objectlab.kit.datecalc.common.WorkingWeek; | |
| 36 | ||
| 37 | import org.joda.time.LocalDate; | |
| 38 | ||
| 39 | /** | |
| 40 | * Immutable class representing a WorkingWeek for the Joda implementation. | |
| 41 | * | |
| 42 | * @author Benoit Xhenseval | |
| 43 | * @author $LastChangedBy: marchy $ | |
| 44 | * @version $Revision: 334 $ $Date: 2010-03-30 07:06:50 -0400 (Tue, 30 Mar 2010) $ | |
| 45 | */ | |
| 46 | public class JodaWorkingWeek extends WorkingWeek { | |
| 47 | ||
| 48 | private static final int MAX_WEEKDAY_INDEX = 7; | |
| 49 | ||
| 50 | 1 | public static final JodaWorkingWeek DEFAULT = new JodaWorkingWeek(); |
| 51 | ||
| 52 | public JodaWorkingWeek() { | |
| 53 | 5 | super(); |
| 54 | 5 | } |
| 55 | ||
| 56 | protected JodaWorkingWeek(final byte workingDays) { | |
| 57 | 34 | super(workingDays); |
| 58 | 34 | } |
| 59 | ||
| 60 | public JodaWorkingWeek(final WorkingWeek ww) { | |
| 61 | 34 | this(ww.getWorkingDays()); |
| 62 | 34 | } |
| 63 | ||
| 64 | // ----------------------------------------------------------------------- | |
| 65 | // | |
| 66 | // ObjectLab, world leaders in the design and development of bespoke | |
| 67 | // applications for the securities financing markets. | |
| 68 | // www.ObjectLab.co.uk | |
| 69 | // | |
| 70 | // ----------------------------------------------------------------------- | |
| 71 | ||
| 72 | public boolean isWorkingDay(final LocalDate date) { | |
| 73 | 4886 | final int dayOfWeek = jodaToCalendarDayConstant(date.getDayOfWeek()); |
| 74 | 4886 | return isWorkingDayFromCalendar(dayOfWeek); |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Return a new JodaWorkingWeek if the status for the given day has changed. | |
| 79 | * | |
| 80 | * @param working | |
| 81 | * true if working day | |
| 82 | * @param givenDayOfWeek | |
| 83 | * e.g. DateTimeConstants.MONDAY, DateTimeConstants.TUESDAY, etc | |
| 84 | */ | |
| 85 | public JodaWorkingWeek withWorkingDayFromDateTimeConstant(final boolean working, int givenDayOfWeek) { | |
| 86 | 4 | int dayOfWeek = jodaToCalendarDayConstant(givenDayOfWeek); |
| 87 | 4 | return new JodaWorkingWeek(super.withWorkingDayFromCalendar(working, dayOfWeek)); |
| 88 | } | |
| 89 | ||
| 90 | public boolean isWorkingDayFromDateTimeConstant(final int dayOfWeek) { | |
| 91 | 23 | return isWorkingDayFromCalendar(jodaToCalendarDayConstant(dayOfWeek)); |
| 92 | } | |
| 93 | ||
| 94 | public int jodaToCalendarDayConstant(final int givenDayOfWeek) { | |
| 95 | 4920 | int dayOfWeek = givenDayOfWeek + 1; |
| 96 | 4920 | return (dayOfWeek <= MAX_WEEKDAY_INDEX ? dayOfWeek : dayOfWeek % MAX_WEEKDAY_INDEX); |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | /* | |
| 101 | * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit. | |
| 102 | * | |
| 103 | * Based in London, we are world leaders in the design and development | |
| 104 | * of bespoke applications for the securities financing markets. | |
| 105 | * | |
| 106 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> | |
| 107 | * ___ _ _ _ _ _ | |
| 108 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 109 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 110 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 111 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 112 | * |__/ | |
| 113 | * | |
| 114 | * www.ObjectLab.co.uk | |
| 115 | */ |