1) subString the given name
def productName = {attrs ->
def name = attrs.name
int max = 25
max = attrs.max
if (name.size() > max) {
def result = ''
int length = 0
def words = name.split()
def preWord
int lbCount = 0
words.each {word ->
//length += word.size()
if((preWord?preWord.size()+word.size():word.size())>22||(length+word.size())>35) {
lbCount++
}
length += lbCount? 25 : word.size()
if (length < max) {
result += "${word} "
}
preWord = word
}
result = result[0..-2] // trim off trailing space
return result += "..."
} else {
return name
}
}
def attrs = [:]
// attrs.name = "Unbreakable Polycarbonate 10pc. Tumbler Set Assorted"
attrs.name = "Sunpentown Bagless Upright Vacuum Red V8506"
attrs.max = 40
println productName(attrs)
分享到:
相关推荐
Algorithm_Groovy_Club Weihan's algorithm showcase space Welcome to my astroworld :star: 二叉树的各种遍历+引申题型 Leetcode/Lintcode coverage: 144, 94, 145, 102, 107, 103, 1469, 515, 513, 404, 199, 106...
Gradle是一个基于Groovy的构建自动化系统,它的灵活性和可扩展性使其在Java项目中广泛应用。与Maven相比,Gradle更注重于构建脚本的可读性和可维护性,通过声明式的方式来定义项目依赖。 在Gradle构建文件(`build....
Groovy JS a MVEL Python Ruby 安装 JStarCraft RNS要求使用者具有以下环境: JDK 8或以上 Maven 3 安装JStarCraft-Core框架 git clone https://github.com/HongZhaoHua/jstarcraft-core.git mvn install -...
本话题将深入探讨如何使用Gradle来生成MD5(Message-Digest Algorithm 5)编码,这是一种广泛用于验证数据完整性的哈希函数。 标题“Gradle生成md5代码”指的是利用Gradle脚本来计算文件或字符串的MD5值。在Android...
Algorithm_Groovy_Club Maze's algorithm showcase space Welcome to my astroworld :star: 二叉树的各种遍历+引申题型 Leetcode/Lintcode coverage: 144, 94, 145, 102, 107, 103, 1469, 515, 513, 404, 199, 106, ...
```groovy dependencies { implementation 'com.ihimanshu.hasher:hasher:版本号' } ``` 这里的"版本号"应替换为Hasher库的实际版本号,如`e806113`可能是库的一个特定提交ID,实际使用时需查找对应的发布版本。 ...
```groovy implementation 'commons-codec:commons-codec:1.15' ``` 在Java中,我们主要使用`org.apache.commons.codec.binary.Base64`类来进行Base64的处理。下面是一个简单的Base64加密和解密的示例: ```java ...
分片策略的配置通常会涉及到分片键(shardingColumn),分片算法(algorithm)以及实际数据节点(actualDataNodes)的设置。 ### 分片算法 分片算法是Sharding-JDBC中的核心组件,它决定了数据如何分布到不同的...
```groovy dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'io.jsonwebtoken:...
大多数算法是用 Python 实现的,但是,其中一些也是用 Groovy 或 Java 实现的。 Python 中的大多数实现(尤其是科学算法)需要几个依赖项: numpy、matplotlib、scipy 。 排序 ,典型的分而治之的实现。 平均以O(n ...
CityEngine的核心功能之一是其基于规则的建模(Rule-Based Modeling),通过CGA(CityGen Algorithm)语言实现,这是一种专门用于3D地理空间建模的编程语言。 CityEngine C++ SDK是开发人员的利器,允许他们构建与...
在IT领域,尤其是Android开发中,了解和掌握数字签名算法(Digital Signature Algorithm,简称DSA)是至关重要的。DSA是一种公钥密码算法,用于验证数据的完整性和来源的可靠性。"minim2"可能是一个与DSA相关的开源...
动作实现可以采用多种方式,如Java类、Groovy脚本、Spring Bean等。Spring Web Flow的灵活性使得开发者可以根据具体需求选择最适合的动作实现方式。 #### 6.6 Action exceptions 动作执行过程中可能会抛出异常,...