Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6986375f9a78965a578b54ebdf79667dbe9f9b58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.skynet.core.attribute;

import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;

/**
 * @author Donald G. Dunne
 */
public class LongAttribute extends CharacterBackedAttribute<Long> {

   private static final Long DEFAULT_LONG = Long.MIN_VALUE;

   @Override
   public Long getValue() throws OseeCoreException {
      return (Long) getAttributeDataProvider().getValue();
   }

   @Override
   public boolean subClassSetValue(Long value) throws OseeCoreException {
      if (value == null) {
         throw new OseeArgumentException("Attribute value was null");
      }
      return getAttributeDataProvider().setValue(value);
   }

   @Override
   public Long convertStringToValue(String value) {
      Long toReturn = null;
      if (isValidLong(value)) {
         toReturn = Long.valueOf(value);
      } else {
         toReturn = getDefaultValue();
      }
      return toReturn;
   }

   public Long getDefaultValue() {
      Long toReturn = DEFAULT_LONG;
      String defaultValue = getAttributeType().getDefaultValue();
      if (isValidLong(defaultValue)) {
         toReturn = Long.valueOf(defaultValue);
      }
      return toReturn;
   }

   private boolean isValidLong(String value) {
      boolean result = false;
      if (Strings.isValid(value)) {
         try {
            Long.getLong(value);
            result = true;
         } catch (NumberFormatException ex) {
            // Do Nothing;
         }
      }
      return result;
   }
}

Back to the top