Example usage for java.lang Object toString

List of usage examples for java.lang Object toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.streamreduce.util.JSONUtils.java

public static Map<String, Object> convertJSONObjectToMap(JSONObject jsonObject) {
    if (jsonObject == null) {
        return null;
    }//w ww.j av a 2s.  c o  m

    Map<String, Object> map = new HashMap<>();
    for (Object key : jsonObject.keySet()) {
        map.put(key.toString(), jsonObject.get(key));
    }

    return replaceJSONNullsFromMap(map);

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java

public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    final JSONObject jsonObject = new JSONObject();
    final Class<? extends DomainObject> clazz = obj.getClass();
    final String objClassName = clazz.getName();

    jsonObject.put("externalId", obj.getExternalId());
    jsonObject.put("className", objClassName);
    final DomainClass domainClass = getDomainClass(objClassName);
    if (domainClass == null) {
        return jsonObject;
    }/*from  ww  w  .j  a va  2 s.  com*/
    for (Slot slot : getAllSlots(domainClass)) {
        final String slotName = slot.getName();
        final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
        final Object result = method.invoke(obj);
        jsonObject.put(slotName, result == null ? null : result.toString());
    }

    for (Role roleSlot : getAllRoleSlots(domainClass)) {
        final String slotName = roleSlot.getName();
        if (roleSlot.getMultiplicityUpper() == 1) {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
            final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj);
            final JSONArray oneRelation = new JSONArray();
            if (singleRelationObj != null) {
                oneRelation.add(singleRelationObj.getExternalId());
            }
            jsonObject.put(slotName, oneRelation);
        } else {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set");
            final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method
                    .invoke(obj);
            jsonObject.put(slotName, serializeRelation(result));
        }

    }

    return jsonObject;
}

From source file:Main.java

public static Map<String, String> asParams(final String username, final Object credential) {
    return new HashMap<String, String>() {
        private static final long serialVersionUID = -1L;
        {//w w  w. j a v a2 s  .  c  om
            put("username", username);
            put("password", credential.toString());
        }
    };
}

From source file:com.jim.im.offline.repo.MessageConverter.java

private static Object getValue(Field field, Object sourceValue) {
    if (sourceValue == null)
        return null;

    if (field.getType() == MsgType.class) {
        return MsgType.valueOf(sourceValue.toString());
    } else if (field.getType() == TopicOwnerType.class) {
        return TopicOwnerType.valueOf(sourceValue.toString());
    } else if (field.getType() == BigInteger.class) {
        return new BigInteger(sourceValue.toString(), 16);
    }//from  w  ww  . jav a 2  s .  c  om
    return sourceValue;
}

From source file:net.sephy.postman.util.PostmanUtils.java

/**
 *  Map ??? List<Header> ?/* www.jav a  2s  .com*/
 * @param map
 * @return
 */
public static List<Header> mapToHeaderList(Map<String, Object> map) {
    List<Header> list = new ArrayList<Header>();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object value = entry.getValue();
        if (value != null) {
            list.add(new BasicHeader(entry.getKey(), value.toString()));
        }
    }
    return list;
}

From source file:de.static_interface.sinklibrary.util.Debug.java

public static void log(@Nonnull Object o) {
    logInternal(Level.INFO, (o == null ? "null" : o.toString()), null);
}

From source file:io.selendroid.standalone.android.impl.AbstractDeviceTest.java

private static final Matcher<CommandLine> matchesCmdLine(final String cmdString) {
    return new BaseMatcher<CommandLine>() {
        @Override//from w w  w .  j  a  va  2s  . c o  m
        public boolean matches(Object cmdLine) {
            if (!(cmdLine instanceof CommandLine)) {
                return false;
            }
            return Pattern.matches(cmdString, cmdLine.toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("command was not " + cmdString);
        }
    };
}

From source file:Main.java

private static void serializeObjectAttributes(JsonObject objectJson, StringBuffer buff) {
    Iterator elements = objectJson.entrySet().iterator();
    while (elements.hasNext()) {
        Entry entry = (Entry) elements.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof JsonPrimitive) {
            if (key.toString().startsWith("-")) {
                buff.append(SPACE).append(key.toString().substring(1)).append(ESQ)
                        .append(value.toString().replace(EQ, EMPTY)).append(EQ);
            }/*  w w  w .  j  a  v  a2 s . c o m*/
        }
    }
}

From source file:tv.icntv.log.crawl2.commons.HttpClientUtil.java

public static String getContentPost(String url, Map<String, String> params) throws IOException {
    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> formParams = new ArrayList<NameValuePair>();
    if (params != null) {
        Set set = params.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = params.get(key);
            formParams.add(new BasicNameValuePair(key.toString(), value.toString()));
        }//  w ww . j ava 2s .co m
    }
    httpPost.setHeader(new BasicHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));
    httpPost.setEntity(new UrlEncodedFormEntity(formParams, HTTP.UTF_8));

    // execute
    CloseableHttpClient client = HttpClientHolder.getClient();
    return EntityUtils.toString(client.execute(httpPost).getEntity(), "utf-8");
}

From source file:com.yahoo.parsec.clients.ParsecEqualsUtil.java

/**
 * ToString equals.//from www  .  ja  v a  2s  .  com
 *
 * @param lhs lhs
 * @param rhs rhs
 *
 * @return true when two objects are equal by toString value
 */
static boolean toStringEquals(final Object lhs, final Object rhs) {
    if (lhs != rhs && (lhs == null || rhs == null || !lhs.toString().equals(rhs.toString()))) {
        return false;
    }
    return true;
}