| 1 | /* | |
| 2 | * Copyright 2001-2013 Stephen Colebourne | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.joda.time; | |
| 17 | ||
| 18 | import java.io.IOException; | |
| 19 | import java.io.ObjectInputStream; | |
| 20 | import java.io.ObjectOutputStream; | |
| 21 | import java.io.Serializable; | |
| 22 | import java.util.Locale; | |
| 23 | ||
| 24 | import org.joda.convert.FromString; | |
| 25 | import org.joda.time.base.BaseDateTime; | |
| 26 | import org.joda.time.field.AbstractReadableInstantFieldProperty; | |
| 27 | import org.joda.time.format.DateTimeFormatter; | |
| 28 | import org.joda.time.format.ISODateTimeFormat; | |
| 29 | ||
| 30 | /** | |
| 31 | * DateMidnight defines a date where the time component is fixed at midnight. | |
| 32 | * The class uses a time zone, thus midnight is local unless a UTC time zone is used. | |
| 33 | *
 | |
| 34 | * It is important to emphasise that this class represents the time of midnight on | |
| 35 | * any given day. | |
| 36 | * Note that midnight is defined as 00:00, which is at the very start of a day. | |
| 37 | *
 | |
| 38 | * This class does not represent a day, but the millisecond instant at midnight. | |
| 39 | * If you need a class that represents the whole day, then an {@link Interval} or | |
| 40 | * a {@link LocalDate} may be more suitable. | |
| 41 | *
 | |
| 42 | * This class uses a Chronology internally. The Chronology determines how the | |
| 43 | * millisecond instant value is converted into the date time fields. | |
| 44 | * The default Chronology is ISOChronology which is the agreed | |
| 45 | * international standard and compatable with the modern Gregorian calendar. | |
| 46 | * | |
| 47 | *
Each individual field can be queried in two ways: | |
| 48 | *
 | |
| 49 | *
getDayOfMonth() | |
| 50 | *
dayOfMonth().get() | |
| 51 | *
 | |
| 52 | * The second technique also provides access to other useful methods on the | |
| 53 | * field: | |
| 54 | *
 | |
| 55 | *
numeric value | |
| 56 | *
text value | |
| 57 | *
short text value | |
| 58 | *
maximum/minimum values | |
| 59 | *
add/subtract | |
| 60 | *
set | |
| 61 | *
rounding | |
| 62 | *
 | |
| 63 | * | |
| 64 | *
 | |
| 65 | * DateMidnight is thread-safe and immutable, provided that the Chronology is as well. | |
| 66 | * All standard Chronology classes supplied are thread-safe and immutable. | |
| 67 | * | |
| 68 | * @author Stephen Colebourne | |
| 69 | * @since 1.0 | |
| 70 | * @deprecated The time of midnight does not exist in some time zones | |
| 71 | * where the daylight saving time forward shift skips the midnight hour. | |
| 72 | * Use {@link LocalDate} to represent a date without a time zone. | |
| 73 | * Or use {@link DateTime} to represent a full date and time, perhaps | |
| 74 | * using {@link DateTime#withTimeAtStartOfDay()} to get an instant at the | |
| 75 | * start of a day. | |
| 76 | */ | |
| 77 | @Deprecated | |
| 78 | public final class DateMidnight | |
| 79 | extends BaseDateTime | |
| 80 | implements ReadableDateTime, Serializable { | |
| 81 | | |
| 82 | /** Serialization lock */ | |
| 83 | private static final long serialVersionUID =<PHONE_NUMBER>18738L; | |
| 84 | ||
| 85 | //----------------------------------------------------------------------- | |
| 86 | /** | |
| 87 | * Obtains a {@code DateMidnight} set to the current system millisecond time | |
| 88 | * using ISOChronology in the default time zone. | |
| 89 | * The constructed object will have a local time of midnight. | |
| 90 | * | |
| 91 | * @return the current date, not null | |
| 92 | * @since 2.0 | |
| 93 | */ | |
| 94 | public static DateMidnight now() { | |
| 95 |
1
1. now : mutated return of Object value for org/joda/time/DateMidnight::now to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new DateMidnight(); |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Obtains a {@code DateMidnight} set to the current system millisecond time | |
| 100 | * using ISOChronology in the specified time zone. | |
| 101 | * The constructed object will have a local time of midnight. | |
| 102 | * | |
| 103 | * @param zone the time zone, not null | |
| 104 | * @return the current date, not null | |
| 105 | * @since 2.0 | |
| 106 | */ | |
| 107 | public static DateMidnight now(DateTimeZone zone) { | |
| 108 |
1
1. now : negated conditional → NO_COVERAGE |
if (zone == null) { |
| 109 | throw new NullPointerException("Zone must not be null"); | |
| 110 | } | |
| 111 |
1
1. now : mutated return of Object value for org/joda/time/DateMidnight::now to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new DateMidnight(zone); |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Obtains a {@code DateMidnight} set to the current system millisecond time | |
| 116 | * using the specified chronology. | |
| 117 | * The constructed object will have a local time of midnight. | |
| 118 | * | |
| 119 | * @param chronology the chronology, not null | |
| 120 | * @return the current date, not null | |
| 121 | * @since 2.0 | |
| 122 | */ | |
| 123 | public static DateMidnight now(Chronology chronology) { | |
| 124 |
1
1. now : negated conditional → NO_COVERAGE |
if (chronology == null) { |
| 125 | throw new NullPointerException("Chronology must not be null"); | |
| 126 | } | |
| 127 |
1
1. now : mutated return of Object value for org/joda/time/DateMidnight::now to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new DateMidnight(chronology); |
| 128 | } | |
| 129 | ||
| 130 | //----------------------------------------------------------------------- | |
| 131 | /** | |
| 132 | * Parses a {@code DateMidnight} from the specified string. | |
| 133 | *
 | |
| 134 | * This uses {@link ISODateTimeFormat#dateTimeParser()}. | |
| 135 | * | |
| 136 | * @param str the string to parse, not null | |
| 137 | * @since 2.0 | |
| 138 | */ | |
| 139 | @FromString | |
| 140 | public static DateMidnight parse(String str) { | |
| 141 |
1
1. parse : mutated return of Object value for org/joda/time/DateMidnight::parse to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed()); |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Parses a {@code DateMidnight} from the specified string using a formatter. | |
| 146 | * | |
| 147 | * @param str the string to parse, not null | |
| 148 | * @param formatter the formatter to use, not null | |
| 149 | * @since 2.0 | |
| 150 | */ | |
| 151 | public static DateMidnight parse(String str, DateTimeFormatter formatter) { | |
| 152 |
1
1. parse : mutated return of Object value for org/joda/time/DateMidnight::parse to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return formatter.parseDateTime(str).toDateMidnight(); |
| 153 | } | |
| 154 | ||
| 155 | //----------------------------------------------------------------------- | |
| 156 | /** | |
| 157 | * Constructs an instance set to the current system millisecond time | |
| 158 | * using ISOChronology in the default time zone. | |
| 159 | * The constructed object will have a local time of midnight. | |
| 160 | * | |
| 161 | * @see #now() | |
| 162 | */ | |
| 163 | public DateMidnight() { | |
| 164 | super(); | |
| 165 | } | |
| 166 | ||
| 167 | /** | |
| 168 | * Constructs an instance set to the current system millisecond time | |
| 169 | * using ISOChronology in the specified time zone. | |
| 170 | * The constructed object will have a local time of midnight. | |
| 171 | *
 | |
| 172 | * If the specified time zone is null, the default zone is used. | |
| 173 | * | |
| 174 | * @param zone the time zone, null means default zone | |
| 175 | * @see #now(DateTimeZone) | |
| 176 | */ | |
| 177 | public DateMidnight(DateTimeZone zone) { | |
| 178 | super(zone); | |
| 179 | } | |
| 180 | ||
| 181 | /** | |
| 182 | * Constructs an instance set to the current system millisecond time | |
| 183 | * using the specified chronology. | |
| 184 | * The constructed object will have a local time of midnight. | |
| 185 | *
 | |
| 186 | * If the chronology is null, ISOChronology | |
| 187 | * in the default time zone is used. | |
| 188 | * | |
| 189 | * @param chronology the chronology, null means ISOChronology in default zone | |
| 190 | * @see #now(Chronology) | |
| 191 | */ | |
| 192 | public DateMidnight(Chronology chronology) { | |
| 193 | super(chronology); | |
| 194 | } | |
| 195 | ||
| 196 | //----------------------------------------------------------------------- | |
| 197 | /** | |
| 198 | * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z | |
| 199 | * using ISOChronology in the default time zone. | |
| 200 | * The constructed object will have a local time of midnight. | |
| 201 | * | |
| 202 | * @param instant the milliseconds from 1970-01-01T00:00:00Z | |
| 203 | */ | |
| 204 | public DateMidnight(long instant) { | |
| 205 | super(instant); | |
| 206 | } | |
| 207 | ||
| 208 | /** | |
| 209 | * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z | |
| 210 | * using ISOChronology in the specified time zone. | |
| 211 | * The constructed object will have a local time of midnight. | |
| 212 | *
 | |
| 213 | * If the specified time zone is null, the default zone is used. | |
| 214 | * | |
| 215 | * @param instant the milliseconds from 1970-01-01T00:00:00Z | |
| 216 | * @param zone the time zone, null means default zone | |
| 217 | */ | |
| 218 | public DateMidnight(long instant, DateTimeZone zone) { | |
| 219 | super(instant, zone); | |
| 220 | } | |
| 221 | ||
| 222 | /** | |
| 223 | * Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z | |
| 224 | * using the specified chronology. | |
| 225 | * The constructed object will have a local time of midnight. | |
| 226 | *
 | |
| 227 | * If the chronology is null, ISOChronology | |
| 228 | * in the default time zone is used. | |
| 229 | * | |
| 230 | * @param instant the milliseconds from 1970-01-01T00:00:00Z | |
| 231 | * @param chronology the chronology, null means ISOChronology in default zone | |
| 232 | */ | |
| 233 | public DateMidnight(long instant, Chronology chronology) { | |
| 234 | super(instant, chronology); | |
| 235 | } | |
| 236 | ||
| 237 | //----------------------------------------------------------------------- | |
| 238 | /** | |
| 239 | * Constructs an instance from an Object that represents a datetime. | |
| 240 | * The constructed object will have a local time of midnight. | |
| 241 | *
 | |
| 242 | * If the object implies a chronology (such as GregorianCalendar does), | |
| 243 | * then that chronology will be used. Otherwise, ISO default is used. | |
| 244 | * Thus if a GregorianCalendar is passed in, the chronology used will | |
| 245 | * be GJ, but if a Date is passed in the chronology will be ISO. | |
| 246 | *
 | |
| 247 | * The recognised object types are defined in | |
| 248 | * {@link org.joda.time.convert.ConverterManager ConverterManager} and | |
| 249 | * include ReadableInstant, String, Calendar and Date. | |
| 250 | * The String formats are described by {@link ISODateTimeFormat#dateTimeParser()}. | |
| 251 | * | |
| 252 | * @param instant the datetime object, null means now | |
| 253 | * @throws IllegalArgumentException if the instant is invalid | |
| 254 | */ | |
| 255 | public DateMidnight(Object instant) { | |
| 256 | super(instant, (Chronology) null); | |
| 257 | } | |
| 258 | ||
| 259 | /** | |
| 260 | * Constructs an instance from an Object that represents a datetime, | |
| 261 | * forcing the time zone to that specified. | |
| 262 | * The constructed object will have a local time of midnight. | |
| 263 | *
 | |
| 264 | * If the object implies a chronology (such as GregorianCalendar does), | |
| 265 | * then that chronology will be used, but with the time zone adjusted. | |
| 266 | * Otherwise, ISO is used in the specified time zone. | |
| 267 | * If the specified time zone is null, the default zone is used. | |
| 268 | * Thus if a GregorianCalendar is passed in, the chronology used will | |
| 269 | * be GJ, but if a Date is passed in the chronology will be ISO. | |
| 270 | *
 | |
| 271 | * The recognised object types are defined in | |
| 272 | * {@link org.joda.time.convert.ConverterManager ConverterManager} and | |
| 273 | * include ReadableInstant, String, Calendar and Date. | |
| 274 | * The String formats are described by {@link ISODateTimeFormat#dateTimeParser()}. | |
| 275 | * | |
| 276 | * @param instant the datetime object, null means now | |
| 277 | * @param zone the time zone, null means default time zone | |
| 278 | * @throws IllegalArgumentException if the instant is invalid | |
| 279 | */ | |
| 280 | public DateMidnight(Object instant, DateTimeZone zone) { | |
| 281 | super(instant, zone); | |
| 282 | } | |
| 283 | ||
| 284 | /** | |
| 285 | * Constructs an instance from an Object that represents a datetime, | |
| 286 | * using the specified chronology. | |
| 287 | * The constructed object will have a local time of midnight. | |
| 288 | *
 | |
| 289 | * If the chronology is null, ISO in the default time zone is used. | |
| 290 | * Any chronology implied by the object (such as GregorianCalendar does) | |
| 291 | * is ignored. | |
| 292 | *
 | |
| 293 | * The recognised object types are defined in | |
| 294 | * {@link org.joda.time.convert.ConverterManager ConverterManager} and | |
| 295 | * include ReadableInstant, String, Calendar and Date. | |
| 296 | * The String formats are described by {@link ISODateTimeFormat#dateTimeParser()}. | |
| 297 | * | |
| 298 | * @param instant the datetime object, null means now | |
| 299 | * @param chronology the chronology, null means ISOChronology in default zone | |
| 300 | * @throws IllegalArgumentException if the instant is invalid | |
| 301 | */ | |
| 302 | public DateMidnight(Object instant, Chronology chronology) { | |
| 303 | super(instant, DateTimeUtils.getChronology(chronology)); | |
| 304 | } | |
| 305 | ||
| 306 | //----------------------------------------------------------------------- | |
| 307 | /** | |
| 308 | * Constructs an instance from datetime field values | |
| 309 | * using ISOChronology in the default time zone. | |
| 310 | * The constructed object will have a local time of midnight. | |
| 311 | * | |
| 312 | * @param year the year | |
| 313 | * @param monthOfYear the month of the year, from 1 to 12 | |
| 314 | * @param dayOfMonth the day of the month, from 1 to 31 | |
| 315 | */ | |
| 316 | public DateMidnight(int year, int monthOfYear, int dayOfMonth) { | |
| 317 | super(year, monthOfYear, dayOfMonth, 0, 0, 0, 0); | |
| 318 | } | |
| 319 | ||
| 320 | /** | |
| 321 | * Constructs an instance from datetime field values | |
| 322 | * using ISOChronology in the specified time zone. | |
| 323 | * The constructed object will have a local time of midnight. | |
| 324 | *
 | |
| 325 | * If the specified time zone is null, the default zone is used. | |
| 326 | * | |
| 327 | * @param year the year | |
| 328 | * @param monthOfYear the month of the year, from 1 to 12 | |
| 329 | * @param dayOfMonth the day of the month, from 1 to 31 | |
| 330 | * @param zone the time zone, null means default time zone | |
| 331 | */ | |
| 332 | public DateMidnight(int year, int monthOfYear, int dayOfMonth, DateTimeZone zone) { | |
| 333 | super(year, monthOfYear, dayOfMonth, 0, 0, 0, 0, zone); | |
| 334 | } | |
| 335 | ||
| 336 | /** | |
| 337 | * Constructs an instance from datetime field values | |
| 338 | * using the specified chronology. | |
| 339 | * The constructed object will have a local time of midnight. | |
| 340 | *
 | |
| 341 | * If the chronology is null, ISOChronology | |
| 342 | * in the default time zone is used. | |
| 343 | * | |
| 344 | * @param year the year, valid values defined by the chronology | |
| 345 | * @param monthOfYear the month of the year, valid values defined by the chronology | |
| 346 | * @param dayOfMonth the day of the month, valid values defined by the chronology | |
| 347 | * @param chronology the chronology, null means ISOChronology in default zone | |
| 348 | */ | |
| 349 | public DateMidnight(int year, int monthOfYear, int dayOfMonth, Chronology chronology) { | |
| 350 | super(year, monthOfYear, dayOfMonth, 0, 0, 0, 0, chronology); | |
| 351 | } | |
| 352 | ||
| 353 | /** | |
| 354 | * Rounds the specified instant to midnight. | |
| 355 | * | |
| 356 | * @param instant the milliseconds from 1970-01-01T00:00:00Z to round | |
| 357 | * @param chronology the chronology to use, not null | |
| 358 | * @return the updated instant, rounded to midnight | |
| 359 | */ | |
| 360 | protected long checkInstant(long instant, Chronology chronology) { | |
| 361 |
1
1. checkInstant : replaced return of long value with value + 1 for org/joda/time/DateMidnight::checkInstant → SURVIVED |
return chronology.dayOfMonth().roundFloor(instant); |
| 362 | } | |
| 363 | ||
| 364 | //----------------------------------------------------------------------- | |
| 365 | /** | |
| 366 | * Returns a copy of this date with a different millisecond instant. | |
| 367 | * The returned object will have a local time of midnight. | |
| 368 | *
 | |
| 369 | * Only the millis will change, the chronology and time zone are kept. | |
| 370 | * The returned object will be either be a new instance or this. | |
| 371 | * | |
| 372 | * @param newMillis the new millis, from 1970-01-01T00:00:00Z | |
| 373 | * @return a copy of this instant with different millis | |
| 374 | */ | |
| 375 | public DateMidnight withMillis(long newMillis) { | |
| 376 | Chronology chrono = getChronology(); | |
| 377 | newMillis = checkInstant(newMillis, chrono); | |
| 378 |
2
1. withMillis : negated conditional → TIMED_OUT 2. withMillis : mutated return of Object value for org/joda/time/DateMidnight::withMillis to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (newMillis == getMillis() ? this : new DateMidnight(newMillis, chrono)); |
| 379 | } | |
| 380 | ||
| 381 | /** | |
| 382 | * Returns a copy of this date with a different chronology, potentially | |
| 383 | * changing the day in unexpected ways. | |
| 384 | *
 | |
| 385 | * This method creates a new DateMidnight using the midnight millisecond value | |
| 386 | * and the new chronology. If the same or similar chronology is specified, but | |
| 387 | * with a different time zone, the day may change. This occurs because the new | |
| 388 | * DateMidnight rounds down the millisecond value to get to midnight, and the | |
| 389 | * time zone change may result in a rounding down to a different day. | |
| 390 | *
 | |
| 391 | * For example, changing time zone from London (+00:00) to Paris (+01:00) will | |
| 392 | * retain the same day, but changing from Paris to London will change the day. | |
| 393 | * (When its midnight in London its the same day in Paris, but when its midnight | |
| 394 | * in Paris its still the previous day in London) | |
| 395 | *
 | |
| 396 | * To avoid these unusual effects, use {@link #withZoneRetainFields(DateTimeZone)} | |
| 397 | * to change time zones. | |
| 398 | * | |
| 399 | * @param newChronology the new chronology | |
| 400 | * @return a copy of this instant with a different chronology | |
| 401 | */ | |
| 402 | public DateMidnight withChronology(Chronology newChronology) { | |
| 403 |
2
1. withChronology : negated conditional → NO_COVERAGE 2. withChronology : mutated return of Object value for org/joda/time/DateMidnight::withChronology to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (newChronology == getChronology() ? this : new DateMidnight(getMillis(), newChronology)); |
| 404 | } | |
| 405 | ||
| 406 | /** | |
| 407 | * Returns a copy of this date with a different time zone, preserving the day | |
| 408 | * The returned object will have a local time of midnight in the new zone on | |
| 409 | * the same day as the original instant. | |
| 410 | * | |
| 411 | * @param newZone the new time zone, null means default | |
| 412 | * @return a copy of this instant with a different time zone | |
| 413 | */ | |
| 414 | public DateMidnight withZoneRetainFields(DateTimeZone newZone) { | |
| 415 | newZone = DateTimeUtils.getZone(newZone); | |
| 416 | DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); | |
| 417 |
1
1. withZoneRetainFields : negated conditional → NO_COVERAGE |
if (newZone == originalZone) { |
| 418 |
1
1. withZoneRetainFields : mutated return of Object value for org/joda/time/DateMidnight::withZoneRetainFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 419 | } | |
| 420 | | |
| 421 | long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); | |
| 422 |
1
1. withZoneRetainFields : mutated return of Object value for org/joda/time/DateMidnight::withZoneRetainFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new DateMidnight(millis, getChronology().withZone(newZone)); |
| 423 | } | |
| 424 | ||
| 425 | //----------------------------------------------------------------------- | |
| 426 | /** | |
| 427 | * Returns a copy of this date with the partial set of fields replacing those | |
| 428 | * from this instance. | |
| 429 | *
 | |
| 430 | * For example, if the partial is a LocalDate then the date fields | |
| 431 | * would be changed in the returned instance. | |
| 432 | * If the partial is null, then this is returned. | |
| 433 | * | |
| 434 | * @param partial the partial set of fields to apply to this datetime, null ignored | |
| 435 | * @return a copy of this datetime with a different set of fields | |
| 436 | * @throws IllegalArgumentException if any value is invalid | |
| 437 | */ | |
| 438 | public DateMidnight withFields(ReadablePartial partial) { | |
| 439 |
1
1. withFields : negated conditional → NO_COVERAGE |
if (partial == null) { |
| 440 |
1
1. withFields : mutated return of Object value for org/joda/time/DateMidnight::withFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 441 | } | |
| 442 |
1
1. withFields : mutated return of Object value for org/joda/time/DateMidnight::withFields to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().set(partial, getMillis())); |
| 443 | } | |
| 444 | ||
| 445 | /** | |
| 446 | * Returns a copy of this date with the specified field set to a new value. | |
| 447 | *
 | |
| 448 | * For example, if the field type is dayOfMonth then the day of month | |
| 449 | * field would be changed in the returned instance. | |
| 450 | * If the field type is null, then this is returned. | |
| 451 | *
 | |
| 452 | * These three lines are equivalent: | |
| 453 | *
 | |
| 454 | * DateTime updated = dt.withField(DateTimeFieldType.dayOfMonth(), 6); | |
| 455 | * DateTime updated = dt.dayOfMonth().setCopy(6); | |
| 456 | * DateTime updated = dt.property(DateTimeFieldType.dayOfMonth()).setCopy(6); | |
| 457 | *
 | |
| 458 | * | |
| 459 | * @param fieldType the field type to set, not null | |
| 460 | * @param value the value to set | |
| 461 | * @return a copy of this datetime with the field set | |
| 462 | * @throws IllegalArgumentException if the value is null or invalid | |
| 463 | */ | |
| 464 | public DateMidnight withField(DateTimeFieldType fieldType, int value) { | |
| 465 |
1
1. withField : negated conditional → NO_COVERAGE |
if (fieldType == null) { |
| 466 | throw new IllegalArgumentException("Field must not be null"); | |
| 467 | } | |
| 468 | long instant = fieldType.getField(getChronology()).set(getMillis(), value); | |
| 469 |
1
1. withField : mutated return of Object value for org/joda/time/DateMidnight::withField to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 470 | } | |
| 471 | ||
| 472 | /** | |
| 473 | * Returns a copy of this date with the value of the specified field increased. | |
| 474 | *
 | |
| 475 | * If the addition is zero or the field is null, then this is returned. | |
| 476 | *
 | |
| 477 | * These three lines are equivalent: | |
| 478 | *
 | |
| 479 | * DateMidnight added = dt.withFieldAdded(DateTimeFieldType.year(), 6); | |
| 480 | * DateMidnight added = dt.plusYears(6); | |
| 481 | * DateMidnight added = dt.year().addToCopy(6); | |
| 482 | *
 | |
| 483 | * | |
| 484 | * @param fieldType the field type to add to, not null | |
| 485 | * @param amount the amount to add | |
| 486 | * @return a copy of this datetime with the field updated | |
| 487 | * @throws IllegalArgumentException if the value is null or invalid | |
| 488 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 489 | */ | |
| 490 | public DateMidnight withFieldAdded(DurationFieldType fieldType, int amount) { | |
| 491 |
1
1. withFieldAdded : negated conditional → NO_COVERAGE |
if (fieldType == null) { |
| 492 | throw new IllegalArgumentException("Field must not be null"); | |
| 493 | } | |
| 494 |
1
1. withFieldAdded : negated conditional → NO_COVERAGE |
if (amount == 0) { |
| 495 |
1
1. withFieldAdded : mutated return of Object value for org/joda/time/DateMidnight::withFieldAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 496 | } | |
| 497 | long instant = fieldType.getField(getChronology()).add(getMillis(), amount); | |
| 498 |
1
1. withFieldAdded : mutated return of Object value for org/joda/time/DateMidnight::withFieldAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 499 | } | |
| 500 | ||
| 501 | //----------------------------------------------------------------------- | |
| 502 | /** | |
| 503 | * Returns a copy of this date with the specified duration added. | |
| 504 | *
 | |
| 505 | * If the addition is zero, then this is returned. | |
| 506 | * | |
| 507 | * @param durationToAdd the duration to add to this one | |
| 508 | * @param scalar the amount of times to add, such as -1 to subtract once | |
| 509 | * @return a copy of this datetime with the duration added | |
| 510 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 511 | */ | |
| 512 | public DateMidnight withDurationAdded(long durationToAdd, int scalar) { | |
| 513 |
2
1. withDurationAdded : negated conditional → NO_COVERAGE 2. withDurationAdded : negated conditional → NO_COVERAGE |
if (durationToAdd == 0 || scalar == 0) { |
| 514 |
1
1. withDurationAdded : mutated return of Object value for org/joda/time/DateMidnight::withDurationAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 515 | } | |
| 516 | long instant = getChronology().add(getMillis(), durationToAdd, scalar); | |
| 517 |
1
1. withDurationAdded : mutated return of Object value for org/joda/time/DateMidnight::withDurationAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 518 | } | |
| 519 | ||
| 520 | /** | |
| 521 | * Returns a copy of this date with the specified duration added. | |
| 522 | *
 | |
| 523 | * If the addition is zero, then this is returned. | |
| 524 | * | |
| 525 | * @param durationToAdd the duration to add to this one, null means zero | |
| 526 | * @param scalar the amount of times to add, such as -1 to subtract once | |
| 527 | * @return a copy of this datetime with the duration added | |
| 528 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 529 | */ | |
| 530 | public DateMidnight withDurationAdded(ReadableDuration durationToAdd, int scalar) { | |
| 531 |
2
1. withDurationAdded : negated conditional → NO_COVERAGE 2. withDurationAdded : negated conditional → NO_COVERAGE |
if (durationToAdd == null || scalar == 0) { |
| 532 |
1
1. withDurationAdded : mutated return of Object value for org/joda/time/DateMidnight::withDurationAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 533 | } | |
| 534 |
1
1. withDurationAdded : mutated return of Object value for org/joda/time/DateMidnight::withDurationAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withDurationAdded(durationToAdd.getMillis(), scalar); |
| 535 | } | |
| 536 | ||
| 537 | /** | |
| 538 | * Returns a copy of this date with the specified period added. | |
| 539 | *
 | |
| 540 | * If the addition is zero, then this is returned. | |
| 541 | *
 | |
| 542 | * This method is typically used to add multiple copies of complex | |
| 543 | * period instances. Adding one field is best achieved using methods | |
| 544 | * like {@link #withFieldAdded(DurationFieldType, int)} | |
| 545 | * or {@link #plusYears(int)}. | |
| 546 | * | |
| 547 | * @param period the period to add to this one, null means zero | |
| 548 | * @param scalar the amount of times to add, such as -1 to subtract once | |
| 549 | * @return a copy of this datetime with the period added | |
| 550 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 551 | */ | |
| 552 | public DateMidnight withPeriodAdded(ReadablePeriod period, int scalar) { | |
| 553 |
2
1. withPeriodAdded : negated conditional → NO_COVERAGE 2. withPeriodAdded : negated conditional → NO_COVERAGE |
if (period == null || scalar == 0) { |
| 554 |
1
1. withPeriodAdded : mutated return of Object value for org/joda/time/DateMidnight::withPeriodAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 555 | } | |
| 556 | long instant = getChronology().add(period, getMillis(), scalar); | |
| 557 |
1
1. withPeriodAdded : mutated return of Object value for org/joda/time/DateMidnight::withPeriodAdded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 558 | } | |
| 559 | ||
| 560 | //----------------------------------------------------------------------- | |
| 561 | /** | |
| 562 | * Returns a copy of this date with the specified duration added. | |
| 563 | *
 | |
| 564 | * If the amount is zero, then this is returned. | |
| 565 | * | |
| 566 | * @param duration the duration, in millis, to add to this one | |
| 567 | * @return a copy of this datetime with the duration added | |
| 568 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 569 | */ | |
| 570 | public DateMidnight plus(long duration) { | |
| 571 |
1
1. plus : mutated return of Object value for org/joda/time/DateMidnight::plus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withDurationAdded(duration, 1); |
| 572 | } | |
| 573 | ||
| 574 | /** | |
| 575 | * Returns a copy of this date with the specified duration added. | |
| 576 | *
 | |
| 577 | * If the amount is zero or null, then this is returned. | |
| 578 | * | |
| 579 | * @param duration the duration to add to this one, null means zero | |
| 580 | * @return a copy of this datetime with the duration added | |
| 581 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 582 | */ | |
| 583 | public DateMidnight plus(ReadableDuration duration) { | |
| 584 |
1
1. plus : mutated return of Object value for org/joda/time/DateMidnight::plus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withDurationAdded(duration, 1); |
| 585 | } | |
| 586 | ||
| 587 | /** | |
| 588 | * Returns a copy of this date with the specified period added. | |
| 589 | *
 | |
| 590 | * If the amount is zero or null, then this is returned. | |
| 591 | *
 | |
| 592 | * This method is typically used to add complex period instances. | |
| 593 | * Adding one field is best achieved using methods | |
| 594 | * like {@link #plusYears(int)}. | |
| 595 | * | |
| 596 | * @param period the duration to add to this one, null means zero | |
| 597 | * @return a copy of this datetime with the period added | |
| 598 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 599 | */ | |
| 600 | public DateMidnight plus(ReadablePeriod period) { | |
| 601 |
1
1. plus : mutated return of Object value for org/joda/time/DateMidnight::plus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withPeriodAdded(period, 1); |
| 602 | } | |
| 603 | ||
| 604 | //----------------------------------------------------------------------- | |
| 605 | /** | |
| 606 | * Returns a copy of this date plus the specified number of years. | |
| 607 | *
 | |
| 608 | * This datetime instance is immutable and unaffected by this method call. | |
| 609 | *
 | |
| 610 | * The following three lines are identical in effect: | |
| 611 | *
 | |
| 612 | * DateMidnight added = dt.plusYears(6); | |
| 613 | * DateMidnight added = dt.plus(Period.years(6)); | |
| 614 | * DateMidnight added = dt.withFieldAdded(DurationFieldType.years(), 6); | |
| 615 | *
 | |
| 616 | * | |
| 617 | * @param years the amount of years to add, may be negative | |
| 618 | * @return the new datetime plus the increased years | |
| 619 | * @since 1.1 | |
| 620 | */ | |
| 621 | public DateMidnight plusYears(int years) { | |
| 622 |
1
1. plusYears : negated conditional → NO_COVERAGE |
if (years == 0) { |
| 623 |
1
1. plusYears : mutated return of Object value for org/joda/time/DateMidnight::plusYears to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 624 | } | |
| 625 | long instant = getChronology().years().add(getMillis(), years); | |
| 626 |
1
1. plusYears : mutated return of Object value for org/joda/time/DateMidnight::plusYears to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 627 | } | |
| 628 | ||
| 629 | /** | |
| 630 | * Returns a copy of this date plus the specified number of months. | |
| 631 | *
 | |
| 632 | * This datetime instance is immutable and unaffected by this method call. | |
| 633 | *
 | |
| 634 | * The following three lines are identical in effect: | |
| 635 | *
 | |
| 636 | * DateMidnight added = dt.plusMonths(6); | |
| 637 | * DateMidnight added = dt.plus(Period.months(6)); | |
| 638 | * DateMidnight added = dt.withFieldAdded(DurationFieldType.months(), 6); | |
| 639 | *
 | |
| 640 | * | |
| 641 | * @param months the amount of months to add, may be negative | |
| 642 | * @return the new datetime plus the increased months | |
| 643 | * @since 1.1 | |
| 644 | */ | |
| 645 | public DateMidnight plusMonths(int months) { | |
| 646 |
1
1. plusMonths : negated conditional → NO_COVERAGE |
if (months == 0) { |
| 647 |
1
1. plusMonths : mutated return of Object value for org/joda/time/DateMidnight::plusMonths to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 648 | } | |
| 649 | long instant = getChronology().months().add(getMillis(), months); | |
| 650 |
1
1. plusMonths : mutated return of Object value for org/joda/time/DateMidnight::plusMonths to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 651 | } | |
| 652 | ||
| 653 | /** | |
| 654 | * Returns a copy of this date plus the specified number of weeks. | |
| 655 | *
 | |
| 656 | * This datetime instance is immutable and unaffected by this method call. | |
| 657 | *
 | |
| 658 | * The following three lines are identical in effect: | |
| 659 | *
 | |
| 660 | * DateMidnight added = dt.plusWeeks(6); | |
| 661 | * DateMidnight added = dt.plus(Period.weeks(6)); | |
| 662 | * DateMidnight added = dt.withFieldAdded(DurationFieldType.weeks(), 6); | |
| 663 | *
 | |
| 664 | * | |
| 665 | * @param weeks the amount of weeks to add, may be negative | |
| 666 | * @return the new datetime plus the increased weeks | |
| 667 | * @since 1.1 | |
| 668 | */ | |
| 669 | public DateMidnight plusWeeks(int weeks) { | |
| 670 |
1
1. plusWeeks : negated conditional → NO_COVERAGE |
if (weeks == 0) { |
| 671 |
1
1. plusWeeks : mutated return of Object value for org/joda/time/DateMidnight::plusWeeks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 672 | } | |
| 673 | long instant = getChronology().weeks().add(getMillis(), weeks); | |
| 674 |
1
1. plusWeeks : mutated return of Object value for org/joda/time/DateMidnight::plusWeeks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 675 | } | |
| 676 | ||
| 677 | /** | |
| 678 | * Returns a copy of this date plus the specified number of days. | |
| 679 | *
 | |
| 680 | * This datetime instance is immutable and unaffected by this method call. | |
| 681 | *
 | |
| 682 | * The following three lines are identical in effect: | |
| 683 | *
 | |
| 684 | * DateMidnight added = dt.plusDays(6); | |
| 685 | * DateMidnight added = dt.plus(Period.days(6)); | |
| 686 | * DateMidnight added = dt.withFieldAdded(DurationFieldType.days(), 6); | |
| 687 | *
 | |
| 688 | * | |
| 689 | * @param days the amount of days to add, may be negative | |
| 690 | * @return the new datetime plus the increased days | |
| 691 | * @since 1.1 | |
| 692 | */ | |
| 693 | public DateMidnight plusDays(int days) { | |
| 694 |
1
1. plusDays : negated conditional → TIMED_OUT |
if (days == 0) { |
| 695 |
1
1. plusDays : mutated return of Object value for org/joda/time/DateMidnight::plusDays to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 696 | } | |
| 697 | long instant = getChronology().days().add(getMillis(), days); | |
| 698 |
1
1. plusDays : mutated return of Object value for org/joda/time/DateMidnight::plusDays to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return withMillis(instant); |
| 699 | } | |
| 700 | ||
| 701 | //----------------------------------------------------------------------- | |
| 702 | /** | |
| 703 | * Returns a copy of this date with the specified duration taken away. | |
| 704 | *
 | |
| 705 | * If the amount is zero or null, then this is returned. | |
| 706 | * | |
| 707 | * @param duration the duration, in millis, to reduce this instant by | |
| 708 | * @return a copy of this datetime with the duration taken away | |
| 709 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 710 | */ | |
| 711 | public DateMidnight minus(long duration) { | |
| 712 |
1
1. minus : mutated return of Object value for org/joda/time/DateMidnight::minus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withDurationAdded(duration, -1); |
| 713 | } | |
| 714 | ||
| 715 | /** | |
| 716 | * Returns a copy of this date with the specified duration taken away. | |
| 717 | *
 | |
| 718 | * If the amount is zero or null, then this is returned. | |
| 719 | * | |
| 720 | * @param duration the duration to reduce this instant by | |
| 721 | * @return a copy of this datetime with the duration taken away | |
| 722 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 723 | */ | |
| 724 | public DateMidnight minus(ReadableDuration duration) { | |
| 725 |
1
1. minus : mutated return of Object value for org/joda/time/DateMidnight::minus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withDurationAdded(duration, -1); |
| 726 | } | |
| 727 | ||
| 728 | /** | |
| 729 | * Returns a copy of this date with the specified period taken away. | |
| 730 | *
 | |
| 731 | * If the amount is zero or null, then this is returned. | |
| 732 | *
 | |
| 733 | * This method is typically used to subtract complex period instances. | |
| 734 | * Subtracting one field is best achieved using methods | |
| 735 | * like {@link #minusYears(int)}. | |
| 736 | * | |
| 737 | * @param period the period to reduce this instant by | |
| 738 | * @return a copy of this datetime with the period taken away | |
| 739 | * @throws ArithmeticException if the new datetime exceeds the capacity of a long | |
| 740 | */ | |
| 741 | public DateMidnight minus(ReadablePeriod period) { | |
| 742 |
1
1. minus : mutated return of Object value for org/joda/time/DateMidnight::minus to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withPeriodAdded(period, -1); |
| 743 | } | |
| 744 | ||
| 745 | //----------------------------------------------------------------------- | |
| 746 | /** | |
| 747 | * Returns a copy of this date minus the specified number of years. | |
| 748 | *
 | |
| 749 | * This datetime instance is immutable and unaffected by this method call. | |
| 750 | *
 | |
| 751 | * The following three lines are identical in effect: | |
| 752 | *
 | |
| 753 | * DateTime subtracted = dt.minusYears(6); | |
| 754 | * DateTime subtracted = dt.minus(Period.years(6)); | |
| 755 | * DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6); | |
| 756 | *
 | |
| 757 | * | |
| 758 | * @param years the amount of years to subtract, may be negative | |
| 759 | * @return the new datetime minus the increased years | |
| 760 | * @since 1.1 | |
| 761 | */ | |
| 762 | public DateMidnight minusYears(int years) { | |
| 763 |
1
1. minusYears : negated conditional → NO_COVERAGE |
if (years == 0) { |
| 764 |
1
1. minusYears : mutated return of Object value for org/joda/time/DateMidnight::minusYears to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 765 | } | |
| 766 | long instant = getChronology().years().subtract(getMillis(), years); | |
| 767 |
1
1. minusYears : mutated return of Object value for org/joda/time/DateMidnight::minusYears to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 768 | } | |
| 769 | ||
| 770 | /** | |
| 771 | * Returns a copy of this date minus the specified number of months. | |
| 772 | *
 | |
| 773 | * This datetime instance is immutable and unaffected by this method call. | |
| 774 | *
 | |
| 775 | * The following three lines are identical in effect: | |
| 776 | *
 | |
| 777 | * DateMidnight subtracted = dt.minusMonths(6); | |
| 778 | * DateMidnight subtracted = dt.minus(Period.months(6)); | |
| 779 | * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.months(), -6); | |
| 780 | *
 | |
| 781 | * | |
| 782 | * @param months the amount of months to subtract, may be negative | |
| 783 | * @return the new datetime minus the increased months | |
| 784 | * @since 1.1 | |
| 785 | */ | |
| 786 | public DateMidnight minusMonths(int months) { | |
| 787 |
1
1. minusMonths : negated conditional → NO_COVERAGE |
if (months == 0) { |
| 788 |
1
1. minusMonths : mutated return of Object value for org/joda/time/DateMidnight::minusMonths to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 789 | } | |
| 790 | long instant = getChronology().months().subtract(getMillis(), months); | |
| 791 |
1
1. minusMonths : mutated return of Object value for org/joda/time/DateMidnight::minusMonths to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 792 | } | |
| 793 | ||
| 794 | /** | |
| 795 | * Returns a copy of this date minus the specified number of weeks. | |
| 796 | *
 | |
| 797 | * This datetime instance is immutable and unaffected by this method call. | |
| 798 | *
 | |
| 799 | * The following three lines are identical in effect: | |
| 800 | *
 | |
| 801 | * DateMidnight subtracted = dt.minusWeeks(6); | |
| 802 | * DateMidnight subtracted = dt.minus(Period.weeks(6)); | |
| 803 | * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6); | |
| 804 | *
 | |
| 805 | * | |
| 806 | * @param weeks the amount of weeks to subtract, may be negative | |
| 807 | * @return the new datetime minus the increased weeks | |
| 808 | * @since 1.1 | |
| 809 | */ | |
| 810 | public DateMidnight minusWeeks(int weeks) { | |
| 811 |
1
1. minusWeeks : negated conditional → NO_COVERAGE |
if (weeks == 0) { |
| 812 |
1
1. minusWeeks : mutated return of Object value for org/joda/time/DateMidnight::minusWeeks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 813 | } | |
| 814 | long instant = getChronology().weeks().subtract(getMillis(), weeks); | |
| 815 |
1
1. minusWeeks : mutated return of Object value for org/joda/time/DateMidnight::minusWeeks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 816 | } | |
| 817 | ||
| 818 | /** | |
| 819 | * Returns a copy of this date minus the specified number of days. | |
| 820 | *
 | |
| 821 | * This datetime instance is immutable and unaffected by this method call. | |
| 822 | *
 | |
| 823 | * The following three lines are identical in effect: | |
| 824 | *
 | |
| 825 | * DateMidnight subtracted = dt.minusDays(6); | |
| 826 | * DateMidnight subtracted = dt.minus(Period.days(6)); | |
| 827 | * DateMidnight subtracted = dt.withFieldAdded(DurationFieldType.days(), -6); | |
| 828 | *
 | |
| 829 | * | |
| 830 | * @param days the amount of days to subtract, may be negative | |
| 831 | * @return the new datetime minus the increased days | |
| 832 | * @since 1.1 | |
| 833 | */ | |
| 834 | public DateMidnight minusDays(int days) { | |
| 835 |
1
1. minusDays : negated conditional → NO_COVERAGE |
if (days == 0) { |
| 836 |
1
1. minusDays : mutated return of Object value for org/joda/time/DateMidnight::minusDays to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
| 837 | } | |
| 838 | long instant = getChronology().days().subtract(getMillis(), days); | |
| 839 |
1
1. minusDays : mutated return of Object value for org/joda/time/DateMidnight::minusDays to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(instant); |
| 840 | } | |
| 841 | ||
| 842 | //----------------------------------------------------------------------- | |
| 843 | /** | |
| 844 | * Gets the property object for the specified type, which contains many useful methods. | |
| 845 | * | |
| 846 | * @param type the field type to get the chronology for | |
| 847 | * @return the property object | |
| 848 | * @throws IllegalArgumentException if the field is null or unsupported | |
| 849 | */ | |
| 850 | public Property property(DateTimeFieldType type) { | |
| 851 |
1
1. property : negated conditional → NO_COVERAGE |
if (type == null) { |
| 852 | throw new IllegalArgumentException("The DateTimeFieldType must not be null"); | |
| 853 | } | |
| 854 | DateTimeField field = type.getField(getChronology()); | |
| 855 |
1
1. property : negated conditional → NO_COVERAGE |
if (field.isSupported() == false) { |
| 856 | throw new IllegalArgumentException("Field '" + type + "' is not supported"); | |
| 857 | } | |
| 858 |
1
1. property : mutated return of Object value for org/joda/time/DateMidnight::property to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, field); |
| 859 | } | |
| 860 | ||
| 861 | //----------------------------------------------------------------------- | |
| 862 | /** | |
| 863 | * Converts this object to a YearMonthDay using the | |
| 864 | * same date and chronology. | |
| 865 | * | |
| 866 | * @return a YearMonthDay using the same millis and chronology | |
| 867 | * @deprecated Use LocalDate instead of YearMonthDay | |
| 868 | */ | |
| 869 | @Deprecated | |
| 870 | public YearMonthDay toYearMonthDay() { | |
| 871 |
1
1. toYearMonthDay : mutated return of Object value for org/joda/time/DateMidnight::toYearMonthDay to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new YearMonthDay(getMillis(), getChronology()); |
| 872 | } | |
| 873 | ||
| 874 | /** | |
| 875 | * Converts this object to a LocalDate with the | |
| 876 | * same date and chronology. | |
| 877 | * | |
| 878 | * @return a LocalDate with the same date and chronology | |
| 879 | * @since 1.3 | |
| 880 | */ | |
| 881 | public LocalDate toLocalDate() { | |
| 882 |
1
1. toLocalDate : mutated return of Object value for org/joda/time/DateMidnight::toLocalDate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new LocalDate(getMillis(), getChronology()); |
| 883 | } | |
| 884 | ||
| 885 | /** | |
| 886 | * Converts this object to an Interval encompassing | |
| 887 | * the whole of this day. | |
| 888 | *
 | |
| 889 | * The interval starts at midnight 00:00 and ends at 00:00 the following day, | |
| 890 | * (which is not included in the interval, as intervals are half-open). | |
| 891 | * | |
| 892 | * @return an interval over the day | |
| 893 | */ | |
| 894 | public Interval toInterval() { | |
| 895 | Chronology chrono = getChronology(); | |
| 896 | long start = getMillis(); | |
| 897 | long end = DurationFieldType.days().getField(chrono).add(start, 1); | |
| 898 |
1
1. toInterval : mutated return of Object value for org/joda/time/DateMidnight::toInterval to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Interval(start, end, chrono); |
| 899 | } | |
| 900 | ||
| 901 | //----------------------------------------------------------------------- | |
| 902 | /** | |
| 903 | * Returns a copy of this date with the era field updated. | |
| 904 | *
 | |
| 905 | * DateMidnight is immutable, so there are no set methods. | |
| 906 | * Instead, this method returns a new instance with the value of | |
| 907 | * era changed. | |
| 908 | * | |
| 909 | * @param era the era to set | |
| 910 | * @return a copy of this object with the field set | |
| 911 | * @throws IllegalArgumentException if the value is invalid | |
| 912 | * @since 1.3 | |
| 913 | */ | |
| 914 | public DateMidnight withEra(int era) { | |
| 915 |
1
1. withEra : mutated return of Object value for org/joda/time/DateMidnight::withEra to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().era().set(getMillis(), era)); |
| 916 | } | |
| 917 | ||
| 918 | /** | |
| 919 | * Returns a copy of this date with the century of era field updated. | |
| 920 | *
 | |
| 921 | * DateMidnight is immutable, so there are no set methods. | |
| 922 | * Instead, this method returns a new instance with the value of | |
| 923 | * century of era changed. | |
| 924 | * | |
| 925 | * @param centuryOfEra the centurey of era to set | |
| 926 | * @return a copy of this object with the field set | |
| 927 | * @throws IllegalArgumentException if the value is invalid | |
| 928 | * @since 1.3 | |
| 929 | */ | |
| 930 | public DateMidnight withCenturyOfEra(int centuryOfEra) { | |
| 931 |
1
1. withCenturyOfEra : mutated return of Object value for org/joda/time/DateMidnight::withCenturyOfEra to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().centuryOfEra().set(getMillis(), centuryOfEra)); |
| 932 | } | |
| 933 | ||
| 934 | /** | |
| 935 | * Returns a copy of this date with the year of era field updated. | |
| 936 | *
 | |
| 937 | * DateMidnight is immutable, so there are no set methods. | |
| 938 | * Instead, this method returns a new instance with the value of | |
| 939 | * year of era changed. | |
| 940 | * | |
| 941 | * @param yearOfEra the year of era to set | |
| 942 | * @return a copy of this object with the field set | |
| 943 | * @throws IllegalArgumentException if the value is invalid | |
| 944 | * @since 1.3 | |
| 945 | */ | |
| 946 | public DateMidnight withYearOfEra(int yearOfEra) { | |
| 947 |
1
1. withYearOfEra : mutated return of Object value for org/joda/time/DateMidnight::withYearOfEra to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().yearOfEra().set(getMillis(), yearOfEra)); |
| 948 | } | |
| 949 | ||
| 950 | /** | |
| 951 | * Returns a copy of this date with the year of century field updated. | |
| 952 | *
 | |
| 953 | * DateMidnight is immutable, so there are no set methods. | |
| 954 | * Instead, this method returns a new instance with the value of | |
| 955 | * year of century changed. | |
| 956 | * | |
| 957 | * @param yearOfCentury the year of century to set | |
| 958 | * @return a copy of this object with the field set | |
| 959 | * @throws IllegalArgumentException if the value is invalid | |
| 960 | * @since 1.3 | |
| 961 | */ | |
| 962 | public DateMidnight withYearOfCentury(int yearOfCentury) { | |
| 963 |
1
1. withYearOfCentury : mutated return of Object value for org/joda/time/DateMidnight::withYearOfCentury to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().yearOfCentury().set(getMillis(), yearOfCentury)); |
| 964 | } | |
| 965 | ||
| 966 | /** | |
| 967 | * Returns a copy of this date with the year field updated. | |
| 968 | *
 | |
| 969 | * DateMidnight is immutable, so there are no set methods. | |
| 970 | * Instead, this method returns a new instance with the value of | |
| 971 | * year changed. | |
| 972 | * | |
| 973 | * @param year the year to set | |
| 974 | * @return a copy of this object with the field set | |
| 975 | * @throws IllegalArgumentException if the value is invalid | |
| 976 | * @since 1.3 | |
| 977 | */ | |
| 978 | public DateMidnight withYear(int year) { | |
| 979 |
1
1. withYear : mutated return of Object value for org/joda/time/DateMidnight::withYear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().year().set(getMillis(), year)); |
| 980 | } | |
| 981 | ||
| 982 | /** | |
| 983 | * Returns a copy of this date with the weekyear field updated. | |
| 984 | *
 | |
| 985 | * The weekyear is the year that matches with the weekOfWeekyear field. | |
| 986 | * In the standard ISO8601 week algorithm, the first week of the year | |
| 987 | * is that in which at least 4 days are in the year. As a result of this | |
| 988 | * definition, day 1 of the first week may be in the previous year. | |
| 989 | * The weekyear allows you to query the effective year for that day. | |
| 990 | *
 | |
| 991 | * DateMidnight is immutable, so there are no set methods. | |
| 992 | * Instead, this method returns a new instance with the value of | |
| 993 | * weekyear changed. | |
| 994 | * | |
| 995 | * @param weekyear the weekyear to set | |
| 996 | * @return a copy of this object with the field set | |
| 997 | * @throws IllegalArgumentException if the value is invalid | |
| 998 | * @since 1.3 | |
| 999 | */ | |
| 1000 | public DateMidnight withWeekyear(int weekyear) { | |
| 1001 |
1
1. withWeekyear : mutated return of Object value for org/joda/time/DateMidnight::withWeekyear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().weekyear().set(getMillis(), weekyear)); |
| 1002 | } | |
| 1003 | ||
| 1004 | /** | |
| 1005 | * Returns a copy of this date with the month of year field updated. | |
| 1006 | *
 | |
| 1007 | * DateMidnight is immutable, so there are no set methods. | |
| 1008 | * Instead, this method returns a new instance with the value of | |
| 1009 | * month of year changed. | |
| 1010 | * | |
| 1011 | * @param monthOfYear the month of year to set | |
| 1012 | * @return a copy of this object with the field set | |
| 1013 | * @throws IllegalArgumentException if the value is invalid | |
| 1014 | * @since 1.3 | |
| 1015 | */ | |
| 1016 | public DateMidnight withMonthOfYear(int monthOfYear) { | |
| 1017 |
1
1. withMonthOfYear : mutated return of Object value for org/joda/time/DateMidnight::withMonthOfYear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear)); |
| 1018 | } | |
| 1019 | ||
| 1020 | /** | |
| 1021 | * Returns a copy of this date with the week of weekyear field updated. | |
| 1022 | *
 | |
| 1023 | * This field is associated with the "weekyear" via {@link #withWeekyear(int)}. | |
| 1024 | * In the standard ISO8601 week algorithm, the first week of the year | |
| 1025 | * is that in which at least 4 days are in the year. As a result of this | |
| 1026 | * definition, day 1 of the first week may be in the previous year. | |
| 1027 | *
 | |
| 1028 | * DateMidnight is immutable, so there are no set methods. | |
| 1029 | * Instead, this method returns a new instance with the value of | |
| 1030 | * week of weekyear changed. | |
| 1031 | * | |
| 1032 | * @param weekOfWeekyear the week of weekyear to set | |
| 1033 | * @return a copy of this object with the field set | |
| 1034 | * @throws IllegalArgumentException if the value is invalid | |
| 1035 | * @since 1.3 | |
| 1036 | */ | |
| 1037 | public DateMidnight withWeekOfWeekyear(int weekOfWeekyear) { | |
| 1038 |
1
1. withWeekOfWeekyear : mutated return of Object value for org/joda/time/DateMidnight::withWeekOfWeekyear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().weekOfWeekyear().set(getMillis(), weekOfWeekyear)); |
| 1039 | } | |
| 1040 | ||
| 1041 | /** | |
| 1042 | * Returns a copy of this date with the day of year field updated. | |
| 1043 | *
 | |
| 1044 | * DateMidnight is immutable, so there are no set methods. | |
| 1045 | * Instead, this method returns a new instance with the value of | |
| 1046 | * day of year changed. | |
| 1047 | * | |
| 1048 | * @param dayOfYear the day of year to set | |
| 1049 | * @return a copy of this object with the field set | |
| 1050 | * @throws IllegalArgumentException if the value is invalid | |
| 1051 | * @since 1.3 | |
| 1052 | */ | |
| 1053 | public DateMidnight withDayOfYear(int dayOfYear) { | |
| 1054 |
1
1. withDayOfYear : mutated return of Object value for org/joda/time/DateMidnight::withDayOfYear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().dayOfYear().set(getMillis(), dayOfYear)); |
| 1055 | } | |
| 1056 | ||
| 1057 | /** | |
| 1058 | * Returns a copy of this date with the day of month field updated. | |
| 1059 | *
 | |
| 1060 | * DateMidnight is immutable, so there are no set methods. | |
| 1061 | * Instead, this method returns a new instance with the value of | |
| 1062 | * day of month changed. | |
| 1063 | * | |
| 1064 | * @param dayOfMonth the day of month to set | |
| 1065 | * @return a copy of this object with the field set | |
| 1066 | * @throws IllegalArgumentException if the value is invalid | |
| 1067 | * @since 1.3 | |
| 1068 | */ | |
| 1069 | public DateMidnight withDayOfMonth(int dayOfMonth) { | |
| 1070 |
1
1. withDayOfMonth : mutated return of Object value for org/joda/time/DateMidnight::withDayOfMonth to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().dayOfMonth().set(getMillis(), dayOfMonth)); |
| 1071 | } | |
| 1072 | ||
| 1073 | /** | |
| 1074 | * Returns a copy of this date with the day of week field updated. | |
| 1075 | *
 | |
| 1076 | * DateMidnight is immutable, so there are no set methods. | |
| 1077 | * Instead, this method returns a new instance with the value of | |
| 1078 | * day of week changed. | |
| 1079 | * | |
| 1080 | * @param dayOfWeek the day of week to set | |
| 1081 | * @return a copy of this object with the field set | |
| 1082 | * @throws IllegalArgumentException if the value is invalid | |
| 1083 | * @since 1.3 | |
| 1084 | */ | |
| 1085 | public DateMidnight withDayOfWeek(int dayOfWeek) { | |
| 1086 |
1
1. withDayOfWeek : mutated return of Object value for org/joda/time/DateMidnight::withDayOfWeek to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return withMillis(getChronology().dayOfWeek().set(getMillis(), dayOfWeek)); |
| 1087 | } | |
| 1088 | ||
| 1089 | // Date properties | |
| 1090 | //----------------------------------------------------------------------- | |
| 1091 | /** | |
| 1092 | * Get the era property which provides access to advanced functionality. | |
| 1093 | * | |
| 1094 | * @return the era property | |
| 1095 | */ | |
| 1096 | public Property era() { | |
| 1097 |
1
1. era : mutated return of Object value for org/joda/time/DateMidnight::era to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().era()); |
| 1098 | } | |
| 1099 | ||
| 1100 | /** | |
| 1101 | * Get the century of era property which provides access to advanced functionality. | |
| 1102 | * | |
| 1103 | * @return the year of era property | |
| 1104 | */ | |
| 1105 | public Property centuryOfEra() { | |
| 1106 |
1
1. centuryOfEra : mutated return of Object value for org/joda/time/DateMidnight::centuryOfEra to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().centuryOfEra()); |
| 1107 | } | |
| 1108 | ||
| 1109 | /** | |
| 1110 | * Get the year of century property which provides access to advanced functionality. | |
| 1111 | * | |
| 1112 | * @return the year of era property | |
| 1113 | */ | |
| 1114 | public Property yearOfCentury() { | |
| 1115 |
1
1. yearOfCentury : mutated return of Object value for org/joda/time/DateMidnight::yearOfCentury to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().yearOfCentury()); |
| 1116 | } | |
| 1117 | ||
| 1118 | /** | |
| 1119 | * Get the year of era property which provides access to advanced functionality. | |
| 1120 | * | |
| 1121 | * @return the year of era property | |
| 1122 | */ | |
| 1123 | public Property yearOfEra() { | |
| 1124 |
1
1. yearOfEra : mutated return of Object value for org/joda/time/DateMidnight::yearOfEra to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().yearOfEra()); |
| 1125 | } | |
| 1126 | ||
| 1127 | /** | |
| 1128 | * Get the year property which provides access to advanced functionality. | |
| 1129 | * | |
| 1130 | * @return the year property | |
| 1131 | */ | |
| 1132 | public Property year() { | |
| 1133 |
1
1. year : mutated return of Object value for org/joda/time/DateMidnight::year to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new Property(this, getChronology().year()); |
| 1134 | } | |
| 1135 | ||
| 1136 | /** | |
| 1137 | * Get the year of a week based year property which provides access to advanced functionality. | |
| 1138 | * | |
| 1139 | * @return the year of a week based year property | |
| 1140 | */ | |
| 1141 | public Property weekyear() { | |
| 1142 |
1
1. weekyear : mutated return of Object value for org/joda/time/DateMidnight::weekyear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().weekyear()); |
| 1143 | } | |
| 1144 | ||
| 1145 | /** | |
| 1146 | * Get the month of year property which provides access to advanced functionality. | |
| 1147 | * | |
| 1148 | * @return the month of year property | |
| 1149 | */ | |
| 1150 | public Property monthOfYear() { | |
| 1151 |
1
1. monthOfYear : mutated return of Object value for org/joda/time/DateMidnight::monthOfYear to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new Property(this, getChronology().monthOfYear()); |
| 1152 | } | |
| 1153 | ||
| 1154 | /** | |
| 1155 | * Get the week of a week based year property which provides access to advanced functionality. | |
| 1156 | * | |
| 1157 | * @return the week of a week based year property | |
| 1158 | */ | |
| 1159 | public Property weekOfWeekyear() { | |
| 1160 |
1
1. weekOfWeekyear : mutated return of Object value for org/joda/time/DateMidnight::weekOfWeekyear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().weekOfWeekyear()); |
| 1161 | } | |
| 1162 | ||
| 1163 | /** | |
| 1164 | * Get the day of year property which provides access to advanced functionality. | |
| 1165 | * | |
| 1166 | * @return the day of year property | |
| 1167 | */ | |
| 1168 | public Property dayOfYear() { | |
| 1169 |
1
1. dayOfYear : mutated return of Object value for org/joda/time/DateMidnight::dayOfYear to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().dayOfYear()); |
| 1170 | } | |
| 1171 | ||
| 1172 | /** | |
| 1173 | * Get the day of month property which provides access to advanced functionality. | |
| 1174 | * | |
| 1175 | * @return the day of month property | |
| 1176 | */ | |
| 1177 | public Property dayOfMonth() { | |
| 1178 |
1
1. dayOfMonth : mutated return of Object value for org/joda/time/DateMidnight::dayOfMonth to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new Property(this, getChronology().dayOfMonth()); |
| 1179 | } | |
| 1180 | ||
| 1181 | /** | |
| 1182 | * Get the day of week property which provides access to advanced functionality. | |
| 1183 | * | |
| 1184 | * @return the day of week property | |
| 1185 | */ | |
| 1186 | public Property dayOfWeek() { | |
| 1187 |
1
1. dayOfWeek : mutated return of Object value for org/joda/time/DateMidnight::dayOfWeek to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Property(this, getChronology().dayOfWeek()); |
| 1188 | } | |
| 1189 | ||
| 1190 | //----------------------------------------------------------------------- | |
| 1191 | /** | |
| 1192 | * DateMidnight.Property binds a DateMidnight to a DateTimeField allowing powerful | |
| 1193 | * datetime functionality to be easily accessed. | |
| 1194 | *
 | |
| 1195 | * The simplest use of this class is as an alternative get method, here used to | |
| 1196 | * get the year '1972' (as an int) and the month 'December' (as a String). | |
| 1197 | *
 | |
| 1198 | * DateMidnight dt = new DateMidnight(1972, 12, 3); | |
| 1199 | * int year = dt.year().get(); | |
| 1200 | * String monthStr = dt.monthOfYear().getAsText(); | |
| 1201 | *
 | |
| 1202 | *
 | |
| 1203 | * Methods are also provided that allow date modification. These return new instances | |
| 1204 | * of DateMidnight - they do not modify the original. The example below yields two | |
| 1205 | * independent immutable date objects 20 years apart. | |
| 1206 | *
 | |
| 1207 | * DateMidnight dt = new DateMidnight(1972, 12, 3); | |
| 1208 | * DateMidnight dt20 = dt.year().addToCopy(20); | |
| 1209 | *
 | |
| 1210 | * Serious modification of dates (ie. more than just changing one or two fields) | |
| 1211 | * should use the {@link org.joda.time.MutableDateTime MutableDateTime} class. | |
| 1212 | *
 | |
| 1213 | * DateMidnight.Property itself is thread-safe and immutable. | |
| 1214 | * | |
| 1215 | * @author Stephen Colebourne | |
| 1216 | * @author Brian S O'Neill | |
| 1217 | * @since 1.0 | |
| 1218 | */ | |
| 1219 | public static final class Property extends AbstractReadableInstantFieldProperty { | |
| 1220 | | |
| 1221 | /** Serialization lock */ | |
| 1222 | private static final long serialVersionUID = 257629620L; | |
| 1223 | | |
| 1224 | /** The instant this property is working against */ | |
| 1225 | private DateMidnight iInstant; | |
| 1226 | /** The field this property is working against */ | |
| 1227 | private DateTimeField iField; | |
| 1228 | | |
| 1229 | /** | |
| 1230 | * Constructor. | |
| 1231 | * | |
| 1232 | * @param instant the instant to set | |
| 1233 | * @param field the field to use | |
| 1234 | */ | |
| 1235 | Property(DateMidnight instant, DateTimeField field) { | |
| 1236 | super(); | |
| 1237 | iInstant = instant; | |
| 1238 | iField = field; | |
| 1239 | } | |
| 1240 | ||
| 1241 | /** | |
| 1242 | * Writes the property in a safe serialization format. | |
| 1243 | */ | |
| 1244 | private void writeObject(ObjectOutputStream oos) throws IOException { | |
| 1245 |
1
1. writeObject : removed call to java/io/ObjectOutputStream::writeObject → NO_COVERAGE |
oos.writeObject(iInstant); |
| 1246 |
1
1. writeObject : removed call to java/io/ObjectOutputStream::writeObject → NO_COVERAGE |
oos.writeObject(iField.getType()); |
| 1247 | } | |
| 1248 | ||
| 1249 | /** | |
| 1250 | * Reads the property from a safe serialization format. | |
| 1251 | */ | |
| 1252 | private void readObject(ObjectInputStream oos) throws IOException, ClassNotFoundException { | |
| 1253 | iInstant = (DateMidnight) oos.readObject(); | |
| 1254 | DateTimeFieldType type = (DateTimeFieldType) oos.readObject(); | |
| 1255 | iField = type.getField(iInstant.getChronology()); | |
| 1256 | } | |
| 1257 | ||
| 1258 | //----------------------------------------------------------------------- | |
| 1259 | /** | |
| 1260 | * Gets the field being used. | |
| 1261 | * | |
| 1262 | * @return the field | |
| 1263 | */ | |
| 1264 | public DateTimeField getField() { | |
| 1265 |
1
1. getField : mutated return of Object value for org/joda/time/DateMidnight$Property::getField to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return iField; |
| 1266 | } | |
| 1267 | ||
| 1268 | /** | |
| 1269 | * Gets the milliseconds of the datetime that this property is linked to. | |
| 1270 | * | |
| 1271 | * @return the milliseconds | |
| 1272 | */ | |
| 1273 | protected long getMillis() { | |
| 1274 |
1
1. getMillis : replaced return of long value with value + 1 for org/joda/time/DateMidnight$Property::getMillis → SURVIVED |
return iInstant.getMillis(); |
| 1275 | } | |
| 1276 | ||
| 1277 | /** | |
| 1278 | * Gets the chronology of the datetime that this property is linked to. | |
| 1279 | * | |
| 1280 | * @return the chronology | |
| 1281 | * @since 1.4 | |
| 1282 | */ | |
| 1283 | protected Chronology getChronology() { | |
| 1284 |
1
1. getChronology : mutated return of Object value for org/joda/time/DateMidnight$Property::getChronology to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.getChronology(); |
| 1285 | } | |
| 1286 | ||
| 1287 | /** | |
| 1288 | * Gets the datetime being used. | |
| 1289 | * | |
| 1290 | * @return the datetime | |
| 1291 | */ | |
| 1292 | public DateMidnight getDateMidnight() { | |
| 1293 |
1
1. getDateMidnight : mutated return of Object value for org/joda/time/DateMidnight$Property::getDateMidnight to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant; |
| 1294 | } | |
| 1295 | ||
| 1296 | //----------------------------------------------------------------------- | |
| 1297 | /** | |
| 1298 | * Adds to this field in a copy of this DateMidnight. | |
| 1299 | *
 | |
| 1300 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1301 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1302 | * and back again when setting one field. When setting multiple fields, | |
| 1303 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1304 | * | |
| 1305 | * @param value the value to add to the field in the copy | |
| 1306 | * @return a copy of the DateMidnight with the field value changed | |
| 1307 | * @throws IllegalArgumentException if the value isn't valid | |
| 1308 | */ | |
| 1309 | public DateMidnight addToCopy(int value) { | |
| 1310 |
1
1. addToCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::addToCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.add(iInstant.getMillis(), value)); |
| 1311 | } | |
| 1312 | ||
| 1313 | /** | |
| 1314 | * Adds to this field in a copy of this DateMidnight. | |
| 1315 | *
 | |
| 1316 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1317 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1318 | * and back again when setting one field. When setting multiple fields, | |
| 1319 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1320 | * | |
| 1321 | * @param value the value to add to the field in the copy | |
| 1322 | * @return a copy of the DateMidnight with the field value changed | |
| 1323 | * @throws IllegalArgumentException if the value isn't valid | |
| 1324 | */ | |
| 1325 | public DateMidnight addToCopy(long value) { | |
| 1326 |
1
1. addToCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::addToCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.add(iInstant.getMillis(), value)); |
| 1327 | } | |
| 1328 | ||
| 1329 | /** | |
| 1330 | * Adds to this field, possibly wrapped, in a copy of this DateMidnight. | |
| 1331 | * A wrapped operation only changes this field. | |
| 1332 | * Thus 31st January addWrapField one day goes to the 1st January. | |
| 1333 | *
 | |
| 1334 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1335 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1336 | * and back again when setting one field. When setting multiple fields, | |
| 1337 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1338 | * | |
| 1339 | * @param value the value to add to the field in the copy | |
| 1340 | * @return a copy of the DateMidnight with the field value changed | |
| 1341 | * @throws IllegalArgumentException if the value isn't valid | |
| 1342 | */ | |
| 1343 | public DateMidnight addWrapFieldToCopy(int value) { | |
| 1344 |
1
1. addWrapFieldToCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::addWrapFieldToCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.addWrapField(iInstant.getMillis(), value)); |
| 1345 | } | |
| 1346 | ||
| 1347 | //----------------------------------------------------------------------- | |
| 1348 | /** | |
| 1349 | * Sets this field in a copy of the DateMidnight. | |
| 1350 | *
 | |
| 1351 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1352 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1353 | * and back again when setting one field. When setting multiple fields, | |
| 1354 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1355 | * | |
| 1356 | * @param value the value to set the field in the copy to | |
| 1357 | * @return a copy of the DateMidnight with the field value changed | |
| 1358 | * @throws IllegalArgumentException if the value isn't valid | |
| 1359 | */ | |
| 1360 | public DateMidnight setCopy(int value) { | |
| 1361 |
1
1. setCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::setCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.set(iInstant.getMillis(), value)); |
| 1362 | } | |
| 1363 | | |
| 1364 | /** | |
| 1365 | * Sets this field in a copy of the DateMidnight to a parsed text value. | |
| 1366 | *
 | |
| 1367 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1368 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1369 | * and back again when setting one field. When setting multiple fields, | |
| 1370 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1371 | * | |
| 1372 | * @param text the text value to set | |
| 1373 | * @param locale optional locale to use for selecting a text symbol | |
| 1374 | * @return a copy of the DateMidnight with the field value changed | |
| 1375 | * @throws IllegalArgumentException if the text value isn't valid | |
| 1376 | */ | |
| 1377 | public DateMidnight setCopy(String text, Locale locale) { | |
| 1378 |
1
1. setCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::setCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.set(iInstant.getMillis(), text, locale)); |
| 1379 | } | |
| 1380 | ||
| 1381 | /** | |
| 1382 | * Sets this field in a copy of the DateMidnight to a parsed text value. | |
| 1383 | *
 | |
| 1384 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1385 | * This operation is faster than converting a DateMidnight to a MutableDateTime | |
| 1386 | * and back again when setting one field. When setting multiple fields, | |
| 1387 | * it is generally quicker to make the conversion to MutableDateTime. | |
| 1388 | * | |
| 1389 | * @param text the text value to set | |
| 1390 | * @return a copy of the DateMidnight with the field value changed | |
| 1391 | * @throws IllegalArgumentException if the text value isn't valid | |
| 1392 | */ | |
| 1393 | public DateMidnight setCopy(String text) { | |
| 1394 |
1
1. setCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::setCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setCopy(text, null); |
| 1395 | } | |
| 1396 | ||
| 1397 | //----------------------------------------------------------------------- | |
| 1398 | /** | |
| 1399 | * Returns a new DateMidnight with this field set to the maximum value | |
| 1400 | * for this field. | |
| 1401 | *
 | |
| 1402 | * This operation is useful for obtaining a DateTime on the last day | |
| 1403 | * of the month, as month lengths vary. | |
| 1404 | *
 | |
| 1405 | * DateMidnight lastDayOfMonth = dt.dayOfMonth().withMaximumValue(); | |
| 1406 | *
 | |
| 1407 | *
 | |
| 1408 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1409 | * | |
| 1410 | * @return a copy of the DateMidnight with this field set to its maximum | |
| 1411 | * @since 1.2 | |
| 1412 | */ | |
| 1413 | public DateMidnight withMaximumValue() { | |
| 1414 |
1
1. withMaximumValue : mutated return of Object value for org/joda/time/DateMidnight$Property::withMaximumValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setCopy(getMaximumValue()); |
| 1415 | } | |
| 1416 | | |
| 1417 | /** | |
| 1418 | * Returns a new DateMidnight with this field set to the minimum value | |
| 1419 | * for this field. | |
| 1420 | *
 | |
| 1421 | * The DateMidnight attached to this property is unchanged by this call. | |
| 1422 | * | |
| 1423 | * @return a copy of the DateMidnight with this field set to its minimum | |
| 1424 | * @since 1.2 | |
| 1425 | */ | |
| 1426 | public DateMidnight withMinimumValue() { | |
| 1427 |
1
1. withMinimumValue : mutated return of Object value for org/joda/time/DateMidnight$Property::withMinimumValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setCopy(getMinimumValue()); |
| 1428 | } | |
| 1429 | | |
| 1430 | //----------------------------------------------------------------------- | |
| 1431 | /** | |
| 1432 | * Rounds to the lowest whole unit of this field on a copy of this DateMidnight. | |
| 1433 | * | |
| 1434 | * @return a copy of the DateMidnight with the field value changed | |
| 1435 | */ | |
| 1436 | public DateMidnight roundFloorCopy() { | |
| 1437 |
1
1. roundFloorCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::roundFloorCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); |
| 1438 | } | |
| 1439 | ||
| 1440 | /** | |
| 1441 | * Rounds to the highest whole unit of this field on a copy of this DateMidnight. | |
| 1442 | * | |
| 1443 | * @return a copy of the DateMidnight with the field value changed | |
| 1444 | */ | |
| 1445 | public DateMidnight roundCeilingCopy() { | |
| 1446 |
1
1. roundCeilingCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::roundCeilingCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.roundCeiling(iInstant.getMillis())); |
| 1447 | } | |
| 1448 | ||
| 1449 | /** | |
| 1450 | * Rounds to the nearest whole unit of this field on a copy of this DateMidnight, | |
| 1451 | * favoring the floor if halfway. | |
| 1452 | * | |
| 1453 | * @return a copy of the DateMidnight with the field value changed | |
| 1454 | */ | |
| 1455 | public DateMidnight roundHalfFloorCopy() { | |
| 1456 |
1
1. roundHalfFloorCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::roundHalfFloorCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.roundHalfFloor(iInstant.getMillis())); |
| 1457 | } | |
| 1458 | ||
| 1459 | /** | |
| 1460 | * Rounds to the nearest whole unit of this field on a copy of this DateMidnight, | |
| 1461 | * favoring the ceiling if halfway. | |
| 1462 | * | |
| 1463 | * @return a copy of the DateMidnight with the field value changed | |
| 1464 | */ | |
| 1465 | public DateMidnight roundHalfCeilingCopy() { | |
| 1466 |
1
1. roundHalfCeilingCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::roundHalfCeilingCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.roundHalfCeiling(iInstant.getMillis())); |
| 1467 | } | |
| 1468 | ||
| 1469 | /** | |
| 1470 | * Rounds to the nearest whole unit of this field on a copy of this DateMidnight. | |
| 1471 | * If halfway, the ceiling is favored over the floor only if it makes this field's value even. | |
| 1472 | * | |
| 1473 | * @return a copy of the DateMidnight with the field value changed | |
| 1474 | */ | |
| 1475 | public DateMidnight roundHalfEvenCopy() { | |
| 1476 |
1
1. roundHalfEvenCopy : mutated return of Object value for org/joda/time/DateMidnight$Property::roundHalfEvenCopy to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return iInstant.withMillis(iField.roundHalfEven(iInstant.getMillis())); |
| 1477 | } | |
| 1478 | ||
| 1479 | } | |
| 1480 | } | |
Mutations | ||
| 95 |
1.1 |
|
| 108 |
1.1 |
|
| 111 |
1.1 |
|
| 124 |
1.1 |
|
| 127 |
1.1 |
|
| 141 |
1.1 |
|
| 152 |
1.1 |
|
| 361 |
1.1 |
|
| 378 |
1.1 2.2 |
|
| 403 |
1.1 2.2 |
|
| 417 |
1.1 |
|
| 418 |
1.1 |
|
| 422 |
1.1 |
|
| 439 |
1.1 |
|
| 440 |
1.1 |
|
| 442 |
1.1 |
|
| 465 |
1.1 |
|
| 469 |
1.1 |
|
| 491 |
1.1 |
|
| 494 |
1.1 |
|
| 495 |
1.1 |
|
| 498 |
1.1 |
|
| 513 |
1.1 2.2 |
|
| 514 |
1.1 |
|
| 517 |
1.1 |
|
| 531 |
1.1 2.2 |
|
| 532 |
1.1 |
|
| 534 |
1.1 |
|
| 553 |
1.1 2.2 |
|
| 554 |
1.1 |
|
| 557 |
1.1 |
|
| 571 |
1.1 |
|
| 584 |
1.1 |
|
| 601 |
1.1 |
|
| 622 |
1.1 |
|
| 623 |
1.1 |
|
| 626 |
1.1 |
|
| 646 |
1.1 |
|
| 647 |
1.1 |
|
| 650 |
1.1 |
|
| 670 |
1.1 |
|
| 671 |
1.1 |
|
| 674 |
1.1 |
|
| 694 |
1.1 |
|
| 695 |
1.1 |
|
| 698 |
1.1 |
|
| 712 |
1.1 |
|
| 725 |
1.1 |
|
| 742 |
1.1 |
|
| 763 |
1.1 |
|
| 764 |
1.1 |
|
| 767 |
1.1 |
|
| 787 |
1.1 |
|
| 788 |
1.1 |
|
| 791 |
1.1 |
|
| 811 |
1.1 |
|
| 812 |
1.1 |
|
| 815 |
1.1 |
|
| 835 |
1.1 |
|
| 836 |
1.1 |
|
| 839 |
1.1 |
|
| 851 |
1.1 |
|
| 855 |
1.1 |
|
| 858 |
1.1 |
|
| 871 |
1.1 |
|
| 882 |
1.1 |
|
| 898 |
1.1 |
|
| 915 |
1.1 |
|
| 931 |
1.1 |
|
| 947 |
1.1 |
|
| 963 |
1.1 |
|
| 979 |
1.1 |
|
| 1001 |
1.1 |
|
| 1017 |
1.1 |
|
| 1038 |
1.1 |
|
| 1054 |
1.1 |
|
| 1070 |
1.1 |
|
| 1086 |
1.1 |
|
| 1097 |
1.1 |
|
| 1106 |
1.1 |
|
| 1115 |
1.1 |
|
| 1124 |
1.1 |
|
| 1133 |
1.1 |
|
| 1142 |
1.1 |
|
| 1151 |
1.1 |
|
| 1160 |
1.1 |
|
| 1169 |
1.1 |
|
| 1178 |
1.1 |
|
| 1187 |
1.1 |
|
| 1245 |
1.1 |
|
| 1246 |
1.1 |
|
| 1265 |
1.1 |
|
| 1274 |
1.1 |
|
| 1284 |
1.1 |
|
| 1293 |
1.1 |
|
| 1310 |
1.1 |
|
| 1326 |
1.1 |
|
| 1344 |
1.1 |
|
| 1361 |
1.1 |
|
| 1378 |
1.1 |
|
| 1394 |
1.1 |
|
| 1414 |
1.1 |
|
| 1427 |
1.1 |
|
| 1437 |
1.1 |
|
| 1446 |
1.1 |
|
| 1456 |
1.1 |
|
| 1466 |
1.1 |
|
| 1476 |
1.1 |


