Java tutorial
/** * Copyright 2011 Caleb Richardson * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.outerspacecat.memcache; import com.google.common.base.Preconditions; import java.util.regex.Pattern; /** * Defines utility methods for working with Memcache. * * @author Caleb Richardson */ public final class Memcache { private final static Pattern KEY_PATTERN = Pattern.compile("[\\x21-\\x7E]{1,250}"); private Memcache() { } /** * Returns whether or not {@code key} is a valid Memcache key. * <p> * Memcache keys must be between 1 and 250 characters in length (inclusive), * and must contain only non-control, non-whitespace ASCII characters, which * corresponds to the range U+0021-U+007E (inclusive). * * @param key the key to check for validity. Must be non {@code null}. * @return whether or not {@code key} is a valid Memcache key */ public static boolean isValidKey(final CharSequence key) { Preconditions.checkNotNull(key, "key required"); return KEY_PATTERN.matcher(key).matches(); } }