本文整理汇总了Java中org.apache.commons.lang.ObjectUtils类的典型用法代码示例。如果您正苦于以下问题:Java ObjectUtils类的具体用法?Java ObjectUtils怎么用?Java ObjectUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectUtils类属于org.apache.commons.lang包,在下文中一共展示了ObjectUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResultString
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* 取得结果字符串
*
* @param result
* @return
*/
protected String getResultString(Object result) {
if (result == null) {
return StringUtils.EMPTY;
}
if (result instanceof Map) { // 处理map
return getMapResultString((Map) result);
} else if (result instanceof List) {// 处理list
return getListResultString((List) result);
} else if (result.getClass().isArray()) {// 处理array
return getArrayResultString((Object[]) result);
} else {
// 直接处理string
return ObjectUtils.toString(result, StringUtils.EMPTY).toString();
// return ToStringBuilder.reflectionToString(result, ToStringStyle.SIMPLE_STYLE);
}
}
示例2: compare
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public int compare(ResolvedArtifact artifact1, ResolvedArtifact artifact2) {
int diff = artifact1.getName().compareTo(artifact2.getName());
if (diff != 0) {
return diff;
}
diff = ObjectUtils.compare(artifact1.getClassifier(), artifact2.getClassifier());
if (diff != 0) {
return diff;
}
diff = ObjectUtils.compare(artifact1.getExtension(), artifact2.getExtension());
if (diff != 0) {
return diff;
}
diff = artifact1.getType().compareTo(artifact2.getType());
if (diff != 0) {
return diff;
}
// Use an arbitrary ordering when the artifacts have the same public attributes
return artifact1.hashCode() - artifact2.hashCode();
}
示例3: insert
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public void insert(List<CanalEntry.Column> data, String schemaName, String tableName) {
DBObject obj = DBConvertUtil.columnToJson(data);
logger.debug("insert :{}", obj.toString());
//订单库单独处理
if (schemaName.equals("order")) {
//保存原始数据
if (tableName.startsWith("order_base_info")) {
tableName = "order_base_info";
} else if (tableName.startsWith("order_detail_info")) {
tableName = "order_detail_info";
} else {
logger.info("unknown data :{}.{}:{}", schemaName, tableName, obj);
return;
}
insertData(schemaName, tableName, obj, obj);
} else {
DBObject newObj = (DBObject) ObjectUtils.clone(obj);
if (newObj.containsField("id")) {
newObj.put("_id", newObj.get("id"));
newObj.removeField("id");
}
insertData(schemaName, tableName, newObj, obj);
}
}
示例4: insertData
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public void insertData(String schemaName, String tableName, DBObject naive, DBObject complete) {
int i = 0;
DBObject logObj = (DBObject) ObjectUtils.clone(complete);
//保存原始数据
try {
String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.INSERT.getNumber();
i++;
naiveMongoTemplate.getCollection(tableName).insert(naive);
i++;
SpringUtil.doEvent(path, complete);
i++;
} catch (MongoClientException | MongoSocketException clientException) {
//客户端连接异常抛出,阻塞同步,防止mongodb宕机
throw clientException;
} catch (Exception e) {
logError(schemaName, tableName, 1, i, logObj, e);
}
}
示例5: updateData
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public void updateData(String schemaName, String tableName, DBObject query, DBObject obj) {
String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.UPDATE.getNumber();
int i = 0;
DBObject newObj = (DBObject) ObjectUtils.clone(obj);
DBObject logObj = (DBObject) ObjectUtils.clone(obj);
//保存原始数据
try {
obj.removeField("id");
i++;
naiveMongoTemplate.getCollection(tableName).update(query, obj);
i++;
SpringUtil.doEvent(path, newObj);
i++;
} catch (MongoClientException | MongoSocketException clientException) {
//客户端连接异常抛出,阻塞同步,防止mongodb宕机
throw clientException;
} catch (Exception e) {
logError(schemaName, tableName, 2, i, logObj, e);
}
}
示例6: deleteData
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public void deleteData(String schemaName, String tableName, DBObject obj) {
int i = 0;
String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.DELETE.getNumber();
DBObject newObj = (DBObject) ObjectUtils.clone(obj);
DBObject logObj = (DBObject) ObjectUtils.clone(obj);
//保存原始数据
try {
i++;
if (obj.containsField("id")) {
naiveMongoTemplate.getCollection(tableName).remove(new BasicDBObject("_id", obj.get("id")));
}
i++;
SpringUtil.doEvent(path, newObj);
} catch (MongoClientException | MongoSocketException clientException) {
//客户端连接异常抛出,阻塞同步,防止mongodb宕机
throw clientException;
} catch (Exception e) {
logError(schemaName, tableName, 3, i, logObj, e);
}
}
示例7: setTaskOwner
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* @param task Task
* @param properties Map<QName, Serializable>
*/
private void setTaskOwner(Task task, Map<QName, Serializable> properties)
{
QName ownerKey = ContentModel.PROP_OWNER;
if (properties.containsKey(ownerKey))
{
Serializable owner = properties.get(ownerKey);
if (owner != null && !(owner instanceof String))
{
throw getInvalidPropertyValueException(ownerKey, owner);
}
String assignee = (String) owner;
String currentAssignee = task.getAssignee();
// Only set the assignee if the value has changes to prevent
// triggering assignementhandlers when not needed
if (ObjectUtils.equals(currentAssignee, assignee)==false)
{
activitiUtil.getTaskService().setAssignee(task.getId(), assignee);
}
}
}
示例8: equals
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* Check if this extended message format is equal to another object.
*
* @param obj the object to compare to
* @return true if this object equals the other, otherwise false
* @since 2.6
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!super.equals(obj)) {
return false;
}
if (ObjectUtils.notEqual(getClass(), obj.getClass())) {
return false;
}
ExtendedMessageFormat rhs = (ExtendedMessageFormat)obj;
if (ObjectUtils.notEqual(toPattern, rhs.toPattern)) {
return false;
}
if (ObjectUtils.notEqual(registry, rhs.registry)) {
return false;
}
return true;
}
示例9: compareKeys
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
private int compareKeys(Optional<Record> record1, Optional<Record> record2, List<Column> primaryKeys) {
if (!record1.isPresent() && !record2.isPresent()) {
throw new IllegalStateException("Cannot compare two nonexistent records.");
}
if (!record1.isPresent()) {
return 1;
}
if (!record2.isPresent()) {
return -1;
}
for (Column keyCol : primaryKeys) {
Comparable<?> value1 = convertToComparableType(keyCol, record1.get());
Comparable<?> value2 = convertToComparableType(keyCol, record2.get());
int result = ObjectUtils.compare(value1, value2);
if (result != 0) {
return result;
}
}
return 0;
}
示例10: compareRecords
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* Compare all the columns for these records.
*
* @param table the active {@link Table}
* @param recordNumber The current record number
* @param record1 The first record
* @param record2 The second record
*/
private void compareRecords(Table table, int recordNumber, Record record1, Record record2, List<Column> primaryKeys) {
for (Column column : FluentIterable.from(table.columns()).filter(excludingExcludedColumns())) {
String columnName = column.getName();
Object value1 = convertToComparableType(column, record1);
Object value2 = convertToComparableType(column, record2);
if (!ObjectUtils.equals(value1, value2)) {
differences.add(String.format(
"Table [%s]: Mismatch on key %s column [%s] row [%d]: [%s]<>[%s]",
table.getName(),
keyColumnsIds(record1, record2, primaryKeys),
columnName,
recordNumber,
value1,
value2
));
}
}
}
示例11: dumpApplierInfo
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
public static void dumpApplierInfo(Long batchId, List<Record> extractorRecords, List<Record> applierRecords,
Position position, boolean dumpDetail) {
applierLogger.info(SEP + "****************************************************" + SEP);
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat(TIMESTAMP_FORMAT);
applierLogger.info(MessageFormat.format(applier_format,
String.valueOf(batchId),
extractorRecords.size(),
applierRecords.size(),
ObjectUtils.toString(position),
format.format(now)));
applierLogger.info("****************************************************" + SEP);
if (dumpDetail) {// 判断一下是否需要打印详细信息,目前只打印applier信息,分开打印
applierLogger.info(dumpRecords(applierRecords));
applierLogger.info("****************************************************" + SEP);
}
}
示例12: asMap
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* 快速生成一个map的工具类
* @author nan.li
* @param objects
* @return
*/
public static Map<String, Object> asMap(Object... objects)
{
Map<String, Object> ret = new HashMap<>();
if (objects != null && objects.length > 0 && objects.length % 2 == 0)
{
for (int i = 0; i + 1 < objects.length; i += 2)
{
ret.put(ObjectUtils.toString(objects[i]), objects[i + 1]);
}
}
else
{
Logs.w("参数个数非法!");
}
return ret;
}
示例13: asStrMap
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
/**
* 返回一个String Map
* @author nan.li
* @param objects
* @return
*/
public static Map<String, String> asStrMap(Object... objects)
{
Map<String, String> ret = new HashMap<>();
if (objects != null && objects.length > 0 && objects.length % 2 == 0)
{
for (int i = 0; i + 1 < objects.length; i += 2)
{
ret.put(ObjectUtils.toString(objects[i]), ObjectUtils.toString(objects[i + 1]));
}
}
else
{
Logs.w("参数个数非法!");
}
return ret;
}
示例14: execute
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
@Override
public void execute() throws ServiceAbortException {
page.clearErrorMessageList();
String password = page.getPassword();
String passwordConf = page.getPasswordConf();
if (!ObjectUtils.equals(password, passwordConf)) {
throw new ServiceAbortException(ApplicationMessageCode.PASSWORD_UNMATCH);
} else {
page.setContextUser(SETUP_USER_ID);
List<SysUsers> userList = new ArrayList<>();
userList.add(setupUserDto());
page.userService.save(userList);
page.setVisibled(3);
page.setPageTitle(3);
page.setBackPage(2);
}
}
示例15: sortProjectRoles
import org.apache.commons.lang.ObjectUtils; //导入依赖的package包/类
protected void sortProjectRoles(List<ProjectRole> projectRoles) {
Collections.sort(projectRoles, new Comparator<ProjectRole>() {
private Map<ProjectRoleCode, Integer> order = ImmutableMap.<ProjectRoleCode, Integer>builder()
.put(ProjectRoleCode.WORKER, 1)
.put(ProjectRoleCode.MANAGER, 2)
.put(ProjectRoleCode.APPROVER, 3)
.put(ProjectRoleCode.OBSERVER, 4).build();
@Override
public int compare(ProjectRole o1, ProjectRole o2) {
ProjectRoleCode code1 = o1.getCode();
ProjectRoleCode code2 = o2.getCode();
Integer order1 = order.get(code1);
Integer order2 = order.get(code2);
return ObjectUtils.compare(order1, order2);
}
});
}