Running multiple workers serially/parallelly. (source code)
💡 Open the developer console to see the results.


Coursera : Provides universal access to the world's best education online.
The Sound of Your Heart : South of Korea's longest-running cartoon series, #1 funniest I've ever seen.
boredpanda : A creative community sharing hilariously stories.


Wheel Adjustment
We are always help to make one of the best adjustment service.
We have the best service for you to make and this is one of the best service.
Read MoreWe have the best service for you to make and this is one of the best service.
Read MoreWe have the best service for you to make and this is one of the best service.
Read MoreWe have a lots of plan to make a good and best & one of the most modern car for you. We have a good experience and a good image on the global sector.
We have a good expert in the global market and this will help us to make a good image on our service market and globally.
We are always help to make one of the best adjustment service.
We are always help to make one of the best adjustment service.
We are always help to make one of the best adjustment service.
We are always help to make one of the best adjustment service.
We are always help to make one of the best adjustment service.
We are always help to make one of the best adjustment service.
We have a good expert in the global market and this will help us to make a good image on our service market and globally.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et amet bibendum ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae pellentesque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipiscing.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua consectetur adipiscing.
We have more than one year work blog and we have a fantastic blog on the global market. This is really helpful for the end user.


Bilgewater introduced several new elements, including the ability to purchase mercenary minion upgrades. Each champion gets to purchase one type of mercenary of the four types available. If we assume that order doesn't matter [1] then there are 70 possible combinations of mercenaries that a team could get [2].
Which of these combinations were successful and which were not? Were some 'counters' to other combinations? Was there any correlation at all, or were the minions not impactful to the game outcome?
Fetch Data
I'm not sure if the order of purchase is reflected in which minion is replaced - therefore changing potentially the marching orders, and possibly making a small difference between groups that otherwise have the same composition
This is combination with repetition, since players could all choose the same merc if they wanted. From 5 players (n) choosing from 4 items (k) is the same as 8 choose 4, or 8!/(4!4!), or 8*6*5 / 4*3*2, or 70.


