001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *
010     *        http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License.
018     */
019    
020    package org.apache.isis.core.progmodel.facets.value.date;
021    
022    import java.util.Date;
023    
024    import org.apache.isis.applib.adapters.EncoderDecoder;
025    import org.apache.isis.applib.adapters.Parser;
026    import org.apache.isis.core.commons.config.IsisConfiguration;
027    import org.apache.isis.core.metamodel.facetapi.FacetHolder;
028    import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
029    
030    public class DateValueSemanticsProvider extends DateValueSemanticsProviderAbstract<org.apache.isis.applib.value.Date> {
031    
032        private static final boolean IMMUTABLE = false;
033        private static final boolean EQUAL_BY_CONTENT = false;
034        private static final org.apache.isis.applib.value.Date DEFAULT_VALUE = null; // new
035                                                                                     // org.apache.isis.applib.value.Date(2007,1,1);
036    
037        // // no default
038    
039        /**
040         * Required because implementation of {@link Parser} and {@link EncoderDecoder}.
041         */
042        @SuppressWarnings("NP_NULL_PARAM_DEREF_NONVIRTUAL")
043        public DateValueSemanticsProvider() {
044            this(null, null, null);
045        }
046    
047        public DateValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration,
048            final ValueSemanticsProviderContext context) {
049            super(holder, org.apache.isis.applib.value.Date.class, IMMUTABLE, EQUAL_BY_CONTENT, DEFAULT_VALUE,
050                configuration, context);
051        }
052    
053        @Override
054        protected org.apache.isis.applib.value.Date add(final org.apache.isis.applib.value.Date original, final int years,
055            final int months, final int days, final int hours, final int minutes) {
056            final org.apache.isis.applib.value.Date date = original;
057            return date.add(years, months, days);
058        }
059    
060        @Override
061        protected org.apache.isis.applib.value.Date now() {
062            return new org.apache.isis.applib.value.Date();
063        }
064    
065        @Override
066        protected Date dateValue(final Object value) {
067            return ((org.apache.isis.applib.value.Date) value).dateValue();
068        }
069    
070        @Override
071        protected org.apache.isis.applib.value.Date setDate(final Date date) {
072            return new org.apache.isis.applib.value.Date(date);
073        }
074    }