List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
From source file:net.awired.visuwall.plugin.teamcity.States.java
public static final State asVisuwallState(String teamcityState) { Preconditions.checkNotNull(teamcityState, "teamcityState is mandatory"); State state = STATE_MAPPING.get(teamcityState); if (state == null) { state = State.UNKNOWN; LOG.warn(// w w w . j a va 2s .com teamcityState + " is not available in TeamCity plugin. Please report it to Visuwall dev team."); } return state; }
From source file:works.chatterbox.hooks.ircchannels.api.modes.ModesAPI.java
public ModesAPI(@NotNull final IRCChannels ircChannels) { Preconditions.checkNotNull(ircChannels, "ircChannels was null"); this.modes = new Modes(ircChannels); }
From source file:org.fundacionjala.sevenwonders.core.Wonder.java
public Wonder(List<Stage> stages) { Preconditions.checkNotNull(stages, "The stages is null"); this.stages = stages; }
From source file:uk.co.brightec.ratetheapp.Utils.java
/** * Formats the manufacturer and model strings into a human readable device name * * @param manufacturer String e.g. Build.MANUFACTURER * @param model String e.g. Build.MODEL * @return String Human readable device name e.g. Samsung S6 *///from w w w.ja v a 2 s . c o m @VisibleForTesting static String formatDeviceName(@NonNull String manufacturer, @NonNull String model) { Preconditions.checkNotNull(manufacturer, "Cannot pass a null object for manufacturer in Utils.formatDeviceName()"); Preconditions.checkNotNull(model, "Cannot pass a null object for model in Utils.formatDeviceName()"); StringBuilder stringBuilder = new StringBuilder(); if (model.startsWith(manufacturer)) { stringBuilder.append(capitalize(model)); } else { stringBuilder.append(capitalize(manufacturer)); if (!stringBuilder.toString().isEmpty() && !model.isEmpty()) { stringBuilder.append(" "); } stringBuilder.append(capitalize(model)); } return stringBuilder.toString(); }
From source file:ninja.leaping.configurate.loader.AtomicFiles.java
private static Path getTemporaryPath(Path parent, String key) { String fileName = System.currentTimeMillis() + Preconditions.checkNotNull(key, "key").replaceAll("\\\\|/|:", "-") + ".tmp"; return parent.resolve(fileName); }
From source file:com.google.security.zynamics.zylib.date.DateHelpers.java
/** * Formats a date string regarding the given locale. * // w w w .ja v a 2 s. c om * @param date The date to format. * @param type Defines the display type of month * @param locale The given locale. * * @return The data string. */ public static String formatDate(final Date date, final int type, final Locale locale) { Preconditions.checkNotNull(date, "Error: Date argument can't be null."); Preconditions.checkNotNull(locale, "Error: Locale argument can't be null."); final String s = String.format("%s %s", DateFormat.getDateInstance(type, locale).format(date), DateFormat.getTimeInstance(type, locale).format(date)); return s; }
From source file:de.cosmocode.commons.Locales.java
/** * Parses a string into a {@link Locale}. * //from w w w . j a va 2 s . c o m * @param value the locale string * @return a new {@link Locale} parsed from value * @throws NullPointerException if value is null * @throws IllegalArgumentException if value is no valid locale */ public static Locale parse(String value) { Preconditions.checkNotNull(value, "Value"); final Matcher matcher = Patterns.LOCALE.matcher(value); Preconditions.checkArgument(matcher.matches(), "%s does not match %s", value, Patterns.LOCALE); final String language = Strings.defaultIfBlank(matcher.group(1), ""); final String country = Strings.defaultIfBlank(matcher.group(2), ""); final String variant = Strings.defaultIfBlank(matcher.group(3), ""); return new Locale(language, country, variant); }
From source file:com.facebook.presto.serde.PagesSerde.java
public static PagesWriter createPagesWriter(final SliceOutput sliceOutput) { checkNotNull(sliceOutput, "sliceOutput is null"); return new PagesWriter() { private BlockEncoding[] blockEncodings; @Override//from ww w. jav a 2s . co m public PagesWriter append(Page page) { Preconditions.checkNotNull(page, "page is null"); if (blockEncodings == null) { Block[] blocks = page.getBlocks(); blockEncodings = new BlockEncoding[blocks.length]; sliceOutput.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { Block block = blocks[i]; BlockEncoding blockEncoding = block.getEncoding(); blockEncodings[i] = blockEncoding; BlockEncodings.writeBlockEncoding(sliceOutput, blockEncoding); } } sliceOutput.writeInt(page.getPositionCount()); Block[] blocks = page.getBlocks(); for (int i = 0; i < blocks.length; i++) { blockEncodings[i].writeBlock(sliceOutput, blocks[i]); } return this; } }; }
From source file:org.anarres.dhcp.server.pcap.DhcpServer.java
@Nonnull private static InterfaceAddress toInterfaceAddress(@Nonnull PcapAddress address) { Preconditions.checkNotNull(address, "PcapAddress was null."); int netmask = AddressUtils.toNetmask(address.getNetmask()); return new InterfaceAddress(address.getAddress(), netmask); }
From source file:net.minecraftforge.server.permission.PermissionAPI.java
/** * <b>Only use this in PreInit state!</b> */// w ww . ja v a 2 s .c om public static void setPermissionHandler(IPermissionHandler handler) { Preconditions.checkNotNull(handler, "Permission handler can't be null!"); Preconditions.checkState( Loader.instance().getLoaderState().ordinal() <= LoaderState.PREINITIALIZATION.ordinal(), "Can't register after IPermissionHandler PreInit!"); FMLLog.log(Level.WARN, "Replacing " + permissionHandler.getClass().getName() + " with " + handler.getClass().getName()); permissionHandler = handler; }