Pretty impressing so far right?
As you are already guessing - there is even more magic in the API hat.
Applause for our last guest for today, the
Faces API
It's about faces, but this time in a veeeery sophisticated way. We can detect the features of the face with their very coordinates in the picture. Furthermore we can say what age and gender a person is. And even if the person is wearing glasses or a beard. Wow!


|
LOC
0.2
Count lines of code
|
Class responsible for holding statistics for a language. More...
#include <languageStatistics.hh>
Public Member Functions | |
| languageStatistics (languageType lType, statistics &s) | |
| Class constructor. More... | |
| languageStatistics (const languageStatistics &ls) | |
| Class constructor. More... | |
| ~languageStatistics (void) | |
| Class destructor. | |
| statistics & | getStatistics (void) |
| Get a reference to a statistics. More... | |
| std::size_t | getNumberLanguages (void) |
| Obtain the number of files that contain statistics for this language. More... | |
| languageType | getType (void) |
| Obtain the number of files that contain statistics for this language. More... | |
| void | addStatistics (statistics &s) |
| Add statistics to the current language. | |
| bool | operator== (languageType key) |
| Compare the language type, i.e. the language ID. More... | |
Class responsible for holding statistics for a language.
|
inline |
Class constructor.
| [in] | lType | - A language type |
| [in] | s | - A language statistic instance |
|
inline |
Class constructor.
| [in] | ls | - A language statistic instance |
|
inline |
Obtain the number of files that contain statistics for this language.
|
inline |
Get a reference to a statistics.
|
inline |
Obtain the number of files that contain statistics for this language.
|
inline |
Compare the language type, i.e. the language ID.


