Example usage for java.lang Long Long

List of usage examples for java.lang Long Long

Introduction

In this page you can find the example usage for java.lang Long Long.

Prototype

@Deprecated(since = "9")
public Long(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Usage

From source file:net.kenblair.scheduler.jpa.JpaScheduledJobRepositoryTest.java

@Test
public void testUpdateLastRun() throws Exception {
    ScheduledJob job = repository.findEnabledJobs().get(0);
    final Date lastDateRun = job.getLastRun();
    repository.updateLastRun(job.getId());
    job = repository.findOne(new Long(job.getId()));
    assertTrue(lastDateRun.before(job.getLastRun()));
}

From source file:com.tesora.dve.sql.util.JdbcConnectionResourceResponse.java

@Override
public void assertEqualResponse(String cntxt, ResourceResponse other) throws Throwable {
    if (results != null) {
        // result set, not much we can do
    } else if (other instanceof JdbcConnectionResourceResponse) {
        JdbcConnectionResourceResponse othResp = (JdbcConnectionResourceResponse) other;
        assertEquals(cntxt + " row count", updateCount, othResp.updateCount);
    } else if (other instanceof ProxyConnectionResourceResponse) {
        ProxyConnectionResourceResponse othResp = (ProxyConnectionResourceResponse) other;
        assertEquals(cntxt + " row count", updateCount, new Long(othResp.getNumRowsAffected()));
    } else if (other == null) {
        // if the other side is null - that's a problem
        fail("missing other response");
    } else {//from  w  w w . j a v a  2s. co m
        throw new Throwable("What kind of ResourceResponse is " + other.getClass().getName());
    }
}

From source file:com.spoledge.audao.parser.gql.impl.ParserUtils.java

public static Long argLong(Object o) {
    if (o == null)
        return null;
    if (o instanceof Long)
        return (Long) o;
    if (o instanceof Number)
        return new Long(((Number) o).longValue());

    return new Long(o.toString());
}

From source file:com.redhat.rhn.manager.kickstart.IpAddressRange.java

/**
 *
 * @param minIn IpNumber to set min IpAddress
 * @param maxIn IpNumber to set max IpAddress
 *///from   w  w  w  .j a va2s .c o  m
public IpAddressRange(Long minIn, Long maxIn) {
    this.min = new IpAddress(minIn.longValue());
    this.max = new IpAddress(maxIn.longValue());
    this.ksid = new Long(0);
}

From source file:com.doculibre.constellio.services.RecordServicesImpl.java

@Override
public Record get(SolrDocument doc) {
    return super.get(new Long(doc.getFieldValue(IndexField.RECORD_ID_FIELD).toString()));
}

From source file:com.redhat.rhn.manager.system.UpdateBaseChannelCommand.java

/**
 * {@inheritDoc}//from w w  w . ja v a 2  s.c  o m
 */
public ValidatorError store() {
    Channel oldChannel = server.getBaseChannel();
    Channel newChannel = null;

    // if new channel equals old, there's nothing to do
    if ((oldChannel == null && baseChannelId.longValue() == -1)
            || (oldChannel != null && oldChannel.getId() == baseChannelId.longValue())) {
        return null;
    }

    // If the new ID is -1 we are unsubscribing to a no-base-channel
    // for the server.
    if (baseChannelId.longValue() != -1) {
        newChannel = ChannelManager.lookupByIdAndUser(new Long(baseChannelId.longValue()), user);
        // Make sure we got a valid base channel from the user
        if (newChannel == null || newChannel.getParentChannel() != null
                || !newChannel.getChannelArch().isCompatible(server.getServerArch())) {
            throw new InvalidChannelException();
        }
    }

    // Check for available subs
    if (newChannel != null && !SystemManager.canServerSubscribeToChannel(user.getOrg(), server, newChannel)) {
        return new ValidatorError("system.channel.nochannelslots");
    }
    List<Long> newKidsToSubscribe = new LinkedList<Long>();

    if (oldChannel != null && newChannel != null) {
        Map<Channel, Channel> preservableChildren = ChannelManager.findCompatibleChildren(oldChannel,
                newChannel, user);
        for (Channel kid : server.getChannels()) {
            if (preservableChildren.containsKey(kid)) {
                newKidsToSubscribe.add(preservableChildren.get(kid).getId());
            }
        }
    }

    // First unsubscribe all the child channels
    UpdateChildChannelsCommand cmd = new UpdateChildChannelsCommand(user, server, ListUtils.EMPTY_LIST);
    cmd.store();

    // Unsubscribe the server from it's current base channel
    try {
        SystemManager.unsubscribeServerFromChannel(user, server, oldChannel);
    } catch (PermissionException e) {
        // convert to FaultException
        throw new PermissionCheckFailureException();
    }

    if (newChannel != null) {
        // Subscribe the server to the new base channel
        try {
            SystemManager.subscribeServerToChannel(user, server, newChannel);
            cmd = new UpdateChildChannelsCommand(user, server, newKidsToSubscribe);
            cmd.store();

        } catch (PermissionException e) {
            // convert to FaultException
            throw new PermissionCheckFailureException();
        }
    }
    return super.store();
}

From source file:Main.java

/**
 * Returns o.toString() unless it throws an exception (which causes it to be
 * stored in unrenderableClasses) or already was present in
 * unrenderableClasses. If so, the same string is returned as would have
 * been returned by Object.toString(). Arrays get special treatment as they
 * don't have usable toString methods./* w  w  w .  jav a 2  s  .co  m*/
 * 
 * @param o
 *            incoming object to render.
 * @return
 */

public static String render(Object o) {
    if (o == null) {
        return String.valueOf(o);
    }
    Class<?> objectClass = o.getClass();

    if (unrenderableClasses.containsKey(objectClass) == false) {
        try {
            if (objectClass.isArray()) {
                return renderArray(o, objectClass).toString();
            } else {
                return o.toString();
            }
        } catch (Exception e) {
            Long now = new Long(System.currentTimeMillis());

            System.err.println(
                    "Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage());

            unrenderableClasses.put(objectClass, now);
        }
    }
    String name = o.getClass().getName();
    return name + "@" + Integer.toHexString(o.hashCode());
}

From source file:com.redhat.rhn.frontend.action.systems.images.ScheduleImageDeploymentAction.java

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Get the current user
    RequestContext ctx = new RequestContext(request);
    User user = ctx.getCurrentUser();//from w w w. j a  va  2 s  . c o  m

    // Put the server object to the request (for system header)
    Long sid = new Long(request.getParameter(RequestContext.SID));
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    request.setAttribute("system", server);

    ActionForward forward;
    if (request.getParameter(RequestContext.DISPATCH) != null) {
        // Read the form parameters
        DynaActionForm form = (DynaActionForm) actionForm;
        Long vcpus = (Long) form.get("vcpus");
        Long memkb = (Long) form.get("mem_mb") * 1024;
        String bridge = form.getString("bridge");
        String proxyServer = form.getString("proxy_server");
        String proxyUser = form.getString("proxy_user");
        String proxyPass = form.getString("proxy_pass");

        // Find the requested image
        String imageId = request.getParameter("image_id");
        Image image = findImage(new Long(imageId), request);

        // Set up the proxy configuration
        ProxyConfig proxy = null;
        if (StringUtils.isNotEmpty(proxyServer)) {
            proxy = new ProxyConfig(proxyServer, proxyUser, proxyPass);
        }

        // Put defaults for deployment parameters
        if (vcpus <= 0) {
            vcpus = Long.valueOf(1);
        }
        if (memkb <= 0) {
            memkb = Long.valueOf(524288);
        }

        // Create the action and store it
        Action action = ActionManager.createDeployImageAction(user, image, vcpus, memkb, bridge, proxy);
        ActionManager.addServerToAction(sid, action);
        ActionManager.storeAction(action);
        createSuccessMessage(request, SUCCESS_KEY, image.getName());

        // Forward the sid as a request parameter
        Map forwardParams = makeParamMap(request);
        forwardParams.put(RequestContext.SID, sid);
        forwardParams.put("load_async", false);
        forward = getStrutsDelegate().forwardParams(actionMapping.findForward("submitted"), forwardParams);
    } else {
        // Load images asynchronously if 'sid' is the only parameter
        if (loadAsync(request)) {
            request.setAttribute("loadAsync", true);
        } else {
            // The 'parentUrl' is needed for the 'listset' tag
            request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
        }
        // Find the default destination
        forward = actionMapping.findForward(RhnHelper.DEFAULT_FORWARD);
    }
    return forward;
}

From source file:bql.util.JsonComparator.java

/**
 * Compares two json objects.// w w w  .  j  a v  a  2s.  co m
 *
 * @param a first element to compare
 * @param b second element to compare
 * @return true if the elements are equal as per the policy.
 */
public boolean isEquals(Object a, Object b) {
    if (a instanceof JSONObject) {
        if (b instanceof JSONObject) {
            return isEqualsJsonObject((JSONObject) a, (JSONObject) b);
        } else {
            return false;
        }
    }

    if (a instanceof JSONArray) {
        if (b instanceof JSONArray) {
            return isEqualsJsonArray((JSONArray) a, (JSONArray) b);
        } else {
            return false;
        }
    }

    if (a instanceof Long) {
        if (b instanceof Long) {
            return isEqualsLong((Long) a, (Long) b);
        } else if (b instanceof Integer) {
            return isEqualsLong((Long) a, new Long(((Integer) b).intValue()));
        } else {
            return false;
        }
    }

    if (a instanceof Integer) {
        if (b instanceof Integer) {
            return isEqualsInteger((Integer) a, (Integer) b);
        } else if (b instanceof Long) {
            return isEqualsInteger((Integer) a, new Integer((int) ((Long) b).longValue()));
        } else {
            return false;
        }
    }

    if (a instanceof String) {
        if (b instanceof String) {
            return isEqualsString((String) a, (String) b);
        } else {
            return false;
        }
    }

    if (a instanceof Boolean) {
        if (b instanceof Boolean) {
            return isEqualsBoolean((Boolean) a, (Boolean) b);
        } else {
            return false;
        }
    }

    if (a instanceof Float || a instanceof Double) {
        double val1 = (a instanceof Float) ? ((Float) a).doubleValue() : ((Double) a).doubleValue();
        if (b instanceof Float || b instanceof Double) {
            double val2 = (b instanceof Float) ? ((Float) b).doubleValue() : ((Double) b).doubleValue();
            return (Math.abs(val1 - val2) < 0.001);
        } else {
            return false;
        }
    }

    if (a == null && b == null) {
        return true;
    }

    if (a != null && b != null) {
        return a.equals(b);
    }

    return false;
}

From source file:Main.java

/**
 * <p>Converts an array of primitive longs to objects.</p>
 *
 * <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
 *
 * @param array  a <code>long</code> array
 * @return a <code>Long</code> array, <code>null</code> if null array input
 *///  w  w  w  .j  a v  a 2 s. co  m
public static Long[] toObject(long[] array) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_LONG_OBJECT_ARRAY;
    }
    final Long[] result = new Long[array.length];
    for (int i = 0; i < array.length; i++) {
        result[i] = new Long(array[i]);
    }
    return result;
}