View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar.cpptasks.types;
21  
22  import java.lang.reflect.Method;
23  
24  /**
25   * Helper class which can be used for Ant task attribute setter methods to
26   * allow the build file to specify a long in either decimal, octal, or
27   * hexadecimal format.
28   * // FlexInteger author
29   * 
30   * @author Erik Hatcher
31   * @see org.apache.tools.ant.types.FlexInteger
32   */
33  public class FlexLong {
34    private Long value;
35  
36    /**
37     * Constructor used by Ant's introspection mechanism for attribute
38     * population
39     */
40    public FlexLong(final String value) {
41      // Java 1.1 did not support Long.decode().. so we call it by
42      // reflection.
43      try {
44        final Method m = Long.class.getMethod("decode", String.class);
45        final Object rc = m.invoke(null, value);
46        this.value = (Long) rc;
47      } catch (final Exception e) {
48        // Try it the old fashioned way, we must be on a 1.1 jre
49        this.value = new Long(value);
50      }
51    }
52  
53    /**
54     * Returns the decimal integer value
55     */
56    public long longValue() {
57      return this.value.longValue();
58    }
59  
60    /**
61     * Overridden method to return the decimal value for display
62     */
63    @Override
64    public String toString() {
65      return this.value.toString();
66    }
67  }