List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
From source file:org.terasology.monitoring.chunk.ChunkMonitor.java
private static synchronized ChunkMonitorEntry registerChunk(Chunk chunk) { Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null"); final Vector3i pos = chunk.getPosition(); ChunkMonitorEntry entry = CHUNKS.get(pos); if (entry == null) { entry = new ChunkMonitorEntry(pos); CHUNKS.put(pos, entry);/*from w w w. j a v a2 s .c om*/ } entry.addChunk(chunk); return entry; }
From source file:com.jivesoftware.os.amza.api.wal.WALKey.java
public static byte[] compose(byte[] prefix, byte[] key) { Preconditions.checkNotNull(key, "Key cannot be null"); int prefixLength = prefix != null ? prefix.length : 0; Preconditions.checkArgument(prefixLength <= Short.MAX_VALUE, "Max prefix length is 32767"); byte[] pk = new byte[2 + prefixLength + key.length]; UIO.shortBytes((short) prefixLength, pk, 0); if (prefix != null) { System.arraycopy(prefix, 0, pk, 2, prefixLength); }//from ww w . j a v a 2s . c o m System.arraycopy(key, 0, pk, 2 + prefixLength, key.length); return pk; }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.db.JDBCConnection.java
/** * The method that create a JDBC connection from a connection and a * (default) schema.//from w w w . j av a2 s. com * * <p>The method resets the auto-commit to {@code false}</p> * @param cnx is an (opened) connection * @param schema is the default schema * @return the matching JDBC connection * @throws SQLException can be thrown while resetting auto commit */ public static JDBCConnection create(Connection cnx, String schema) throws SQLException { Preconditions.checkNotNull(cnx, "null connection supplied"); Preconditions.checkNotNull(schema, "null schema supplied"); cnx.setAutoCommit(false); return new JDBCConnection(cnx, schema); }
From source file:org.apache.james.jmap.api.vacation.RecipientId.java
public static RecipientId fromMailAddress(MailAddress mailAddress) { Preconditions.checkNotNull(mailAddress, "RecipientId mailAddress should not be null"); return new RecipientId(mailAddress); }
From source file:io.fabric8.jube.process.support.FileUtils.java
public static void extractArchive(File archiveFile, File targetDirectory, String extractCommand, Duration timeLimit, Executor executor) throws CommandFailedException { Preconditions.checkNotNull(archiveFile, "archiveFile is null"); Preconditions.checkNotNull(targetDirectory, "targetDirectory is null"); Preconditions.checkArgument(targetDirectory.isDirectory(), "targetDirectory is not a directory: " + targetDirectory.getAbsolutePath()); final String[] commands = splitCommands(extractCommand); final String[] args = Arrays.copyOf(commands, commands.length + 1); args[args.length - 1] = archiveFile.getAbsolutePath(); LOG.info("Extracting archive with commands: " + Arrays.asList(args)); new Command(args).setDirectory(targetDirectory).setTimeLimit(timeLimit).execute(executor); }
From source file:com.zaradai.kunzite.trader.events.MarketData.java
public static MarketData newInstance(String instrumentId, DateTime timestamp, List<MarketDataField> fields) { Preconditions.checkArgument(!Strings.isNullOrEmpty(instrumentId), "Invalid Instrument"); Preconditions.checkNotNull(timestamp, "Invalid timestamp"); Preconditions.checkNotNull(fields, "Invalid fields specified"); return new MarketData(instrumentId, timestamp, fields); }
From source file:net.awired.visuwall.plugin.jenkins.States.java
public static final State asVisuwallState(String jenkinsState) { Preconditions.checkNotNull(jenkinsState, "jenkinsState is mandatory"); jenkinsState = jenkinsState.toLowerCase(); State state = STATE_MAPPING.get(jenkinsState); if (state == null) { state = State.UNKNOWN; LOG.warn(jenkinsState + " is not available in Jenkins plugin. Please report it to Visuwall dev team."); }/*w w w . j av a 2s .c om*/ return state; }
From source file:com.google.security.zynamics.zylib.general.ClipboardHelpers.java
/** * Copies a string to the system clipboard. * * @param string The string to be copied to the system clipboard. *//*from w w w . j ava 2 s . co m*/ public static void copyToClipboard(final String string) { Preconditions.checkNotNull(string, "Error: String argument can not be null"); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(string), new ClipboardOwner() { @Override public void lostOwnership(final Clipboard clipboard, final Transferable contents) { } }); }
From source file:com.google.security.zynamics.binnavi.ZyGraph.Implementations.CEdgeFunctions.java
/** * Shows the dialog for editing edge comments. * * @param parent Parent window used for dialogs. * @param edge The edge whose comments are edited. *//*from ww w.j a v a 2s .c om*/ public static void editEdgeComments(final JFrame parent, final NaviEdge edge) { Preconditions.checkNotNull(parent, "IE02115: Parent argument can not be null"); Preconditions.checkNotNull(edge, "IE02116: Edge argument can not be null"); final CDialogEditEdgeComment dlg = new CDialogEditEdgeComment(parent, edge.getRawEdge()); GuiHelper.centerChildToParent(parent, dlg, true); dlg.setVisible(true); }
From source file:io.kazuki.v0.store.index.SecondaryIndexQueryValidation.java
public static void validateQuery(String indexName, List<QueryTerm> query, Schema schema) { Preconditions.checkNotNull(query, "query"); Preconditions.checkNotNull(schema, "schema"); IndexDefinition indexDef = schema.getIndex(indexName); Preconditions.checkNotNull(indexDef, "index"); boolean containsFirst = false; boolean allEquality = true; Set<String> seenCols = new HashSet<String>(); String firstIndexCol = indexDef.getAttributeNames().get(0); for (QueryTerm term : query) { String attrName = term.getField(); Attribute existsSchema = schema.getAttribute(attrName); if (existsSchema == null) { throw new IllegalArgumentException("unknown schema attribute: " + attrName); }// ww w. ja v a2 s. c om IndexAttribute existsIndex = indexDef.getIndexAttribute(attrName); if (existsIndex == null) { throw new IllegalArgumentException("unknown index attribute: " + attrName); } containsFirst = containsFirst || attrName.equals(firstIndexCol); allEquality = allEquality && term.getOperator().equals(QueryOperator.EQ); seenCols.add(attrName); } if (!containsFirst) { throw new IllegalArgumentException("query must contain first index attribute: " + firstIndexCol); } if (indexDef.isUnique()) { boolean containsAll = (seenCols.size() == indexDef.getIndexAttributeMap().size()); if (!containsAll) { throw new IllegalArgumentException("unique index query must contain all index attributes"); } if (!allEquality) { throw new IllegalArgumentException("unique index query must use equality operator only"); } } }