001/**
002 * Milliseconds.java
003 *
004 * Copyright (c) 2004-2012, Nicole C. Tedesco.  All rights reserved.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * 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, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package net.sf.jaccumulator.functions;
020
021import java.util.Date;
022
023import net.sf.jaccumulator.ConcurrencyStrategy;
024import net.sf.jaccumulator.Domain;
025import net.sf.jaccumulator.longs.AbstractLongPrimitive;
026import net.sf.jaccumulator.primitives.Primitive;
027
028/**
029 * Provides a non-{@link #isMutable() mutable} function for retrieving the
030 * current millisecond-precision system {@link System#currentTimeMillis() time}
031 *
032 * @since JAccumulator 4.0
033 * @author Nicole Tedesco (<a
034 *         href="mailto:nicole@tedesco.name">nicole@tedesco.name</a>)
035 */
036public final class Milliseconds extends AbstractLongPrimitive<Milliseconds>
037{
038    private static final long serialVersionUID = -4909844610385168442L;
039
040    public static final Primitive<?> INSTANCE = new Milliseconds();
041
042    private Milliseconds()
043    {
044        super(Domain.FUNCTION);
045    }
046
047    @Override
048    public final Milliseconds copy() {
049        return this;
050    }
051
052    @Override
053    public final Milliseconds copyUsing( final long aValue ) {
054        return this;
055    }
056
057    @Override
058    public final Milliseconds decrement()
059        throws UnsupportedOperationException,
060            IllegalArgumentException,
061            ArithmeticException
062    {
063        throw new UnsupportedOperationException();
064    }
065
066    @Override
067    public final ConcurrencyStrategy getConcurrency() {
068        return ConcurrencyStrategy.CONCURRENT;
069    }
070
071    @Override
072    public final Milliseconds increment()
073        throws UnsupportedOperationException,
074            ArithmeticException,
075            IllegalArgumentException
076    {
077        throw new UnsupportedOperationException();
078    }
079
080    @Override
081    public final boolean isConfigurable() {
082        return false;
083    }
084
085    @Override
086    public final long longPostDecrement()
087        throws UnsupportedOperationException,
088            ArithmeticException,
089            IllegalArgumentException
090    {
091        throw new UnsupportedOperationException();
092    }
093
094    @Override
095    public final long longPostIncrement()
096        throws UnsupportedOperationException,
097            ArithmeticException,
098            IllegalArgumentException
099    {
100        throw new UnsupportedOperationException();
101    }
102
103    @Override
104    public final long longValue() {
105        return System.currentTimeMillis();
106    }
107
108    @Override
109    public final Milliseconds milliseconds() {
110        return this;
111    }
112
113    @Override
114    public final Milliseconds nanoseconds() {
115        return this;
116    }
117
118    @Override
119    public final Milliseconds not()
120        throws UnsupportedOperationException,
121            IllegalArgumentException,
122            ArithmeticException
123    {
124        throw new UnsupportedOperationException();
125    }
126
127    @Override
128    public final Milliseconds setScalar( final long aValue )
129        throws UnsupportedOperationException,
130            IllegalArgumentException,
131            ArithmeticException
132    {
133        throw new UnsupportedOperationException();
134    }
135
136    @Override
137    public final Milliseconds shiftLeft( final int count )
138        throws UnsupportedOperationException,
139            IllegalArgumentException,
140            ArithmeticException
141    {
142        throw new UnsupportedOperationException();
143    }
144
145    @Override
146    public final Milliseconds shiftRight( final int count )
147        throws UnsupportedOperationException,
148            IllegalArgumentException,
149            ArithmeticException
150    {
151        throw new UnsupportedOperationException();
152    }
153
154    @Override
155    public String toString() {
156        return new Date().toString();
157    }
158}