当前位置: 首页>>代码示例>>Java>>正文


Java Assert.hasLength方法代码示例

本文整理汇总了Java中org.springframework.util.Assert.hasLength方法的典型用法代码示例。如果您正苦于以下问题:Java Assert.hasLength方法的具体用法?Java Assert.hasLength怎么用?Java Assert.hasLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.util.Assert的用法示例。


在下文中一共展示了Assert.hasLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.springframework.util.Assert; //导入方法依赖的package包/类
@PostConstruct
public void init() {
  log.info("Initializing...");
  Assert.hasLength(zkUrl, MiscUtils.missingProperty("zk.url"));
  Assert.notNull(zkRetryInterval, MiscUtils.missingProperty("zk.retry_interval_ms"));
  Assert.notNull(zkConnectionTimeout, MiscUtils.missingProperty("zk.connection_timeout_ms"));
  Assert.notNull(zkSessionTimeout, MiscUtils.missingProperty("zk.session_timeout_ms"));

  log.info("Initializing discovery service using ZK connect string: {}", zkUrl);

  zkNodesDir = zkDir + "/nodes";
  try {
    client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout,
        new RetryForever(zkRetryInterval));
    client.start();
    client.blockUntilConnected();
    cache = new PathChildrenCache(client, zkNodesDir, true);
    cache.getListenable().addListener(this);
    cache.start();
  } catch (Exception e) {
    log.error("Failed to connect to ZK: {}", e.getMessage(), e);
    CloseableUtils.closeQuietly(client);
    throw new RuntimeException(e);
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:26,代码来源:ZkDiscoveryService.java

示例2: encodeUri

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Encodes the given source URI into an encoded String. All various URI components are
 * encoded according to their respective valid character sets.
 * <p><strong>Note</strong> that this method does not attempt to encode "=" and "&"
 * characters in query parameter names and query parameter values because they cannot
 * be parsed in a reliable way. Instead use:
 * <pre class="code">
 * UriComponents uriComponents = UriComponentsBuilder.fromUri("/path?name={value}").buildAndExpand("a=b");
 * String encodedUri = uriComponents.encode().toUriString();
 * </pre>
 * @param uri the URI to be encoded
 * @param encoding the character encoding to encode to
 * @return the encoded URI
 * @throws IllegalArgumentException when the given uri parameter is not a valid URI
 * @throws UnsupportedEncodingException when the given encoding parameter is not supported
 * @deprecated in favor of {@link UriComponentsBuilder}; see note about query param encoding
 */
@Deprecated
public static String encodeUri(String uri, String encoding) throws UnsupportedEncodingException {
	Assert.notNull(uri, "URI must not be null");
	Assert.hasLength(encoding, "Encoding must not be empty");
	Matcher matcher = URI_PATTERN.matcher(uri);
	if (matcher.matches()) {
		String scheme = matcher.group(2);
		String authority = matcher.group(3);
		String userinfo = matcher.group(5);
		String host = matcher.group(6);
		String port = matcher.group(8);
		String path = matcher.group(9);
		String query = matcher.group(11);
		String fragment = matcher.group(13);
		return encodeUriComponents(scheme, authority, userinfo, host, port, path, query, fragment, encoding);
	}
	else {
		throw new IllegalArgumentException("[" + uri + "] is not a valid URI");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:UriUtils.java

示例3: updateGroup

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "updateGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public String updateGroup(String groupId, GroupRequest groupRequest, String username) {
    Assert.hasLength(groupId, "followGroup input is empty");
    Assert.hasLength(username, "followGroup input is empty");

    checkUser(username, groupId);
    Group group = groupRepository.findOne(groupId);
    group.setAbout(groupRequest.getAbout());
    group.setName(groupRequest.getName());
    group.setRelatedGroupIds(groupRequest.getRelatedGroupIds());

    groupRepository.save(group);
    return Constants.OK;

}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:17,代码来源:AdministrativeServiceImpl.java

示例4: retrieveHotStories

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public List<Story> retrieveHotStories(String username, Geolocation geolocation) {
    Assert.notNull(geolocation, "retrieveHotStories input is null");
    Assert.hasLength(username, "retrieveHotStories input is empty or null");

    List<Story> hotStoriesOfUser = new ArrayList<>();
    List<String> followingIds = new ArrayList<>();
    User user = userRepository.findByUsername(username);

    if(user!=null)
        followingIds.addAll(user.getFollowingIds());

    for (String followingsUsername : followingIds) {
        hotStoriesOfUser.addAll(client.getHotStoriesOfUser(followingsUsername));
    }

    List<Story> hotStoriesOfLocation = client.getHotStoriesOfLocation(geolocation.getLatitude(), geolocation.getLongitude());

    List<Story> stories = mergeAndRemoveDuplicates(hotStoriesOfUser, hotStoriesOfLocation);
    Collections.sort(stories, ((o2, o1) -> o1.getComments().size() - o2.getComments().size()));
    return stories;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:23,代码来源:HomepageServiceImpl.java

示例5: retrieveGroup

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@CachePut(cacheNames = "RetrieveGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "retrieveGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public Group retrieveGroup(String groupId) {
    Assert.hasLength(groupId, "retrieveGroup input is empty");
    Group group = groupRepository.findOne(groupId);
    if(group == null){
        logger.warn("No group with id={} was found.", groupId);
        return new Group();
    }
    return group;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:AdministrativeServiceImpl.java

示例6: getStoriesOfGroup

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@CachePut(cacheNames = "HotStoriesOfGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "hotStoriesOfGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public List<Story> getStoriesOfGroup(String groupId) {
    Assert.hasLength(groupId, "Hot stories of group input was null or empty");
    return storyRepository.findHotStoriesOfGroup(groupId);
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:8,代码来源:HotStoriesService.java

示例7: unFollowGroup

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "unfollowGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public String unFollowGroup(String username, String groupId) {
    Assert.hasLength(username, "unFollowGroup input is empty");
    Assert.hasLength(groupId, "unFollowGroup input is empty");

    User user = userRepository.findByUsername(username);
    if (user == null) {
        logger.warn("No user with id={} was found.", username);
        return Constants.NOK;
    }
    if (!user.getFollowingGroupIds().contains(groupId)) {
        logger.warn("User with id={} not subscribed to group with id ={}.", username, groupId);
        return Constants.NOK;
    }

    String groupResponse = groupClient.unFollow(groupId);
    if ((!Constants.OK.equals(groupResponse))) {
        logger.warn("Group {} un-subscription of user {} failed", groupId, username);
        return Constants.NOK;
    }

    user.removeFollowingGroupId(groupId);
    userRepository.save(user);

    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:28,代码来源:AdministrativeServiceImpl.java

示例8: deleteStory

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "fallbackDeleteStory", ignoreExceptions = IllegalArgumentException.class)
public String deleteStory(String storyId, String userId) {
    Assert.hasLength(storyId, "deleteStory input was null or empty");

    Story story = storyRepository.findById(storyId);
    if(!userId.equals(story.getUserId()))
        throw new UnauthorizedUserException("Unauthorized user for this action");

    storyRepository.delete(storyId);
    return Constants.OK;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:13,代码来源:StoryServiceImpl.java

示例9: decode

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Decodes the given encoded source String into an URI. Based on the following rules:
 * <ul>
 * <li>Alphanumeric characters {@code "a"} through {@code "z"}, {@code "A"} through {@code "Z"}, and
 * {@code "0"} through {@code "9"} stay the same.</li>
 * <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
 * <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal representation of the character.</li>
 * </ul>
 * @param source the source string
 * @param encoding the encoding
 * @return the decoded URI
 * @throws IllegalArgumentException when the given source contains invalid encoded sequences
 * @throws UnsupportedEncodingException when the given encoding parameter is not supported
 * @see java.net.URLDecoder#decode(String, String)
 */
public static String decode(String source, String encoding) throws UnsupportedEncodingException {
	Assert.notNull(source, "Source must not be null");
	Assert.hasLength(encoding, "Encoding must not be empty");
	int length = source.length();
	ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
	boolean changed = false;
	for (int i = 0; i < length; i++) {
		int ch = source.charAt(i);
		if (ch == '%') {
			if ((i + 2) < length) {
				char hex1 = source.charAt(i + 1);
				char hex2 = source.charAt(i + 2);
				int u = Character.digit(hex1, 16);
				int l = Character.digit(hex2, 16);
				if (u == -1 || l == -1) {
					throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
				}
				bos.write((char) ((u << 4) + l));
				i += 2;
				changed = true;
			}
			else {
				throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
			}
		}
		else {
			bos.write(ch);
		}
	}
	return (changed ? new String(bos.toByteArray(), encoding) : source);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:UriUtils.java

示例10: afterPropertiesSet

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws IllegalArgumentException {
	Assert.notNull(type, "'type' must not be null");
	Assert.hasLength(hostname, "'hostname' must not be empty");
	Assert.isTrue(port >= 0 && port <= 65535, "'port' out of range: " + port);

	SocketAddress socketAddress = new InetSocketAddress(hostname, port);
	this.proxy = new Proxy(type, socketAddress);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ProxyFactoryBean.java

示例11: encode

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Encodes all URI components using their specific encoding rules, and returns the result as a new
 * {@code UriComponents} instance.
 * @param encoding the encoding of the values contained in this map
 * @return the encoded uri components
 * @throws UnsupportedEncodingException if the given encoding is not supported
 */
@Override
public HierarchicalUriComponents encode(String encoding) throws UnsupportedEncodingException {
	Assert.hasLength(encoding, "Encoding must not be empty");
	if (this.encoded) {
		return this;
	}
	String encodedScheme = encodeUriComponent(getScheme(), encoding, Type.SCHEME);
	String encodedUserInfo = encodeUriComponent(this.userInfo, encoding, Type.USER_INFO);
	String encodedHost = encodeUriComponent(this.host, encoding, getHostType());

	PathComponent encodedPath = this.path.encode(encoding);
	MultiValueMap<String, String> encodedQueryParams =
			new LinkedMultiValueMap<String, String>(this.queryParams.size());
	for (Map.Entry<String, List<String>> entry : this.queryParams.entrySet()) {
		String encodedName = encodeUriComponent(entry.getKey(), encoding, Type.QUERY_PARAM);
		List<String> encodedValues = new ArrayList<String>(entry.getValue().size());
		for (String value : entry.getValue()) {
			String encodedValue = encodeUriComponent(value, encoding, Type.QUERY_PARAM);
			encodedValues.add(encodedValue);
		}
		encodedQueryParams.put(encodedName, encodedValues);
	}
	String encodedFragment = encodeUriComponent(this.getFragment(), encoding, Type.FRAGMENT);
	return new HierarchicalUriComponents(encodedScheme, encodedUserInfo, encodedHost, this.port, encodedPath,
			encodedQueryParams, encodedFragment, true, false);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:HierarchicalUriComponents.java

示例12: retrieveGroupIds

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@CachePut(cacheNames = "RetrieveGroupIds", key = "#username")
@HystrixCommand(fallbackMethod = "retrieveGroupIdsFallback", ignoreExceptions = IllegalArgumentException.class)
public List<String> retrieveGroupIds(String username) {
    Assert.hasLength(username, "retrieveGroupIds input is empty or null");
    if (!userRepository.exists(username)) {
        logger.warn("No user with id={} was found.", username);
        return new ArrayList<>();
    }

    List<String> followingGroupIds = userRepository.getGroupIdsByUsername(username).getFollowingGroupIds();
    return followingGroupIds;
}
 
开发者ID:nicolasmanic,项目名称:Facegram,代码行数:14,代码来源:AdministrativeServiceImpl.java

示例13: checkHasLength

import org.springframework.util.Assert; //导入方法依赖的package包/类
public static String checkHasLength(String value) {
 Assert.hasLength(value);
 return value;
}
 
开发者ID:innodev-au,项目名称:wmboost-data,代码行数:5,代码来源:Preconditions.java

示例14: loadBible

import org.springframework.util.Assert; //导入方法依赖的package包/类
private void loadBible(BibleDTO bibleDTO) {
    String line;
    String cvsSplitBy = "\\|\\|";

    try (BufferedReader br = new BufferedReader(new FileReader(new ClassPathResource(bibleDTO.getFileName()).getFile()))) {
        while ((line = br.readLine()) != null) {
            // use comma as separator
            String[] lineContent = line.split(cvsSplitBy);

            Assert.isTrue(lineContent.length == 3 || lineContent.length == 4, "lineContent has wrong length for input line: " + line);

            // BookDTO e.g. 42N or 03O
            Assert.hasLength(lineContent[0], "lineContent[0] is empty");
            int bookNumber = Integer.parseInt(lineContent[0].substring(0, 2));
            String testament = lineContent[0].substring(2, 3);

            // ChapterDTO
            Assert.hasLength(lineContent[1], "lineContent[1] is empty");
            int chapterNumber = Integer.parseInt(lineContent[1]);

            // VerseDTO
            Assert.hasLength(lineContent[2], "lineContent[2] is empty");
            int verseNumber = Integer.parseInt(lineContent[2]);

            // VerseDTO text
            String text;
            if (lineContent.length == 3) {
                text = "";
            } else {
                Assert.hasLength(lineContent[3], "lineContent[3] is empty");
                text = lineContent[3];
            }

            // Create BookDTO object
            BookDTO bookDTO = bibleDTO.getOrCreateBook(bookNumber);

            // Create ChapterDTO object
            ChapterDTO chapterDTO = bookDTO.getOrCreateChapter(chapterNumber);

            // Create VerseDTO object
            VerseDTO verseDTO = chapterDTO.getOrCreateVerse(verseNumber);

            verseDTO.setChapterDTO(chapterDTO);
            verseDTO.setText(text);

            verseDTO.setChapterDTO(chapterDTO);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:sscholl,项目名称:biblebot,代码行数:52,代码来源:BibleImportService.java

示例15: afterPropertiesSet

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
    Assert.hasLength(getLoginUrl(), "loginUrl must be specified");
    Assert.notNull(getServiceProperties(), "serviceProperties must be specified");
}
 
开发者ID:kakawait,项目名称:cas-security-spring-boot-starter,代码行数:6,代码来源:RequestAwareCasAuthenticationEntryPoint.java


注:本文中的org.springframework.util.Assert.hasLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。