本文整理了Java中io.kaif.model.zone.Zone
类的一些代码示例,展示了Zone
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Zone
类的具体详情如下:
包路径:io.kaif.model.zone.Zone
类名称:Zone
暂无
代码示例来源:origin: kaif-open/kaif
@Test
public void zoneFallback() throws Exception {
assertEquals("foo", Zone.tryFallback("foo").get().value());
assertEquals("foo", Zone.tryFallback("Foo").get().value());
//fallback do not handle space, because url may use %20
assertFalse(Zone.tryFallback(" foo ").isPresent());
assertFalse(Zone.tryFallback(" ").isPresent());
assertFalse(Zone.tryFallback(null).isPresent());
assertEquals("a-b-cd-e", Zone.tryFallback("a--b__cd-e").get().value());
}
代码示例来源:origin: kaif-open/kaif
@Override
public Zone deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
String value = jp.readValueAs(String.class);
return Zone.valueOf(value);
}
}
代码示例来源:origin: kaif-open/kaif
public static Zone valueOf(String validValue) {
Preconditions.checkArgument(isValid(validValue), "invalid zone value: %s", validValue);
return new Zone(validValue);
}
代码示例来源:origin: kaif-open/kaif
@Override
public boolean isZoneAvailable(String zone) {
return Zone.isValid(zone) && ZoneInfo.isValidDefault(zone) && !zoneDao.findZoneWithoutCache(Zone
.valueOf(zone)).isPresent();
}
代码示例来源:origin: kaif-open/kaif
/**
* shortcut to zone.value()
*/
public String getName() {
return zone.value();
}
代码示例来源:origin: kaif-open/kaif
@Test
public void valueValidation() throws Exception {
assertEquals("abc", Zone.valueOf("abc").value());
assertEquals("111111111", Zone.valueOf("111111111").value());
assertInvalidZone(null);
assertInvalidZone("null");
assertInvalidZone("NULL");
assertInvalidZone("");
assertInvalidZone(" ");
assertInvalidZone("a");
assertInvalidZone("ab");
assertInvalidZone("123456789012345678901");
assertInvalidZone("a__b");
assertInvalidZone("+++ab");
assertInvalidZone("-ab");
assertInvalidZone("ab-");
assertInvalidZone("a--b");
assertInvalidZone("a----b");
}
代码示例来源:origin: kaif-open/kaif
@Override
public int hashCode() {
return zone != null ? zone.hashCode() : 0;
}
代码示例来源:origin: kaif-open/kaif
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ZoneInfo zoneInfo = (ZoneInfo) o;
if (zone != null ? !zone.equals(zoneInfo.zone) : zoneInfo.zone != null) {
return false;
}
return true;
}
代码示例来源:origin: kaif-open/kaif
/**
* fallback to valid zone name whenever possible (user is easily typo)
* <p>
* fallback rule is follow valid zone pattern
*/
public static Optional<Zone> tryFallback(String rawZone) {
return Optional.ofNullable(valueFallback(rawZone)).filter(Zone::isValid).map(Zone::new);
}
代码示例来源:origin: kaif-open/kaif
private static String zoneUrl(Zone zone) {
return SCHEME_AND_HOST + "/z/" + zone.value();
}
代码示例来源:origin: kaif-open/kaif
@Test
public void createKaif() throws Exception {
ZoneInfo zoneInfo = service.createKaif("faq", "FAQ");
ZoneInfo loaded = zoneDao.loadZoneWithoutCache(Zone.valueOf("faq"));
assertEquals(zoneInfo, loaded);
assertEquals("faq", loaded.getZone().value());
assertEquals("FAQ", loaded.getAliasName());
assertEquals(Authority.CITIZEN, loaded.getVoteAuthority());
assertEquals(Authority.CITIZEN, loaded.getDebateAuthority());
assertEquals(Authority.FORBIDDEN, loaded.getWriteAuthority());
assertEquals(ZoneInfo.THEME_KAIF, loaded.getTheme());
assertTrue(loaded.isHideFromTop());
assertEquals(0, loaded.getAdminAccountIds().size());
}
代码示例来源:origin: kaif-open/kaif
@Override
public int hashCode() {
int result = accountId.hashCode();
result = 31 * result + (zone != null ? zone.hashCode() : 0);
result = 31 * result + bucket.hashCode();
result = 31 * result + username.hashCode();
result = 31 * result + (int) (articleUpVoted ^ (articleUpVoted >>> 32));
result = 31 * result + (int) (debateUpVoted ^ (debateUpVoted >>> 32));
result = 31 * result + (int) (debateDownVoted ^ (debateDownVoted >>> 32));
return result;
}
代码示例来源:origin: kaif-open/kaif
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HonorRoll honorRoll = (HonorRoll) o;
if (articleUpVoted != honorRoll.articleUpVoted) {
return false;
}
if (debateUpVoted != honorRoll.debateUpVoted) {
return false;
}
if (debateDownVoted != honorRoll.debateDownVoted) {
return false;
}
if (!accountId.equals(honorRoll.accountId)) {
return false;
}
if (zone != null ? !zone.equals(honorRoll.zone) : honorRoll.zone != null) {
return false;
}
if (!bucket.equals(honorRoll.bucket)) {
return false;
}
return username.equals(honorRoll.username);
}
代码示例来源:origin: kaif-open/kaif
@RequestMapping(value = "/external-link", method = RequestMethod.GET)
public List<FlakeId> listArticleIdsByExternalLink(@RequestParam("zone") String rawZone,
@RequestParam("url") String url) {
return articleService.listArticlesByExternalLink(Zone.valueOf(rawZone), url)
.stream()
.map(Article::getArticleId)
.collect(toList());
}
代码示例来源:origin: kaif-open/kaif
@Override
public void serialize(Zone zone, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeString(zone.value());
}
代码示例来源:origin: kaif-open/kaif
private Object resolveZone(HttpServletRequest request,
String decodedRawZone,
Function<ZoneInfo, ModelAndView> onZoneInfo) {
// note that decodedRawZone already do http url decode, and PathVariable already trim()
// space of value
return Zone.tryFallback(decodedRawZone).map(zone -> {
if (!zone.value().equals(decodedRawZone)) {
String orgUrl = request.getRequestURL().toString();
// replace pattern is combine of fallback pattern and valid pattern
// TODO refactor replace rule to Zone
String location = orgUrl.replaceFirst("/z/[a-zA-Z0-9_\\-]+", "/z/" + zone);
//check if fallback success, this prevent infinite redirect loop
if (!location.equals(orgUrl)) {
RedirectView redirectView = new RedirectView(location);
redirectView.setPropagateQueryParams(true);
redirectView.setExpandUriTemplateVariables(false);
redirectView.setExposeModelAttributes(false);
redirectView.setExposeContextBeansAsAttributes(false);
redirectView.setExposePathVariables(false);
redirectView.setContextRelative(true);
redirectView.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
return redirectView;
}
}
return onZoneInfo.apply(zoneService.loadZone(zone));
}).orElseThrow(() -> new EmptyResultDataAccessException("no such zone: " + decodedRawZone, 1));
}
代码示例来源:origin: kaif-open/kaif
@ApiOperation(value = "[public] check url already submitted in zone",
notes = "Check url already submitted as external-url-article in zone")
@RequiredScope(ClientAppScope.PUBLIC)
@RequestMapping(value = "/zone/{zone}/external-link/exist", method = RequestMethod.GET)
public boolean isExternalLinkExist(ClientAppUserAccessToken accessToken,
@PathVariable(value = "zone") String zone,
@RequestParam("url") String url) {
return articleService.isExternalLinkExist(Zone.valueOf(zone), url);
}
代码示例来源:origin: kaif-open/kaif
@Override
public Map<String, List<ZoneInfo>> listZoneAtoZ() {
Function<ZoneInfo, String> capitalizeFirstChar = zoneInfo -> zoneInfo.getZone()
.value()
.substring(0, 1)
.toUpperCase();
return zoneDao.listOrderByName()
.stream()
.collect(Collectors.groupingBy(capitalizeFirstChar, LinkedHashMap::new, toList()));
}
代码示例来源:origin: kaif-open/kaif
@ApiOperation(value = "[public] List administrators of the zone", notes = "List username of administrators of the zone")
@RequiredScope(PUBLIC)
@RequestMapping(value = "/{zone}/administrator/username", method = RequestMethod.GET)
public List<String> listAdministrators(ClientAppUserAccessToken token,
@PathVariable("zone") String zone) {
return zoneService.listAdministratorsWithCache(Zone.valueOf(zone));
}
}
代码示例来源:origin: kaif-open/kaif
@Cacheable("listAdministrators")
public List<String> listAdministratorsWithCache(Zone zone) {
//TODO evict if we can add new administrators
return jdbc().query(""
+ " SELECT Account.username "
+ " FROM Account "
+ " JOIN ZoneAdmin ON (ZoneAdmin.accountId = Account.accountId) "
+ " WHERE zone = ? "
+ " ORDER BY Account.username ", (rs, n) -> rs.getString("username"), zone.value());
}
}
内容来源于网络,如有侵权,请联系作者删除!