Sisense Embedding
Dashboard
Export
Advanced Mode
Sizing Mode
Edit Mode
Filters
From
From
To
To
Country
Country
Save changes
Apply
Clear


CNIT 133
JavaScript
Home
Basic Ops
Functions
Loops
Arrays
Objects
jQuery
Ajax
Homework 8 Part 4
State Code:
Name:
Capital:
Population:


Melodies: Create Climaxes with Intervalic Tension
August 31, 2018 | Nick Mazuk
You’ve probably heard about certain intervals being more dissonant when those two notes are played.
But have you ever thought about using that dissonance to your advantage? Especially in the context of a melody?
Believe it or note, using dissonant or hard to sing intervals in a melody can actually make your melody more memorable and more singable!
Specifically, these intervals create tension that is waiting for some release.
And when you use this tension in your melodies, magic can happen!
So today I’m going to show you how to unlock this magic to make your melodies sparkle.
The Secret Behind Large Intervals
To understand how large intervals can work in the context of a melody, let’s look at the best singing intervals.
Here are some of the rules for a singable melody.
- Mostly stepwise motion
- Leaps of 4th or larger followed by a step in the opposite direction
- Permitted intervals: 2nd, 3rd, P4, P5, octave, ascending m6 (no 7ths)
- Two leaps in the same direction cannot outline a tritone or 7th
- If there are two leaps in the same direction, the second has to be smaller. Then you need to go stepwise in the opposite direction
These rules date back to the Renaissance. However, it’s not then, so you can break these rules in instrumental writing.
In fact, to create intervallic tension, you need to break these rules.
And notice this, large intervals like the M6, 7th, 9th, 10th, etc. are not allowed with these rules. And if these rules are about creating singable melodies, then adding large intervals creates tension because it’s hard to sing.
If you read the post on climaxes in melody, you will remember me using Binary Sunset as the example there. Here it is again. This time, though, as an exercise, try finding all the places in which John Williams breaks these rules. Then, try to find all the places he abides by them. Finally, ask yourself why is this melody so effective? And why does he break the rules when he does?
How many times does John Williams break one of the above rules in this melody?
The Notes Matter Just Like The Intervals
However, adding larger intervals isn’t the only way to create tension through intervals. There are other methods you can use which we’ll uncover.
Firstly, the placement of the interval matter as well. For instance, the P5 is a consonant interval and is somewhat large. And using it between 1̂ and 5̂ releases lots of tension.
However, what happens if you go from 3̂ to 7̂ (7̂ being the leading tone and having tension in and of itself)?
That’s exactly what Brahms does in his Cradle Song, a melody which you’ve probably heard dozens of times.
There are two things going on. First is that he used the interval to a note full of tension (7̂). Second he used increasingly larger intervals until the climactic interval.
But when you don’t simply want a larger interval, ask yourself if you can place the interval somewhere that would be more tense.
Using Dissonant Intervals
Another way to create tension through intervals is to have dissonant intervals. What would these intervals look like? Here’s some examples.
- A4/d5 (tritone)
- m7 and M7
- m9
- Any augmented or diminished interval
Usually, these intervals will require accidentals when in a diatonic scale (not between 4̂ and 7̂).
Because dissonance is tension, you can use these dissonant intervals to create tension for a release. Simply place this interval at the climax and you can create a convincing climax.
Combining Dissonant Intervals with Unexpected Notes For More Power
One powerful way to create a climax with a dissonant interval is to combine it with an unexpected note climax. It’s a two for one. Two climaxes for a single note!
Furthermore, the example I wrote for the unexpected note climax melody actually is also an example of a dissonant interval climax. Go check it out to see it how to combine both.
In the meantime, download the free worksheet below to get practice writing intervallic climaxes. It will give you practice opportunities with each of the ways to create a climax through an interval. If you are already a subscriber, the worksheet is in your inbox.
Happy writing!


