Java Code Examples for com.jstarcraft.core.utility.StringUtility#isBlank()
The following examples show how to use
com.jstarcraft.core.utility.StringUtility#isBlank() .
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: HttpUtility.java From jstarcraft-example with Apache License 2.0 | 6 votes |
/** * 获取IP地址 * * @param request * @return */ public static String getIp(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (StringUtility.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (StringUtility.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtility.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } // 多级反向代理 if (!StringUtility.isBlank(ip)) { int index = ip.indexOf(","); if (index > 0) { ip = ip.substring(0, index); } } return ip; }
Example 2
Source File: OutputDefinition.java From jstarcraft-core with Apache License 2.0 | 6 votes |
Type getContentType() { // 没有输入 if (outputVariable == null) { return void.class; } // 存在指定的内容类型 if (!(void.class.equals(contentType) || Void.class.equals(contentType))) { return contentType; } // 以变量类型作为内容类型 CommandVariable variable = outputVariable.getVariable(); if (VariableType.MESSAGE_BODY.equals(variable.type()) && StringUtility.isBlank(variable.property())) { // 以变量类型作为输出类型 return outputVariable.getType(); } else { return void.class; } }
Example 3
Source File: OutputDefinition.java From jstarcraft-core with Apache License 2.0 | 6 votes |
Type getOutputType() { // 没有输出 if (outputVariable == null) { return void.class; } CommandVariable variable = outputVariable.getVariable(); if (VariableType.MESSAGE_BODY.equals(variable.type()) && StringUtility.isBlank(variable.property())) { // 以变量类型作为输出类型 return outputVariable.getType(); } // 以内容类型作为输出类型 if (!(void.class.equals(contentType) || Void.class.equals(contentType))) { return contentType; } else { return void.class; } }
Example 4
Source File: CoreNlpTokenizer.java From jstarcraft-nlp with Apache License 2.0 | 5 votes |
@Override public Iterable<CoreNlpToken> tokenize(CharSequence text) { Iterable<CoreLabel> iterator; if (StringUtility.isBlank(text)) { // 空格无需分词 iterator = Collections.EMPTY_LIST; } else { Annotation annotation = new Annotation(text.toString()); annotator.annotate(annotation); iterator = annotation.get(CoreAnnotations.TokensAnnotation.class); } CoreNlpToken iterable = new CoreNlpToken(iterator.iterator()); return iterable; }
Example 5
Source File: MongoMetadata.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 构造方法 * * @param metadata */ MongoMetadata(Class<?> clazz) { Document document = clazz.getAnnotation(Document.class); if (document == null) { throw new IllegalArgumentException(); } ormName = document.collection(); if (StringUtility.isBlank(ormName)) { ormName = clazz.getSimpleName(); ormName = ormName.substring(0, 1).toLowerCase() + ormName.substring(1, ormName.length()); } ormClass = clazz; ReflectionUtility.doWithFields(ormClass, (field) -> { if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) { return; } if (field.isAnnotationPresent(Version.class)) { versionName = field.getName(); return; } Class<?> type = field.getType(); fields.put(field.getName(), type); if (field.isAnnotationPresent(Id.class)) { primaryName = field.getName(); primaryClass = type; } if (field.isAnnotationPresent(Indexed.class)) { indexNames.add(field.getName()); } }); }
Example 6
Source File: JsonUtility.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 将JSON字符串转换为对象 * * @param json * @param type * @return */ public static <T> T string2Object(String json, Type type) { if (StringUtility.isBlank(json)) { return null; } try { return (T) TYPE_CONVERTER.readValue(json, TYPE_FACTORY.constructType(type)); } catch (Exception exception) { String message = StringUtility.format("将JSON字符串[{}]转换为对象时异常", json); throw new RuntimeException(message, exception); } }
Example 7
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 5 votes |
default Class getClass(String name, Class instead) { String value = getString(name); try { return StringUtility.isBlank(value) ? instead : Class.forName(value); } catch (ClassNotFoundException exception) { throw new RuntimeException(exception); } }
Example 8
Source File: MovieService.java From jstarcraft-example with Apache License 2.0 | 5 votes |
/** * * @param userIndex * @param modelKey * @param queryKey * @param filterClicked * @return * @throws Exception */ @LockableMethod(strategy = HashLockableStrategy.class) public Object2FloatMap<MovieItem> getItems(@LockableParameter int userIndex, String modelKey, String queryKey, boolean filterClicked) throws Exception { // 标识-得分映射 Object2FloatMap<MovieItem> item2ScoreMap = new Object2FloatOpenHashMap<>(); long current = System.currentTimeMillis(); Model model = models.get(modelKey); ArrayInstance instance = new ArrayInstance(qualityOrder, quantityOrder); MovieUser user = users.get(userIndex); Query query = StringUtility.isBlank(queryKey) ? new MatchAllDocsQuery() : queryParser.parse(queryKey, MovieItem.TITLE); KeyValue<List<Document>, FloatList> retrieve = engine.retrieveDocuments(query, null, 0, 1000); List<Document> documents = retrieve.getKey(); for (int index = 0, size = documents.size(); index < size; index++) { Document document = documents.get(index); MovieItem item = items.get(document.getField(MovieItem.INDEX).numericValue().intValue()); int itemIndex = item.getIndex(); // 过滤条目 if (filterClicked && user.isClicked(itemIndex)) { continue; } instance.setQualityFeature(userDimension, userIndex); instance.setQualityFeature(itemDimension, itemIndex); model.predict(instance); float score = instance.getQuantityMark(); item2ScoreMap.put(item, score); } String message = StringUtility.format("预测数量:{},预测耗时:{}", modelKey, documents.size(), System.currentTimeMillis() - current); logger.info(message); return item2ScoreMap; }
Example 9
Source File: OutputDefinition.java From jstarcraft-core with Apache License 2.0 | 4 votes |
static OutputDefinition instanceOf(Method method, Class<?> outputClass, MessageCodec socketCodec) { if (!CommandDefinition.checkType(method.getGenericReturnType())) { throw new CommunicationDefinitionException("指令的参数与返回不能有擦拭类型与通配符类型"); } int modifier = outputClass.getModifiers(); if (!outputClass.isPrimitive() && Modifier.isAbstract(modifier)) { throw new CommunicationDefinitionException("指令的参数与返回不能为抽象"); } if (Modifier.isInterface(modifier)) { throw new CommunicationDefinitionException("指令的参数与返回不能为接口"); } OutputDefinition instance = new OutputDefinition(); instance.contentFormat = MessageFormat.toByte(socketCodec.outputFormat(), socketCodec.outputZip()); instance.contentType = outputClass; AnnotatedType annotatedType = method.getAnnotatedReturnType(); Annotation[] annotations = annotatedType.getAnnotations(); boolean hasBodyVariable = false; CommandVariable variable = null; for (Annotation annotation : annotations) { if (annotation instanceof CommandVariable) { if (variable != null) { throw new CommunicationDefinitionException(); } variable = (CommandVariable) annotation; if (VariableType.MESSAGE_BODY.equals(variable.type())) { hasBodyVariable = true; } } } if (variable != null) { instance.outputVariable = VariableDefinition.instanceOf(annotatedType.getType(), variable, null); } if (instance.outputVariable == null && !(outputClass.equals(void.class) || outputClass.equals(Void.class))) { throw new CommunicationDefinitionException(); } if (instance.outputVariable != null) { if (!hasBodyVariable && !(outputClass.equals(void.class) || outputClass.equals(Void.class))) { throw new CommunicationDefinitionException(); } if (hasBodyVariable && !StringUtility.isBlank(instance.outputVariable.getVariable().property()) && outputClass.equals(void.class)) { throw new CommunicationDefinitionException(); } } return instance; }
Example 10
Source File: InputDefinition.java From jstarcraft-core with Apache License 2.0 | 4 votes |
static InputDefinition instanceOf(Method method, Class<?> inputClass, MessageCodec socketCodec) { for (Type type : method.getGenericParameterTypes()) { if (!CommandDefinition.checkType(type)) { throw new CommunicationDefinitionException("指令的参数与返回不能有擦拭类型与通配符类型"); } } int modifier = inputClass.getModifiers(); if (!inputClass.isPrimitive() && Modifier.isAbstract(modifier)) { throw new CommunicationDefinitionException("指令的参数与返回不能为抽象"); } if (Modifier.isInterface(modifier)) { throw new CommunicationDefinitionException("指令的参数与返回不能为接口"); } InputDefinition instance = new InputDefinition(); instance.contentFormat = MessageFormat.toByte(socketCodec.inputFormat(), socketCodec.inputZip()); instance.contentType = inputClass; instance.inputVariables = getVariables(method); instance.inputVariableIndex = null; boolean hasBodyVariable = false; for (VariableDefinition definition : instance.inputVariables) { CommandVariable variable = definition.getVariable(); if (VariableType.MESSAGE_BODY.equals(variable.type())) { if (StringUtility.isBlank(variable.property()) && !MessageBody.class.equals(definition.getType())) { if (instance.inputVariableIndex != null) { throw new CommunicationDefinitionException(); } instance.inputVariableIndex = definition.getPosition(); } hasBodyVariable = true; } } if (instance.inputVariables.length == 0 && !inputClass.equals(void.class)) { throw new CommunicationDefinitionException(); } if (instance.inputVariables.length != 0) { if (!hasBodyVariable && !inputClass.equals(void.class)) { throw new CommunicationDefinitionException(); } if (hasBodyVariable && instance.inputVariableIndex == null && inputClass.equals(void.class)) { throw new CommunicationDefinitionException(); } } // TODO 存在索引变量,类型必须为Array或者Collection return instance; }
Example 11
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default String getString(String name, String instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : value; }
Example 12
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Long getLong(String name, Long instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Long.valueOf(value); }
Example 13
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Integer getInteger(String name, Integer instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Integer.valueOf(value); }
Example 14
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Float getFloat(String name, Float instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Float.valueOf(value); }
Example 15
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Double getDouble(String name, Double instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Double.valueOf(value); }
Example 16
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Character getCharacter(String name, Character instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Character.valueOf(value.charAt(0)); }
Example 17
Source File: Configurator.java From jstarcraft-core with Apache License 2.0 | 4 votes |
default Boolean getBoolean(String name, Boolean instead) { String value = getString(name); return StringUtility.isBlank(value) ? instead : Boolean.valueOf(value); }