List of usage examples for java.util Objects toString
public static String toString(Object o)
From source file:acmi.l2.clientmod.xdat.Controller.java
private static boolean checkTreeNode(TreeItem<Object> treeItem, String nameFilter) { if (checkName(Objects.toString(treeItem.getValue()), nameFilter)) return true; for (TreeItem<Object> childItem : treeItem.getChildren()) if (checkTreeNode(childItem, nameFilter)) return true; return false; }
From source file:dk.kontentsu.api.exposure.ItemExposure.java
private static MultipartUploadItemRepresentation valid( final MultipartUploadItemRepresentation uploadItemRepresentation) { ValidatorFactory vf = Validation.buildDefaultValidatorFactory(); Validator validator = vf.getValidator(); Set<ConstraintViolation<MultipartUploadItemRepresentation>> errors = validator .validate(uploadItemRepresentation, Default.class); if (!errors.isEmpty()) { throw new ConstraintViolationException("Error in multipart upload for item with URI: " + Objects.toString(uploadItemRepresentation.getUri()), errors); }//from w ww .j av a 2 s. co m return uploadItemRepresentation; }
From source file:org.xwiki.contrib.oidc.auth.internal.OIDCUserManager.java
private void setValue(BaseObject xobject, String key, Object value, XWikiContext xcontext) { Object cleanValue;//from w ww .ja v a2s . c o m if (value instanceof List) { cleanValue = value; } else { // Go through String to be safe // TODO: find a more effective converter (the best would be to userObject#set to be stronger) cleanValue = Objects.toString(value); } xobject.set(key, cleanValue, xcontext); }
From source file:com.wrmsr.neurosis.util.Configs.java
protected static Map<Sigil, String> flattenMap(Map<?, ?> map) { return map.entrySet().stream().flatMap(e -> { String key = Objects.toString(e.getKey()); return flattenValues(e.getValue()).entrySet().stream() .map(e2 -> ImmutablePair.of(new MapEntrySigil(key, e2.getKey()), e2.getValue())); }).collect(ImmutableCollectors.toImmutableMap(e -> e.getKey(), e -> e.getValue())); }
From source file:com.nubits.nubot.tasks.strategy.PriceMonitorTriggerTask.java
public void gracefulPause(LastPrice lp) { //This is called is an abnormal price is detected for one whole refresh period String logMessage;//from www .j av a2 s . c om String notification; String subject; Color notificationColor; double sleepTime = 0; //we need to check the reason that the refresh took a whole period. //if it's because of a no connection issue, we need to wait to see if connection restarts if (!Global.exchange.getLiveData().isConnected()) { currentTime = System.currentTimeMillis(); logMessage = "There has been a connection issue for " + Integer.parseInt(Global.settings.getProperty("refresh_time_seconds")) + " seconds\n" + "Consider restarting the bot if the connection issue persists"; notification = ""; notificationColor = Color.YELLOW; subject = Global.exchange.getName() + " Bot is suffering a connection issue"; } else { //otherwise something bad has happened so we shutdown. sleepTime = (Integer.parseInt(Global.settings.getProperty("refresh_time_seconds")) * 3); logMessage = "The Fetched Exchange rate data has remained outside of the required price band for " + Integer.parseInt(Global.settings.getProperty("refresh_time_seconds")) + "seconds.\nThe bot will notify and restart in " + sleepTime + "seconds."; notification = "A large price difference was detected at " + Global.exchange.getName() + ".\nThe Last obtained price of " + Objects.toString(lp.getPrice().getQuantity()) + " was outside of " + Objects.toString(PRICE_PERCENTAGE) + "% of the moving average figure of " + Objects.toString(getMovingAverage()) + ".\nNuBot will remove the current orders and replace them in " + sleepTime + "seconds."; notificationColor = Color.PURPLE; subject = Global.exchange.getName() + " Moving Average issue. Bot will replace orders in " + sleepTime + "seconds."; } //we want to send Hip Chat and mail notifications, // cancel all orders to avoid arbitrage against the bot and // exit execution gracefully LOG.severe(logMessage); LOG.severe("Notifying HipChat"); HipChatNotifications.sendMessage(notification, notificationColor); LOG.severe("Sending Email"); MailNotifications.send(Global.options.getMailRecipient(), subject, notification); if (sleepTime > 0) { LOG.severe("Cancelling Orders to avoid Arbitrage against the bot"); Global.exchange.getTrade().clearOrders(Global.options.getPair()); //clear the moving average so the restart is fresh queueMA.clear(); LOG.severe("Sleeping for " + sleepTime); SLEEP_COUNT = 3; } currentTime = System.currentTimeMillis(); }
From source file:dk.kontentsu.api.exposure.ItemExposure.java
private String uriToString(final MultipartUploadItemRepresentation uploadItemRepresentation) { return (uploadItemRepresentation == null) ? "null" : Objects.toString(uploadItemRepresentation.getUri()); }
From source file:com.wrmsr.neurosis.util.Configs.java
protected static Map<Sigil, String> flattenValues(Object object) { if (object instanceof List) { return flattenList((List) object); } else if (object instanceof Map) { return flattenMap((Map) object); } else {/* w w w. ja v a 2 s .c o m*/ return ImmutableMap.of(TerminalSigil.INSTANCE, Objects.toString(object)); } }
From source file:edu.umich.oasis.sandbox.ResolvedSoda.java
@Override public void call(int flags, ISodaCallback callback, List<CallParam> params) throws RemoteException { try {//from ww w . ja va2s . c om if (localLOGD) { Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor, params.size())); for (CallParam param : params) { Log.d(TAG, param.toString(mContext.getClassLoader())); } } if (localLOGV) { Log.v(TAG, String.format("Callback %s, flags %d", callback, flags)); } // Sanity check. final int numParams = params.size(); if (numParams != mMemberData.countParameters()) { throw new IllegalArgumentException("Wrong number of arguments supplied"); } boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0; final ArrayList<Object> args = new ArrayList<>(); final SparseArray<IBinder> outs = new SparseArray<>(); mContext.beginSoda(); try { if (hasReturn) { outs.append(CallResult.RETURN_VALUE, null); } for (int i = 0; i < numParams; i++) { CallParam param = params.get(i); int paramHeader = param.getHeader(); if (param.getType() == CallParam.TYPE_HANDLE && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) { Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor); continue; } // Deserialize argument, marshaling as necessary. Object arg = unpack(param); // TODO: FLAG_BY_REF args.add(arg); // Put together the out parameter for inout params. if ((paramHeader & CallParam.FLAG_RETURN) != 0) { if (localLOGV) { Log.v(TAG, String.format("Adding out param %d", i)); } outs.append(i, SandboxObject.binderForObject(this, arg)); } } // Actually do the call. Object[] argArray = args.toArray(); if (localLOGD) { Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray)); } Object retval = mMemberData.call(argArray); if (localLOGD) { Log.d(TAG, "Call returned: " + Objects.toString(retval)); } // Bundle up handle for return value. if (hasReturn) { IBinder retvalObj = SandboxObject.binderForObject(this, retval); outs.put(CallResult.RETURN_VALUE, retvalObj); } // DEBUG: print out params if (localLOGV) { for (int i = 0; i < outs.size(); i++) { Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i))); } } // Post results to caller. if (localLOGD) { Log.d(TAG, "Posting results to caller"); } callback.onResult(new CallResult(outs)); } catch (InvocationTargetException ioe) { Throwable t = ioe.getTargetException(); if (t instanceof Exception) { throw ((Exception) t); } throw ioe; } finally { // Clear our ambient context. if (localLOGD) { Log.d(TAG, "Clearing call token"); } mContext.endSoda(); } } catch (Exception e) { //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e); callback.onResult(new CallResult(e)); } }
From source file:edu.umich.flowfence.sandbox.ResolvedQM.java
@Override public void call(int flags, IQMCallback callback, List<CallParam> params) throws RemoteException { try {//from w ww. j a v a2 s.c om if (localLOGD) { Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor, params.size())); for (CallParam param : params) { Log.d(TAG, param.toString(mContext.getClassLoader())); } } if (localLOGV) { Log.v(TAG, String.format("Callback %s, flags %d", callback, flags)); } // Sanity check. final int numParams = params.size(); if (numParams != mMemberData.countParameters()) { throw new IllegalArgumentException("Wrong number of arguments supplied"); } boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0; final ArrayList<Object> args = new ArrayList<>(); final SparseArray<IBinder> outs = new SparseArray<>(); mContext.beginQM(); try { if (hasReturn) { outs.append(CallResult.RETURN_VALUE, null); } for (int i = 0; i < numParams; i++) { CallParam param = params.get(i); int paramHeader = param.getHeader(); if (param.getType() == CallParam.TYPE_HANDLE && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) { Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor); continue; } // Deserialize argument, marshaling as necessary. Object arg = unpack(param); // TODO: FLAG_BY_REF args.add(arg); // Put together the out parameter for inout params. if ((paramHeader & CallParam.FLAG_RETURN) != 0) { if (localLOGV) { Log.v(TAG, String.format("Adding out param %d", i)); } outs.append(i, SandboxObject.binderForObject(this, arg)); } } // Actually do the call. Object[] argArray = args.toArray(); if (localLOGD) { Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray)); } Object retval = mMemberData.call(argArray); if (localLOGD) { Log.d(TAG, "Call returned: " + Objects.toString(retval)); } // Bundle up handle for return value. if (hasReturn) { IBinder retvalObj = SandboxObject.binderForObject(this, retval); outs.put(CallResult.RETURN_VALUE, retvalObj); } // DEBUG: print out params if (localLOGV) { for (int i = 0; i < outs.size(); i++) { Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i))); } } // Post results to caller. if (localLOGD) { Log.d(TAG, "Posting results to caller"); } callback.onResult(new CallResult(outs)); } catch (InvocationTargetException ioe) { Throwable t = ioe.getTargetException(); if (t instanceof Exception) { throw ((Exception) t); } throw ioe; } finally { // Clear our ambient context. if (localLOGD) { Log.d(TAG, "Clearing call token"); } mContext.endQM(); } } catch (Exception e) { //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e); callback.onResult(new CallResult(e)); } }
From source file:com.nubits.nubot.tasks.strategy.PriceMonitorTriggerTask.java
public void updateLastPrice(LastPrice lp) { //We need to fill up the moving average queue so that 30 data points exist. if (queueMA.size() < MOVING_AVERAGE_SIZE) { initMA(lp.getPrice().getQuantity()); }/*from w ww . j a v a2 s. c o m*/ if (!Global.options.isMultipleCustodians()) { // //we check against the moving average double current = lp.getPrice().getQuantity(); double MA = getMovingAverage(); //calculate the percentage difference double percentageDiff = (((MA - current) / ((MA + current) / 2)) * 100); if ((percentageDiff > PRICE_PERCENTAGE) || (percentageDiff < -PRICE_PERCENTAGE)) { //The potential price is more than % different to the moving average //add it to the MA-Queue to raise the Moving Average and re-request the currency data //in this way we can react to a large change in price when we are sure it is not an anomaly LOG.warning("Latest price " + Objects.toString(current) + " is " + Objects.toString(percentageDiff) + "% outside of the moving average of " + Objects.toString(MA) + "." + "\nShifting moving average and re-fetching exchange rate data."); updateMovingAverageQueue(current); executeUpdatePrice(1); return; } //the potential price is within the % boundary. //add it to the MA-Queue to keep the moving average moving // Only do this if the standard update interval hasn't passed if (((System.currentTimeMillis() - (currentTime + REFRESH_OFFSET)) / 1000L) < Integer .parseInt(Global.settings.getProperty("refresh_time_seconds"))) { updateMovingAverageQueue(current); } else { //If we get here, we haven't had a price within % of the average for as long as a standard update period //the action is to send notifications, cancel all orders and turn off the bot gracefulPause(lp); return; } } //carry on with updating the wall price shift this.lastPrice = lp; LOG.fine("Price Updated." + lp.getSource() + ":1 " + lp.getCurrencyMeasured().getCode() + " = " + "" + lp.getPrice().getQuantity() + " " + lp.getPrice().getCurrency().getCode() + "\n"); if (isFirstTimeExecution) { initStrategy(lp.getPrice().getQuantity()); currentWallPEGPrice = lp; isFirstTimeExecution = false; } else { verifyPegPrices(); } }