org.apache.commons.lang.ObjectUtils Java Examples
The following examples show how to use
org.apache.commons.lang.ObjectUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void test3() { String input = "a;b; c;\"d;\"\"e\";f; ; ;"; StrTokenizer tok = new StrTokenizer(input); tok.setDelimiterChar(';'); tok.setQuoteChar('"'); tok.setIgnoredMatcher(StrMatcher.noneMatcher()); tok.setIgnoreEmptyTokens(false); String tokens[] = tok.getTokenArray(); String expected[] = new String[]{"a", "b", " c", "d;\"e", "f", " ", " ", "",}; assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); for (int i = 0; i < expected.length; i++) { assertTrue("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", ObjectUtils.equals(expected[i], tokens[i])); } }
Example #2
Source File: ConvertorHelper.java From tddl with Apache License 2.0 | 6 votes |
private void initCommonTypes() { commonTypes.put(int.class, ObjectUtils.NULL); commonTypes.put(Integer.class, ObjectUtils.NULL); commonTypes.put(short.class, ObjectUtils.NULL); commonTypes.put(Short.class, ObjectUtils.NULL); commonTypes.put(long.class, ObjectUtils.NULL); commonTypes.put(Long.class, ObjectUtils.NULL); commonTypes.put(boolean.class, ObjectUtils.NULL); commonTypes.put(Boolean.class, ObjectUtils.NULL); commonTypes.put(byte.class, ObjectUtils.NULL); commonTypes.put(Byte.class, ObjectUtils.NULL); commonTypes.put(char.class, ObjectUtils.NULL); commonTypes.put(Character.class, ObjectUtils.NULL); commonTypes.put(float.class, ObjectUtils.NULL); commonTypes.put(Float.class, ObjectUtils.NULL); commonTypes.put(double.class, ObjectUtils.NULL); commonTypes.put(Double.class, ObjectUtils.NULL); commonTypes.put(BigDecimal.class, ObjectUtils.NULL); commonTypes.put(BigInteger.class, ObjectUtils.NULL); }
Example #3
Source File: DataService.java From canal-mongo with Apache License 2.0 | 6 votes |
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); } }
Example #4
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void test7() { String input = "a b c \"d e\" f "; StrTokenizer tok = new StrTokenizer(input); tok.setDelimiterMatcher(StrMatcher.spaceMatcher()); tok.setQuoteMatcher(StrMatcher.doubleQuoteMatcher()); tok.setIgnoredMatcher(StrMatcher.noneMatcher()); tok.setIgnoreEmptyTokens(false); String tokens[] = tok.getTokenArray(); String expected[] = new String[]{"a", "", "", "b", "c", "d e", "f", "",}; assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); for (int i = 0; i < expected.length; i++) { assertTrue("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", ObjectUtils.equals(expected[i], tokens[i])); } }
Example #5
Source File: KostZuweisungDO.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Override public boolean equals(final Object o) { if (o instanceof KostZuweisungDO) { final KostZuweisungDO other = (KostZuweisungDO) o; if (ObjectUtils.equals(this.getIndex(), other.getIndex()) == false) return false; if (ObjectUtils.equals(this.getRechnungsPositionId(), other.getRechnungsPositionId()) == false) return false; if (ObjectUtils.equals(this.getEingangsrechnungsPositionId(), other.getEingangsrechnungsPositionId()) == false) return false; if (ObjectUtils.equals(this.getEmployeeSalaryId(), other.getEmployeeSalaryId()) == false) return false; return true; } return false; }
Example #6
Source File: TeamEventRight.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
/** * Owners of the given calendar and users with full and read-only access have update access to the given calendar: obj.getCalendar(). * @see org.projectforge.user.UserRightAccessCheck#hasHistoryAccess(org.projectforge.user.PFUserDO, java.lang.Object) */ @Override public boolean hasHistoryAccess(final PFUserDO user, final TeamEventDO obj) { if (obj == null) { return true; } final TeamCalDO calendar = obj.getCalendar(); if (calendar == null) { return false; } if (ObjectUtils.equals(user.getId(), calendar.getOwnerId()) == true) { // User has full access to it's own calendars. return true; } final Integer userId = user.getId(); if (teamCalRight.hasFullAccess(calendar, userId) == true || teamCalRight.hasReadonlyAccess(calendar, userId) == true) { return true; } return false; }
Example #7
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void test8() { String input = "a b c \"d e\" f "; StrTokenizer tok = new StrTokenizer(input); tok.setDelimiterMatcher(StrMatcher.spaceMatcher()); tok.setQuoteMatcher(StrMatcher.doubleQuoteMatcher()); tok.setIgnoredMatcher(StrMatcher.noneMatcher()); tok.setIgnoreEmptyTokens(true); String tokens[] = tok.getTokenArray(); String expected[] = new String[]{"a", "b", "c", "d e", "f",}; assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); for (int i = 0; i < expected.length; i++) { assertTrue("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", ObjectUtils.equals(expected[i], tokens[i])); } }
Example #8
Source File: PropertyStateSupport.java From ymate-platform-v2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public T bind() { if (__bound == null) { __bound = (T) ClassUtils.wrapper(__source).duplicate(Enhancer.create(__targetClass, new MethodInterceptor() { @Override public Object intercept(Object targetObject, Method targetMethod, Object[] methodParams, MethodProxy methodProxy) throws Throwable { PropertyStateMeta _meta = __propertyStates.get(targetMethod.getName()); if (_meta != null && ArrayUtils.isNotEmpty(methodParams) && !ObjectUtils.equals(_meta.getOriginalValue(), methodParams[0])) { if (__ignoreNull && methodParams[0] == null) { methodParams[0] = _meta.getOriginalValue(); } _meta.setNewValue(methodParams[0]); } return methodProxy.invokeSuper(targetObject, methodParams); } })); } return __bound; }
Example #9
Source File: XdsSymbolParser.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Replaces static reference to the symbols by the dynamic ones. */ protected void replaceStaticRefs() { for (IProxyReference<IModulaSymbol> proxyRef : symbolReferences) { Assert.isTrue(proxyRef.getReference() instanceof IStaticModulaSymbolReference<?>); IModulaSymbol staticSymbol = proxyRef.resolve(); IModulaSymbolReference<IModulaSymbol> dynamicRef = ReferenceFactory.createRef(staticSymbol); proxyRef.setReference(dynamicRef); if (CHECK_REFERENCE_INTEGRITY) { IModulaSymbol dynamicSymbol = ReferenceUtils.resolve(dynamicRef); if (!(staticSymbol instanceof IInvalidModulaSymbol) && !ObjectUtils.equals(staticSymbol, dynamicSymbol)) { System.out.println("-- staticSymbol: " + staticSymbol.getQualifiedName() ); String message = String.format( REFERENCE_IS_RESOLVED_INCORRECTLY_MSG_BASE + REFERENCE_IS_RESOLVED_INCORRECTLY_MSG_DETAILS, dynamicRef, staticSymbol, dynamicSymbol ); error(staticSymbol.getPosition(), staticSymbol.getName().length(), message); } } } symbolReferences.clear(); }
Example #10
Source File: HRPlanningEntryDO.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Override public boolean equals(Object o) { if (o instanceof HRPlanningEntryDO) { HRPlanningEntryDO other = (HRPlanningEntryDO) o; if (this.getId() != null || other.getId() != null) { return ObjectUtils.equals(this.getId(), other.getId()); } if (ObjectUtils.equals(this.getPlanningId(), other.getPlanningId()) == false) return false; if (ObjectUtils.equals(this.getProjektId(), other.getProjektId()) == false) return false; if (ObjectUtils.equals(this.getStatus(), other.getStatus()) == false) return false; return true; } return false; }
Example #11
Source File: DocumentSearchCriteriaTranslatorImpl.java From rice with Educational Community License v2.0 | 6 votes |
/** * Looks up a property on the criteria object and sets it as a key/value pair in the values Map * @param criteria the DocumentSearchCriteria * @param property the DocumentSearchCriteria property name * @param fieldName the destination field name * @param values the map of values to update */ protected static void convertCriteriaPropertyToField(DocumentSearchCriteria criteria, String property, String fieldName, Map<String, String[]> values) { try { Object val = PropertyUtils.getProperty(criteria, property); if (val != null) { values.put(fieldName, new String[] { ObjectUtils.toString(val) }); } } catch (NoSuchMethodException nsme) { LOG.error("Error reading property '" + property + "' of criteria", nsme); } catch (InvocationTargetException ite) { LOG.error("Error reading property '" + property + "' of criteria", ite); } catch (IllegalAccessException iae) { LOG.error("Error reading property '" + property + "' of criteria", iae); } }
Example #12
Source File: DefaultResolvedDependency.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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 = artifact1.getExtension().compareTo(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(); }
Example #13
Source File: WeatherTokenResolver.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Replaces the token with properties of the weather LocationConfig object. */ private String replaceConfig(Token token) { LocationConfig locationConfig = WeatherContext.getInstance().getConfig().getLocationConfig(locationId); if (locationConfig == null) { throw new RuntimeException("Weather locationId '" + locationId + "' does not exist"); } if ("latitude".equals(token.name)) { return locationConfig.getLatitude().toString(); } else if ("longitude".equals(token.name)) { return locationConfig.getLongitude().toString(); } else if ("name".equals(token.name)) { return locationConfig.getName(); } else if ("language".equals(token.name)) { return locationConfig.getLanguage(); } else if ("updateInterval".equals(token.name)) { return ObjectUtils.toString(locationConfig.getUpdateInterval()); } else if ("locationId".equals(token.name)) { return locationConfig.getLocationId(); } else if ("providerName".equals(token.name)) { return ObjectUtils.toString(locationConfig.getProviderName()); } else { throw new RuntimeException("Invalid weather token: " + token.full); } }
Example #14
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void test5() { String input = "a;b; c;\"d;\"\"e\";f; ; ;"; StrTokenizer tok = new StrTokenizer(input); tok.setDelimiterChar(';'); tok.setQuoteChar('"'); tok.setIgnoredMatcher(StrMatcher.trimMatcher()); tok.setIgnoreEmptyTokens(false); tok.setEmptyTokenAsNull(true); String tokens[] = tok.getTokenArray(); String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", null, null, null,}; assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); for (int i = 0; i < expected.length; i++) { assertTrue("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", ObjectUtils.equals(expected[i], tokens[i])); } }
Example #15
Source File: DefaultResolvedDependency.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 = artifact1.getExtension().compareTo(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(); }
Example #16
Source File: SkillRatingRight.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Override public boolean hasAccess(final PFUserDO user, final SkillRatingDO obj, final SkillRatingDO oldObj, final OperationType operationType) { final SkillRatingDO skill = (oldObj != null) ? oldObj : obj; if (skill == null) { return true; // General insert and select access given by default. } switch (operationType) { case SELECT: case INSERT: // Everyone is allowed to read and create skillratings return true; case UPDATE: case DELETE: // Only owner is allowed to edit his skillratings return ObjectUtils.equals(user.getId(), skill.getUserId()); default: return false; } }
Example #17
Source File: AbstractPredicateUtil.java From ranger with Apache License 2.0 | 6 votes |
@Override public int compare(RangerBaseModelObject o1, RangerBaseModelObject o2) { String val1 = null; String val2 = null; if(o1 != null) { if(o1 instanceof RangerServiceDef) { val1 = ((RangerServiceDef)o1).getName(); } else if(o1 instanceof RangerService) { val1 = ((RangerService)o1).getType(); } } if(o2 != null) { if(o2 instanceof RangerServiceDef) { val2 = ((RangerServiceDef)o2).getName(); } else if(o2 instanceof RangerService) { val2 = ((RangerService)o2).getType(); } } return ObjectUtils.compare(val1, val2); }
Example #18
Source File: ConvertorHelper.java From tddl5 with Apache License 2.0 | 6 votes |
private void initCommonTypes() { commonTypes.put(int.class, ObjectUtils.NULL); commonTypes.put(Integer.class, ObjectUtils.NULL); commonTypes.put(short.class, ObjectUtils.NULL); commonTypes.put(Short.class, ObjectUtils.NULL); commonTypes.put(long.class, ObjectUtils.NULL); commonTypes.put(Long.class, ObjectUtils.NULL); commonTypes.put(boolean.class, ObjectUtils.NULL); commonTypes.put(Boolean.class, ObjectUtils.NULL); commonTypes.put(byte.class, ObjectUtils.NULL); commonTypes.put(Byte.class, ObjectUtils.NULL); commonTypes.put(char.class, ObjectUtils.NULL); commonTypes.put(Character.class, ObjectUtils.NULL); commonTypes.put(float.class, ObjectUtils.NULL); commonTypes.put(Float.class, ObjectUtils.NULL); commonTypes.put(double.class, ObjectUtils.NULL); commonTypes.put(Double.class, ObjectUtils.NULL); commonTypes.put(BigDecimal.class, ObjectUtils.NULL); commonTypes.put(BigInteger.class, ObjectUtils.NULL); }
Example #19
Source File: CcuClient.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public void setDatapointValue(HmDatapoint dp, String datapointName, Object value) throws HomematicClientException { HmInterface hmInterface = dp.getChannel().getDevice().getHmInterface(); if (hmInterface == HmInterface.VIRTUALDEVICES) { String groupName = HmInterface.VIRTUALDEVICES + "." + dp.getChannel().getAddress() + "." + datapointName; if (dp.isIntegerValue() && value instanceof Double) { value = ((Number) value).intValue(); } String strValue = ObjectUtils.toString(value); if (dp.isStringValue()) { strValue = "\"" + strValue + "\""; } HmResult result = sendScriptByName("setVirtualGroup", HmResult.class, new String[] { "group_name", "group_state" }, new String[] { groupName, strValue }); if (!result.isValid()) { throw new HomematicClientException("Unable to set CCU group " + groupName); } } else { super.setDatapointValue(dp, datapointName, value); } }
Example #20
Source File: SysMenuController.java From microservices-platform with Apache License 2.0 | 6 votes |
/** * 两层循环实现建树 * * @param sysMenus * @return */ public static List<SysMenu> treeBuilder(List<SysMenu> sysMenus) { List<SysMenu> menus = new ArrayList<>(); for (SysMenu sysMenu : sysMenus) { if (ObjectUtils.equals(-1L, sysMenu.getParentId())) { menus.add(sysMenu); } for (SysMenu menu : sysMenus) { if (menu.getParentId().equals(sysMenu.getId())) { if (sysMenu.getSubMenus() == null) { sysMenu.setSubMenus(new ArrayList<>()); } sysMenu.getSubMenus().add(menu); } } } return menus; }
Example #21
Source File: ObjectUtil.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Determine if they have the same values in the specified fields * * @param targetObject the target object * @param sourceObject the source object * @param keyFields the specified fields * @return true if the two objects have the same values in the specified fields; otherwise, false */ public static boolean equals(Object targetObject, Object sourceObject, List<String> keyFields) { if (targetObject == sourceObject) { return true; } if (targetObject == null || sourceObject == null) { return false; } for (String propertyName : keyFields) { try { Object propertyValueOfSource = PropertyUtils.getProperty(sourceObject, propertyName); Object propertyValueOfTarget = PropertyUtils.getProperty(targetObject, propertyName); if (!ObjectUtils.equals(propertyValueOfSource, propertyValueOfTarget)) { return false; } } catch (Exception e) { LOG.info(e); return false; } } return true; }
Example #22
Source File: TeamCalDOConverter.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
public static CalendarObject getCalendarObject(final TeamCalDO src) { if (src == null) { return null; } final Integer userId = PFUserContext.getUserId(); final CalendarObject cal = new CalendarObject(); DOConverter.copyFields(cal, src); cal.setTitle(src.getTitle()); cal.setDescription(src.getDescription()); cal.setExternalSubscription(src.isExternalSubscription()); final TeamCalRight right = (TeamCalRight) UserRights.instance().getRight(TeamCalDao.USER_RIGHT_ID); cal.setMinimalAccess(right.hasMinimalAccess(src, userId)); cal.setReadonlyAccess(right.hasReadonlyAccess(src, userId)); cal.setFullAccess(right.hasFullAccess(src, userId)); cal.setOwner(ObjectUtils.equals(userId, src.getOwnerId())); return cal; }
Example #23
Source File: PlugwiseBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void setupNonStickDevices(Dictionary<String, ?> config) { Set<String> deviceNames = getDeviceNamesFromConfig(config); for (String deviceName : deviceNames) { if ("stick".equals(deviceName)) { continue; } if (stick.getDeviceByName(deviceName) != null) { continue; } String MAC = ObjectUtils.toString(config.get(deviceName + ".mac"), null); if (MAC == null || MAC.equals("")) { logger.warn("Plugwise cannot add device with name {} without a MAC address", deviceName); } else if (stick.getDeviceByMAC(MAC) != null) { logger.warn( "Plugwise cannot add device with name: {} and MAC address: {}, " + "the same MAC address is already used by device with name: {}", deviceName, MAC, stick.getDeviceByMAC(MAC).name); } else { String deviceType = ObjectUtils.toString(config.get(deviceName + ".type"), null); PlugwiseDevice device = createPlugwiseDevice(deviceType, MAC, deviceName); if (device != null) { stick.addDevice(device); } } } }
Example #24
Source File: SubQueryPreProcessor.java From tddl5 with Apache License 2.0 | 5 votes |
private static IBooleanFilter buildConstanctFilter(Object constant, String alias) { IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter(); f.setOperation(OPERATION.CONSTANT); f.setColumn(constant); f.setColumnName(ObjectUtils.toString(constant)); f.setAlias(alias); return f; }
Example #25
Source File: ValidatingMavenPublisher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void checkNotDuplicate(MavenNormalizedPublication publication, Set<MavenArtifact> artifacts, String extension, String classifier) { for (MavenArtifact artifact : artifacts) { if (ObjectUtils.equals(artifact.getExtension(), extension) && ObjectUtils.equals(artifact.getClassifier(), classifier)) { String message = String.format( "multiple artifacts with the identical extension and classifier ('%s', '%s').", extension, classifier ); throw new InvalidMavenPublicationException(publication.getName(), message); } } }
Example #26
Source File: ModulaEditor.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void buildSettingsReload(IProject p) { IEditorInput editorInput = getEditorInput(); if (ObjectUtils.equals(p, CoreEditorUtils.getIProjectFrom(editorInput))) { ParseTask parseTask = ParseTaskFactory.create(editorInput); parseTask.setNeedModulaAst(true); SymbolModelManager.instance().scheduleParse(parseTask, null); } }
Example #27
Source File: BasicExecutionEnvironment.java From rice with Educational Community License v2.0 | 5 votes |
@Override public boolean publishFact(Term factName, Object factValue) { if (facts.containsKey(factName) && ObjectUtils.equals(facts.get(factName), factValue)) { return false; } facts.put(factName, factValue); termResolutionEngine.addTermValue(factName, factValue); return true; }
Example #28
Source File: SLDTreeItemWrapper.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Generate a unique key. * * @param sldItem the sld item * @return the string */ public static String generateKey(Object sldItem) { if (sldItem == null) { return NULL_VALUE; } return ObjectUtils.identityToString(sldItem); }
Example #29
Source File: right_IssueSearch_1.66.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
/** * Set the value of stateChangeFromDate. * @param v Value to assign to stateChangeFromDate. */ public void setStateChangeFromDate(String v) { if ( v != null && v.length() == 0 ) { v = null; } if (!ObjectUtils.equals(v, this.stateChangeFromDate)) { modified = true; this.stateChangeFromDate = v; } }
Example #30
Source File: TaskNode.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * Sets the task group access to this task node for the given group. Removes any previous stored GroupTaskAccessDO for the same group if * exists. Multiple GroupTaskAccessDO entries for one group will be avoided. * @param GroupTaskAccessDO */ void setGroupTaskAccess(final GroupTaskAccessDO groupTaskAccess) { Validate.isTrue(ObjectUtils.equals(this.getTaskId(), groupTaskAccess.getTaskId()) == true); // TODO: Should be called after update and insert into database. if (log.isInfoEnabled() == true) { log.debug("Set explicit access, taskId = " + getTaskId() + ", groupId = " + groupTaskAccess.getGroupId()); } synchronized (groupTaskAccessList) { removeGroupTaskAccess(groupTaskAccess.getGroupId()); groupTaskAccessList.add(groupTaskAccess); } }