1 /* 2 * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * * Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * * Neither the name of JSR-310 nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.threeten.bp.temporal; 33 34 import static org.threeten.bp.temporal.ChronoUnit.MONTHS; 35 import static org.threeten.bp.temporal.ChronoUnit.WEEKS; 36 37 import java.util.Locale; 38 import java.util.Map; 39 40 import org.threeten.bp.DateTimeException; 41 import org.threeten.bp.format.ResolverStyle; 42 43 /** 44 * Mock DateTimeField that returns null. 45 */ 46 public enum MockFieldNoValue implements TemporalField { 47 48 INSTANCE; 49 50 @Override toString()51 public String toString() { 52 return null; 53 } 54 55 @Override getBaseUnit()56 public TemporalUnit getBaseUnit() { 57 return WEEKS; 58 } 59 60 @Override getRangeUnit()61 public TemporalUnit getRangeUnit() { 62 return MONTHS; 63 } 64 65 @Override range()66 public ValueRange range() { 67 return ValueRange.of(1, 20); 68 } 69 70 //----------------------------------------------------------------------- 71 @Override isDateBased()72 public boolean isDateBased() { 73 return true; 74 } 75 76 @Override isTimeBased()77 public boolean isTimeBased() { 78 return false; 79 } 80 81 @Override isSupportedBy(TemporalAccessor dateTime)82 public boolean isSupportedBy(TemporalAccessor dateTime) { 83 return true; 84 } 85 86 @Override rangeRefinedBy(TemporalAccessor dateTime)87 public ValueRange rangeRefinedBy(TemporalAccessor dateTime) { 88 return ValueRange.of(1, 20); 89 } 90 91 @Override getFrom(TemporalAccessor dateTime)92 public long getFrom(TemporalAccessor dateTime) { 93 throw new DateTimeException("Mock"); 94 } 95 96 @Override adjustInto(R dateTime, long newValue)97 public <R extends Temporal> R adjustInto(R dateTime, long newValue) { 98 throw new DateTimeException("Mock"); 99 } 100 101 @Override getDisplayName(Locale locale)102 public String getDisplayName(Locale locale) { 103 return "Mock"; 104 } 105 106 //----------------------------------------------------------------------- 107 @Override resolve(Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle)108 public TemporalAccessor resolve(Map<TemporalField, Long> fieldValues, 109 TemporalAccessor partialTemporal, ResolverStyle resolverStyle) { 110 return null; 111 } 112 113 } 114