List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:org.opendaylight.neutron.hostconfig.vpp.HostconfigUtil.java
public static Map<String, String> createHostconfigsDataFor(NodeId nodeId, SocketInfo socketInfo) { Preconditions.checkNotNull(nodeId); Preconditions.checkNotNull(socketInfo); JsonObject odlL2 = new JsonObject(); odlL2.add("allowed_network_types", buildSupportedNetworkTypes()); odlL2.add("supported_vnic_types", buildSupportedVnicTypes(socketInfo)); Map<String, String> hostConfigs = new HashMap<>(); hostConfigs.put(L2_HOST_TYPE, odlL2.toString()); return hostConfigs; }
From source file:org.apache.phoenix.flume.SchemaHandler.java
public static boolean createTable(Connection connection, String createTableDdl) { Preconditions.checkNotNull(connection); Preconditions.checkNotNull(createTableDdl); boolean status = true; try {//from w w w .j ava 2s. c o m status = connection.createStatement().execute(createTableDdl); } catch (SQLException e) { logger.error("An error occurred during executing the create table ddl {} ", createTableDdl); Throwables.propagate(e); } return status; }
From source file:org.xacml4j.v30.types.DoubleExp.java
public static DoubleExp of(Number value) { Preconditions.checkNotNull(value); return new DoubleExp(value.doubleValue()); }
From source file:org.ros.internal.node.topic.PublisherDeclaration.java
public static PublisherDeclaration newFromNodeIdentifier(NodeIdentifier nodeIdentifier, TopicDeclaration topicDeclaration) { Preconditions.checkNotNull(nodeIdentifier); Preconditions.checkNotNull(topicDeclaration); return new PublisherDeclaration(new PublisherIdentifier(nodeIdentifier, topicDeclaration.getIdentifier()), topicDeclaration);//from w w w . jav a2 s. c om }
From source file:com.cloudera.oryx.rdf.computation.RDFJobStepConfig.java
public static RDFJobStepConfig fromArgsArray(String... args) { Preconditions.checkNotNull(args); Preconditions.checkArgument(args.length >= 4); return new RDFJobStepConfig(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])); }
From source file:io.macgyver.plugin.github.GitHubUtil.java
/** * github-api does not provide a way to set the default branch until 1.69. * GHRepository.edit() can do it, but is private. This is a simple workaround * that uses reflection to work around the private limitation. * /*from www.j av a2 s . c o m*/ * @param repo * @param branchName * @throws IOException */ public static void setDefaultBranch(GHRepository repo, String branchName) throws IOException { Preconditions.checkNotNull(repo); Preconditions.checkNotNull(branchName); try { Method editMethod = repo.getClass().getDeclaredMethod("edit", String.class, String.class); editMethod.setAccessible(true); editMethod.invoke(repo, "default_branch", branchName); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IOException(e); } }
From source file:com.haoocai.jscheduler.core.tracker.TaskTrackerFactory.java
public synchronized static ZKTaskTracker getTaskTracker(TaskID taskID, ZKAccessor zkAccessor) throws Exception { Preconditions.checkNotNull(taskID); Preconditions.checkNotNull(zkAccessor); Task task = TaskRegisterCenter.task(taskID); ZKTaskTracker taskTracker = taskTrackerRegMap.get(taskID); if (taskTracker == null) { taskTracker = new ZKTaskTracker(zkAccessor, task); taskTrackerRegMap.put(taskID, taskTracker); }/*from w w w . j av a2 s . co m*/ return taskTracker; }
From source file:com.facebook.buck.util.Paths.java
/** * @param from must always refer to a directory (it should either be the empty string or end with * a slash).//from w ww. j av a 2 s .co m * @param to may refer to either a file or a directory */ public static String computeRelativePath(String from, String to) { Preconditions.checkNotNull(from); Preconditions.checkArgument(from.isEmpty() || from.endsWith("/"), "Directory path must either be the empty string or end with a slash"); Preconditions.checkNotNull(to); if (from.isEmpty()) { return to; } // Both from and to have the same string prefix through this character index. int samePrefixIndex = 0; while (true) { int slashIndex = from.indexOf('/', samePrefixIndex); if (slashIndex < 0) { break; } int indexIncludingSlash = slashIndex + 1; if (indexIncludingSlash > to.length()) { break; } String fromPathElement = from.substring(samePrefixIndex, indexIncludingSlash); String toPathElement = to.substring(samePrefixIndex, indexIncludingSlash); if (fromPathElement.equals(toPathElement)) { samePrefixIndex = indexIncludingSlash; } else { break; } } int directoryDepth = 0; for (int charIndex = samePrefixIndex + 1; charIndex < from.length(); charIndex++) { if (from.charAt(charIndex) == '/') { directoryDepth++; } } return Strings.repeat("../", directoryDepth) + to.substring(samePrefixIndex); }
From source file:com.google.api.explorer.client.base.NameHelper.java
/** * Generate the title for the specified title and name. * * @param title Title to directly return or {@code null}. * @param name Name which should be turned into a title if the title is null. * @return Printable title./*from w w w .j ava 2s . com*/ */ public static String generateDisplayTitle(@Nullable String title, String name) { return Objects.firstNonNull(title, Preconditions.checkNotNull(name) + " API"); }
From source file:com.metamx.emitter.EmittingLogger.java
public static void registerEmitter(ServiceEmitter emitter) { Preconditions.checkNotNull(emitter); EmittingLogger.emitter = emitter; }