本文整理匯總了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);
}
});
}