_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3 values | text stringlengths 73 34.1k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q179500 | PublicId.stringReplace | test | private static String stringReplace(String str,
String oldStr,
String newStr) {
String result = "";
int pos = str.indexOf(oldStr);
// System.out.println(str + ": " + oldStr + " => " + newStr);
while (pos >= 0) {
// System.out.println(str + " (" + pos + ")");
result += str.substring(0, pos);
result += newStr;
str = str.substring(pos+1);
pos = str.indexOf(oldStr);
}
return result + str;
} | java | {
"resource": ""
} |
q179501 | StopWatch.start | test | public void start(final boolean reset)
{
if (!running) {
if (reset) reset();
start = System.currentTimeMillis();
running = true;
}
} | java | {
"resource": ""
} |
q179502 | StopWatch.stop | test | public long stop()
{
long lap = 0;
if (running) {
count++;
stop = System.currentTimeMillis();
lap = stop - start;
total += lap;
running = false;
}
return lap;
} | java | {
"resource": ""
} |
q179503 | StopWatch.makeSynchronized | test | public static StopWatch makeSynchronized(final StopWatch watch)
{
return new Wrapper(watch)
{
/** The serialVersionUID */
private static final long serialVersionUID = -6284244000894114817L;
public synchronized void start(final boolean reset) {
this.watch.start(reset);
}
public synchronized void start() {
this.watch.start();
}
public synchronized long stop() {
return this.watch.stop();
}
public synchronized void reset() {
this.watch.reset();
}
public synchronized long getLapTime() {
return this.watch.getLapTime();
}
public synchronized long getAverageLapTime() {
return this.watch.getAverageLapTime();
}
public synchronized int getLapCount() {
return this.watch.getLapCount();
}
public synchronized long getTime() {
return this.watch.getTime();
}
public synchronized boolean isRunning() {
return this.watch.isRunning();
}
public synchronized String toString() {
return this.watch.toString();
}
};
} | java | {
"resource": ""
} |
q179504 | HashCode.compareTo | test | public int compareTo(final Object obj) throws ClassCastException {
HashCode hashCode = (HashCode)obj;
return compareTo(hashCode.value);
} | java | {
"resource": ""
} |
q179505 | HashCode.generate | test | public static int generate(final byte[] bytes) {
int hashcode = 0;
for (int i=0; i<bytes.length; i++) {
hashcode <<= 1;
hashcode ^= bytes[i];
}
return hashcode;
} | java | {
"resource": ""
} |
q179506 | HashCode.generate | test | public static int generate(final Object array[], final boolean deep) {
int hashcode = 0;
for (int i=0; i<array.length; i++) {
if (deep && (array[i] instanceof Object[])) {
hashcode ^= generate((Object[])array[i], true);
}
else {
hashcode ^= array[i].hashCode();
}
}
return hashcode;
} | java | {
"resource": ""
} |
q179507 | LRUCachePolicy.create | test | public void create()
{
m_map = createMap();
m_list = createList();
m_list.m_maxCapacity = m_maxCapacity;
m_list.m_minCapacity = m_minCapacity;
m_list.m_capacity = m_maxCapacity;
} | java | {
"resource": ""
} |
q179508 | FieldBoundPropertyListener.setFieldValue | test | protected void setFieldValue(String value) {
try {
// filter property value
value = filterValue(value);
// coerce value to field type
Class<?> type = fieldInstance.getField().getType();
PropertyEditor editor = PropertyEditors.findEditor(type);
editor.setAsText(value);
Object coerced = editor.getValue();
// bind value to field
fieldInstance.set(coerced);
}
catch (IllegalAccessException e) {
throw new PropertyException(e);
}
} | java | {
"resource": ""
} |
q179509 | TextCatalogReader.nextToken | test | protected String nextToken() throws IOException {
String token = "";
int ch, nextch;
if (!tokenStack.empty()) {
return (String) tokenStack.pop();
}
// Skip over leading whitespace and comments
while (true) {
// skip leading whitespace
ch = catfile.read();
while (ch <= ' ') { // all ctrls are whitespace
ch = catfile.read();
if (ch < 0) {
return null;
}
}
// now 'ch' is the current char from the file
nextch = catfile.read();
if (nextch < 0) {
return null;
}
if (ch == '-' && nextch == '-') {
// we've found a comment, skip it...
ch = ' ';
nextch = nextChar();
while (ch != '-' || nextch != '-') {
ch = nextch;
nextch = nextChar();
}
// Ok, we've found the end of the comment,
// loop back to the top and start again...
} else {
stack[++top] = nextch;
stack[++top] = ch;
break;
}
}
ch = nextChar();
if (ch == '"' || ch == '\'') {
int quote = ch;
while ((ch = nextChar()) != quote) {
char[] chararr = new char[1];
chararr[0] = (char) ch;
String s = new String(chararr);
token = token.concat(s);
}
return token;
} else {
// return the next whitespace or comment delimited
// string
while (ch > ' ') {
nextch = nextChar();
if (ch == '-' && nextch == '-') {
stack[++top] = ch;
stack[++top] = nextch;
return token;
} else {
char[] chararr = new char[1];
chararr[0] = (char) ch;
String s = new String(chararr);
token = token.concat(s);
ch = nextch;
}
}
return token;
}
} | java | {
"resource": ""
} |
q179510 | DateEditor.initialize | test | public static void initialize()
{
PrivilegedAction action = new PrivilegedAction()
{
public Object run()
{
String defaultFormat = System.getProperty("org.jboss.util.propertyeditor.DateEditor.format", "MMM d, yyyy");
String defaultLocale = System.getProperty("org.jboss.util.propertyeditor.DateEditor.locale");
DateFormat defaultDateFormat;
if (defaultLocale == null || defaultLocale.length() == 0)
{
defaultDateFormat = new SimpleDateFormat(defaultFormat);
}
else
{
defaultDateFormat = new SimpleDateFormat(defaultFormat, Strings.parseLocaleString(defaultLocale));
}
formats = new DateFormat[]
{
defaultDateFormat,
// Tue Jan 04 00:00:00 PST 2005
new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"),
// Wed, 4 Jul 2001 12:08:56 -0700
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z")
};
return null;
}
};
AccessController.doPrivileged(action);
} | java | {
"resource": ""
} |
q179511 | Graph.addVertex | test | public boolean addVertex(Vertex<T> v)
{
if( verticies.containsValue(v) == false )
{
verticies.put(v.getName(), v);
return true;
}
return false;
} | java | {
"resource": ""
} |
q179512 | Graph.setRootVertex | test | public void setRootVertex(Vertex<T> root)
{
this.rootVertex = root;
if( verticies.containsValue(root) == false )
addVertex(root);
} | java | {
"resource": ""
} |
q179513 | Graph.removeVertex | test | public boolean removeVertex(Vertex<T> v)
{
if (!verticies.containsValue(v))
return false;
verticies.remove(v.getName());
if( v == rootVertex )
rootVertex = null;
// Remove the edges associated with v
for(int n = 0; n < v.getOutgoingEdgeCount(); n ++)
{
Edge<T> e = v.getOutgoingEdge(n);
v.remove(e);
Vertex<T> to = e.getTo();
to.remove(e);
edges.remove(e);
}
for(int n = 0; n < v.getIncomingEdgeCount(); n ++)
{
Edge<T> e = v.getIncomingEdge(n);
v.remove(e);
Vertex<T> predecessor = e.getFrom();
predecessor.remove(e);
}
return true;
} | java | {
"resource": ""
} |
q179514 | Graph.depthFirstSearch | test | public void depthFirstSearch(Vertex<T> v, final Visitor<T> visitor)
{
VisitorEX<T, RuntimeException> wrapper = new VisitorEX<T, RuntimeException>()
{
public void visit(Graph<T> g, Vertex<T> v) throws RuntimeException
{
if (visitor != null)
visitor.visit(g, v);
}
};
this.depthFirstSearch(v, wrapper);
} | java | {
"resource": ""
} |
q179515 | Graph.dfsSpanningTree | test | public void dfsSpanningTree(Vertex<T> v, DFSVisitor<T> visitor)
{
v.visit();
if( visitor != null )
visitor.visit(this, v);
for (int i = 0; i < v.getOutgoingEdgeCount(); i++)
{
Edge<T> e = v.getOutgoingEdge(i);
if (!e.getTo().visited())
{
if( visitor != null )
visitor.visit(this, v, e);
e.mark();
dfsSpanningTree(e.getTo(), visitor);
}
}
} | java | {
"resource": ""
} |
q179516 | Graph.findVertexByData | test | public Vertex<T> findVertexByData(T data, Comparator<T> compare)
{
Vertex<T> match = null;
for(Vertex<T> v : verticies.values())
{
if( compare.compare(data, v.getData()) == 0 )
{
match = v;
break;
}
}
return match;
} | java | {
"resource": ""
} |
q179517 | Graph.findCycles | test | public Edge<T>[] findCycles()
{
ArrayList<Edge<T>> cycleEdges = new ArrayList<Edge<T>>();
// Mark all verticies as white
for(int n = 0; n < verticies.size(); n ++)
{
Vertex<T> v = getVertex(n);
v.setMarkState(VISIT_COLOR_WHITE);
}
for(int n = 0; n < verticies.size(); n ++)
{
Vertex<T> v = getVertex(n);
visit(v, cycleEdges);
}
Edge<T>[] cycles = new Edge[cycleEdges.size()];
cycleEdges.toArray(cycles);
return cycles;
} | java | {
"resource": ""
} |
q179518 | DOMWriter.normalize | test | public static String normalize(String s, boolean canonical)
{
StringBuffer str = new StringBuffer();
int len = (s != null) ? s.length() : 0;
for (int i = 0; i < len; i++)
{
char ch = s.charAt(i);
switch (ch)
{
case '<':
{
str.append("<");
break;
}
case '>':
{
str.append(">");
break;
}
case '&':
{
str.append("&");
break;
}
case '"':
{
str.append(""");
break;
}
case '\'':
{
str.append("'");
break;
}
case '\r':
case '\n':
{
if (canonical)
{
str.append("&#");
str.append(Integer.toString(ch));
str.append(';');
break;
}
// else, default append char
}
default:
{
str.append(ch);
}
}
}
return (str.toString());
} | java | {
"resource": ""
} |
q179519 | DOMUtils.parse | test | public static Element parse(String xmlString) throws IOException
{
try
{
return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
}
catch (IOException e)
{
log.error("Cannot parse: " + xmlString);
throw e;
}
} | java | {
"resource": ""
} |
q179520 | DOMUtils.parse | test | public static Element parse(InputStream xmlStream) throws IOException
{
try
{
Document doc = getDocumentBuilder().parse(xmlStream);
Element root = doc.getDocumentElement();
return root;
}
catch (SAXException e)
{
throw new IOException(e.toString());
}
} | java | {
"resource": ""
} |
q179521 | DOMUtils.parse | test | public static Element parse(InputSource source) throws IOException
{
try
{
Document doc = getDocumentBuilder().parse(source);
Element root = doc.getDocumentElement();
return root;
}
catch (SAXException e)
{
throw new IOException(e.toString());
}
} | java | {
"resource": ""
} |
q179522 | DOMUtils.createElement | test | public static Element createElement(String localPart)
{
Document doc = getOwnerDocument();
log.trace("createElement {}" + localPart);
return doc.createElement(localPart);
} | java | {
"resource": ""
} |
q179523 | DOMUtils.resolveQName | test | public static QName resolveQName(Element el, String qualifiedName)
{
QName qname;
String prefix = "";
String namespaceURI = "";
String localPart = qualifiedName;
int colIndex = qualifiedName.indexOf(":");
if (colIndex > 0)
{
prefix = qualifiedName.substring(0, colIndex);
localPart = qualifiedName.substring(colIndex + 1);
if ("xmlns".equals(prefix))
{
namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
}
else
{
Element nsElement = el;
while (namespaceURI.equals("") && nsElement != null)
{
namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
if (namespaceURI.equals(""))
nsElement = getParentElement(nsElement);
}
}
if (namespaceURI.equals(""))
throw new IllegalArgumentException("Cannot find namespace uri for: " + qualifiedName);
}
qname = new QName(namespaceURI, localPart, prefix);
return qname;
} | java | {
"resource": ""
} |
q179524 | DOMUtils.copyAttributes | test | public static void copyAttributes(Element destElement, Element srcElement)
{
NamedNodeMap attribs = srcElement.getAttributes();
for (int i = 0; i < attribs.getLength(); i++)
{
Attr attr = (Attr)attribs.item(i);
String uri = attr.getNamespaceURI();
String qname = attr.getName();
String value = attr.getNodeValue();
// Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
// change an object in a way which is incorrect with regard to namespaces.
if (uri == null && qname.startsWith("xmlns"))
{
log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
}
else
{
destElement.setAttributeNS(uri, qname, value);
}
}
} | java | {
"resource": ""
} |
q179525 | DOMUtils.hasChildElements | test | public static boolean hasChildElements(Node node)
{
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Node child = nlist.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE)
return true;
}
return false;
} | java | {
"resource": ""
} |
q179526 | DOMUtils.getChildElements | test | public static Iterator getChildElements(Node node)
{
ArrayList list = new ArrayList();
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Node child = nlist.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE)
list.add(child);
}
return list.iterator();
} | java | {
"resource": ""
} |
q179527 | DOMUtils.getTextContent | test | public static String getTextContent(Node node, boolean replaceProps)
{
boolean hasTextContent = false;
StringBuffer buffer = new StringBuffer();
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Node child = nlist.item(i);
if (child.getNodeType() == Node.TEXT_NODE)
{
buffer.append(child.getNodeValue());
hasTextContent = true;
}
}
String text = (hasTextContent ? buffer.toString() : null);
if ( text != null && replaceProps)
text = StringPropertyReplacer.replaceProperties(text);
return text;
} | java | {
"resource": ""
} |
q179528 | DOMUtils.getChildElements | test | public static Iterator getChildElements(Node node, String nodeName)
{
return getChildElementsIntern(node, new QName(nodeName));
} | java | {
"resource": ""
} |
q179529 | DOMUtils.getParentElement | test | public static Element getParentElement(Node node)
{
Node parent = node.getParentNode();
return (parent instanceof Element ? (Element)parent : null);
} | java | {
"resource": ""
} |
q179530 | DeadlockDetector.addWaiting | test | public void addWaiting(Object holder, Resource resource)
{
synchronized (waiting)
{
waiting.put(holder, resource);
}
} | java | {
"resource": ""
} |
q179531 | DOMCatalogReader.readCatalog | test | public void readCatalog(Catalog catalog, InputStream is)
throws IOException, CatalogException {
DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
throw new CatalogException(CatalogException.UNPARSEABLE);
}
Document doc = null;
try {
doc = builder.parse(is);
} catch (SAXException se) {
throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
}
Element root = doc.getDocumentElement();
String namespaceURI = Namespaces.getNamespaceURI(root);
String localName = Namespaces.getLocalName(root);
String domParserClass = getCatalogParser(namespaceURI,
localName);
if (domParserClass == null) {
if (namespaceURI == null) {
catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
+ localName);
} else {
catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
+ "{" + namespaceURI + "}"
+ localName);
}
return;
}
DOMCatalogParser domParser = null;
try {
domParser = (DOMCatalogParser) Class.forName(domParserClass).newInstance();
} catch (ClassNotFoundException cnfe) {
catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (InstantiationException ie) {
catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (IllegalAccessException iae) {
catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (ClassCastException cce ) {
catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
throw new CatalogException(CatalogException.UNPARSEABLE);
}
Node node = root.getFirstChild();
while (node != null) {
domParser.parseCatalogEntry(catalog, node);
node = node.getNextSibling();
}
} | java | {
"resource": ""
} |
q179532 | DOMCatalogReader.readCatalog | test | public void readCatalog(Catalog catalog, String fileUrl)
throws MalformedURLException, IOException, CatalogException {
URL url = new URL(fileUrl);
URLConnection urlCon = url.openConnection();
readCatalog(catalog, urlCon.getInputStream());
} | java | {
"resource": ""
} |
q179533 | VMID.getHostAddress | test | private static byte[] getHostAddress() {
return (byte[]) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
return InetAddress.getLocalHost().getAddress();
}
catch (Exception e) {
return UNKNOWN_HOST;
}
}
});
} | java | {
"resource": ""
} |
q179534 | CatalogLocation.resolveEntity | test | public InputSource resolveEntity(String publicId, String systemId) throws MalformedURLException, IOException
{
String resolvedURI = catologResolver.resolveSystem(systemId);
if (resolvedURI == null)
{
resolvedURI = catologResolver.resolvePublic(publicId, systemId);
}
if (resolvedURI != null)
{
final InputSource is = new InputSource();
is.setPublicId(publicId);
is.setSystemId(systemId);
is.setByteStream(this.loadResource(resolvedURI));
this.isLastEntityResolved = true;
return is;
}
else
{
//resource could�t be resloved
this.isLastEntityResolved = false;
return null;
}
} | java | {
"resource": ""
} |
q179535 | SystemPropertyClassValue.setSystemPropertyClassValue | test | public static Throwable setSystemPropertyClassValue(String property, String className)
{
// Validation
if (property == null || property.trim().length() == 0)
throw new IllegalArgumentException("Null or empty property");
if (className == null || className.trim().length() == 0)
throw new IllegalArgumentException("Null or empty class name");
// Is the class available?
try
{
Thread.currentThread().getContextClassLoader().loadClass(className);
}
catch (Throwable problem)
{
return problem;
}
// The class is there, set the property.
System.setProperty(property, className);
return null;
} | java | {
"resource": ""
} |
q179536 | Classes.displayClassInfo | test | public static void displayClassInfo(Class clazz, StringBuffer results)
{
// Print out some codebase info for the clazz
ClassLoader cl = clazz.getClassLoader();
results.append("\n");
results.append(clazz.getName());
results.append("(");
results.append(Integer.toHexString(clazz.hashCode()));
results.append(").ClassLoader=");
results.append(cl);
ClassLoader parent = cl;
while( parent != null )
{
results.append("\n..");
results.append(parent);
URL[] urls = getClassLoaderURLs(parent);
int length = urls != null ? urls.length : 0;
for(int u = 0; u < length; u ++)
{
results.append("\n....");
results.append(urls[u]);
}
if( parent != null )
parent = parent.getParent();
}
CodeSource clazzCS = clazz.getProtectionDomain().getCodeSource();
if( clazzCS != null )
{
results.append("\n++++CodeSource: ");
results.append(clazzCS);
}
else
results.append("\n++++Null CodeSource");
results.append("\nImplemented Interfaces:");
Class[] ifaces = clazz.getInterfaces();
for(int i = 0; i < ifaces.length; i ++)
{
Class iface = ifaces[i];
results.append("\n++");
results.append(iface);
results.append("(");
results.append(Integer.toHexString(iface.hashCode()));
results.append(")");
ClassLoader loader = ifaces[i].getClassLoader();
results.append("\n++++ClassLoader: ");
results.append(loader);
ProtectionDomain pd = ifaces[i].getProtectionDomain();
CodeSource cs = pd.getCodeSource();
if( cs != null )
{
results.append("\n++++CodeSource: ");
results.append(cs);
}
else
results.append("\n++++Null CodeSource");
}
} | java | {
"resource": ""
} |
q179537 | Classes.describe | test | public static void describe(StringBuffer buffer, Class clazz)
{
if (clazz == null)
buffer.append("**null**");
else
{
buffer.append("{class=").append(clazz.getName());
Class[] intfs = clazz.getInterfaces();
if (intfs.length > 0)
{
buffer.append(" intfs=");
for (int i = 0; i < intfs.length; ++i)
{
buffer.append(intfs[i].getName());
if (i < intfs.length-1)
buffer.append(", ");
}
}
buffer.append("}");
}
} | java | {
"resource": ""
} |
q179538 | Classes.stripPackageName | test | public static String stripPackageName(final String classname)
{
int idx = classname.lastIndexOf(PACKAGE_SEPARATOR);
if (idx != -1)
return classname.substring(idx + 1, classname.length());
return classname;
} | java | {
"resource": ""
} |
q179539 | Classes.getPackageName | test | public static String getPackageName(final String classname)
{
if (classname.length() == 0)
throw new EmptyStringException();
int index = classname.lastIndexOf(PACKAGE_SEPARATOR);
if (index != -1)
return classname.substring(0, index);
return "";
} | java | {
"resource": ""
} |
q179540 | Classes.forceLoad | test | public static void forceLoad(final Class type)
{
if (type == null)
throw new NullArgumentException("type");
// don't attempt to force primitives to load
if (type.isPrimitive()) return;
// don't attempt to force java.* classes to load
String packageName = Classes.getPackageName(type);
// System.out.println("package name: " + packageName);
if (packageName.startsWith("java.") ||
packageName.startsWith("javax."))
{
return;
}
// System.out.println("forcing class to load: " + type);
try
{
Method methods[] = type.getDeclaredMethods();
Method method = null;
for (int i = 0; i < methods.length; i++)
{
int modifiers = methods[i].getModifiers();
if (Modifier.isStatic(modifiers))
{
method = methods[i];
break;
}
}
if (method != null)
{
method.invoke(null, (Object[]) null);
}
else
{
type.newInstance();
}
}
catch (Exception ignore)
{
ThrowableHandler.add(ignore);
}
} | java | {
"resource": ""
} |
q179541 | Classes.getPrimitiveWrapper | test | public static Class getPrimitiveWrapper(final Class type)
{
if (!type.isPrimitive())
{
throw new IllegalArgumentException("type is not a primitive class");
}
for (int i = 0; i < PRIMITIVE_WRAPPER_MAP.length; i += 2)
{
if (type.equals(PRIMITIVE_WRAPPER_MAP[i]))
return PRIMITIVE_WRAPPER_MAP[i + 1];
}
// should never get here, if we do then PRIMITIVE_WRAPPER_MAP
// needs to be updated to include the missing mapping
throw new UnreachableStatementException();
} | java | {
"resource": ""
} |
q179542 | Classes.getAllInterfaces | test | public static void getAllInterfaces(List allIfaces, Class c)
{
while (c != null)
{
Class[] ifaces = c.getInterfaces();
for (int n = 0; n < ifaces.length; n ++)
{
allIfaces.add(ifaces[n]);
}
c = c.getSuperclass();
}
} | java | {
"resource": ""
} |
q179543 | Classes.getAllUniqueInterfaces | test | public static Class[] getAllUniqueInterfaces(Class c)
{
Set uniqueIfaces = new HashSet();
while (c != null )
{
Class[] ifaces = c.getInterfaces();
for (int n = 0; n < ifaces.length; n ++)
{
uniqueIfaces.add(ifaces[n]);
}
c = c.getSuperclass();
}
return (Class[])uniqueIfaces.toArray(new Class[uniqueIfaces.size()]);
} | java | {
"resource": ""
} |
q179544 | Classes.isPrimitiveWrapper | test | public static boolean isPrimitiveWrapper(final Class type)
{
for (int i = 0; i < PRIMITIVE_WRAPPER_MAP.length; i += 2)
{
if (type.equals(PRIMITIVE_WRAPPER_MAP[i + 1]))
{
return true;
}
}
return false;
} | java | {
"resource": ""
} |
q179545 | Classes.instantiate | test | public static Object instantiate(Class expected, String property, String defaultClassName)
{
String className = getProperty(property, defaultClassName);
Class clazz = null;
try
{
clazz = loadClass(className);
}
catch (ClassNotFoundException e)
{
throw new NestedRuntimeException("Cannot load class " + className, e);
}
Object result = null;
try
{
result = clazz.newInstance();
}
catch (InstantiationException e)
{
throw new NestedRuntimeException("Error instantiating " + className, e);
}
catch (IllegalAccessException e)
{
throw new NestedRuntimeException("Error instantiating " + className, e);
}
if (expected.isAssignableFrom(clazz) == false)
throw new NestedRuntimeException("Class " + className + " from classloader " + clazz.getClassLoader() +
" is not of the expected class " + expected + " loaded from " + expected.getClassLoader());
return result;
} | java | {
"resource": ""
} |
q179546 | Classes.getAttributeGetter | test | public final static Method getAttributeGetter(Class cls, String attr) throws NoSuchMethodException
{
StringBuffer buf = new StringBuffer(attr.length() + 3);
buf.append("get");
if(Character.isLowerCase(attr.charAt(0)))
{
buf.append(Character.toUpperCase(attr.charAt(0)))
.append(attr.substring(1));
}
else
{
buf.append(attr);
}
try
{
return cls.getMethod(buf.toString(), (Class[]) null);
}
catch (NoSuchMethodException e)
{
buf.replace(0, 3, "is");
return cls.getMethod(buf.toString(), (Class[]) null);
}
} | java | {
"resource": ""
} |
q179547 | Classes.getAttributeSetter | test | public final static Method getAttributeSetter(Class cls, String attr, Class type) throws NoSuchMethodException
{
StringBuffer buf = new StringBuffer(attr.length() + 3);
buf.append("set");
if(Character.isLowerCase(attr.charAt(0)))
{
buf.append(Character.toUpperCase(attr.charAt(0)))
.append(attr.substring(1));
}
else
{
buf.append(attr);
}
return cls.getMethod(buf.toString(), new Class[]{type});
} | java | {
"resource": ""
} |
q179548 | Classes.convertToJavaClass | test | private final static Class convertToJavaClass(String name,
ClassLoader cl)
throws ClassNotFoundException
{
int arraySize = 0;
while (name.endsWith("[]"))
{
name = name.substring(0, name.length() - 2);
arraySize++;
}
// Check for a primitive type
Class c = (Class) PRIMITIVE_NAME_TYPE_MAP.get(name);
if (c == null)
{
// No primitive, try to load it from the given ClassLoader
try
{
c = cl.loadClass(name);
}
catch (ClassNotFoundException cnfe)
{
throw new ClassNotFoundException("Parameter class not found: " +
name);
}
}
// if we have an array get the array class
if (arraySize > 0)
{
int[] dims = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
dims[i] = 1;
}
c = Array.newInstance(c, dims).getClass();
}
return c;
} | java | {
"resource": ""
} |
q179549 | Classes.getProperty | test | private static String getProperty(final String name, final String defaultValue)
{
return (String) AccessController.doPrivileged(
new PrivilegedAction()
{
public Object run()
{
return System.getProperty(name, defaultValue);
}
});
} | java | {
"resource": ""
} |
q179550 | DefaultPropertyReader.getFilenames | test | public static String[] getFilenames(final String propertyName)
throws PropertyException
{
String filenames[];
// check for singleton property first
Object filename = PropertyManager.getProperty(propertyName);
if (filename != null) {
filenames = new String[] { String.valueOf(filename) };
}
else {
// if no singleton property exists then look for array props
filenames = PropertyManager.getArrayProperty(propertyName);
}
return filenames;
} | java | {
"resource": ""
} |
q179551 | WeakSet.maintain | test | protected final void maintain() {
WeakObject weak;
while ((weak = (WeakObject)queue.poll()) != null) {
set.remove(weak);
}
} | java | {
"resource": ""
} |
q179552 | WeakSet.iterator | test | public Iterator iterator() {
return new Iterator() {
/** The set's iterator */
Iterator iter = set.iterator();
/** JBCOMMON-24, handle null values and multiple invocations of hasNext() */
Object UNKNOWN = new Object();
/** The next available object. */
Object next = UNKNOWN;
public boolean hasNext() {
if (next != UNKNOWN) {
return true;
}
while (iter.hasNext()) {
WeakObject weak = (WeakObject)iter.next();
Object obj = null;
if (weak != null && (obj = weak.get()) == null) {
// object has been reclaimed by the GC
continue;
}
next = obj;
return true;
}
return false;
}
public Object next() {
if ((next == UNKNOWN) && !hasNext()) {
throw new NoSuchElementException();
}
Object obj = next;
next = UNKNOWN;
return obj;
}
public void remove() {
iter.remove();
}
};
} | java | {
"resource": ""
} |
q179553 | URLListerFactory.createURLLister | test | public URLLister createURLLister(String protocol) throws MalformedURLException {
try {
String className = (String) classes.get(protocol);
if (className == null) {
throw new MalformedURLException("No lister class defined for protocol "+protocol);
}
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
return (URLLister) clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new MalformedURLException(e.getMessage());
} catch (InstantiationException e) {
throw new MalformedURLException(e.getMessage());
} catch (IllegalAccessException e) {
throw new MalformedURLException(e.getMessage());
}
} | java | {
"resource": ""
} |
q179554 | PropertyGroup.entrySet | test | @SuppressWarnings("unchecked")
public Set entrySet()
{
final Set superSet = super.entrySet(true);
return new java.util.AbstractSet()
{
private boolean isInGroup(Map.Entry entry)
{
String key = (String) entry.getKey();
return key.startsWith(basename);
}
public int size()
{
Iterator iter = superSet.iterator();
int count = 0;
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
if (isInGroup(entry))
{
count++;
}
}
return count;
}
public Iterator iterator()
{
return new Iterator()
{
private Iterator iter = superSet.iterator();
private Object next;
public boolean hasNext()
{
if (next != null)
return true;
while (next == null)
{
if (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
if (isInGroup(entry))
{
next = entry;
return true;
}
}
else
{
break;
}
}
return false;
}
public Object next()
{
if (next == null)
throw new java.util.NoSuchElementException();
Object obj = next;
next = null;
return obj;
}
public void remove()
{
iter.remove();
}
};
}
};
} | java | {
"resource": ""
} |
q179555 | PropertyGroup.addPropertyListener | test | protected void addPropertyListener(final BoundPropertyListener listener)
{
// get the bound property name
String name = makePropertyName(listener.getPropertyName());
// get the bound listener list for the property
List list = (List) boundListeners.get(name);
// if list is null, then add a new list
if (list == null)
{
list = new ArrayList();
boundListeners.put(name, list);
}
// if listener is not in the list already, then add it
if (!list.contains(listener))
{
list.add(listener);
// notify listener that is is bound
listener.propertyBound(this);
}
} | java | {
"resource": ""
} |
q179556 | PropertyGroup.removePropertyListener | test | protected boolean removePropertyListener(final BoundPropertyListener listener)
{
// get the bound property name
String name = makePropertyName(listener.getPropertyName());
// get the bound listener list for the property
List list = (List) boundListeners.get(name);
boolean removed = false;
if (list != null)
{
removed = list.remove(listener);
// notify listener that is was unbound
if (removed)
listener.propertyUnbound(this);
}
return removed;
} | java | {
"resource": ""
} |
q179557 | PropertyEditors.isNull | test | public static final boolean isNull(final String value, final boolean trim, final boolean empty)
{
// For backwards compatibility
if (disableIsNull)
return false;
// No value?
if (value == null)
return true;
// Trim the text when requested
String trimmed = trim ? value.trim() : value;
// Is the empty string null?
if (empty && trimmed.length() == 0)
return true;
// Just check it.
return NULL.equalsIgnoreCase(trimmed);
} | java | {
"resource": ""
} |
q179558 | PropertyEditors.findEditor | test | public static PropertyEditor findEditor(final String typeName)
throws ClassNotFoundException
{
// see if it is a primitive type first
Class<?> type = Classes.getPrimitiveTypeForName(typeName);
if (type == null)
{
// nope try look up
ClassLoader loader = Thread.currentThread().getContextClassLoader();
type = loader.loadClass(typeName);
}
return PropertyEditorManager.findEditor(type);
} | java | {
"resource": ""
} |
q179559 | PropertyEditors.registerEditor | test | public static void registerEditor(final String typeName,
final String editorTypeName)
throws ClassNotFoundException
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> type = loader.loadClass(typeName);
Class<?> editorType = loader.loadClass(editorTypeName);
PropertyEditorManager.registerEditor(type, editorType);
} | java | {
"resource": ""
} |
q179560 | PropertyEditors.convertValue | test | public static Object convertValue(String text, String typeName)
throws ClassNotFoundException, IntrospectionException
{
// see if it is a primitive type first
Class<?> typeClass = Classes.getPrimitiveTypeForName(typeName);
if (typeClass == null)
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
typeClass = loader.loadClass(typeName);
}
PropertyEditor editor = PropertyEditorManager.findEditor(typeClass);
if (editor == null)
{
throw new IntrospectionException
("No property editor for type=" + typeClass);
}
editor.setAsText(text);
return editor.getValue();
} | java | {
"resource": ""
} |
q179561 | ContextClassLoader.getContextClassLoader | test | public ClassLoader getContextClassLoader(final Thread thread)
{
return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
return thread.getContextClassLoader();
}
});
} | java | {
"resource": ""
} |
q179562 | ApplicationDeadlockException.isADE | test | public static ApplicationDeadlockException isADE(Throwable t)
{
while (t!=null)
{
if (t instanceof ApplicationDeadlockException)
{
return (ApplicationDeadlockException)t;
}
else
{
t = t.getCause();
}
}
return null;
} | java | {
"resource": ""
} |
q179563 | TimeoutFactory.schedule | test | public Timeout schedule(long time, TimeoutTarget target)
{
if (cancelled.get())
throw new IllegalStateException("TimeoutFactory has been cancelled");
if (time < 0)
throw new IllegalArgumentException("Negative time");
if (target == null)
throw new IllegalArgumentException("Null timeout target");
return queue.offer(time, target);
} | java | {
"resource": ""
} |
q179564 | TimeoutFactory.doWork | test | private void doWork()
{
while (cancelled.get() == false)
{
TimeoutExt work = queue.take();
// Do work, if any
if (work != null)
{
// Wrap the TimeoutExt with a runnable that invokes the target callback
TimeoutWorker worker = new TimeoutWorker(work);
try
{
threadPool.run(worker);
}
catch (Throwable t)
{
// protect the worker thread from pool enqueue errors
ThrowableHandler.add(ThrowableHandler.Type.ERROR, t);
}
synchronized (work)
{
work.done();
}
}
}
// TimeoutFactory was cancelled
queue.cancel();
} | java | {
"resource": ""
} |
q179565 | Util.createSubcontext | test | public static Context createSubcontext(Context ctx, String name) throws NamingException
{
Name n = ctx.getNameParser("").parse(name);
return createSubcontext(ctx, n);
} | java | {
"resource": ""
} |
q179566 | Util.lookup | test | public static Object lookup(String name, Class<?> clazz) throws Exception
{
InitialContext ctx = new InitialContext();
try
{
return lookup(ctx, name, clazz);
}
finally
{
ctx.close();
}
} | java | {
"resource": ""
} |
q179567 | Util.checkObject | test | protected static void checkObject(Context context, String name, Object object, Class clazz) throws Exception
{
Class objectClass = object.getClass();
if (clazz.isAssignableFrom(objectClass) == false)
{
StringBuffer buffer = new StringBuffer(100);
buffer.append("Object at '").append(name);
buffer.append("' in context ").append(context.getEnvironment());
buffer.append(" is not an instance of ");
appendClassInfo(buffer, clazz);
buffer.append(" object class is ");
appendClassInfo(buffer, object.getClass());
throw new ClassCastException(buffer.toString());
}
} | java | {
"resource": ""
} |
q179568 | Util.appendClassInfo | test | protected static void appendClassInfo(StringBuffer buffer, Class clazz)
{
buffer.append("[class=").append(clazz.getName());
buffer.append(" classloader=").append(clazz.getClassLoader());
buffer.append(" interfaces={");
Class[] interfaces = clazz.getInterfaces();
for (int i=0; i<interfaces.length; ++i)
{
if (i > 0)
buffer.append(", ");
buffer.append("interface=").append(interfaces[i].getName());
buffer.append(" classloader=").append(interfaces[i].getClassLoader());
}
buffer.append("}]");
} | java | {
"resource": ""
} |
q179569 | State.getTransition | test | public Transition getTransition(String name)
{
Transition t = (Transition) allowedTransitions.get(name);
return t;
} | java | {
"resource": ""
} |
q179570 | CatalogManager.readProperties | test | private synchronized void readProperties() {
try {
propertyFileURI = CatalogManager.class.getResource("/"+propertyFile);
InputStream in =
CatalogManager.class.getResourceAsStream("/"+propertyFile);
if (in==null) {
if (!ignoreMissingProperties) {
System.err.println("Cannot find "+propertyFile);
// there's no reason to give this warning more than once
ignoreMissingProperties = true;
}
return;
}
resources = new PropertyResourceBundle(in);
} catch (MissingResourceException mre) {
if (!ignoreMissingProperties) {
System.err.println("Cannot read "+propertyFile);
}
} catch (java.io.IOException e) {
if (!ignoreMissingProperties) {
System.err.println("Failure trying to read "+propertyFile);
}
}
// This is a bit of a hack. After we've successfully read the properties,
// use them to set the default debug level, if the user hasn't already set
// the default debug level.
if (verbosity == null) {
try {
String verbStr = resources.getString("verbosity");
int verb = Integer.parseInt(verbStr.trim());
debug.setDebug(verb);
verbosity = new Integer(verb);
} catch (Exception e) {
// nop
}
}
} | java | {
"resource": ""
} |
q179571 | CatalogManager.queryVerbosity | test | private int queryVerbosity () {
String verbStr = System.getProperty(pVerbosity);
if (verbStr == null) {
if (resources==null) readProperties();
if (resources==null) return defaultVerbosity;
try {
verbStr = resources.getString("verbosity");
} catch (MissingResourceException e) {
return defaultVerbosity;
}
}
try {
int verb = Integer.parseInt(verbStr.trim());
return verb;
} catch (Exception e) {
System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
return defaultVerbosity;
}
} | java | {
"resource": ""
} |
q179572 | CatalogManager.queryRelativeCatalogs | test | private boolean queryRelativeCatalogs () {
if (resources==null) readProperties();
if (resources==null) return defaultRelativeCatalogs;
try {
String allow = resources.getString("relative-catalogs");
return (allow.equalsIgnoreCase("true")
|| allow.equalsIgnoreCase("yes")
|| allow.equalsIgnoreCase("1"));
} catch (MissingResourceException e) {
return defaultRelativeCatalogs;
}
} | java | {
"resource": ""
} |
q179573 | CatalogManager.queryCatalogFiles | test | private String queryCatalogFiles () {
String catalogList = System.getProperty(pFiles);
fromPropertiesFile = false;
if (catalogList == null) {
if (resources == null) readProperties();
if (resources != null) {
try {
catalogList = resources.getString("catalogs");
fromPropertiesFile = true;
} catch (MissingResourceException e) {
System.err.println(propertyFile + ": catalogs not found.");
catalogList = null;
}
}
}
if (catalogList == null) {
catalogList = defaultCatalogFiles;
}
return catalogList;
} | java | {
"resource": ""
} |
q179574 | CatalogManager.getCatalogFiles | test | public Vector getCatalogFiles() {
if (catalogFiles == null) {
catalogFiles = queryCatalogFiles();
}
StringTokenizer files = new StringTokenizer(catalogFiles, ";");
Vector catalogs = new Vector();
while (files.hasMoreTokens()) {
String catalogFile = files.nextToken();
URL absURI = null;
if (fromPropertiesFile && !relativeCatalogs()) {
try {
absURI = new URL(propertyFileURI, catalogFile);
catalogFile = absURI.toString();
} catch (MalformedURLException mue) {
absURI = null;
}
}
catalogs.add(catalogFile);
}
return catalogs;
} | java | {
"resource": ""
} |
q179575 | CatalogManager.queryPreferPublic | test | private boolean queryPreferPublic () {
String prefer = System.getProperty(pPrefer);
if (prefer == null) {
if (resources==null) readProperties();
if (resources==null) return defaultPreferPublic;
try {
prefer = resources.getString("prefer");
} catch (MissingResourceException e) {
return defaultPreferPublic;
}
}
if (prefer == null) {
return defaultPreferPublic;
}
return (prefer.equalsIgnoreCase("public"));
} | java | {
"resource": ""
} |
q179576 | CatalogManager.queryUseStaticCatalog | test | private boolean queryUseStaticCatalog () {
String staticCatalog = System.getProperty(pStatic);
if (useStaticCatalog == null) {
if (resources==null) readProperties();
if (resources==null) return defaultUseStaticCatalog;
try {
staticCatalog = resources.getString("static-catalog");
} catch (MissingResourceException e) {
return defaultUseStaticCatalog;
}
}
if (staticCatalog == null) {
return defaultUseStaticCatalog;
}
return (staticCatalog.equalsIgnoreCase("true")
|| staticCatalog.equalsIgnoreCase("yes")
|| staticCatalog.equalsIgnoreCase("1"));
} | java | {
"resource": ""
} |
q179577 | BootstrapResolver.resolveEntity | test | public InputSource resolveEntity (String publicId, String systemId) {
String resolved = null;
if (systemId != null && systemMap.containsKey(systemId)) {
resolved = (String) systemMap.get(systemId);
} else if (publicId != null && publicMap.containsKey(publicId)) {
resolved = (String) publicMap.get(publicId);
}
if (resolved != null) {
try {
InputSource iSource = new InputSource(resolved);
iSource.setPublicId(publicId);
// Ideally this method would not attempt to open the
// InputStream, but there is a bug (in Xerces, at least)
// that causes the parser to mistakenly open the wrong
// system identifier if the returned InputSource does
// not have a byteStream.
//
// It could be argued that we still shouldn't do this here,
// but since the purpose of calling the entityResolver is
// almost certainly to open the input stream, it seems to
// do little harm.
//
URL url = new URL(resolved);
InputStream iStream = url.openStream();
iSource.setByteStream(iStream);
return iSource;
} catch (Exception e) {
// FIXME: silently fail?
return null;
}
}
return null;
} | java | {
"resource": ""
} |
q179578 | BootstrapResolver.resolve | test | public Source resolve(String href, String base)
throws TransformerException {
String uri = href;
int hashPos = href.indexOf("#");
if (hashPos >= 0) {
uri = href.substring(0, hashPos);
}
String result = null;
if (href != null && uriMap.containsKey(href)) {
result = (String) uriMap.get(href);
}
if (result == null) {
try {
URL url = null;
if (base==null) {
url = new URL(uri);
result = url.toString();
} else {
URL baseURL = new URL(base);
url = (href.length()==0 ? baseURL : new URL(baseURL, uri));
result = url.toString();
}
} catch (java.net.MalformedURLException mue) {
// try to make an absolute URI from the current base
String absBase = makeAbsolute(base);
if (!absBase.equals(base)) {
// don't bother if the absBase isn't different!
return resolve(href, absBase);
} else {
throw new TransformerException("Malformed URL "
+ href + "(base " + base + ")",
mue);
}
}
}
SAXSource source = new SAXSource();
source.setInputSource(new InputSource(result));
return source;
} | java | {
"resource": ""
} |
q179579 | BootstrapResolver.makeAbsolute | test | private String makeAbsolute(String uri) {
if (uri == null) {
uri = "";
}
try {
URL url = new URL(uri);
return url.toString();
} catch (MalformedURLException mue) {
String dir = System.getProperty("user.dir");
String file = "";
if (dir.endsWith("/")) {
file = "file://" + dir + uri;
} else {
file = "file://" + dir + "/" + uri;
}
try {
URL fileURL = new URL(file);
return fileURL.toString();
} catch (MalformedURLException mue2) {
// bail
return uri;
}
}
} | java | {
"resource": ""
} |
q179580 | MarshalledValueInputStream.resolveClass | test | protected Class<?> resolveClass(ObjectStreamClass v)
throws IOException, ClassNotFoundException
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String className = v.getName();
try
{
// JDK 6, by default, only supports array types (ex. [[B) using Class.forName()
return Class.forName(className, false, loader);
}
catch (ClassNotFoundException cnfe)
{
Class cl = primClasses.get(className);
if (cl == null)
throw cnfe;
else
return cl;
}
} | java | {
"resource": ""
} |
q179581 | MethodBoundPropertyListener.invokeSetter | test | protected void invokeSetter(String value) {
try {
// coerce value to field type
Class<?> type = descriptor.getPropertyType();
PropertyEditor editor = PropertyEditors.findEditor(type);
editor.setAsText(value);
Object coerced = editor.getValue();
// System.out.println("type: " + type);
// System.out.println("coerced: " + coerced);
// invoke the setter method
setter.invoke(instance, new Object[] { coerced });
}
catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if (target instanceof PropertyException) {
throw (PropertyException)target;
}
else {
throw new PropertyException(target);
}
}
catch (Exception e) {
throw new PropertyException(e);
}
} | java | {
"resource": ""
} |
q179582 | Namespaces.getLocalName | test | public static String getLocalName(Element element) {
String name = element.getTagName();
if (name.indexOf(':') > 0) {
name = name.substring(name.indexOf(':')+1);
}
return name;
} | java | {
"resource": ""
} |
q179583 | Namespaces.getNamespaceURI | test | public static String getNamespaceURI(Node node, String prefix) {
if (node == null || node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
if (prefix.equals("")) {
if (((Element) node).hasAttribute("xmlns")) {
return ((Element) node).getAttribute("xmlns");
}
} else {
String nsattr = "xmlns:" + prefix;
if (((Element) node).hasAttribute(nsattr)) {
return ((Element) node).getAttribute(nsattr);
}
}
return getNamespaceURI(node.getParentNode(), prefix);
} | java | {
"resource": ""
} |
q179584 | Namespaces.getNamespaceURI | test | public static String getNamespaceURI(Element element) {
String prefix = getPrefix(element);
return getNamespaceURI(element, prefix);
} | java | {
"resource": ""
} |
q179585 | CollectionsUtil.list | test | public static List list(Enumeration e)
{
ArrayList result = new ArrayList();
while (e.hasMoreElements())
result.add(e.nextElement());
return result;
} | java | {
"resource": ""
} |
q179586 | FilePropertyReader.getInputStream | test | protected InputStream getInputStream(String filename) throws IOException {
File file = new File(filename);
return new FileInputStream(file);
} | java | {
"resource": ""
} |
q179587 | FilePropertyReader.loadProperties | test | protected void loadProperties(Properties props, String filename)
throws IOException
{
if (filename == null)
throw new NullArgumentException("filename");
if (filename.equals(""))
throw new IllegalArgumentException("filename");
InputStream in = new BufferedInputStream(getInputStream(filename));
props.load(in);
in.close();
} | java | {
"resource": ""
} |
q179588 | FilePropertyReader.readProperties | test | public Map readProperties()
throws PropertyException, IOException
{
Properties props = new Properties();
// load each specified property file
for (int i=0; i<filenames.length; i++) {
loadProperties(props, filenames[i]);
}
return props;
} | java | {
"resource": ""
} |
q179589 | Vertex.addEdge | test | public boolean addEdge(Edge<T> e)
{
if (e.getFrom() == this)
outgoingEdges.add(e);
else if (e.getTo() == this)
incomingEdges.add(e);
else
return false;
return true;
} | java | {
"resource": ""
} |
q179590 | Vertex.addOutgoingEdge | test | public void addOutgoingEdge(Vertex<T> to, int cost)
{
Edge<T> out = new Edge<T>(this, to, cost);
outgoingEdges.add(out);
} | java | {
"resource": ""
} |
q179591 | Vertex.addIncomingEdge | test | public void addIncomingEdge(Vertex<T> from, int cost)
{
Edge<T> out = new Edge<T>(this, from, cost);
incomingEdges.add(out);
} | java | {
"resource": ""
} |
q179592 | Vertex.hasEdge | test | public boolean hasEdge(Edge<T> e)
{
if (e.getFrom() == this)
return outgoingEdges.contains(e);
else if (e.getTo() == this)
return incomingEdges.contains(e);
else
return false;
} | java | {
"resource": ""
} |
q179593 | Vertex.remove | test | public boolean remove(Edge<T> e)
{
if (e.getFrom() == this)
outgoingEdges.remove(e);
else if (e.getTo() == this)
incomingEdges.remove(e);
else
return false;
return true;
} | java | {
"resource": ""
} |
q179594 | Vertex.findEdge | test | public Edge<T> findEdge(Vertex<T> dest)
{
for (Edge<T> e : outgoingEdges)
{
if (e.getTo() == dest)
return e;
}
return null;
} | java | {
"resource": ""
} |
q179595 | Vertex.findEdge | test | public Edge<T> findEdge(Edge<T> e)
{
if (outgoingEdges.contains(e))
return e;
else
return null;
} | java | {
"resource": ""
} |
q179596 | Vertex.cost | test | public int cost(Vertex<T> dest)
{
if (dest == this)
return 0;
Edge<T> e = findEdge(dest);
int cost = Integer.MAX_VALUE;
if (e != null)
cost = e.getCost();
return cost;
} | java | {
"resource": ""
} |
q179597 | JarUtils.jar | test | private static void jar(File src, String prefix, JarInfo info)
throws IOException
{
JarOutputStream jout = info.out;
if (src.isDirectory())
{
// create / init the zip entry
prefix = prefix + src.getName() + "/";
ZipEntry entry = new ZipEntry(prefix);
entry.setTime(src.lastModified());
entry.setMethod(JarOutputStream.STORED);
entry.setSize(0L);
entry.setCrc(0L);
jout.putNextEntry(entry);
jout.closeEntry();
// process the sub-directories
File[] files = src.listFiles(info.filter);
for (int i = 0; i < files.length; i++)
{
jar(files[i], prefix, info);
}
}
else if (src.isFile())
{
// get the required info objects
byte[] buffer = info.buffer;
// create / init the zip entry
ZipEntry entry = new ZipEntry(prefix + src.getName());
entry.setTime(src.lastModified());
jout.putNextEntry(entry);
// dump the file
FileInputStream in = new FileInputStream(src);
int len;
while ((len = in.read(buffer, 0, buffer.length)) != -1)
{
jout.write(buffer, 0, len);
}
in.close();
jout.closeEntry();
}
} | java | {
"resource": ""
} |
q179598 | CompoundIterator.hasNext | test | public boolean hasNext() {
for (; index < iters.length; index++) {
if (iters[index] != null && iters[index].hasNext()) {
return true;
}
}
return false;
} | java | {
"resource": ""
} |
q179599 | TinyMachine.fireEvent | test | public void fireEvent(Object event) {
if (event == null) {
throw new IllegalArgumentException("Event must not be null.");
}
mTaskQueue.offer(Task.obtainTask(Task.CODE_FIRE_EVENT, event, -1));
if (!mQueueProcessed) processTaskQueue();
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.