<p>Return the specified attribute value, converted to a
<code>long</code>.</p>

@param attributeValue The attribute value to be converted
@throws NumberFormatException if conversion is not possible
355738
private static long longValue(Object attributeValue)
         throws NumberFormatException {

        if (attributeValue instanceof Number) {
            return (((Number) attributeValue).longValue());
        } else {
            return (Long.parseLong(attributeValue.toString()));
        }

    }
1238006
public static long longVal(String val, long defaultValue) {
        try {
            return NumberUtils.createNumber(val).longValue();
        } catch (Exception e) {
            log.warn("longVal(String, int) throw {}, return defaultValue = {}", e, defaultValue);
            return defaultValue;
        }
    }
62540
public static String extractAsEnumerationValue(Element item, Class<? extends Annotation> annotationClass, AnnotationAttributeType attribute) {
		final Elements elementUtils=BindDataSourceSubProcessor.elementUtils;
		final One<String> result = new One<String>();

		extractAttributeValue(elementUtils, item, annotationClass.getName(), attribute, new OnAttributeFoundListener() {

			@Override
			public void onFound(String value) {
				if (value.indexOf(".") >= 0)
					result.value0 = value.substring(value.lastIndexOf(".") + 1);
			}
		});

		return result.value0;
	}
543239
public int toInt(int defaultValue) {
		try {
			return Integer.parseInt(sb.toString());
		} catch (java.lang.NumberFormatException e) {
			e.printStackTrace();
		}
		return defaultValue;
	}
1191488
public static String longToString(long longValue, boolean noCase) {
        char[] digits = noCase ? DIGITS_NOCASE : DIGITS;
        int digitsLength = digits.length;

        if (longValue == 0) {
            return String.valueOf(digits[0]);
        }

        if (longValue < 0) {
            longValue = -longValue;
        }

        StringBuilder strValue = new StringBuilder();

        while (longValue != 0) {
            int digit = (int) (longValue % digitsLength);
            longValue = longValue / digitsLength;

            strValue.append(digits[digit]);
        }

        return strValue.toString();
    }
465825
public byte readByte(byte defaultValue, String attribute)
    {
        return Byte.parseByte(getValue(String.valueOf(defaultValue), attribute));
    }
190667
public static Long toLong(Object value, Long defaultValue) {
		return convert(Long.class, value, defaultValue);
	}
862271
public static Long extractToLong(final DeviceAttribute deviceAttributeRead) throws DevFailed {
	final Object value = AttributeHelper.extract(deviceAttributeRead);
	Long argout = null;
	if (value instanceof Short) {
	    argout = Long.valueOf(((Short) value).longValue());
	} else if (value instanceof String) {
	    try {
		argout = Long.valueOf((String) value);
	    } catch (final Exception e) {
		Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value
			+ " is not a numerical",
			"AttributeHelper.extractToLong(deviceAttributeWritten)");
	    }
	} else if (value instanceof Integer) {
	    argout = Long.valueOf(((Integer) value).longValue());
	} else if (value instanceof Long) {
	    argout = Long.valueOf(((Long) value).longValue());
	} else if (value instanceof Float) {
	    argout = Long.valueOf(((Float) value).longValue());
	} else if (value instanceof Boolean) {
	    if (((Boolean) value).booleanValue()) {
		argout = Long.valueOf(1);
	    } else {
		argout = Long.valueOf(0);
	    }
	} else if (value instanceof Double) {
	    argout = Long.valueOf(((Double) value).longValue());
	} else if (value instanceof DevState) {
	    argout = Long.valueOf(Integer.valueOf(((DevState) value).value()).longValue());
	} else {
	    Except.throw_exception("TANGO_WRONG_DATA_ERROR", "output type " + value.getClass()
		    + " not supported",
		    "AttributeHelper.extractToLong(Object value,deviceAttributeWritten)");
	}

	return argout;
    }
507427
public static Number toNumber(String str, Number defaultValue) {
	try {
	    // float
	    if (str.indexOf('.') != -1) {
		return new BigDecimal(str);
	    }
	    // integer
	    BigInteger bi = new BigInteger(str);
	    int l = bi.bitLength();
	    if (l < 32) return new Integer(bi.intValue());
	    if (l < 64) return new Long(bi.longValue());
	    return bi;
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return defaultValue;
	}
    }
768659
public final int getAttributeValueAsInteger(String attributeName) {
    Attribute attribute = getAttribute(attributeName);
    if (attribute == null) {
      return 0;
    }
    else {
      try {
        return attribute.getIntValue();
      }
      catch (DataConversionException ex) {
        return 0;
      }
    }
  }
