_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17900 | StringUtils.lastIndexOf | train | @NullSafe
public static int lastIndexOf(String text, String value) {
return text != null && value != null ? text.lastIndexOf(value) : -1;
} | java | {
"resource": ""
} |
q17901 | StringUtils.pad | train | @NullSafe
public static String pad(String value, int length) {
return pad(value, SINGLE_SPACE_CHAR, length);
} | java | {
"resource": ""
} |
q17902 | StringUtils.pad | train | @NullSafe
@SuppressWarnings("all")
public static String pad(String value, char padding, int length) {
assertThat(length).throwing(new IllegalArgumentException(String.format(
"[%d] must be greater than equal to 0", length))).isGreaterThanEqualTo(0);
if (length > 0) {
StringBuilder builder = new StringBuilder(ObjectUtils.defaultIfNull(value, EMPTY_STRING));
while (length - builder.length() > 0) {
builder.append(padding);
}
return builder.toString();
}
return value;
} | java | {
"resource": ""
} |
q17903 | StringUtils.singleSpaceObjects | train | public static String singleSpaceObjects(Object... values) {
List<String> valueList = new ArrayList<>(values.length);
for (Object value : values) {
valueList.add(String.valueOf(value));
}
return trim(concat(valueList.toArray(new String[valueList.size()]), SINGLE_SPACE));
} | java | {
"resource": ""
} |
q17904 | StringUtils.singleSpaceString | train | public static String singleSpaceString(String value) {
Assert.hasText(value, "String value must contain text");
return trim(concat(value.split("\\s+"), SINGLE_SPACE));
} | java | {
"resource": ""
} |
q17905 | StringUtils.toLowerCase | train | @NullSafe
public static String toLowerCase(String value) {
return value != null ? value.toLowerCase() : null;
} | java | {
"resource": ""
} |
q17906 | StringUtils.toStringArray | train | @NullSafe
@SuppressWarnings("all")
public static String[] toStringArray(String delimitedValue, String delimiter) {
return ArrayUtils.transform(ObjectUtils.defaultIfNull(delimitedValue, EMPTY_STRING).split(
defaultIfBlank(delimiter, COMMA_DELIMITER)), StringUtils::trim);
} | java | {
"resource": ""
} |
q17907 | StringUtils.toUpperCase | train | @NullSafe
public static String toUpperCase(String value) {
return value != null ? value.toUpperCase() : null;
} | java | {
"resource": ""
} |
q17908 | StringUtils.trim | train | @NullSafe
public static String trim(String value) {
return value != null ? value.trim() : null;
} | java | {
"resource": ""
} |
q17909 | StringUtils.truncate | train | @NullSafe
public static String truncate(String value, int length) {
assertThat(length).throwing(new IllegalArgumentException(String.format(
"[%d] must be greater than equal to 0", length))).isGreaterThanEqualTo(0);
return (value != null ? value.substring(0, Math.min(value.length(), length)) : null);
} | java | {
"resource": ""
} |
q17910 | StringUtils.wrap | train | public static String wrap(String line, int widthInCharacters, String indent) {
StringBuilder buffer = new StringBuilder();
int lineCount = 1;
int spaceIndex;
// if indent is null, then do not indent the wrapped lines
indent = (indent != null ? indent : EMPTY_STRING);
while (line.length() > widthInCharacters) {
spaceIndex = line.substring(0, widthInCharacters).lastIndexOf(SINGLE_SPACE);
buffer.append(lineCount++ > 1 ? indent : EMPTY_STRING);
// throws IndexOutOfBoundsException if spaceIndex is -1, implying no word boundary was found within
// the given width; this also avoids the infinite loop
buffer.append(line.substring(0, spaceIndex));
buffer.append(LINE_SEPARATOR);
// possible infinite loop if spaceIndex is -1, see comment above
line = line.substring(spaceIndex + 1);
}
buffer.append(lineCount > 1 ? indent : EMPTY_STRING);
buffer.append(line);
return buffer.toString();
} | java | {
"resource": ""
} |
q17911 | Initializer.init | train | public static boolean init(Object initableObj) {
if (initableObj instanceof Initable) {
((Initable) initableObj).init();
return true;
}
return false;
} | java | {
"resource": ""
} |
q17912 | xen_health_monitor_fan_speed.get_filtered | train | public static xen_health_monitor_fan_speed[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
xen_health_monitor_fan_speed obj = new xen_health_monitor_fan_speed();
options option = new options();
option.set_filter(filter);
xen_health_monitor_fan_speed[] response = (xen_health_monitor_fan_speed[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17913 | ns_vserver_appflow_config.get_filtered | train | public static ns_vserver_appflow_config[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
ns_vserver_appflow_config obj = new ns_vserver_appflow_config();
options option = new options();
option.set_filter(filter);
ns_vserver_appflow_config[] response = (ns_vserver_appflow_config[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17914 | techsupport.get_filtered | train | public static techsupport[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
techsupport obj = new techsupport();
options option = new options();
option.set_filter(filter);
techsupport[] response = (techsupport[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17915 | MathUtils.cylinderSurfaceArea | train | public static double cylinderSurfaceArea(final double radius, final double height) {
return ((2.0d * Math.PI * Math.pow(radius, 2)) + (2.0d * Math.PI * radius * height));
} | java | {
"resource": ""
} |
q17916 | MathUtils.factorial | train | public static BigInteger factorial(BigInteger value) {
Assert.notNull(value, "value must not be null");
Assert.isTrue(value.compareTo(BigInteger.ZERO) >= 0, String.format(NUMBER_LESS_THAN_ZERO_ERROR_MESSAGE, value));
if (value.compareTo(TWO) <= 0) {
return (value.equals(TWO) ? TWO : BigInteger.ONE);
}
BigInteger result = value;
for (value = result.add(NEGATIVE_ONE) ; value.compareTo(BigInteger.ONE) > 0; value = value.add(NEGATIVE_ONE)) {
result = result.multiply(value);
}
return result;
} | java | {
"resource": ""
} |
q17917 | MathUtils.fibonacciSequence | train | public static int[] fibonacciSequence(final int n) {
Assert.argument(n > 0, "The number of elements from the Fibonacci Sequence to calculate must be greater than equal to 0!");
int[] fibonacciNumbers = new int[n];
for (int position = 0; position < n; position++) {
if (position == 0) {
fibonacciNumbers[position] = 0;
}
else if (position < 2) {
fibonacciNumbers[position] = 1;
}
else {
fibonacciNumbers[position] = (fibonacciNumbers[position - 1] + fibonacciNumbers[position - 2]);
}
}
return fibonacciNumbers;
} | java | {
"resource": ""
} |
q17918 | MathUtils.max | train | @NullSafe
public static double max(final double... values) {
double maxValue = Double.NaN;
if (values != null) {
for (double value : values) {
maxValue = (Double.isNaN(maxValue) ? value : Math.max(maxValue, value));
}
}
return maxValue;
} | java | {
"resource": ""
} |
q17919 | MathUtils.min | train | @NullSafe
public static double min(final double... values) {
double minValue = Double.NaN;
if (values != null) {
for (double value : values) {
minValue = (Double.isNaN(minValue) ? value : Math.min(minValue, value));
}
}
return minValue;
} | java | {
"resource": ""
} |
q17920 | MathUtils.multiply | train | @NullSafe
public static int multiply(final int... numbers) {
int result = 0;
if (numbers != null) {
result = (numbers.length > 0 ? 1 : 0);
for (int number : numbers) {
result *= number;
}
}
return result;
} | java | {
"resource": ""
} |
q17921 | MathUtils.rectangularPrismSurfaceArea | train | public static double rectangularPrismSurfaceArea(final double length, final double height, final double width) {
return ((2 * length * height) + (2 * length * width) + (2 * height * width));
} | java | {
"resource": ""
} |
q17922 | MathUtils.sum | train | @NullSafe
public static int sum(final int... numbers) {
int sum = 0;
if (numbers != null) {
for (int number : numbers) {
sum += number;
}
}
return sum;
} | java | {
"resource": ""
} |
q17923 | mps.get | train | public static mps get(nitro_service client) throws Exception
{
mps resource = new mps();
resource.validate("get");
return ((mps[]) resource.get_resources(client))[0];
} | java | {
"resource": ""
} |
q17924 | ObjectUtils.copy | train | public static Serializable copy(Serializable obj) {
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
ObjectOutputStream out = new ObjectOutputStream(buf);
out.writeObject(obj);
out.close();
ByteArrayInputStream buf2 = new ByteArrayInputStream(buf.toByteArray());
ObjectInputStream in = new ObjectInputStream(buf2);
Serializable obj2 = (Serializable) in.readObject();
in.close();
return obj2;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} | java | {
"resource": ""
} |
q17925 | ObjectUtils.getConstructor | train | public static <T> Constructor<T> getConstructor(Class<T> cls, Class... params) {
try {
return cls.getConstructor(params);
} catch (Exception e) {
throw new ClientException(e);
}
} | java | {
"resource": ""
} |
q17926 | ObjectUtils.newInstance | train | public static <T> T newInstance(Constructor<T> constructor, Object... args) {
try {
return constructor.newInstance(args);
} catch (Exception e) {
throw new ClientException(e);
}
} | java | {
"resource": ""
} |
q17927 | MoreGraphs.topologicalSort | train | private static <T> @NonNull List<T> topologicalSort(final @NonNull Graph<T> graph, final @NonNull SortType<T> type) {
checkArgument(graph.isDirected(), "the graph must be directed");
checkArgument(!graph.allowsSelfLoops(), "the graph cannot allow self loops");
final Map<T, Integer> requiredCounts = new HashMap<>();
for(final T node : graph.nodes()) {
for(final T successor : graph.successors(node)) {
requiredCounts.merge(successor, 1, (a, b) -> a + b);
}
}
final Queue<T> processing = type.createQueue();
final List<T> results = new ArrayList<>();
for(final T node : graph.nodes()) {
if(!requiredCounts.containsKey(node)) {
processing.add(node);
}
}
while(!processing.isEmpty()) {
final T now = processing.poll();
for(final T successor : graph.successors(now)) {
final int newCount = requiredCounts.get(successor) - 1;
if(newCount == 0) {
processing.add(successor);
requiredCounts.remove(successor);
} else {
requiredCounts.put(successor, newCount);
}
}
results.add(now);
}
if(!requiredCounts.isEmpty()) {
final StronglyConnectedComponentAnalyzer<T> analyzer = new StronglyConnectedComponentAnalyzer<>(graph);
analyzer.analyze();
throw new CyclePresentException("Graph (" + graph + ") has cycle(s): " + analyzer.renderCycles(), analyzer.components());
}
return results;
} | java | {
"resource": ""
} |
q17928 | EnvelopeServerHandler.invoke | train | private <I extends Message, O extends Message> void invoke(
ServerMethod<I, O> method, ByteString payload, long requestId, Channel channel) {
FutureCallback<O> callback = new ServerMethodCallback<>(method, requestId, channel);
try {
I request = method.inputParser().parseFrom(payload);
ListenableFuture<O> result = method.invoke(request);
pendingRequests.put(requestId, result);
Futures.addCallback(result, callback, responseCallbackExecutor);
} catch (InvalidProtocolBufferException ipbe) {
callback.onFailure(ipbe);
}
} | java | {
"resource": ""
} |
q17929 | CFProperties.getPreferenceValue | train | public String getPreferenceValue(String key, String defaultValue) {
if (userCFProperties.containsKey(key))
return userCFProperties.getProperty(key);
else if (userHomeCFProperties.containsKey(key))
return userHomeCFProperties.getProperty(key);
else if (systemCFProperties.containsKey(key))
return systemCFProperties.getProperty(key);
else if (defaultProperties.containsKey(key))
return defaultProperties.getProperty(key);
else
return defaultValue;
} | java | {
"resource": ""
} |
q17930 | xen_health_monitor_temp.get_filtered | train | public static xen_health_monitor_temp[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
xen_health_monitor_temp obj = new xen_health_monitor_temp();
options option = new options();
option.set_filter(filter);
xen_health_monitor_temp[] response = (xen_health_monitor_temp[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17931 | Pair.left | train | public static <L, R> @NonNull Pair<L, R> left(final @Nullable L left) {
return of(left, null);
} | java | {
"resource": ""
} |
q17932 | Pair.right | train | public static <L, R> @NonNull Pair<L, R> right(final @Nullable R right) {
return of(null, right);
} | java | {
"resource": ""
} |
q17933 | Pair.of | train | public static <L, R> @NonNull Pair<L, R> of(final Map.Entry<L, R> entry) {
return of(entry.getKey(), entry.getValue());
} | java | {
"resource": ""
} |
q17934 | Pair.of | train | public static <L, R> @NonNull Pair<L, R> of(final @Nullable L left, final @Nullable R right) {
return new Pair<>(left, right);
} | java | {
"resource": ""
} |
q17935 | Pair.map | train | public <NL, NR> @NonNull Pair<NL, NR> map(final @NonNull Function<? super L, ? extends NL> left, final @NonNull Function<? super R, ? extends NR> right) {
return new Pair<>(left.apply(this.left), right.apply(this.right));
} | java | {
"resource": ""
} |
q17936 | Pair.lmap | train | public <NL> @NonNull Pair<NL, R> lmap(final @NonNull Function<? super L, ? extends NL> function) {
return new Pair<>(function.apply(this.left), this.right);
} | java | {
"resource": ""
} |
q17937 | Pair.rmap | train | public <NR> @NonNull Pair<L, NR> rmap(final @NonNull Function<? super R, ? extends NR> function) {
return new Pair<>(this.left, function.apply(this.right));
} | java | {
"resource": ""
} |
q17938 | VictimsDB.defaultURL | train | public static String defaultURL(String driver) {
assert Driver.exists(driver);
String home = "";
try {
home = VictimsConfig.home().toString();
} catch (VictimsException e) {
// Ignore and use cwd
}
return Driver.url(driver, FilenameUtils.concat(home, "victims"));
} | java | {
"resource": ""
} |
q17939 | xen_brvpx_image.get | train | public static xen_brvpx_image get(nitro_service client, xen_brvpx_image resource) throws Exception
{
resource.validate("get");
return ((xen_brvpx_image[]) resource.get_resources(client))[0];
} | java | {
"resource": ""
} |
q17940 | base_resource.get_resources | train | protected base_resource[] get_resources(nitro_service service, options option) throws Exception
{
if (!service.isLogin())
service.login();
String response = _get(service, option);
return get_nitro_response(service, response);
} | java | {
"resource": ""
} |
q17941 | base_resource.perform_operation | train | public base_resource[] perform_operation(nitro_service service) throws Exception
{
if (!service.isLogin() && !get_object_type().equals("login"))
service.login();
return post_request(service, null);
} | java | {
"resource": ""
} |
q17942 | base_resource.add_resource | train | protected base_resource[] add_resource(nitro_service service, options option) throws Exception
{
if (!service.isLogin() && !get_object_type().equals("login"))
service.login();
String request = resource_to_string(service, option);
return post_data(service, request);
} | java | {
"resource": ""
} |
q17943 | base_resource.update_resource | train | protected base_resource[] update_resource(nitro_service service, options option) throws Exception
{
if (!service.isLogin() && !get_object_type().equals("login"))
service.login();
String request = resource_to_string(service, option);
return put_data(service,request);
} | java | {
"resource": ""
} |
q17944 | base_resource.delete_resource | train | protected base_resource[] delete_resource(nitro_service service) throws Exception
{
if (!service.isLogin())
service.login();
String str = nitro_util.object_to_string_withoutquotes(this);
String response = _delete(service, str);
return get_nitro_response(service, response);
} | java | {
"resource": ""
} |
q17945 | base_resource._delete | train | private String _delete(nitro_service service, String req_args) throws Exception
{
StringBuilder responseStr = new StringBuilder();
HttpURLConnection httpURLConnection = null;
try
{
String urlstr;
String ipaddress = service.get_ipaddress();
String version = service.get_version();
String sessionid = service.get_sessionid();
String objtype = get_object_type();
String protocol = service.get_protocol();
// build URL
urlstr = protocol + "://" + ipaddress + "/nitro/" + version + "/config/" + objtype;
String name = this.get_object_id();
if (name != null && name.length() > 0)
{
urlstr = urlstr + "/" + nitro_util.encode(nitro_util.encode(name));
}
/*if(req_args != null && req_args.length() > 0)
{
urlstr = urlstr + "?args=" + req_args;
}*/
URL url = new URL(urlstr);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("DELETE");
if(sessionid != null)
{
httpURLConnection.setRequestProperty("Cookie", "SESSID=" + nitro_util.encode(sessionid));
httpURLConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
}
if (httpURLConnection instanceof HttpsURLConnection)
{
SSLContext sslContext = SSLContext.getInstance("SSL");
//we are using an empty trust manager, because MPS currently presents
//a test certificate not issued by any signing authority, so we need to bypass
//the credentials check
sslContext.init(null, new TrustManager[]{new EmptyTrustManager()}, null);
SocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection secured = (HttpsURLConnection) httpURLConnection;
secured.setSSLSocketFactory((SSLSocketFactory)sslSocketFactory);
secured.setHostnameVerifier(new EmptyHostnameVerifier());
}
InputStream input = httpURLConnection.getInputStream();
String contentEncoding = httpURLConnection.getContentEncoding();
// get correct input stream for compressed data:
if (contentEncoding != null)
{
if(contentEncoding.equalsIgnoreCase("gzip"))
input = new GZIPInputStream(input); //reads 2 bytes to determine GZIP stream!
else if(contentEncoding.equalsIgnoreCase("deflate"))
input = new InflaterInputStream(input);
}
int numOfTotalBytesRead;
byte [] buffer = new byte[1024];
while ((numOfTotalBytesRead = input.read(buffer, 0, buffer.length)) != -1)
{
responseStr.append(new String(buffer, 0, numOfTotalBytesRead));
}
httpURLConnection.disconnect();
input.close();
}
catch (MalformedURLException mue)
{
System.err.println("Invalid URL");
}
catch (IOException ioe)
{
System.err.println("I/O Error - " + ioe);
}
catch(Exception e)
{
System.err.println("Error - " + e);
}
return responseStr.toString();
} | java | {
"resource": ""
} |
q17946 | base_resource.update_bulk_request | train | protected static base_resource[] update_bulk_request(nitro_service service,base_resource resources[]) throws Exception
{
if (!service.isLogin())
service.login();
String objtype = resources[0].get_object_type();
String onerror = service.get_onerror();
//String id = service.get_sessionid();
String request = service.get_payload_formatter().resource_to_string(resources, null, onerror);
String result = put_bulk_data(service,request,objtype);
if(resources.length == 1)
return resources[0].get_nitro_response(service, result);
return resources[0].get_nitro_bulk_response(service, result);
} | java | {
"resource": ""
} |
q17947 | UpgradeProcess.uninstallBundle | train | public void uninstallBundle(final String symbolicName, final String version) {
Bundle bundle = bundleDeployerService.getExistingBundleBySymbolicName(symbolicName, version, null);
if (bundle != null) {
stateChanged = true;
Logger.info("Uninstalling bundle: " + bundle);
BundleStartLevel bundleStartLevel = bundle.adapt(BundleStartLevel.class);
if (bundleStartLevel.getStartLevel() < currentFrameworkStartLevelValue) {
setFrameworkStartLevel(bundleStartLevel.getStartLevel());
}
try {
bundle.uninstall();
} catch (BundleException e) {
Logger.error("Error during uninstalling bundle: " + bundle.toString(), e);
}
}
} | java | {
"resource": ""
} |
q17948 | EnvelopeFuture.setResponse | train | public void setResponse(Envelope response) {
if (response.hasControl() && response.getControl().hasError()) {
setException(new Exception(response.getControl().getError()));
return;
}
try {
set(clientMethod.outputParser().parseFrom(response.getPayload()));
clientLogger.logSuccess(clientMethod);
} catch (InvalidProtocolBufferException ipbe) {
setException(ipbe);
}
} | java | {
"resource": ""
} |
q17949 | host_interface.reset | train | public static host_interface reset(nitro_service client, host_interface resource) throws Exception
{
return ((host_interface[]) resource.perform_operation(client, "reset"))[0];
} | java | {
"resource": ""
} |
q17950 | ChannelUtil.getTagNames | train | public static Collection<String> getTagNames(Channel channel) {
Collection<String> tagNames = new HashSet<String>();
for (Tag tag : channel.getTags()) {
tagNames.add(tag.getName());
}
return tagNames;
} | java | {
"resource": ""
} |
q17951 | ChannelUtil.getAllTagNames | train | public static Collection<String> getAllTagNames(Collection<Channel> channels) {
Collection<String> tagNames = new HashSet<String>();
for (Channel channel : channels) {
tagNames.addAll(getTagNames(channel));
}
return tagNames;
} | java | {
"resource": ""
} |
q17952 | ChannelUtil.getPropertyNames | train | public static Collection<String> getPropertyNames(Channel channel) {
Collection<String> propertyNames = new HashSet<String>();
for (Property property : channel.getProperties()) {
if (property.getValue() != null)
propertyNames.add(property.getName());
}
return propertyNames;
} | java | {
"resource": ""
} |
q17953 | ChannelUtil.getTag | train | @Deprecated
public static Tag getTag(Channel channel, String tagName) {
Collection<Tag> tag = Collections2.filter(channel.getTags(),
new TagNamePredicate(tagName));
if (tag.size() == 1)
return tag.iterator().next();
else
return null;
} | java | {
"resource": ""
} |
q17954 | ChannelUtil.getProperty | train | @Deprecated
public static Property getProperty(Channel channel, String propertyName) {
Collection<Property> property = Collections2.filter(
channel.getProperties(),
new PropertyNamePredicate(propertyName));
if (property.size() == 1)
return property.iterator().next();
else
return null;
} | java | {
"resource": ""
} |
q17955 | ChannelUtil.getPropertyNames | train | public static Collection<String> getPropertyNames(
Collection<Channel> channels) {
Collection<String> propertyNames = new HashSet<String>();
for (Channel channel : channels) {
propertyNames.addAll(getPropertyNames(channel));
}
return propertyNames;
} | java | {
"resource": ""
} |
q17956 | ChannelUtil.getChannelNames | train | public static Collection<String> getChannelNames(
Collection<Channel> channels) {
Collection<String> channelNames = new HashSet<String>();
for (Channel channel : channels) {
channelNames.add(channel.getName());
}
return channelNames;
} | java | {
"resource": ""
} |
q17957 | sdx_network_config.get | train | public static sdx_network_config get(nitro_service client) throws Exception
{
sdx_network_config resource = new sdx_network_config();
resource.validate("get");
return ((sdx_network_config[]) resource.get_resources(client))[0];
} | java | {
"resource": ""
} |
q17958 | VictimsSqlDB.getVulnerabilities | train | protected HashSet<String> getVulnerabilities(int recordId)
throws SQLException {
HashSet<String> cves = new HashSet<String>();
Connection connection = getConnection();
try {
PreparedStatement ps = setObjects(connection, Query.FIND_CVES,
recordId);
ResultSet matches = ps.executeQuery();
while (matches.next()) {
cves.add(matches.getString(1));
}
matches.close();
} finally {
connection.close();
}
return cves;
} | java | {
"resource": ""
} |
q17959 | VictimsSqlDB.getEmbeddedRecords | train | protected HashSet<Integer> getEmbeddedRecords(Set<String> hashes)
throws SQLException {
HashSet<Integer> results = new HashSet<Integer>();
Connection connection = getConnection();
PreparedStatement ps = setObjects(connection,
Query.FILEHASH_EMBEDDED_MATCH, (Object) hashes.toArray());
try {
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
results.add(resultSet.getInt("record"));
}
resultSet.close();
} finally {
connection.close();
}
return results;
} | java | {
"resource": ""
} |
q17960 | WebSocketClient.connect | train | public synchronized void connect() {
if (state != State.NONE) {
eventHandler.onError(new WebSocketException("connect() already called"));
close();
return;
}
getIntializer().setName(getInnerThread(), THREAD_BASE_NAME + "Reader-" + clientId);
state = State.CONNECTING;
getInnerThread().start();
} | java | {
"resource": ""
} |
q17961 | WebSocketClient.close | train | public synchronized void close() {
switch (state) {
case NONE:
state = State.DISCONNECTED;
return;
case CONNECTING:
// don't wait for an established connection, just close the tcp socket
closeSocket();
return;
case CONNECTED:
// This method also shuts down the writer
// the socket will be closed once the ack for the close was received
sendCloseHandshake(true);
return;
case DISCONNECTING:
return; // no-op;
case DISCONNECTED:
return; // No-op
}
} | java | {
"resource": ""
} |
q17962 | WebSocketClient.blockClose | train | public void blockClose() throws InterruptedException {
// If the thread is new, it will never run, since we closed the connection before we actually connected
if (writer.getInnerThread().getState() != Thread.State.NEW) {
writer.getInnerThread().join();
}
getInnerThread().join();
} | java | {
"resource": ""
} |
q17963 | ns_image.get_filtered | train | public static ns_image[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
ns_image obj = new ns_image();
options option = new options();
option.set_filter(filter);
ns_image[] response = (ns_image[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17964 | xen_health_resource.get_filtered | train | public static xen_health_resource[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
xen_health_resource obj = new xen_health_resource();
options option = new options();
option.set_filter(filter);
xen_health_resource[] response = (xen_health_resource[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17965 | AbstractConfiguration.convert | train | protected <T> T convert(final String value, final Class<T> type) {
Assert.notNull(type, "The Class type to convert the String value to cannot be null!");
if (getConversionService().canConvert(String.class, type)) {
return getConversionService().convert(value, type);
}
throw new ConversionException(String.format("Cannot convert String value (%1$s) into a value of type (%2$s)!",
value, type.getName()));
} | java | {
"resource": ""
} |
q17966 | AbstractConfiguration.defaultIfUnset | train | protected String defaultIfUnset(final String value, final String defaultValue) {
return (StringUtils.hasText(value) ? value : defaultValue);
} | java | {
"resource": ""
} |
q17967 | AbstractConfiguration.isPresent | train | public boolean isPresent(final String propertyName) {
for (String configurationPropertyName : this) {
if (configurationPropertyName.equals(propertyName)) {
return true;
}
}
return false;
} | java | {
"resource": ""
} |
q17968 | AbstractConfiguration.getPropertyValue | train | public String getPropertyValue(final String propertyName, final boolean required) {
String propertyValue = doGetPropertyValue(propertyName);
if (StringUtils.isBlank(propertyValue) && getParent() != null) {
propertyValue = getParent().getPropertyValue(propertyName, required);
}
if (StringUtils.isBlank(propertyValue) && required) {
throw new ConfigurationException(String.format("The property (%1$s) is required!", propertyName));
}
return defaultIfUnset(propertyValue, null);
} | java | {
"resource": ""
} |
q17969 | AbstractConfiguration.getPropertyValue | train | public String getPropertyValue(final String propertyName, final String defaultPropertyValue) {
return defaultIfUnset(getPropertyValue(propertyName, NOT_REQUIRED), defaultPropertyValue);
} | java | {
"resource": ""
} |
q17970 | AbstractConfiguration.getPropertyValueAs | train | public <T> T getPropertyValueAs(final String propertyName, final Class<T> type) {
return convert(getPropertyValue(propertyName, DEFAULT_REQUIRED), type);
} | java | {
"resource": ""
} |
q17971 | AbstractConfiguration.getPropertyValueAs | train | public <T> T getPropertyValueAs(final String propertyName, final boolean required, final Class<T> type) {
try {
return convert(getPropertyValue(propertyName, required), type);
}
catch (ConversionException e) {
if (required) {
throw new ConfigurationException(String.format(
"Failed to get the value of configuration setting property (%1$s) as type (%2$s)!", propertyName,
ClassUtils.getName(type)), e);
}
return null;
}
} | java | {
"resource": ""
} |
q17972 | AbstractConfiguration.getPropertyValueAs | train | @SuppressWarnings("unchecked")
public <T> T getPropertyValueAs(final String propertyName, final T defaultPropertyValue, final Class<T> type) {
try {
return ObjectUtils.defaultIfNull(convert(getPropertyValue(propertyName, NOT_REQUIRED), type),
defaultPropertyValue);
}
catch (ConversionException ignore) {
return defaultPropertyValue;
}
} | java | {
"resource": ""
} |
q17973 | SorterFactory.createSorter | train | @SuppressWarnings("unchecked")
public static <T extends Sorter> T createSorter(final SortType type) {
switch (ObjectUtils.defaultIfNull(type, SortType.UNKONWN)) {
case BUBBLE_SORT:
return (T) new BubbleSort();
case COMB_SORT:
return (T) new CombSort();
case HEAP_SORT:
return (T) new HeapSort();
case INSERTION_SORT:
return (T) new InsertionSort();
case MERGE_SORT:
return (T) new MergeSort();
case QUICK_SORT:
return (T) new QuickSort();
case SELECTION_SORT:
return (T) new SelectionSort();
case SHELL_SORT:
return (T) new ShellSort();
default:
throw new IllegalArgumentException(String.format("The SortType (%1$s) is not supported by the %2$s!", type,
SorterFactory.class.getSimpleName()));
}
} | java | {
"resource": ""
} |
q17974 | SorterFactory.createSorterElseDefault | train | public static <T extends Sorter> T createSorterElseDefault(final SortType type, final T defaultSorter) {
try {
return createSorter(type);
}
catch (IllegalArgumentException ignore) {
return defaultSorter;
}
} | java | {
"resource": ""
} |
q17975 | EmitToGraphiteLogbackAppender.start | train | @Override
public void start() {
super.start();
// If disabled we do not create a publisher to graphite but error counts are still collected.
if(enabled) {
metricPublishing.start(new GraphiteConfigImpl(host, port, pollintervalseconds, queuesize, sendasrate));
}
this.startUpMetric = factory.createStartUpMetric(metricObjects, subsystem, new Timer());
startUpMetric.start();
} | java | {
"resource": ""
} |
q17976 | EmitToGraphiteLogbackAppender.stop | train | @Override
public void stop() {
if(enabled) {
metricPublishing.stop();
}
if(startUpMetric != null) {
startUpMetric.stop();
}
super.stop();
} | java | {
"resource": ""
} |
q17977 | AbstractBean.getFieldName | train | protected String getFieldName(String propertyName) {
return ObjectUtils.defaultIfNull(propertyNameToFieldNameMapping.get(propertyName), propertyName);
} | java | {
"resource": ""
} |
q17978 | AbstractBean.setModifiedBy | train | @SuppressWarnings("unchecked")
public void setModifiedBy(USER modifiedBy) {
processChange("modifiedBy", this.modifiedBy, modifiedBy);
this.lastModifiedBy = ObjectUtils.defaultIfNull(this.lastModifiedBy, this.modifiedBy);
} | java | {
"resource": ""
} |
q17979 | AbstractBean.changeState | train | void changeState(String propertyName, Object newValue) {
try {
ObjectUtils.setField(this, getFieldName(propertyName), newValue);
}
catch (IllegalArgumentException e) {
throw new PropertyNotFoundException(String.format(
"The property (%1$s) corresponding to field (%2$s) was not found in this Bean (%3$s)!",
propertyName, getFieldName(propertyName), getClass().getName()), e);
}
} | java | {
"resource": ""
} |
q17980 | AbstractBean.compareTo | train | @SuppressWarnings("all")
public int compareTo(Bean<ID, USER, PROCESS> obj) {
Assert.isInstanceOf(obj, getClass(), new ClassCastException(String.format(
"The Bean being compared with this Bean must be an instance of %1$s!", getClass().getName())));
return ComparatorUtils.compareIgnoreNull(getId(), obj.getId());
} | java | {
"resource": ""
} |
q17981 | AbstractBean.newPropertyChangeEvent | train | protected PropertyChangeEvent newPropertyChangeEvent(String propertyName, Object oldValue, Object newValue) {
if (isEventDispatchEnabled()) {
if (vetoableChangeSupport.hasListeners(propertyName) || propertyChangeSupport.hasListeners(propertyName)) {
return new PropertyChangeEvent(this, propertyName, oldValue, newValue);
}
}
return this.propertyChangeEvent;
} | java | {
"resource": ""
} |
q17982 | AbstractBean.firePropertyChange | train | protected void firePropertyChange(PropertyChangeEvent event) {
if (isEventDispatchEnabled()) {
Assert.notNull(event, "The PropertyChangeEvent cannot be null!");
if (propertyChangeSupport.hasListeners(event.getPropertyName())) {
propertyChangeSupport.firePropertyChange(event);
}
}
} | java | {
"resource": ""
} |
q17983 | AbstractBean.fireVetoableChange | train | protected void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
if (isEventDispatchEnabled()) {
Assert.notNull(event, "The PropertyChangeEvent cannot be null!");
if (vetoableChangeSupport.hasListeners(event.getPropertyName())) {
vetoableChangeSupport.fireVetoableChange(event);
}
}
} | java | {
"resource": ""
} |
q17984 | AbstractBean.mapPropertyNameToFieldName | train | protected boolean mapPropertyNameToFieldName(final String propertyName, final String fieldName) {
// TODO add possible validation for the property name and field name of this Bean class.
propertyNameToFieldNameMapping.put(propertyName, fieldName);
return propertyNameToFieldNameMapping.containsKey(propertyName);
} | java | {
"resource": ""
} |
q17985 | AbstractBean.mapPropertyNameToParameterizedStateChangeCallback | train | protected boolean mapPropertyNameToParameterizedStateChangeCallback(String propertyName,
ParameterizedStateChangeCallback callback) {
propertyNameToParameterizedStateChangeCallbackMapping.put(propertyName, callback);
return propertyNameToParameterizedStateChangeCallbackMapping.containsKey(propertyName);
} | java | {
"resource": ""
} |
q17986 | snmp_manager.get_filtered | train | public static snmp_manager[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
snmp_manager obj = new snmp_manager();
options option = new options();
option.set_filter(filter);
snmp_manager[] response = (snmp_manager[]) obj.getfiltered(service, option);
return response;
} | java | {
"resource": ""
} |
q17987 | sms_server.count | train | public static long count(nitro_service service) throws Exception
{
sms_server obj = new sms_server();
options option = new options();
option.set_count(true);
sms_server[] response = (sms_server[])obj.get_resources(service, option);
if (response != null && response.length > 0)
return response[0].__count;
return 0;
} | java | {
"resource": ""
} |
q17988 | options.set_filter | train | public void set_filter(filtervalue[] filter)
{
String str = null;
for (int i = 0; i < filter.length; i++)
{
if (str != null)
str = str + ",";
if (str == null)
str = filter[i].get_name() + ":" + nitro_util.encode(filter[i].get_value());
else
str = str + filter[i].get_name() + ":" + nitro_util.encode(filter[i].get_value());;
}
this.filter = str;
} | java | {
"resource": ""
} |
q17989 | task_device_log.get | train | public static task_device_log get(nitro_service client, task_device_log resource) throws Exception
{
resource.validate("get");
return ((task_device_log[]) resource.get_resources(client))[0];
} | java | {
"resource": ""
} |
q17990 | FakerMock.withFields | train | public static <T> T withFields(Class<T> clazz, Object... keysAndValues) {
return Mockito.mock(clazz, new FakerAnswer(keysAndValues));
} | java | {
"resource": ""
} |
q17991 | ChannelFinderClientImpl.getAllProperties | train | public Collection<String> getAllProperties() {
return wrappedSubmit(new Callable<Collection<String>>() {
@Override
public Collection<String> call() throws Exception {
Collection<String> allProperties = new HashSet<String>();
ObjectMapper mapper = new ObjectMapper();
List<XmlProperty> xmlproperties = new ArrayList<XmlProperty>();
try {xmlproperties = mapper.readValue(
service.path(resourceProperties)
.accept(MediaType.APPLICATION_JSON)
.get(String.class)
,new TypeReference<List<XmlProperty>>(){});
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientHandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (XmlProperty xmlproperty : xmlproperties) {
allProperties.add(xmlproperty.getName());
}
return allProperties;
}
});
} | java | {
"resource": ""
} |
q17992 | ChannelFinderClientImpl.getAllTags | train | public Collection<String> getAllTags() {
return wrappedSubmit(new Callable<Collection<String>>() {
@Override
public Collection<String> call() throws Exception {
Collection<String> allTags = new HashSet<String>();
ObjectMapper mapper = new ObjectMapper();
List<XmlTag> xmltags = new ArrayList<XmlTag>();
try {xmltags = mapper.readValue(
service.path(resourceTags)
.accept(MediaType.APPLICATION_JSON)
.get(String.class)
,new TypeReference<List<XmlTag>>(){});
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientHandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (XmlTag xmltag : xmltags) {
allTags.add(xmltag.getName());
}
return allTags;
}
});
} | java | {
"resource": ""
} |
q17993 | ChannelFinderClientImpl.set | train | public void set(Collection<Builder> channels) throws ChannelFinderException {
wrappedSubmit(new SetChannels(ChannelUtil.toCollectionXmlChannels(channels)));
} | java | {
"resource": ""
} |
q17994 | BooleanUtils.and | train | @SuppressWarnings("all")
@NullSafe
public static boolean and(Boolean... values) {
boolean result = (values != null); // innocent until proven guilty
if (result) {
for (Boolean value : values) {
result &= valueOf(value);
if (!result) { // short-circuit if we find a false value
break;
}
}
}
return result;
} | java | {
"resource": ""
} |
q17995 | BooleanUtils.or | train | @SuppressWarnings("all")
@NullSafe
public static boolean or(Boolean... values) {
boolean result = false; // guilty until proven innocent
for (Boolean value : nullSafeArray(values, Boolean.class)) {
result |= valueOf(value);
if (result) { // short-circuit if we find a true value
break;
}
}
return result;
} | java | {
"resource": ""
} |
q17996 | BooleanUtils.xor | train | @NullSafe
public static boolean xor(Boolean... values) {
boolean result = false; // guilty until proven innocent.
for (Boolean value : nullSafeArray(values, Boolean.class)) {
boolean primitiveValue = valueOf(value);
if (result && primitiveValue) {
return false; // short-circuit if we find more than 1 true value
}
result |= primitiveValue;
}
return result;
} | java | {
"resource": ""
} |
q17997 | StrategicQueues.newStrategicLinkedBlockingQueue | train | public static <V> StrategicBlockingQueue<V> newStrategicLinkedBlockingQueue(QueueingStrategy<V> queueingStrategy) {
return new StrategicBlockingQueue<V>(new LinkedBlockingQueue<V>(), queueingStrategy);
} | java | {
"resource": ""
} |
q17998 | StrategicQueues.newStrategicArrayBlockingQueue | train | public static <V> StrategicBlockingQueue<V> newStrategicArrayBlockingQueue(int capacity, QueueingStrategy<V> queueingStrategy) {
return new StrategicBlockingQueue<V>(new ArrayBlockingQueue<V>(capacity), queueingStrategy);
} | java | {
"resource": ""
} |
q17999 | StrategicQueues.newStrategicBlockingQueue | train | public static <V> StrategicBlockingQueue<V> newStrategicBlockingQueue(BlockingQueue<V> blockingQueue, QueueingStrategy<V> queueingStrategy) {
return new StrategicBlockingQueue<V>(blockingQueue, queueingStrategy);
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.