
guava-patterns
Google Guava 最佳实践模式。从官方 wiki 提炼,覆盖 Immutable集合的 of/copyOf/builder 三模式与防御性拷贝规则、Cache 选择决策(LoadingCache vs Cache vs Caffeine)、Joiner/Splitter 不可变流水线、CharMatcher 替代正则、Preconditions 格式化消息校验、CaseFormat 命名互转。 纠正 LLM 误用:手写不可变集合、ConcurrentHashMap 替代 Cache、不知 CharMatcher。
- Installs
- 93
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/java-skills --skill guava-patterns- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads guava-patterns automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Google Guava 最佳实践模式
来源: Guava Wiki | GitHub: google/guava
Capability Boundaries
✅ Strong Suits
- Immutable集合三模式 —
of()静态常量 /copyOf()防御性拷贝 /builder()渐进构建 - Cache模式选择 — Cache(无默认加载) vs LoadingCache(有默认加载函数) vs Caffeine(高性能)
- Joiner/Splitter流水线 — 函数式组合,实例线程安全可作 static final 常量
- CharMatcher — 预定义字符类操作,比正则更可读更安全
- Preconditions — checkArgument/checkNotNull/checkState 三剑客,格式化消息(类似printf)
- CaseFormat — LOWER_CAMEL/UPPER_UNDERSCORE 等 ASCII 命名风格互转
❌ Out of Scope
- ListenableFuture → 已被 Java8 CompletableFuture 替代,不要再用
- EventBus → 仅进程内,跨服务用 kafka-patterns
- 高性能缓存 → caffeine-patterns(API兼容Guava,性能更好)
核心模式
模式 1: Immutable 集合三选择
// ✅ of() — 编译期已知元素(作静态常量)
public static final ImmutableSet<String> COLORS = ImmutableSet.of("red","green","blue");
// ✅ copyOf() — 防御性拷贝(接收外部集合)
class Foo {
final ImmutableSet<Bar> bars;
Foo(Set<Bar> bars) { this.bars = ImmutableSet.copyOf(bars); }
}
// ✅ builder() — 渐进构建(合并多来源)
ImmutableSet<Color> colors = ImmutableSet.<Color>builder()
.addAll(WEBSAFE_COLORS).add(new Color(0,191,255)).build();
// ❌ Collections.unmodifiableXXX — 冗长/不安全(持有引用仍可改)/低效(保留并发检查)
模式 2: Cache 选择决策
有明确的"未命中→加载"函数 → LoadingCache (get(key)自动加载)
加载函数因key而异 → Cache (get(key, callable)每次指定)
高频+高并发+追求性能 → Caffeine (API兼容,窗口TinyLFU)
多实例共享 → Redis
// ✅ LoadingCache: 统一加载函数
LoadingCache<String, User> cache = CacheBuilder.newBuilder()
.maximumSize(1000).expireAfterWrite(10, TimeUnit.MINUTES)
.build(new CacheLoader<>() { public User load(String k) { return loadDB(k); }});
User u = cache.get("user:1"); // 自动加载+缓存
// ✅ 异步刷新(旧值仍可用,后台加载新值)
LoadingCache<String, Config> cfg = CacheBuilder.newBuilder()
.refreshAfterWrite(1, TimeUnit.MINUTES)
.build(new CacheLoader<>() { public Config load(String k) { ... }});
// ✅ RemovalListener: 异步拆除资源避免阻塞缓存
RemovalListener<String, Conn> listener = RemovalListeners.asynchronous(
notif -> notif.getValue().close(), executor);
模式 3: Joiner/Splitter 不可变流水线
// Joiner: 实例不可变,可作 static final 常量
private static final Joiner JOINER = Joiner.on(",").skipNulls();
JOINER.join(list); // "a,b,c"
Joiner.on("; ").useForNull("N/A").join("a",null,"c"); // "a; N/A; c"
// Splitter: 链式修饰 trimResults → omitEmptyStrings → limit
List<String> parts = Splitter.on(',').trimResults()
.omitEmptyStrings().splitToList("foo,bar,, qux"); // ["foo","bar","qux"]
// Map Splitter: URL参数解析
Map<String,String> m = Splitter.on('&')
.withKeyValueSeparator('=').split("id=123&name=foo");
// 固定长度切分
Splitter.fixedLength(3).splitToList("abcdefg"); // ["abc","def","g"]
模式 4: CharMatcher 替代正则
// ✅ CharMatcher — 编译期类型安全,比正则更可读
CharMatcher.digit().retainFrom("abc123"); // "123"
CharMatcher.javaIsoControl().removeFrom(string); // 删除控制字符
CharMatcher.whitespace().trimAndCollapseFrom(" foo bar ", ' '); // "foo bar"
CharMatcher.inRange('a','z').or(CharMatcher.is('_')).matchesAllOf(input);
// ❌ 反模式:Pattern.compile("\\d+") — CharMatcher 更优
模式 5: Preconditions vs Objects
// ✅ Guava Preconditions: 格式化消息(类似printf)
checkNotNull(obj, "参数不能为空: %s", userId);
checkArgument(age > 0, "年龄必须>0: %s", age);
// ✅ Java Objects: 简单非空(无格式化)
Objects.requireNonNull(obj, "参数不能为空");
// 选择: 需要消息格式化 → Preconditions; 简单判空 → Objects
Gotchas
- ImmutableList.of() 不接受 null — 含null抛NPE,需null用Collections.unmodifiableList
- Cache.get() 加载异常抛 ExecutionException — 需要try-catch或getUnchecked()
- expireAfterAccess vs expireAfterWrite — access适合频繁读(会话),write适合稳定数据
- refreshAfterWrite 必须小于 expireAfterWrite — 否则刷新在过期后执行,无意义
- Guava Reflect/ListenableFuture 已被 JDK 替代 — Java8+ 不要再用Guava版本
- Caffeine 性能优于 Guava Cache — 新项目优先Caffeine,仅旧项目兼容用Guava
- CharMatcher 只匹配单个字符 — 多字符模式(如关键词匹配)仍需正则
Data Privacy
本技能不收集、存储或传输任何用户数据。
FAQ
What does the guava-patterns skill do?
Google Guava 最佳实践模式。从官方 wiki 提炼,覆盖 Immutable集合的 of/copyOf/builder 三模式与防御性拷贝规则、Cache 选择决策(LoadingCache vs Cache vs Caffeine)、Joiner/Splitter 不可变流水线、CharMatcher 替代正则、Preconditions 格式化消息校验、CaseFormat 命名互转。 纠正 LLM 误用:手写不可变集合、ConcurrentHashMap 替代 Cache、不知 CharMatcher。
How do I install guava-patterns?
Run npx skills add https://github.com/full-stack-skills/java-skills --skill guava-patterns in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/guava-patterns/ (personal) or .claude/skills/guava-patterns/ (project).
Which AI agents can use guava-patterns?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is guava-patterns safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains guava-patterns?
It is published by full-stack-skills in full-stack-skills/java-skills. It has 93 recorded installs.
More from full-stack-skills/java-skills
java-development-manual
full-stack-skills/java-skills
Java开发手册规约集合,基于阿里巴巴Java开发手册(嵩山版)。 涵盖7大维度:编程规约、异常日志、单元测试、安全规约、MySQL数据库、工程结构、设计规约。 当用户需要:(1) 编写或审查Java代码 (2) 检查命名/代码规范 (3) 处理异常和日志 (4) 编写单元测试 (5) 安全编码 (6) 数据库设计 (7) 工程架构设计时使用此skill。 触发词:Java规范、阿里规约、代码规范、开发手册、编程规约、异常处理、单元测试、安全、MySQL、工程结构、设计模式。
mybatis-plus-patterns
full-stack-skills/java-skills
Open the skill to read its SKILL.md instructions.
java-code-comments
full-stack-skills/java-skills
Provides comprehensive guidance for adding Java code comments following industry standards and best practices. This skill helps add class-level comments, method-level comments, and field-level comments to Java code. Use when the user wants to add comments to Java code, needs to document Java classes/methods/fields, wants to improve code documentation, or needs to generate JavaDoc comments. This skill covers Controller, Service, ServiceImpl, Mapper, Model, Entity, BO (Business Object), DTO, VO, and other common Java component types. The skill follows a systematic workflow: scan codebase, identify components, create todo list, and add comments in order (class comments → method comments → field comments).
java-conventions
full-stack-skills/java-skills
统一 Java 项目编码规范与注释规范(SLF4J+Lombok 日志、Bean Lombok 注解选择、判空 Objects/Optional、工具类优先级 Spring→Apache Commons→Hutool→Guava、复杂逻辑用设计模式/简单逻辑不拆分、Controller/Service/ServiceImpl/Mapper 注释一致性)。当需要“按 Java 规范重构/Review/补全注释/统一日志/统一工具类使用/补全 JavaDoc”时使用。
mybatis-patterns
full-stack-skills/java-skills
Open the skill to read its SKILL.md instructions.
mapstruct-patterns
full-stack-skills/java-skills
MapStruct 最佳实践模式。从官方 Reference Guide 提炼,覆盖 Mapper 三种定义方式(接口/抽象类/default方法)、Spring 注入策略(CONSTRUCTOR推荐/SETTER解决循环依赖)、嵌套映射模式(显式子方法 dot notation 一次性配置)、@Qualifier @Named 的安全选择、Lombok 集成规则、@MappingComposition 谨慎使用。 纠正 LLM 最常见的错误:用反射 BeanUtils 而非编译期 MapStruct、嵌套映射全写在一个方法、不知 SETTER 解决循环依赖。
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.