A key tension when choosing an infrastructure concerns how to manage product performance with issues of extensibility (ie, confidence in future usability of a language or tool) and ongoing maintenance. Part of this tension is that infrastructure management is a dynamic effort. For example, distributed (and/or NoSQL) systems, but they only become pertinent as a company’s user base moves into the millions (or tens of millions). This is the point at which the organization might run into database issues around contention with the write master, which basically means you’re sending too much write traffic to one server.
Part of the tension is rooted in experience: large companies, some of whom may have little experience with managing a digital-scale infrastructure, are being asked to adopt these evolving technologies that require a very specific skillset. On top of this, a common adage is that the best operators won’t use a component until they know how it breaks. So, how might one generate this experience?
To start, I’ve pulled together a few primers on more commonly used NoSQL databases to give a sense of:
- When they are used (use cases), and
- Common considerations / limitations / challenges
Let’s begin with MongoDB, a popular document-oriented database. It is used by organizations of all sizes to power mission-critical, operational applications where low latency, high throughput and continuous availability are critical requirements of the system—you think about using MongoDB when you need fast use cases that can’t fail.
##MongoDB: A Background
MongoDB provides horizontal scale-out for databases using a technique called sharding, which is transparent to applications. MongoDB distributes data across multiple Replica Sets called shards. Sharding is basically when datasets are split amongst multiple servers (e.g., by name: A-G in Server 1, H-R in Server 2, and S-Z in Server 3, or by geography: I am in the West Coast Server and my parents are in the East Coast Server).
With automatic balancing, MongoDB ensures data is equally distributed across shards as data volumes grow or the size of the cluster increases or decreases. Sharding allows MongoDB deployments to scale beyond the limitations of a single server, such as bottlenecks in RAM or disk I/O, without adding complexity to the application. MongoDB supports three types of sharding policy, enabling administrators to accommodate diverse query patterns:
- Range-based sharding: Documents are partitioned across shards according to the shard key value.
- Hash-based sharding: Documents are uniformly distributed according to an MD5 hash of the shard key value.
- Location-aware sharding: The data set needs to be assigned to a specific data center to support low latency local reads and writes.
##Common Considerations with MongoDB
- The obstacles to scaling performance as your usage grows may not be what you’d expect. Performance bottlenecks usually are (in this order):
- Sub-optimal schema design for application access patterns
- Poor or missing indexes, occasionally too many unneeded indexes
- Slow disks/insufficient disk IOPS for workload, especially to the write throughput
- Insufficient RAM for indexes, will cause a lot of page faulting
- Replica set health is more than replication lag. “Replication lag,” which is a measure of how far a secondary is behind the primary, is just one indicator of the health of your replica sets. Just as important as monitoring replication lag is keeping an eye on your replication oplog window.
- Place your database server at the inner data storage layer. If public network exposure is combined with lack of access control, the entire content of the database is up for grabs for anyone who cares to look. In addition, an attacker could intentionally or accidentally change the database configuration, modify the application behavior or perform a Denial of Service (DoS) attack. It is surprisingly common to deploy MongoDB database servers directly online or in a DMZ.
- MongoDB’s map-reduce functionality just isn’t meant for real time computing. It is extremely slow, especially when you have a large amount of data in a sharded environment. Especially in a sharded mongoDB setup the I/O load increases rapidly with growing data, so fast disks are even more important than computing power or even memory for scaling your mongoDB servers.
- The debugging experience is very painful. There is no proper debugger, no console.log. The best tool you have is conditionally throwing, because the only thing you can get back from a MapReduce operation is the final data or the first uncaught error (which stops the operation). That’s annoying when your map or reduce or finalize function gets above 30 lines.
- The user will need to start with an intuition of chunks and sharding protocol. MongoDBs documents are stored in so called chunks. For each chunk the maximum and minimum shardKey as well as the location (on which shard it is stored) and its size are known. Now when another document is inserted it will be stored within the chunk with the fitting id (shardKey) range. Then a few things happen:
- If you are lucky and the shards are balanced already, and the document doesn’t increase the chunks size over a given limit, thats just it, the document is inserted and you are fine.
- If the document exceeds the chunks size limit, the chunk will be split into two different chunks.
- And if the shards are unbalanced, on top of that the new chunk will be moved to another shard. The split is a rather inexpensive operation, but moving the data to a different shard can be very expensive.
Hopefully this record helps clarify some situations in which MongoDB might be useful, and some associated maintenance considerations. Many thanks to these articles as the primary references when putting this together:
- 10 Things You Should Know About Running MongoDB at Scale (High Scalability)
- MongoDB Security Part II: 10 mistakes that can compromise your database (MongoDB blog)
- MongoDB – the pitfalls and how to avoid them (Mayflower)
- Read before considering using MongoDB for your next app (Long Term Laziness)