code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public static FieldLocation getFieldLocation(final Node aNode, final Set<FieldLocation> fieldLocations) {
FieldLocation toReturn = null;
if (aNode != null) {
if (CLASS_FIELD_METHOD_ELEMENT_NAMES.contains(aNode.getLocalName().toLowerCase())) {
// This is a ComplexType whic... | java |
public static <T extends FieldLocation> T getFieldOrMethodLocationIfValid(
final Node aNode,
final Node containingClassNode,
final Set<? extends FieldLocation> locations) {
T toReturn = null;
if (containingClassNode != null) {
// Do we have a FieldLocat... | java |
public static void insertXmlDocumentationAnnotationsFor(
final Node aNode,
final SortedMap<ClassLocation, JavaDocData> classJavaDocs,
final SortedMap<FieldLocation, JavaDocData> fieldJavaDocs,
final SortedMap<MethodLocation, JavaDocData> methodJavaDocs,
final ... | java |
private void initialize(final Reader xmlFileStream) {
// Build a DOM model.
final Document parsedDocument = XsdGeneratorHelper.parseXmlStream(xmlFileStream);
// Process the DOM model.
XsdGeneratorHelper.process(parsedDocument.getFirstChild(), true, new NamespaceAttributeNodeProce... | java |
public final void setPatternPrefix(final String patternPrefix) {
// Check sanity
validateDiSetterCalledBeforeInitialization("patternPrefix");
// Check sanity
if (patternPrefix != null) {
// Assign internal state
this.patternPrefix = patternPrefix;
} els... | java |
public void setConverter(final StringConverter<T> converter) {
// Check sanity
Validate.notNull(converter, "converter");
validateDiSetterCalledBeforeInitialization("converter");
// Assign internal state
this.converter = converter;
} | java |
public static <T> boolean matchAtLeastOnce(final T object, final List<Filter<T>> filters) {
// Check sanity
Validate.notNull(filters, "filters");
boolean acceptedByAtLeastOneFilter = false;
for (Filter<T> current : filters) {
if (current.accept(object)) {
ac... | java |
public static <T> boolean rejectAtLeastOnce(final T object, final List<Filter<T>> filters) {
// Check sanity
Validate.notNull(filters, "filters");
boolean rejectedByAtLeastOneFilter = false;
for (Filter<T> current : filters) {
if (!current.accept(object)) {
... | java |
public static <T> boolean noFilterMatches(final T object, final List<Filter<T>> filters) {
// Check sanity
Validate.notNull(filters, "filters");
boolean matchedAtLeastOnce = false;
for (Filter<T> current : filters) {
if (current.accept(object)) {
matchedAtLe... | java |
public static FileFilter adapt(final Filter<File> toAdapt) {
// Check sanity
Validate.notNull(toAdapt, "toAdapt");
// Already a FileFilter?
if (toAdapt instanceof FileFilter) {
return (FileFilter) toAdapt;
}
// Wrap and return.
return new FileFilter... | java |
public static List<FileFilter> adapt(final List<Filter<File>> toAdapt) {
final List<FileFilter> toReturn = new ArrayList<FileFilter>();
if (toAdapt != null) {
for (Filter<File> current : toAdapt) {
toReturn.add(adapt(current));
}
}
// All done.
... | java |
public static <T> void initialize(final Log log, final List<Filter<T>> filters) {
// Check sanity
Validate.notNull(log, "log");
Validate.notNull(filters, "filters");
for (Filter<T> current : filters) {
current.initialize(log);
}
} | java |
public static File getCanonicalFile(final File file) {
// Check sanity
Validate.notNull(file, "file");
// All done
try {
return file.getCanonicalFile();
} catch (IOException e) {
throw new IllegalArgumentException("Could not acquire the canonical file fo... | java |
public static URL getUrlFor(final File aFile) throws IllegalArgumentException {
// Check sanity
Validate.notNull(aFile, "aFile");
try {
return aFile.toURI().normalize().toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Could not re... | java |
public static File getFileFor(final URL anURL, final String encoding) {
// Check sanity
Validate.notNull(anURL, "anURL");
Validate.notNull(encoding, "encoding");
final String protocol = anURL.getProtocol();
File toReturn = null;
if ("file".equalsIgnoreCase(protocol)) {
... | java |
public static void createDirectory(final File aDirectory, final boolean cleanBeforeCreate)
throws MojoExecutionException {
// Check sanity
Validate.notNull(aDirectory, "aDirectory");
validateFileOrDirectoryName(aDirectory);
// Clean an existing directory?
if (cleanB... | java |
public static String relativize(final String path,
final File parentDir,
final boolean removeInitialFileSep) {
// Check sanity
Validate.notNull(path, "path");
Validate.notNull(parentDir, "parentDir");
final String ... | java |
public String getNormalizedXml(String filePath) {
// Read the provided filename
final StringWriter toReturn = new StringWriter();
final BufferedReader in;
try {
in = new BufferedReader(new FileReader(new File(filePath)));
} catch (FileNotFoundException e) {
... | java |
public static Map<String, SimpleNamespaceResolver> getFileNameToResolverMap(final File outputDirectory)
throws MojoExecutionException {
final Map<String, SimpleNamespaceResolver> toReturn = new TreeMap<String, SimpleNamespaceResolver>();
// Each generated schema file should be written... | java |
public static void validateSchemasInPluginConfiguration(final List<TransformSchema> configuredTransformSchemas)
throws MojoExecutionException {
final List<String> uris = new ArrayList<String>();
final List<String> prefixes = new ArrayList<String>();
final List<String> fileNames... | java |
public static int insertJavaDocAsAnnotations(final Log log,
final String encoding,
final File outputDir,
final SearchableDocumentation docs,
... | java |
public static void replaceNamespacePrefixes(
final Map<String, SimpleNamespaceResolver> resolverMap,
final List<TransformSchema> configuredTransformSchemas,
final Log mavenLog,
final File schemaDirectory,
final String encoding) throws MojoExecutionExcepti... | java |
public static void renameGeneratedSchemaFiles(final Map<String, SimpleNamespaceResolver> resolverMap,
final List<TransformSchema> configuredTransformSchemas,
final Log mavenLog,
... | java |
public static Document parseXmlStream(final Reader xmlStream) {
// Build a DOM model of the provided xmlFileStream.
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
return factory.newDocumentBuilder()... | java |
protected static String getHumanReadableXml(final Node node) {
StringWriter toReturn = new StringWriter();
try {
Transformer transformer = getFactory().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(Outp... | java |
private static Document parseXmlToDocument(final File xmlFile) {
Document result = null;
Reader reader = null;
try {
reader = new FileReader(xmlFile);
result = parseXmlStream(reader);
} catch (FileNotFoundException e) {
// This should never happ... | java |
public ArgumentBuilder withPreCompiledArguments(final List<String> preCompiledArguments) {
// Check sanity
Validate.notNull(preCompiledArguments, "preCompiledArguments");
// Add the preCompiledArguments in the exact order they were given.
synchronized (lock) {
for (String c... | java |
public static int getJavaMajorVersion() {
final String[] versionElements = System.getProperty(JAVA_VERSION_PROPERTY).split("\\.");
final int[] versionNumbers = new int[versionElements.length];
for (int i = 0; i < versionElements.length; i++) {
try {
versionNumbers[i... | java |
public <V, T extends Enum & Option> OptionsMapper env(final String name, final T option,
final Function<String, V> converter) {
register("env: " + name, option, System.getenv(name), converter);
return this;
} | java |
public <V, T extends Enum & Option> OptionsMapper string(final T option, final String value,
final Function<String, V> converter) {
register("", option, value, converter);
return this;
} | java |
public static Managed registerInjector(final Application application, final Injector injector) {
Preconditions.checkNotNull(application, "Application instance required");
Preconditions.checkArgument(!INJECTORS.containsKey(application),
"Injector already registered for application %s", ap... | java |
@SuppressWarnings("unchecked")
public static <T> Class<T> getInstanceClass(final T object) {
final Class cls = object.getClass();
return cls.getName().contains("$$EnhancerByGuice") ? (Class<T>) cls.getSuperclass() : cls;
} | java |
public void scan(final ClassVisitor visitor) {
if (scanned == null) {
performScan();
}
for (Class<?> cls : scanned) {
visitor.visit(cls);
}
} | java |
public static <T> List<T> removeTypes(final List<T> list, final List<Class<? extends T>> filter) {
final Iterator it = list.iterator();
while (it.hasNext()) {
final Class type = it.next().getClass();
if (filter.contains(type)) {
it.remove();
}
... | java |
public ConfigPath findByPath(final String path) {
return paths.stream()
.filter(it -> it.getPath().equalsIgnoreCase(path))
.findFirst()
.orElse(null);
} | java |
public List<ConfigPath> findAllRootPaths() {
return paths.stream()
.filter(it -> !it.getPath().contains(DOT))
.collect(Collectors.toList());
} | java |
public void hkManage(final Class<?> type) {
if (!JerseyBinding.isHK2Managed(type, options.get(JerseyExtensionsManagedByGuice))) {
throw new WrongContextException("HK2 creates service %s which must be managed by guice.",
type.getName());
}
hkManaged.add(type);
... | java |
public void guiceManage(final Class<?> type) {
if (JerseyBinding.isHK2Managed(type, options.get(JerseyExtensionsManagedByGuice))) {
throw new WrongContextException("Guice creates service %s which must be managed by HK2.",
type.getName());
}
guiceManaged.add(type);... | java |
private void checkHkFirstMode() {
final boolean guiceyFirstMode = context.option(JerseyExtensionsManagedByGuice);
if (!guiceyFirstMode) {
Preconditions.checkState(context.option(UseHkBridge),
"HK2 management for jersey extensions is enabled by default "
... | java |
public static void register(final GuiceyConfigurationHook hook) {
if (HOOKS.get() == null) {
// to avoid duplicate registrations
HOOKS.set(new LinkedHashSet<>());
}
HOOKS.get().add(hook);
} | java |
@SuppressWarnings("unchecked")
public static void configureModules(final ConfigurationContext context) {
final Options options = new Options(context.options());
for (Module mod : context.getEnabledModules()) {
if (mod instanceof BootstrapAwareModule) {
((BootstrapAwareMod... | java |
public void activate() {
GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
final GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(injector);
} | java |
protected boolean isForceSingleton(final Class<?> type, final boolean hkManaged) {
return ((Boolean) option(ForceSingletonForJerseyExtensions)) && !hasScopeAnnotation(type, hkManaged);
} | java |
private boolean hasScopeAnnotation(final Class<?> type, final boolean hkManaged) {
boolean found = false;
for (Annotation ann : type.getAnnotations()) {
final Class<? extends Annotation> annType = ann.annotationType();
if (annType.isAnnotationPresent(Scope.class)) {
... | java |
public void registerCommands(final List<Class<Command>> commands) {
setScope(ConfigScope.ClasspathScan.getType());
for (Class<Command> cmd : commands) {
register(ConfigItem.Command, cmd);
}
closeScope();
} | java |
private void applyPredicatesForRegisteredItems(final List<PredicateHandler> predicates) {
ImmutableList.builder()
.addAll(getEnabledModules())
.addAll(getEnabledBundles())
.addAll(getEnabledExtensions())
.addAll(getEnabledInstallers())
... | java |
@SuppressWarnings("unchecked")
private <T extends ItemInfoImpl> T getOrCreateInfo(final ConfigItem type, final Object item) {
final Class<?> itemType = getType(item);
final T info;
// details holder allows to implicitly filter by type and avoid duplicate registration
if (detailsHolde... | java |
@SafeVarargs
public final OptionsConfig hideGroups(final Class<Enum>... groups) {
hiddenGroups.addAll(Arrays.asList(groups));
return this;
} | java |
public static void overrideScope(final Runnable action) {
override.set(true);
try {
action.run();
} finally {
override.remove();
}
} | java |
public final Reporter line(final String line, final Object... args) {
counter++;
wasEmptyLine = false;
message.append(TAB).append(String.format(line, args)).append(NEWLINE);
return this;
} | java |
@Override
public String renderReport(final ContextTreeConfig config) {
final Set<Class<?>> scopes = service.getActiveScopes(!config.isHideDisables());
final TreeNode root = new TreeNode("APPLICATION");
if (!config.getHiddenScopes().contains(Application.getType())) {
renderScope... | java |
private void renderBundle(final ContextTreeConfig config, final TreeNode root,
final Class<?> scope, final Class<Object> bundle) {
final BundleItemInfo info = service.getData().getInfo(bundle);
if (isHidden(config, info, scope)) {
return;
}
final... | java |
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
private boolean isHidden(final ContextTreeConfig config, final ItemInfo info, final Class<?> scope) {
// item explicitly hidden
final boolean hidden = config.getHiddenItems().contains(info.getItemType());
// installer disabled
... | java |
public static ConfigurationTree build(final Bootstrap bootstrap,
final Configuration configuration,
final boolean introspect) {
final List<Class> roots = resolveRootTypes(new ArrayList<>(), configuration.getClass());
if ... | java |
@Override
public String renderReport(final OptionsConfig config) {
final StringBuilder res = new StringBuilder();
render(config, res);
return res.toString();
} | java |
public void count(final Stat name, final int count) {
Integer value = counters.get(name);
value = value == null ? count : value + count;
counters.put(name, value);
} | java |
public void startHkTimer(final Stat name) {
timer(GuiceyTime);
if (!HKTime.equals(name)) {
timer(HKTime);
}
timer(name);
} | java |
private List<FeatureInstaller> prepareInstallers(
final List<Class<? extends FeatureInstaller>> installerClasses) {
final List<FeatureInstaller> installers = Lists.newArrayList();
// different instance then used in guice context, but it's just an accessor object
final Options options... | java |
@SuppressWarnings("PMD.PrematureDeclaration")
private void resolveExtensions(final ExtensionsHolder holder) {
final Stopwatch timer = context.stat().timer(Stat.ExtensionsRecognitionTime);
final boolean guiceFirstMode = context.option(JerseyExtensionsManagedByGuice);
final List<Class<?>> manu... | java |
@SuppressWarnings("unchecked")
private void bindExtension(final ExtensionItemInfo item, final FeatureInstaller installer,
final ExtensionsHolder holder) {
final Class<? extends FeatureInstaller> installerClass = installer.getClass();
final Class<?> type = item.getType(... | java |
public static String renderDisabledInstaller(final Class<FeatureInstaller> type) {
return String.format("-%-19s %-38s",
FeatureUtils.getInstallerExtName(type), brackets(renderClass(type)));
} | java |
public static String renderPackage(final Class<?> type) {
return PACKAGE_FORMATTER.abbreviate(type.isMemberClass() && !type.isAnonymousClass()
? type.getDeclaringClass().getName() : type.getPackage().getName());
} | java |
@Override
public String renderReport(final DiagnosticConfig config) {
final StringBuilder res = new StringBuilder();
printCommands(config, res);
printBundles(config, res);
if (config.isPrintInstallers()) {
printInstallers(config, res);
printDisabledExtensions(... | java |
private void configureFromBundles() {
context.lifecycle().runPhase(context.getConfiguration(), context.getConfigurationTree(),
context.getEnvironment());
final Stopwatch timer = context.stat().timer(BundleTime);
final Stopwatch resolutionTimer = context.stat().timer(BundleResolut... | java |
@SuppressWarnings("deprecation")
private void bindEnvironment() {
bind(Bootstrap.class).toInstance(bootstrap());
bind(Environment.class).toInstance(environment());
install(new ConfigBindingModule(configuration(), configurationTree(),
context.option(BindConfigurationInterfaces... | java |
@SafeVarargs
public static void enableBundles(final Class<? extends GuiceyBundle>... bundles) {
final String prop = Joiner.on(',').join(toStrings(Lists.newArrayList(bundles)));
System.setProperty(BUNDLES_PROPERTY, prop);
} | java |
public boolean cancel(boolean ign) {
assert op != null : "No operation";
op.cancel();
notifyListeners();
return op.getState() == OperationState.WRITE_QUEUED;
} | java |
public Long getCas() {
if (cas == null) {
try {
get();
} catch (InterruptedException e) {
status = new OperationStatus(false, "Interrupted", StatusCode.INTERRUPTED);
} catch (ExecutionException e) {
getLogger().warn("Error getting cas of operation", e);
}
}
if... | java |
public OperationStatus getStatus() {
if (status == null) {
try {
get();
} catch (InterruptedException e) {
status = new OperationStatus(false, "Interrupted", StatusCode.INTERRUPTED);
} catch (ExecutionException e) {
getLogger().warn("Error getting status of operation", e);
... | java |
public void set(T o, OperationStatus s) {
objRef.set(o);
status = s;
} | java |
public static Logger getLogger(String name) {
if (name == null) {
throw new NullPointerException("Logger name may not be null.");
}
init();
return (instance.internalGetLogger(name));
} | java |
private Logger internalGetLogger(String name) {
assert name != null : "Name was null";
Logger rv = instances.get(name);
if (rv == null) {
Logger newLogger = null;
try {
newLogger = getNewInstance(name);
} catch (Exception e) {
throw new RuntimeException("Problem getting lo... | java |
@SuppressWarnings("unchecked")
private void getConstructor() {
Class<? extends Logger> c = DefaultLogger.class;
String className = System.getProperty("net.spy.log.LoggerImpl");
if (className != null) {
try {
c = (Class<? extends Logger>) Class.forName(className);
} catch (NoClassDefFo... | java |
public Throwable getThrowable(Object[] args) {
Throwable rv = null;
if (args.length > 0) {
if (args[args.length - 1] instanceof Throwable) {
rv = (Throwable) args[args.length - 1];
}
}
return rv;
} | java |
public void trace(Object message, Throwable exception) {
log(Level.TRACE, message, exception);
} | java |
public void trace(String message, Object... args) {
if (isDebugEnabled()) {
trace(String.format(message, args), getThrowable(args));
}
} | java |
public void debug(Object message, Throwable exception) {
log(Level.DEBUG, message, exception);
} | java |
public void info(String message, Object... args) {
if (isInfoEnabled()) {
info(String.format(message, args), getThrowable(args));
}
} | java |
public void warn(Object message, Throwable exception) {
log(Level.WARN, message, exception);
} | java |
public void error(Object message, Throwable exception) {
log(Level.ERROR, message, exception);
} | java |
public void fatal(Object message, Throwable exception) {
log(Level.FATAL, message, exception);
} | java |
@Override
public void log(Level level, Object message, Throwable e) {
if(level == null) {
level = Level.FATAL;
}
switch(level) {
case TRACE:
logger.trace(message.toString(), e);
break;
case DEBUG:
logger.debug(message.toString(), e);
break;
case INFO:
logge... | java |
public synchronized void authConnection(MemcachedConnection conn,
OperationFactory opFact, AuthDescriptor authDescriptor,
MemcachedNode node) {
interruptOldAuth(node);
AuthThread newSASLAuthenticator =
new AuthThread(conn, opFact, authDescriptor, node);
nodeMap.put(node, newSASLAuthentic... | java |
private void parseHeaderFromBuffer() {
int magic = header[0];
assert magic == RES_MAGIC : "Invalid magic: " + magic;
responseCmd = header[1];
assert cmd == DUMMY_OPCODE || responseCmd == cmd
: "Unexpected response command value";
keyLen = decodeShort(header, 2);
errorCode = decodeShort(he... | java |
private void readPayloadFromBuffer(final ByteBuffer buffer)
throws IOException {
int toRead = payload.length - payloadOffset;
int available = buffer.remaining();
toRead = Math.min(toRead, available);
getLogger().debug("Reading %d payload bytes", toRead);
buffer.get(payload, payloadOffset, toRead... | java |
protected OperationStatus getStatusForErrorCode(int errCode, byte[] errPl)
throws IOException {
if(errCode == SUCCESS) {
return STATUS_OK;
} else {
StatusCode statusCode = StatusCode.fromBinaryCode(errCode);
errorMsg = errPl.clone();
switch (errCode) {
case ERR_... | java |
protected void prepareBuffer(final String key, final long cas,
final byte[] val, final Object... extraHeaders) {
int extraLen = 0;
int extraHeadersLength = extraHeaders.length;
if (extraHeadersLength > 0) {
extraLen = calculateExtraLength(extraHeaders);
}
final byte[] keyBytes = KeyUtil.... | java |
private void initReporter() {
String reporterType =
System.getProperty("net.spy.metrics.reporter.type", DEFAULT_REPORTER_TYPE);
String reporterInterval =
System.getProperty("net.spy.metrics.reporter.interval", DEFAULT_REPORTER_INTERVAL);
String reporterDir =
System.getProperty("net.spy.met... | java |
public ResponseMessage getNextMessage(long time, TimeUnit timeunit) {
try {
Object m = rqueue.poll(time, timeunit);
if (m == null) {
return null;
} else if (m instanceof ResponseMessage) {
return (ResponseMessage) m;
} else if (m instanceof TapAck) {
TapAck ack = (Tap... | java |
public boolean hasMoreMessages() {
if (!rqueue.isEmpty()) {
return true;
} else {
synchronized (omap) {
Iterator<TapStream> itr = omap.keySet().iterator();
while (itr.hasNext()) {
TapStream ts = itr.next();
if (ts.isCompleted() || ts.isCancelled() || ts.hasErrored... | java |
public TapStream tapCustom(final String id, final RequestMessage message)
throws ConfigurationException, IOException {
final TapConnectionProvider conn = new TapConnectionProvider(addrs);
final TapStream ts = new TapStream();
conn.broadcastOp(new BroadcastOpFactory() {
public Operation newOp(final... | java |
public void shutdown() {
synchronized (omap) {
for (Map.Entry<TapStream, TapConnectionProvider> me : omap.entrySet()) {
me.getValue().shutdown();
}
}
} | java |
public static long fieldToValue(byte[] buffer, int offset, int length) {
long total = 0;
long val = 0;
for (int i = 0; i < length; i++) {
val = buffer[offset + i];
if (val < 0) {
val = val + 256;
}
total += (long) Math.pow(256.0, (double) (length - 1 - i)) * val;
}
re... | java |
public static void valueToFieldOffest(byte[] buffer, int offset, int length,
long l) {
long divisor;
for (int i = 0; i < length; i++) {
divisor = (long) Math.pow(256.0, (double) (length - 1 - i));
buffer[offset + i] = (byte) (l / divisor);
l = l % divisor;
}
} | java |
protected final synchronized void transitionState(OperationState newState) {
getLogger().debug("Transitioned state from %s to %s", state, newState);
state = newState;
// Discard our buffer when we no longer need it.
if(state != OperationState.WRITE_QUEUED
&& state != OperationState.WRITING) {
... | java |
public boolean isCompleted() {
for (TapOperation op : ops) {
if (!op.getState().equals(OperationState.COMPLETE)) {
return false;
}
}
return true;
} | java |
public void setFlags(TapRequestFlag f) {
if (!flagList.contains(f)) {
if (!hasFlags) {
hasFlags = true;
extralength += 4;
totalbody += 4;
}
if (f.equals(TapRequestFlag.BACKFILL)) {
hasBackfill = true;
totalbody += 8;
}
if (f.equals(TapRequestFlag... | java |
public void setVbucketlist(short[] vbs) {
int oldSize = (vblist.length + 1) * 2;
int newSize = (vbs.length + 1) * 2;
totalbody += newSize - oldSize;
vblist = vbs;
} | java |
public void setvBucketCheckpoints(Map<Short, Long> vbchkpnts) {
int oldSize = (vBucketCheckpoints.size()) * 10;
int newSize = (vbchkpnts.size()) * 10;
totalbody += newSize - oldSize;
vBucketCheckpoints = vbchkpnts;
} | java |
public void setName(String n) {
if (n.length() > 65535) {
throw new IllegalArgumentException("Tap name too long");
}
totalbody += n.length() - name.length();
keylength = (short) n.length();
name = n;
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.