code
stringlengths
73
34.1k
label
stringclasses
1 value
public static void assertOnlyOneMethod(final Collection<Method> methods, Class<? extends Annotation> annotation) { if (methods.size() > 1) { throw annotation == null ? MESSAGES.onlyOneMethodCanExist() : MESSAGES.onlyOneMethodCanExist2(annotation); } }
java
public final void invoke(final Endpoint endpoint, final Invocation invocation) throws Exception { try { // prepare for invocation this.init(endpoint, invocation); final Object targetBean = invocation.getInvocationContext().getTargetBean(); final Class<?> implClass = ta...
java
@Override public <T> T getSPI(Class<T> spiType, ClassLoader loader) { T returnType = null; // SPIs provided by framework, defaults can be overridden if (DeploymentModelFactory.class.equals(spiType)) { returnType = loadService(spiType, DefaultDeploymentModelFactory.class, loader);...
java
@SuppressWarnings("unchecked") private <T> T loadService(Class<T> spiType, Class<?> defaultImpl, ClassLoader loader) { final String defaultImplName = defaultImpl != null ? defaultImpl.getName() : null; return (T)ServiceLoader.loadService(spiType.getName(), defaultImplName, loader); }
java
private boolean isRecording(Endpoint endpoint) { List<RecordProcessor> processors = endpoint.getRecordProcessors(); if (processors == null || processors.isEmpty()) { return false; } for (RecordProcessor processor : processors) { if (processor.isRecording()) ...
java
public static void rethrow(final String message, final Exception reason) { if (reason == null) { throw new IllegalArgumentException(); } Loggers.ROOT_LOGGER.error(message == null ? reason.getMessage() : message, reason); throw new InjectionException(message, reason); }
java
public EndpointConfig resolveEndpointConfig() { final String endpointClassName = getEndpointClassName(); // 1) default values //String configName = org.jboss.wsf.spi.metadata.config.EndpointConfig.STANDARD_ENDPOINT_CONFIG; String configName = endpointClassName; String configFile = Endpoint...
java
public Set<String> getAllHandlers(EndpointConfig config) { Set<String> set = new HashSet<String>(); if (config != null) { for (UnifiedHandlerChainMetaData uhcmd : config.getPreHandlerChains()) { for (UnifiedHandlerMetaData uhmd : uhcmd.getHandlers()) { set.add(uhmd.getHan...
java
@SuppressWarnings("unchecked") protected void publishWsdlImports(URL parentURL, Definition parentDefinition, List<String> published, String expLocation) throws Exception { @SuppressWarnings("rawtypes") Iterator it = parentDefinition.getImports().values().iterator(); while (it.hasNext()) { ...
java
protected void publishSchemaImports(URL parentURL, Element element, List<String> published, String expLocation) throws Exception { Element childElement = getFirstChildElement(element); while (childElement != null) { //first check on namespace only to avoid doing anything on any other wsdl/schema...
java
public void unpublishWsdlFiles() throws IOException { String deploymentDir = (dep.getParent() != null ? dep.getParent().getSimpleName() : dep.getSimpleName()); File serviceDir = new File(serverConfig.getServerDataDir().getCanonicalPath() + "/wsdl/" + deploymentDir); deleteWsdlPublishDirectory(serv...
java
protected void deleteWsdlPublishDirectory(File dir) throws IOException { String[] files = dir.list(); for (int i = 0; files != null && i < files.length; i++) { String fileName = files[i]; File file = new File(dir + "/" + fileName); if (file.isDirectory()) { ...
java
protected Object readResolve() throws ObjectStreamException { try { Class<?> proxyClass = getProxyClass(); Object instance = proxyClass.newInstance(); ProxyFactory.setInvocationHandlerStatic(instance, handler); return instance; } catch (InstantiationExcept...
java
protected Class<?> getProxyClass() throws ClassNotFoundException { ClassLoader classLoader = getProxyClassLoader(); return Class.forName(proxyClassName, false, classLoader); }
java
public static DocumentBuilder newDocumentBuilder(final DocumentBuilderFactory factory) { try { final DocumentBuilder builder = factory.newDocumentBuilder(); return builder; } catch (Exception e) { throw MESSAGES.unableToCreateInstanceOf(e, DocumentBuilder.clas...
java
public static Element parse(String xmlString) throws IOException { try { return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8"))); } catch (IOException e) { ROOT_LOGGER.cannotParse(xmlString); throw e; } }
java
public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws IOException { try { Document doc; synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder { doc = builder.parse(xmlStream); } ...
java
public static Element parse(InputStream xmlStream) throws IOException { DocumentBuilder builder = getDocumentBuilder(); return parse(xmlStream, builder); }
java
public static Element parse(InputSource source) throws IOException { try { Document doc; DocumentBuilder builder = getDocumentBuilder(); synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder { doc = builder.parse(sou...
java
public static Element createElement(String localPart) { Document doc = getOwnerDocument(); if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.trace("createElement {}" + localPart); return doc.createElement(localPart); }
java
public static Element createElement(String localPart, String prefix, String uri) { Document doc = getOwnerDocument(); if (prefix == null || prefix.length() == 0) { if (ROOT_LOGGER.isTraceEnabled()) ROOT_LOGGER.trace("createElement {" + uri + "}" + localPart); return doc.createElem...
java
public static Element createElement(QName qname) { return createElement(qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI()); }
java
public static Text createTextNode(String value) { Document doc = getOwnerDocument(); return doc.createTextNode(value); }
java
public static Document getOwnerDocument() { Document doc = documentThreadLocal.get(); if (doc == null) { doc = getDocumentBuilder().newDocument(); documentThreadLocal.set(doc); } return doc; }
java
public static Element sourceToElement(Source source) throws IOException { Element retElement = null; if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource)source; InputStream ins = streamSource.getInputStream(); if (ins != null) { ...
java
public static String node2String(final Node node) throws UnsupportedEncodingException { return node2String(node, true, Constants.DEFAULT_XML_CHARSET); }
java
public static String node2String(final Node node, boolean prettyPrint) throws UnsupportedEncodingException { return node2String(node, prettyPrint, Constants.DEFAULT_XML_CHARSET); }
java
public static String node2String(final Node node, boolean prettyPrint, String encoding) throws UnsupportedEncodingException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new DOMWriter(new PrintWriter(baos), encoding).setPrettyprint(prettyPrint).print(node); return baos.toString...
java
public void setContextProperties(Map<String, String> contextProperties) { if (contextProperties != null) { this.contextProperties = new HashMap<String, String>(4); this.contextProperties.putAll(contextProperties); } }
java
public String[] getParameterTypes() { final String[] parameterTypes = this.parameterTypes; return parameterTypes == NO_STRINGS ? parameterTypes : parameterTypes.clone(); }
java
public Method getPublicMethod(final Class<?> clazz) throws NoSuchMethodException, ClassNotFoundException { return clazz.getMethod(name, typesOf(parameterTypes, clazz.getClassLoader())); }
java
public static MethodIdentifier getIdentifier(final Class<?> returnType, final String name, final Class<?>... parameterTypes) { return new MethodIdentifier(returnType.getName(), name, namesOf(parameterTypes)); }
java
public static MethodIdentifier getIdentifier(final String returnType, final String name, final String... parameterTypes) { return new MethodIdentifier(returnType, name, parameterTypes); }
java
public ProxyConfiguration<T> setProxyName(final Package pkg, final String simpleName) { this.proxyName = pkg.getName() + '.' + simpleName; return this; }
java
public static Class<?> loadJavaType(String typeName, ClassLoader classLoader) throws ClassNotFoundException { if (classLoader == null) classLoader = getContextClassLoader(); Class<?> javaType = primitiveNames.get(typeName); if (javaType == null) javaType = getArray(typeName, clas...
java
public static boolean isPrimitive(Class<?> javaType) { return javaType.isPrimitive() || (javaType.isArray() && isPrimitive(javaType.getComponentType())); }
java
public static String getJustClassName(Class<?> cls) { if (cls == null) return null; if (cls.isArray()) { Class<?> c = cls.getComponentType(); return getJustClassName(c.getName()); } return getJustClassName(cls.getName()); }
java
public static String getJustClassName(String classname) { int index = classname.lastIndexOf('.'); if (index < 0) index = 0; else index = index + 1; return classname.substring(index); }
java
public static Class<?> getPrimitiveType(Class<?> javaType) { if (javaType == Integer.class) return int.class; if (javaType == Short.class) return short.class; if (javaType == Boolean.class) return boolean.class; if (javaType == Byte.class) return byte.class...
java
public static Object getPrimitiveValueArray(Object value) { if (value == null) return null; Class<?> javaType = value.getClass(); if (javaType.isArray()) { int length = Array.getLength(value); Object destArr = Array.newInstance(getPrimitiveType(javaType.getComponen...
java
public static boolean isAssignableFrom(Class<?> dest, Class<?> src) { if (dest == null || src == null) throw MESSAGES.cannotCheckClassIsAssignableFrom(dest, src); boolean isAssignable = dest.isAssignableFrom(src); if (isAssignable == false && dest.getName().equals(src.getName())) { ...
java
public static Class<?> erasure(Type type) { if (type instanceof ParameterizedType) { return erasure(((ParameterizedType)type).getRawType()); } if (type instanceof TypeVariable<?>) { return erasure(((TypeVariable<?>)type).getBounds()[0]); } if (type instance...
java
public static boolean isJBossRepositoryClassLoader(ClassLoader loader) { Class<?> clazz = loader.getClass(); while (!clazz.getName().startsWith("java")) { if ("org.jboss.mx.loading.RepositoryClassLoader".equals(clazz.getName())) return true; clazz = clazz.getSuperclass...
java
public static void clearBlacklists(ClassLoader loader) { if (isJBossRepositoryClassLoader(loader)) { for(Method m : loader.getClass().getMethods()) { if("clearBlackLists".equalsIgnoreCase(m.getName())) { try { m.invoke(loader); } catch (Exception e) { ...
java
private static String getName(final String resourceName, final String fallBackName) { return resourceName.length() > 0 ? resourceName : fallBackName; }
java
private static String convertToBeanName(final String methodName) { return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); }
java
protected final Method getImplMethod(final Class<?> implClass, final Method seiMethod) throws NoSuchMethodException { final String methodName = seiMethod.getName(); final Class<?>[] paramTypes = seiMethod.getParameterTypes(); return implClass.getMethod(methodName, paramTypes); }
java
@SuppressWarnings("rawtypes") public void setupConfigHandlers(Binding binding, CommonConfig config) { if (config != null) { //start with the use handlers only to remove the previously set configuration List<Handler> userHandlers = getNonConfigHandlers(binding.getHandlerChain()); L...
java
public T newInstance(InvocationHandler handler) throws InstantiationException, IllegalAccessException { T ret = newInstance(); setInvocationHandler(ret, handler); return ret; }
java
public void setInvocationHandler(Object proxy, InvocationHandler handler) { Field field = getInvocationHandlerField(); try { field.set(proxy, handler); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { ...
java
public InvocationHandler getInvocationHandler(Object proxy) { Field field = getInvocationHandlerField(); try { return (InvocationHandler) field.get(proxy); } catch (IllegalArgumentException e) { throw new RuntimeException("Object is not a proxy of correct type", e); ...
java
public boolean isProxyClassDefined(ClassLoader classLoader) { try { // first check that the proxy has not already been created classLoader.loadClass(this.className); return true; } catch (ClassNotFoundException e) { return false; } }
java
protected String getImplicitContextRoot(ArchiveDeployment dep) { String simpleName = dep.getSimpleName(); String contextRoot = simpleName.substring(0, simpleName.length() - 4); return contextRoot; }
java
public static void copyReader(OutputStream outs, Reader reader) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter(outs, StandardCharsets.UTF_8); char[] bytes = new char[1024]; int r = reader.read(bytes); while (r > 0) { ...
java
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { InterceptorContext context = new InterceptorContext(); context.setParameters(args); context.setMethod(method); return interceptor.processInvocation(context); }
java
public static byte[] generateRandomUUIDBytes() { if (rand == null) rand = new SecureRandom(); byte[] buffer = new byte[16]; rand.nextBytes(buffer); // Set version to 3 (Random) buffer[6] = (byte) ((buffer[6] & 0x0f) | 0x40); // Set variant to 2 (IETF) buffe...
java
public static String convertToString(byte[] uuid) { if (uuid.length != 16) throw Messages.MESSAGES.uuidMustBeOf16Bytes(); String string = bytesToHex(uuid, 0, 4) + "-" + bytesToHex(uuid, 4, 2) + "-" + bytesToHex(uuid, 6, 2) + "-" ...
java
@Override public void afterClassLoad(Class<?> clazz) { super.afterClassLoad(clazz); //force <clinit> to be run, while the correct ThreadLocal is set //if we do not run this then <clinit> may be run later, perhaps even in //another thread try { Class.forName(clazz....
java
static boolean isEscaped(final String characters, final int position) { int p = position; int nbBackslash = 0; while (p > 0 && characters.charAt(--p) == '\\') { nbBackslash++; } return (nbBackslash % 2 == 1); }
java
private Object wrappedAction(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args, final int actionType) { // take care to set the context's RegExp proxy to the original one as // this is checked // (cf net.sourceforge.htmlunit.corejs.javascript.regexp.RegExpImp:334) try {...
java
static String jsRegExpToJavaRegExp(String re) { re = re.replaceAll("\\[\\^\\\\\\d\\]", "."); re = re.replaceAll("\\[([^\\]]*)\\\\b([^\\]]*)\\]", "[$1\\\\cH$2]"); // [...\b...] // -> // [...\cH...] re = re.replaceAll("(?<!\\\\)\\[([^((?<!\\\\)\\[)\\]]*)\\[", "[$1\\\\["); // ...
java
private void consumeInputFully(HttpServletRequest req) { try { ServletInputStream is = req.getInputStream(); while (!is.isFinished() && is.read() != -1) { } } catch (IOException e) { log.info("Could not consume full client request", e); } }
java
public void toSAX(ContentHandler contentHandler) throws SAXException { for (SaxBit saxbit : this.saxbits) { saxbit.send(contentHandler); } }
java
public void dump(Writer writer) throws IOException { Iterator<SaxBit> i = this.saxbits.iterator(); while (i.hasNext()) { final SaxBit saxbit = i.next(); saxbit.dump(writer); } writer.flush(); }
java
@Override public void addChild(Tree t) { //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); //System.out.println("existing children: "+children); if ( t==null ) { return; // do nothing upon addChild(null) } BaseTree childTree = (BaseTree)t; if ( childTree.isNil() ) { // t is an...
java
public void addChildren(List<? extends Tree> kids) { for (int i = 0; i < kids.size(); i++) { Tree t = kids.get(i); addChild(t); } }
java
@Override public Tree getAncestor(int ttype) { Tree t = this; t = t.getParent(); while ( t!=null ) { if ( t.getType()==ttype ) return t; t = t.getParent(); } return null; }
java
@Override public List<? extends Tree> getAncestors() { if ( getParent()==null ) return null; List<Tree> ancestors = new ArrayList<Tree>(); Tree t = this; t = t.getParent(); while ( t!=null ) { ancestors.add(0, t); // insert at start t = t.getParent(); ...
java
@Override public String toStringTree() { if ( children==null || children.isEmpty() ) { return this.toString(); } StringBuilder buf = new StringBuilder(); if ( !isNil() ) { buf.append("("); buf.append(this.toString()); buf.append(' '); } for (int i = 0; children!=null && i < children.size(); ...
java
public Obj work(Obj cmd) throws Exception { stopping = false; return status().with(P_STATUS, STATUS_STARTED); }
java
public String render(SoyMapData model, String view) throws IOException { return getSoyTofu(null).newRenderer(view).setData(model).render(); }
java
public Obj buildObject(Object... members) { Obj o = newObject(); for (int i = 0; i < members.length; i+=2) { o.put((String)members[i], members[i+1]); } return o; }
java
@SuppressWarnings("unchecked") public <T> void sort(Arr arr, Comparator<T> c) { int l = arr.getLength(); Object[] objs = new Object[l]; for (int i=0; i<l; i++) { objs[i] = arr.get(i); } Arrays.sort((T[])objs, c); for (int i=0; i<l; i++) { arr.put(i, objs[i]); } }
java
public JsonTransformer build() { try { return new WrappingTransformer(buildPipe()); } catch(Exception e) { throw new RuntimeException("Failed to build pipeline: " + e.getMessage(), e); } }
java
public List<String> getSearchDimensions() { List<String> dimensions = new ArrayList<String>(); for (int i = 0; i < m_Space.dimensions(); ++i) { dimensions.add(m_Space.getDimension(i).getLabel()); } return dimensions; }
java
protected String logPerformances(Space space, Vector<Performance> performances, Tag type) { return m_Owner.logPerformances(space, performances, type); }
java
protected void logPerformances(Space space, Vector<Performance> performances) { m_Owner.logPerformances(space, performances); }
java
public void addPerformance(Performance performance, int folds) { m_Performances.add(performance); m_Cache.add(folds, performance); m_Trace.add(new AbstractMap.SimpleEntry<Integer, Performance>(folds, performance)); }
java
public List<Entry<String, Object>> getTraceParameterSettings(int index) { List<Entry<String, Object>> result = new ArrayList<Map.Entry<String,Object>>(); List<String> dimensions = getSearchDimensions(); for (int i = 0; i < dimensions.size(); ++i) { String parameter = dimensions.get(i); Object va...
java
public SearchResult search(Instances data) throws Exception { SearchResult result; SearchResult best; try { log("\n" + getClass().getName() + "\n" + getClass().getName().replaceAll(".", "=") + "\n" + "Options: " + Utils.joinOptions(getOptions()) + "\n"); log("\n---> check"); check(da...
java
public void cleanUp() { m_Owner = null; m_Train = null; m_Test = null; m_Generator = null; m_Values = null; }
java
public int compareTo(Point<E> obj) { if (obj == null) return -1; if (dimensions() != obj.dimensions()) return -1; for (int i = 0; i < dimensions(); i++) { if (getValue(i).getClass() != obj.getValue(i).getClass()) return -1; if (getValue(i) instanceof Double) { ...
java
public Space subspace(Point<Integer> center) { Space result; SpaceDimension[] dimensions; int i; dimensions = new SpaceDimension[dimensions()]; for (i = 0; i < dimensions.length; i++) dimensions[i] = getDimension(i).subdimension( center.getValue(i) - 1, center.getValue(i) + 1); ...
java
protected boolean inc(Integer[] locations, int[] max) { boolean result; int i; result = true; i = 0; while (i < locations.length) { if (locations[i] < max[i] - 1) { locations[i]++; break; } else { locations[i] = 0; i++; // adding was not po...
java
protected Vector<Point<Integer>> listPoints() { Vector<Point<Integer>> result; int i; int[] max; Integer[] locations; boolean ok; result = new Vector<Point<Integer>>(); // determine maximum locations per dimension max = new int[dimensions()]; for (i = 0; i < max.length; i++...
java
protected String getID(int cv, Point<Object> values) { String result; int i; result = "" + cv; for (i = 0; i < values.dimensions(); i++) result += "\t" + values.getValue(i); return result; }
java
public Performance get(int cv, Point<Object> values) { return m_Cache.get(getID(cv, values)); }
java
public void add(int cv, Performance p) { m_Cache.put(getID(cv, p.getValues()), p); }
java
@Override public DefaultEvaluationTask newTask(MultiSearchCapable owner, Instances train, Instances test, SetupGenerator generator, Point<Object> values, int folds, int eval, int classLabel) { return new DefaultEvaluationTask(owner, train, test, generator, values, folds, eval, classLabel); }
java
public boolean check(int id) { for (Tag tag: getTags()) { if (tag.getID() == id) return true; } return false; }
java
public double getMetric(int id, int classLabel) { try { switch (id) { case DefaultEvaluationMetrics.EVALUATION_CC: return m_Evaluation.correlationCoefficient(); case DefaultEvaluationMetrics.EVALUATION_MATTHEWS_CC: return m_Evaluation.matthewsCorrelationCoefficient(0); ...
java
public boolean invert(int id) { switch (id) { case EVALUATION_CC: case EVALUATION_ACC: case EVALUATION_KAPPA: case EVALUATION_MATTHEWS_CC: case EVALUATION_PRECISION: case EVALUATION_WEIGHTED_PRECISION: case EVALUATION_RECALL: case EVALUATION_WEIGHTED_RECALL: cas...
java
public String[] getItems() throws Exception { String[] result; if (getCustomDelimiter().isEmpty()) result = Utils.splitOptions(getList()); else result = getList().split(getCustomDelimiter()); return result; }
java
public SpaceDimension spaceDimension() throws Exception { String[] items; items = getItems(); return new ListSpaceDimension(0, items.length - 1, items, getProperty()); }
java
public boolean getBooleanSetting( final ChaiSetting setting ) { final String settingValue = getSetting( setting ); return StringHelper.convertStrToBoolean( settingValue ); }
java
public List<String> bindURLsAsList() { final List<String> splitUrls = Arrays.asList( getSetting( ChaiSetting.BIND_URLS ).split( LDAP_URL_SEPARATOR_REGEX_PATTERN ) ); return Collections.unmodifiableList( splitUrls ); }
java
private static void pause( final long time ) { final long startTime = System.currentTimeMillis(); do { try { final long sleepTime = time - ( System.currentTimeMillis() - startTime ); Thread.sleep( sleepTime > 0 ? sleepTime : 10 ); ...
java
public static ChaiResponseSet newChaiResponseSet( final Map<Challenge, String> challengeResponseMap, final Locale locale, final int minimumRandomRequired, final ChaiConfiguration chaiConfiguration, final String csIdentifier ) throws ChaiValidat...
java
private void checkTimer() { try { serviceThreadLock.lock(); if ( watchdogTimer == null ) { // if there is NOT an active timer if ( !issuedWatchdogWrappers.allValues().isEmpty() ) { // if there ar...
java
public static ConfigObjectRecord createNew( final ChaiEntry entry, final String attr, final String recordType, final String guid1, ...
java