60622
@SuppressWarnings("unchecked")
    public <T> T getAttribute( String attrName, Class<T> adaptee ) {
        if (attrName == null) {
            return null;
        }
        if (adaptee == null) {
            adaptee = (Class<T>) String.class;
        }

        Object attribute = feature.getAttribute(attrName);
        if (attribute == null) {
            return null;
        }
        if (attribute instanceof Number) {
            Number num = (Number) attribute;
            if (adaptee.isAssignableFrom(Double.class)) {
                return adaptee.cast(num.doubleValue());
            } else if (adaptee.isAssignableFrom(Float.class)) {
                return adaptee.cast(num.floatValue());
            } else if (adaptee.isAssignableFrom(Integer.class)) {
                return adaptee.cast(num.intValue());
            } else if (adaptee.isAssignableFrom(Long.class)) {
                return adaptee.cast(num.longValue());
            } else if (adaptee.isAssignableFrom(String.class)) {
                return adaptee.cast(num.toString());
            } else {
                throw new IllegalArgumentException();
            }
        } else if (attribute instanceof String) {
            if (adaptee.isAssignableFrom(Double.class)) {
                try {
                    Double parsed = Double.parseDouble((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(Float.class)) {
                try {
                    Float parsed = Float.parseFloat((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(Integer.class)) {
                try {
                    Integer parsed = Integer.parseInt((String) attribute);
                    return adaptee.cast(parsed);
                } catch (Exception e) {
                    return null;
                }
            } else if (adaptee.isAssignableFrom(String.class)) {
                return adaptee.cast(attribute);
            } else {
                throw new IllegalArgumentException();
            }
        } else if (attribute instanceof Geometry) {
            return null;
        } else {
            throw new IllegalArgumentException("Can't adapt attribute of type: " + attribute.getClass().getCanonicalName());
        }
    }
564995
public static Long getLongProperty(String property) {
        if (property == null) {
            return null;
        }
        Long propertyLong = null;
        try {
            propertyLong = Long.valueOf(property);
        } catch (NumberFormatException e) {
            LOG.warn("Cannot convert string value into number", e);
        }
        return propertyLong;
    }
1107777
public static long readLongAttribute(String attributeName, long defaultValue) {
        try {
            String methodName = "get" + attributeName;
            OperatingSystemMXBean systemMXBean = OPERATING_SYSTEM_MX_BEAN;
            Method method = systemMXBean.getClass().getMethod(methodName);
            method.setAccessible(true);

            Object value = method.invoke(systemMXBean);
            if (value == null) {
                return defaultValue;
            }

            if (value instanceof Long) {
                return (Long) value;
            }

            if (value instanceof Double) {
                double v = (Double) value;
                return Math.round(v * PERCENTAGE_MULTIPLIER);
            }

            if (value instanceof Number) {
                return ((Number) value).longValue();
            }

        } catch (RuntimeException re) {
            throw re;
        } catch (Exception ignored) {
            ignore(ignored);
        }
        return defaultValue;
    }
68128
private Object parseAttributeValue(XAttribute xAttribute) {
		String attributeString = xAttribute.toString();

		// TODO better solution?

		// All numeric values as double
		try {
			double a = Double.parseDouble(attributeString);
			return a;
		} catch (NumberFormatException e) {
			// Ignore
		}
		// Boolean
		if (attributeString.trim().toLowerCase().equals("true"))
			return true;
		if (attributeString.trim().toLowerCase().equals("false"))
			return false;
		// String
		return attributeString;
	}
702755
public void setAttribute(final String attributeName, final String attributeValue) {
        uiObject.getElement().setAttribute(attributeName, attributeValue);
    }
342048
public static long toLongValue(Object o, long defaultValue) {
	if (o instanceof Character) return (((Character) o).charValue());
	else if (o instanceof Boolean) return ((((Boolean) o).booleanValue()) ? 1L : 0L);
	else if (o instanceof Number) return (((Number) o).longValue());
	else if (o instanceof CharSequence) return (long) toDoubleValue(o.toString(), defaultValue);
	else if (o instanceof Castable) {
	    return (long) ((Castable) o).castToDoubleValue(defaultValue);
	}
	else if (o instanceof Character) return (long) (((Character) o).charValue());
	else if (o instanceof ObjectWrap) return toLongValue(((ObjectWrap) o).getEmbededObject(toLong(defaultValue)), defaultValue);

	return defaultValue;
    }
191010
public Object getAttributeValue(String attributeName) {
		Attribute attribute = getAllAttributes().get(attributeName);
		if (attribute != null) {
			return attribute.getValue();
		}
		return null;
	}