org.apache.commons.lang3.ObjectUtils Java Examples
The following examples show how to use
org.apache.commons.lang3.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: DynProperty.java From gvnix with GNU General Public License v3.0 | 6 votes |
/** * {@inheritDoc} Two properties are equal if their key and value are equals. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } DynProperty other = (DynProperty) obj; if (!ObjectUtils.equals(key, other.key)) { return false; } if (!ObjectUtils.equals(value, other.value)) { return false; } return true; }
Example #2
Source File: AnyTypeRestClient.java From syncope with Apache License 2.0 | 6 votes |
@Override public int compare(final AnyTypeTO o1, final AnyTypeTO o2) { if (o1.getKind() == AnyTypeKind.USER) { return -1; } if (o2.getKind() == AnyTypeKind.USER) { return 1; } if (o1.getKind() == AnyTypeKind.GROUP) { return -1; } if (o2.getKind() == AnyTypeKind.GROUP) { return 1; } return ObjectUtils.compare(o1.getKey(), o2.getKey()); }
Example #3
Source File: MappingCompiler.java From jsonix-schema-compiler with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("deprecation") private JSMemberExpression createNameExpression(final QName name, final String defaultNamespaceURI) { final String draftNamespaceURI = name.getNamespaceURI(); final String namespaceURI = StringUtils.isEmpty(draftNamespaceURI) ? null : draftNamespaceURI; if (ObjectUtils.equals(defaultNamespaceURI, namespaceURI)) { return this.codeModel.string(name.getLocalPart()); } else { final JSObjectLiteral nameExpression = this.codeModel.object(); nameExpression.append(naming.localPart(), this.codeModel.string(name.getLocalPart())); if (!StringUtils.isEmpty(namespaceURI)) { nameExpression.append(naming.namespaceURI(), this.codeModel.string(namespaceURI)); } return nameExpression; } }
Example #4
Source File: AnyTypeRestClient.java From syncope with Apache License 2.0 | 6 votes |
@Override public int compare(final String o1, final String o2) { if (SyncopeConstants.REALM_ANYTYPE.equals(o1)) { return -1; } if (SyncopeConstants.REALM_ANYTYPE.equals(o2)) { return 1; } if (AnyTypeKind.USER.name().equals(o1)) { return -1; } if (AnyTypeKind.USER.name().equals(o2)) { return 1; } if (AnyTypeKind.GROUP.name().equals(o1)) { return -1; } if (AnyTypeKind.GROUP.name().equals(2)) { return 1; } return ObjectUtils.compare(o1, o2); }
Example #5
Source File: DefaultOrganisationUnitService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @Transactional( readOnly = true ) public List<OrganisationUnitLevel> getFilledOrganisationUnitLevels() { Map<Integer, OrganisationUnitLevel> levelMap = getOrganisationUnitLevelMap(); List<OrganisationUnitLevel> levels = new ArrayList<>(); int levelNo = getNumberOfOrganisationalLevels(); for ( int i = 0; i < levelNo; i++ ) { int level = i + 1; OrganisationUnitLevel filledLevel = ObjectUtils.firstNonNull( levelMap.get( level ), new OrganisationUnitLevel( level, LEVEL_PREFIX + level ) ); levels.add( filledLevel ); } return levels; }
Example #6
Source File: ConfigurationSubscriptionService.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Override protected ConfigurationSubscriptionDto merge(ConfigurationSubscriptionDto existingSubscription, ConfigurationSubscriptionDto newSubscription) { super.merge(existingSubscription, newSubscription); String mtaId = ObjectUtils.firstNonNull(newSubscription.getMtaId(), existingSubscription.getMtaId()); String appName = ObjectUtils.firstNonNull(newSubscription.getAppName(), existingSubscription.getAppName()); String spaceId = ObjectUtils.firstNonNull(newSubscription.getSpaceId(), existingSubscription.getSpaceId()); String filter = ObjectUtils.firstNonNull(newSubscription.getFilter(), existingSubscription.getFilter()); String moduleContent = ObjectUtils.firstNonNull(newSubscription.getModuleContent(), existingSubscription.getModuleContent()); String resourceProperties = ObjectUtils.firstNonNull(newSubscription.getResourceProperties(), existingSubscription.getResourceProperties()); String resourceName = ObjectUtils.firstNonNull(newSubscription.getResourceName(), existingSubscription.getResourceName()); return ConfigurationSubscriptionDto.builder() .id(newSubscription.getPrimaryKey()) .mtaId(mtaId) .spaceId(spaceId) .appName(appName) .filter(filter) .module(moduleContent) .resourceName(resourceName) .resourceProperties(resourceProperties) .build(); }
Example #7
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 #8
Source File: KeyEventSetpDefinitions.java From IridiumApplicationTesting with MIT License | 6 votes |
/** * Press the delete key on the active element. This step is known to have issues with * the Firefox Marionette driver. * @param times The number of times to press the delete key * @param ignoreErrors Add this text to ignore any exceptions. This is really only useful for debugging. */ @When("^I press(?: the)? Delete(?: key)? on the active element(?: \"(\\d+)\" times)?( ignoring errors)?$") public void pressDeleteStep(final Integer times, final String ignoreErrors) { try { final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); final WebElement element = webDriver.switchTo().activeElement(); for (int i = 0; i < ObjectUtils.defaultIfNull(times, 1); ++i) { element.sendKeys(Keys.DELETE); sleepUtils.sleep(State.getFeatureStateForThread().getDefaultKeyStrokeDelay()); } sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep()); } catch (final Exception ex) { if (StringUtils.isBlank(ignoreErrors)) { throw ex; } } }
Example #9
Source File: ChangeLogSet.java From arcusplatform with Apache License 2.0 | 6 votes |
public static ChangeLogSet fromChangesets(List<ChangeSet> changeSets) { Collections.sort(changeSets, (ChangeSet cs1, ChangeSet cs2) -> ObjectUtils.compare(cs1.getTimestamp(), cs2.getTimestamp())); List<ChangeLog> derivedChangeLogs = new LinkedList<ChangeLog>(); ChangeLog curChangeLog = null; for(ChangeSet cs : changeSets) { if(curChangeLog == null || !cs.getSource().equals(curChangeLog.getSource())) { curChangeLog = new ChangeLog(); curChangeLog.setSource(cs.getSource()); curChangeLog.setVersion(cs.getVersion()); derivedChangeLogs.add(curChangeLog); } curChangeLog.addChangeSet(cs); } return new ChangeLogSet(derivedChangeLogs); }
Example #10
Source File: UidsCookieService.java From prebid-server-java with Apache License 2.0 | 6 votes |
/** * Enriches {@link Uids} parsed from request cookies with uid from host cookie (if applicable) and removes * invalid uids. Also converts legacy uids to uids with expiration. */ private Map<String, UidWithExpiry> enrichAndSanitizeUids(Uids uids, Map<String, String> cookies) { final Map<String, UidWithExpiry> originalUidsMap = uids != null ? uids.getUids() : null; final Map<String, UidWithExpiry> workingUidsMap = new HashMap<>( ObjectUtils.defaultIfNull(originalUidsMap, Collections.emptyMap())); final Map<String, String> legacyUids = uids != null ? uids.getUidsLegacy() : null; if (workingUidsMap.isEmpty() && legacyUids != null) { legacyUids.forEach((key, value) -> workingUidsMap.put(key, UidWithExpiry.expired(value))); } final String hostCookie = parseHostCookie(cookies); if (hostCookie != null && hostCookieDiffers(hostCookie, workingUidsMap.get(hostCookieFamily))) { // make host cookie precedence over uids workingUidsMap.put(hostCookieFamily, UidWithExpiry.live(hostCookie)); } workingUidsMap.entrySet().removeIf(UidsCookieService::facebookSentinelOrEmpty); return workingUidsMap; }
Example #11
Source File: YamlRepresenter.java From multiapps with Apache License 2.0 | 6 votes |
@Override protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) { if (ObjectUtils.isEmpty(propertyValue)) { return null; } Field field = getField(javaBean.getClass(), property.getName()); String nodeName = field.isAnnotationPresent(YamlElement.class) ? field.getAnnotation(YamlElement.class) .value() : property.getName(); if (field.isAnnotationPresent(YamlAdapter.class)) { return getAdaptedTuple(propertyValue, field, nodeName); } NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); return new NodeTuple(representData(nodeName), defaultNode.getValueNode()); }
Example #12
Source File: SysUserServiceImpl.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@Override public PageResult<SysUser> findUsers(Map<String, Object> params) { int total = sysUserDao.count(params); List<SysUser> list = Collections.emptyList(); if (total > 0) { PageUtil.pageParamConver(params, true); list = sysUserDao.findList(params); List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList()); List<SysRole> sysRoles = userRoleDao.findRolesByUserIds(userIds); list.forEach(u -> { u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId())) .collect(Collectors.toList())); }); } return PageResult.<SysUser>builder().data(list).code(0).count((long)total).build(); }
Example #13
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void test2() { 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 #14
Source File: OperationsTransformer.java From spring-openapi with MIT License | 6 votes |
private void mapRequestMapping(RequestMapping requestMapping, Method method, Map<String, Path> operationsMap, String controllerClassName, String baseControllerPath) { List<HttpMethod> httpMethods = Arrays.stream(requestMapping.method()) .map(this::getSpringMethod) .collect(toList()); httpMethods.forEach(httpMethod -> { Operation operation = mapOperation(requestMapping.name(), httpMethod, method, requestMapping.produces(), requestMapping.consumes(), controllerClassName); String path = ObjectUtils.defaultIfNull(getFirstFromArray(requestMapping.value()), getFirstFromArray(requestMapping.path())); updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> setContentBasedOnHttpMethod(pathItem, httpMethod, operation) ); }); }
Example #15
Source File: ValueMap.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Convert a value to a {@link Long} (if possible). * @param value a value * @return an {@link Optional} containing a {@link Long} or empty if * the value could not be converted. */ public Optional<Long> toLong(Object value) { if (value instanceof Double) { return Optional.of(((Double)value).longValue()); } else if (value instanceof Long) { return Optional.of((Long)value); } else if (value instanceof Integer) { return Optional.of(((Integer)value).longValue()); } else if (value instanceof String) { try { return Optional.of(Long.parseLong((String) value)); } catch (NumberFormatException e) { LOG.warn("Error converting '" + value + "' to long", e); return Optional.empty(); } } else { LOG.warn("Value '" + ObjectUtils.toString(value) + "' could not be converted to long."); return Optional.empty(); } }
Example #16
Source File: StrTokenizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void test4() { String input = "a;b; c;\"d;\"\"e\";f; ; ;"; StrTokenizer tok = new StrTokenizer(input); tok.setDelimiterChar(';'); tok.setQuoteChar('"'); tok.setIgnoredMatcher(StrMatcher.trimMatcher()); 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 #17
Source File: TableDataHomology.java From morf with Apache License 2.0 | 6 votes |
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) { @SuppressWarnings({ "rawtypes" }) Comparable value1 = convertToComparableType(keyCol, record1.get()); @SuppressWarnings({ "rawtypes" }) Comparable value2 = convertToComparableType(keyCol, record2.get()); @SuppressWarnings("unchecked") int result = ObjectUtils.compare(value1, value2); if (result != 0) { return result; } } return 0; }
Example #18
Source File: TestITCHHelper.java From sailfish-core with Apache License 2.0 | 5 votes |
protected static ITCHCodec getCodec(MessageHelper helper) throws IOException { ITCHCodec codec = new ITCHCodec(); ITCHCodecSettings settings = new ITCHCodecSettings(); IDictionaryStructure dictionary = helper.getDictionaryStructure(); Integer msgLength = ObjectUtils.defaultIfNull(ITCHMessageHelper.extractLengthSize(dictionary), 1); settings.setMsgLength(msgLength); settings.setDictionaryURI(SailfishURI.unsafeParse(dictionary.getNamespace())); codec.init(serviceContext, settings, msgFactory, dictionary); return codec; }
Example #19
Source File: BlueprintService.java From cloudbreak with Apache License 2.0 | 5 votes |
public PlatformRecommendation getRecommendation(Long workspaceId, String blueprintName, String credentialName, String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType) { if (!ObjectUtils.allNotNull(region)) { throw new BadRequestException("region cannot be null"); } return cloudResourceAdvisor.createForBlueprint(workspaceId, blueprintName, credentialName, region, platformVariant, availabilityZone, cdpResourceType); }
Example #20
Source File: ResourceLimit.java From mr4c with Apache License 2.0 | 5 votes |
public boolean equals(Object obj) { if ( this==obj ) return true; if ( !obj.getClass().equals(this.getClass()) ) return false; ResourceLimit limit = (ResourceLimit) obj; if ( !ObjectUtils.equals(m_resource, limit.m_resource) ) return false; if ( !ObjectUtils.equals(m_value, limit.m_value) ) return false; if ( !ObjectUtils.equals(m_source, limit.m_source) ) return false; return true; }
Example #21
Source File: Cvar.java From riiablo with Apache License 2.0 | 5 votes |
public void reset() { if (!ObjectUtils.equals(value, DEFAULT_VALUE)) { T prev = value; value = DEFAULT_VALUE; for (StateListener<T> l : STATE_LISTENERS) l.onChanged(this, prev, value); } }
Example #22
Source File: FreeIpaBackupConfigView.java From cloudbreak with Apache License 2.0 | 5 votes |
@SuppressWarnings("ExecutableStatementCount") public Map<String, Object> toMap() { Map<String, Object> map = new HashMap<>(); map.put("enabled", enabled); map.put("location", ObjectUtils.defaultIfNull(location, EMPTY_CONFIG_DEFAULT)); map.put("monthly_full_enabled", monthlyFullEnabled); map.put("hourly_enabled", hourlyEnabled); map.put("initial_full_enabled", initialFullEnabled); map.put("platform", ObjectUtils.defaultIfNull(platform, EMPTY_CONFIG_DEFAULT)); map.put("azure_instance_msi", ObjectUtils.defaultIfNull(azureInstanceMsi, EMPTY_CONFIG_DEFAULT)); map.put("http_proxy", ObjectUtils.defaultIfNull(proxyUrl, EMPTY_CONFIG_DEFAULT)); map.put("aws_region", ObjectUtils.defaultIfNull(awsRegion, EMPTY_CONFIG_DEFAULT)); return map; }
Example #23
Source File: MenuFragment.java From line-sdk-android with Apache License 2.0 | 5 votes |
private void setSelectedUILocale(@Nullable Locale locale) { String localeStr = ObjectUtils.toString(locale, null); int index = locales.indexOf(localeStr); if (index < 0) { index = 0; } uiLocaleSpinner.setSelection(index); }
Example #24
Source File: StrBuilder.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Appends an array placing separators between each value, but * not before the first or after the last. * Appending a null array will have no effect. * Each object is appended using {@link #append(Object)}. * * @param array the array to append * @param separator the separator to use, null means no separator * @return this, to enable chaining */ public StrBuilder appendWithSeparators(Object[] array, String separator) { if (array != null && array.length > 0) { separator = ObjectUtils.toString(separator); append(array[0]); for (int i = 1; i < array.length; i++) { append(separator); append(array[i]); } } return this; }
Example #25
Source File: ZkUtils.java From GoPush with GNU General Public License v2.0 | 5 votes |
/** * 检查节点是否存在 * * @param path * @return */ public Stat exists(String path) { if (!ObjectUtils.allNotNull(zkClient, path)) { return null; } try { return zkClient.checkExists().forPath(path); } catch (Exception e) { log.error("check node exists fail! path: {}, error: {}", path, e); } return null; }
Example #26
Source File: ExchangeService.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Check whether the User fields should be changed. */ private static boolean checkUserFieldsHavingValue(User user) { final boolean hasUser = user != null; final String keywords = hasUser ? user.getKeywords() : null; final String gender = hasUser ? user.getGender() : null; final Integer yob = hasUser ? user.getYob() : null; final Geo geo = hasUser ? user.getGeo() : null; final ObjectNode ext = hasUser ? user.getExt() : null; return ObjectUtils.anyNotNull(keywords, gender, yob, geo, ext); }
Example #27
Source File: DatabaseMessageStorage.java From sailfish-core with Apache License 2.0 | 5 votes |
private long getFirstMessageID(Session session, String serviceID) { String hql = "select msg.id from StoredMessage msg"; if(serviceID != null) { hql += " where msg.serviceId = :serviceID"; } Query query = session.createQuery(hql + " order by msg.id asc"); if(serviceID != null) { query.setString("serviceID", serviceID); } return (long)ObjectUtils.defaultIfNull(query.setMaxResults(1).uniqueResult(), -1L); }
Example #28
Source File: BaseNotify4MchPay.java From xxpay-master with MIT License | 5 votes |
/** * 处理支付结果后台服务器通知 */ public void doNotify(PayOrder payOrder, boolean isFirst) { _log.info(">>>>>> PAY开始回调通知业务系统 <<<<<<"); // 发起后台通知业务系统 JSONObject object = createNotifyInfo(payOrder, isFirst); try { mq4MchPayNotify.send(object.toJSONString()); } catch (Exception e) { _log.error(e, "payOrderId=%s,sendMessage error.", ObjectUtils.defaultIfNull(payOrder.getPayOrderId(), "")); } _log.info(">>>>>> PAY回调通知业务系统完成 <<<<<<"); }
Example #29
Source File: Triple.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Compares this triple to another based on the three elements.</p> * * @param obj the object to compare to, null returns false * @return true if the elements of the triple are equal */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof Triple<?, ?, ?>) { final Triple<?, ?, ?> other = (Triple<?, ?, ?>) obj; return ObjectUtils.equals(getLeft(), other.getLeft()) && ObjectUtils.equals(getMiddle(), other.getMiddle()) && ObjectUtils.equals(getRight(), other.getRight()); } return false; }
Example #30
Source File: SortTools.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public static void asc(List<?> list, final boolean nullGreater, final String... attributes) throws Exception { Collections.sort(list, new Comparator<Object>() { @SuppressWarnings({ "unchecked", "rawtypes" }) public int compare(Object o1, Object o2) { int c = 0; try { for (String attribute : attributes) { Object p1 = PropertyUtils.getProperty(o1, attribute); Object p2 = PropertyUtils.getProperty(o2, attribute); Comparable c1 = null; Comparable c2 = null; if (null != p1) { c1 = (p1 instanceof Comparable) ? (Comparable) p1 : p1.toString(); } if (null != p2) { c2 = (p2 instanceof Comparable) ? (Comparable) p2 : p2.toString(); } c = ObjectUtils.compare(c1, c2, nullGreater); if (c != 0) { return c; } } } catch (Exception e) { e.printStackTrace(); } return c; } }); }