repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
rometools/rome | rome-modules/src/main/java/com/rometools/modules/georss/geometries/PositionList.java | PositionList.replace | public void replace(final int pos, final double latitude, final double longitude) {
this.longitude[pos] = longitude;
this.latitude[pos] = latitude;
} | java | public void replace(final int pos, final double latitude, final double longitude) {
this.longitude[pos] = longitude;
this.latitude[pos] = latitude;
} | [
"public",
"void",
"replace",
"(",
"final",
"int",
"pos",
",",
"final",
"double",
"latitude",
",",
"final",
"double",
"longitude",
")",
"{",
"this",
".",
"longitude",
"[",
"pos",
"]",
"=",
"longitude",
";",
"this",
".",
"latitude",
"[",
"pos",
"]",
"=",... | Replace the position at the index with new values
@param pos position index | [
"Replace",
"the",
"position",
"at",
"the",
"index",
"with",
"new",
"values"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/georss/geometries/PositionList.java#L143-L146 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/georss/geometries/PositionList.java | PositionList.remove | public void remove(final int pos) {
System.arraycopy(longitude, pos + 1, longitude, pos, size - pos - 1);
System.arraycopy(latitude, pos + 1, latitude, pos, size - pos - 1);
--size;
} | java | public void remove(final int pos) {
System.arraycopy(longitude, pos + 1, longitude, pos, size - pos - 1);
System.arraycopy(latitude, pos + 1, latitude, pos, size - pos - 1);
--size;
} | [
"public",
"void",
"remove",
"(",
"final",
"int",
"pos",
")",
"{",
"System",
".",
"arraycopy",
"(",
"longitude",
",",
"pos",
"+",
"1",
",",
"longitude",
",",
"pos",
",",
"size",
"-",
"pos",
"-",
"1",
")",
";",
"System",
".",
"arraycopy",
"(",
"latit... | Remove the position at the index, the rest of the list is shifted one place to the "left"
@param pos position index | [
"Remove",
"the",
"position",
"at",
"the",
"index",
"the",
"rest",
"of",
"the",
"list",
"is",
"shifted",
"one",
"place",
"to",
"the",
"left"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/georss/geometries/PositionList.java#L153-L157 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.findBaseURI | private String findBaseURI(final Element root) throws MalformedURLException {
String ret = null;
if (findAtomLink(root, "self") != null) {
ret = findAtomLink(root, "self");
if (".".equals(ret) || "./".equals(ret)) {
ret = "";
}
if (ret.indexOf("/") != -1) {
ret = ret.substring(0, ret.lastIndexOf("/"));
}
ret = resolveURI(null, root, ret);
}
return ret;
} | java | private String findBaseURI(final Element root) throws MalformedURLException {
String ret = null;
if (findAtomLink(root, "self") != null) {
ret = findAtomLink(root, "self");
if (".".equals(ret) || "./".equals(ret)) {
ret = "";
}
if (ret.indexOf("/") != -1) {
ret = ret.substring(0, ret.lastIndexOf("/"));
}
ret = resolveURI(null, root, ret);
}
return ret;
} | [
"private",
"String",
"findBaseURI",
"(",
"final",
"Element",
"root",
")",
"throws",
"MalformedURLException",
"{",
"String",
"ret",
"=",
"null",
";",
"if",
"(",
"findAtomLink",
"(",
"root",
",",
"\"self\"",
")",
"!=",
"null",
")",
"{",
"ret",
"=",
"findAtom... | Find base URI of feed considering relative URIs.
@param root Root element of feed. | [
"Find",
"base",
"URI",
"of",
"feed",
"considering",
"relative",
"URIs",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L600-L613 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.findAtomLink | private String findAtomLink(final Element parent, final String rel) {
String ret = null;
final List<Element> linksList = parent.getChildren("link", ATOM_10_NS);
if (linksList != null) {
for (final Element element : linksList) {
final Element link = element;
final Attribute relAtt = getAttribute(link, "rel");
final Attribute hrefAtt = getAttribute(link, "href");
if (relAtt == null && "alternate".equals(rel) || relAtt != null && relAtt.getValue().equals(rel)) {
ret = hrefAtt.getValue();
break;
}
}
}
return ret;
} | java | private String findAtomLink(final Element parent, final String rel) {
String ret = null;
final List<Element> linksList = parent.getChildren("link", ATOM_10_NS);
if (linksList != null) {
for (final Element element : linksList) {
final Element link = element;
final Attribute relAtt = getAttribute(link, "rel");
final Attribute hrefAtt = getAttribute(link, "href");
if (relAtt == null && "alternate".equals(rel) || relAtt != null && relAtt.getValue().equals(rel)) {
ret = hrefAtt.getValue();
break;
}
}
}
return ret;
} | [
"private",
"String",
"findAtomLink",
"(",
"final",
"Element",
"parent",
",",
"final",
"String",
"rel",
")",
"{",
"String",
"ret",
"=",
"null",
";",
"final",
"List",
"<",
"Element",
">",
"linksList",
"=",
"parent",
".",
"getChildren",
"(",
"\"link\"",
",",
... | Return URL string of Atom link element under parent element. Link with no rel attribute is
considered to be rel="alternate"
@param parent Consider only children of this parent element
@param rel Consider only links with this relationship | [
"Return",
"URL",
"string",
"of",
"Atom",
"link",
"element",
"under",
"parent",
"element",
".",
"Link",
"with",
"no",
"rel",
"attribute",
"is",
"considered",
"to",
"be",
"rel",
"=",
"alternate"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L622-L637 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.formURI | private static String formURI(String base, String append) {
base = stripTrailingSlash(base);
append = stripStartingSlash(append);
if (append.startsWith("..")) {
final String[] parts = append.split("/");
for (final String part : parts) {
if ("..".equals(part)) {
final int last = base.lastIndexOf("/");
if (last != -1) {
base = base.substring(0, last);
append = append.substring(3, append.length());
} else {
break;
}
}
}
}
return base + "/" + append;
} | java | private static String formURI(String base, String append) {
base = stripTrailingSlash(base);
append = stripStartingSlash(append);
if (append.startsWith("..")) {
final String[] parts = append.split("/");
for (final String part : parts) {
if ("..".equals(part)) {
final int last = base.lastIndexOf("/");
if (last != -1) {
base = base.substring(0, last);
append = append.substring(3, append.length());
} else {
break;
}
}
}
}
return base + "/" + append;
} | [
"private",
"static",
"String",
"formURI",
"(",
"String",
"base",
",",
"String",
"append",
")",
"{",
"base",
"=",
"stripTrailingSlash",
"(",
"base",
")",
";",
"append",
"=",
"stripStartingSlash",
"(",
"append",
")",
";",
"if",
"(",
"append",
".",
"startsWit... | Form URI by combining base with append portion and giving special consideration to append
portions that begin with ".."
@param base Base of URI, may end with trailing slash
@param append String to append, may begin with slash or ".." | [
"Form",
"URI",
"by",
"combining",
"base",
"with",
"append",
"portion",
"and",
"giving",
"special",
"consideration",
"to",
"append",
"portions",
"that",
"begin",
"with",
".."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L646-L664 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.stripStartingSlash | private static String stripStartingSlash(String s) {
if (s != null && s.startsWith("/")) {
s = s.substring(1, s.length());
}
return s;
} | java | private static String stripStartingSlash(String s) {
if (s != null && s.startsWith("/")) {
s = s.substring(1, s.length());
}
return s;
} | [
"private",
"static",
"String",
"stripStartingSlash",
"(",
"String",
"s",
")",
"{",
"if",
"(",
"s",
"!=",
"null",
"&&",
"s",
".",
"startsWith",
"(",
"\"/\"",
")",
")",
"{",
"s",
"=",
"s",
".",
"substring",
"(",
"1",
",",
"s",
".",
"length",
"(",
"... | Strip starting slash from beginning of string. | [
"Strip",
"starting",
"slash",
"from",
"beginning",
"of",
"string",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L669-L674 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.stripTrailingSlash | private static String stripTrailingSlash(String s) {
if (s != null && s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
}
return s;
} | java | private static String stripTrailingSlash(String s) {
if (s != null && s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
}
return s;
} | [
"private",
"static",
"String",
"stripTrailingSlash",
"(",
"String",
"s",
")",
"{",
"if",
"(",
"s",
"!=",
"null",
"&&",
"s",
".",
"endsWith",
"(",
"\"/\"",
")",
")",
"{",
"s",
"=",
"s",
".",
"substring",
"(",
"0",
",",
"s",
".",
"length",
"(",
")"... | Strip trailing slash from end of string. | [
"Strip",
"trailing",
"slash",
"from",
"end",
"of",
"string",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L679-L684 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java | Atom10Parser.parseEntry | public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException,
FeedException {
// Parse entry into JDOM tree
final SAXBuilder builder = new SAXBuilder();
final Document entryDoc = builder.build(rd);
final Element fetchedEntryElement = entryDoc.getRootElement();
fetchedEntryElement.detach();
// Put entry into a JDOM document with 'feed' root so that Rome can
// handle it
final Feed feed = new Feed();
feed.setFeedType("atom_1.0");
final WireFeedOutput wireFeedOutput = new WireFeedOutput();
final Document feedDoc = wireFeedOutput.outputJDom(feed);
feedDoc.getRootElement().addContent(fetchedEntryElement);
if (baseURI != null) {
feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE);
}
final WireFeedInput input = new WireFeedInput(false, locale);
final Feed parsedFeed = (Feed) input.build(feedDoc);
return parsedFeed.getEntries().get(0);
} | java | public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException,
FeedException {
// Parse entry into JDOM tree
final SAXBuilder builder = new SAXBuilder();
final Document entryDoc = builder.build(rd);
final Element fetchedEntryElement = entryDoc.getRootElement();
fetchedEntryElement.detach();
// Put entry into a JDOM document with 'feed' root so that Rome can
// handle it
final Feed feed = new Feed();
feed.setFeedType("atom_1.0");
final WireFeedOutput wireFeedOutput = new WireFeedOutput();
final Document feedDoc = wireFeedOutput.outputJDom(feed);
feedDoc.getRootElement().addContent(fetchedEntryElement);
if (baseURI != null) {
feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE);
}
final WireFeedInput input = new WireFeedInput(false, locale);
final Feed parsedFeed = (Feed) input.build(feedDoc);
return parsedFeed.getEntries().get(0);
} | [
"public",
"static",
"Entry",
"parseEntry",
"(",
"final",
"Reader",
"rd",
",",
"final",
"String",
"baseURI",
",",
"final",
"Locale",
"locale",
")",
"throws",
"JDOMException",
",",
"IOException",
",",
"IllegalArgumentException",
",",
"FeedException",
"{",
"// Parse ... | Parse entry from reader. | [
"Parse",
"entry",
"from",
"reader",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/Atom10Parser.java#L689-L713 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.getFeedDocument | public Feed getFeedDocument() throws AtomException {
InputStream in = null;
synchronized (FileStore.getFileStore()) {
in = FileStore.getFileStore().getFileInputStream(getFeedPath());
if (in == null) {
in = createDefaultFeedDocument(contextURI + servletPath + "/" + handle + "/" + collection);
}
}
try {
final WireFeedInput input = new WireFeedInput();
final WireFeed wireFeed = input.build(new InputStreamReader(in, "UTF-8"));
return (Feed) wireFeed;
} catch (final Exception ex) {
throw new AtomException(ex);
}
} | java | public Feed getFeedDocument() throws AtomException {
InputStream in = null;
synchronized (FileStore.getFileStore()) {
in = FileStore.getFileStore().getFileInputStream(getFeedPath());
if (in == null) {
in = createDefaultFeedDocument(contextURI + servletPath + "/" + handle + "/" + collection);
}
}
try {
final WireFeedInput input = new WireFeedInput();
final WireFeed wireFeed = input.build(new InputStreamReader(in, "UTF-8"));
return (Feed) wireFeed;
} catch (final Exception ex) {
throw new AtomException(ex);
}
} | [
"public",
"Feed",
"getFeedDocument",
"(",
")",
"throws",
"AtomException",
"{",
"InputStream",
"in",
"=",
"null",
";",
"synchronized",
"(",
"FileStore",
".",
"getFileStore",
"(",
")",
")",
"{",
"in",
"=",
"FileStore",
".",
"getFileStore",
"(",
")",
".",
"ge... | Get feed document representing collection.
@throws com.rometools.rome.propono.atom.server.AtomException On error retrieving feed file.
@return Atom Feed representing collection. | [
"Get",
"feed",
"document",
"representing",
"collection",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L130-L145 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.getCategories | public List<Categories> getCategories(final boolean inline) {
final Categories cats = new Categories();
cats.setFixed(true);
cats.setScheme(contextURI + "/" + handle + "/" + singular);
if (inline) {
for (final String catName : catNames) {
final Category cat = new Category();
cat.setTerm(catName);
cats.addCategory(cat);
}
} else {
cats.setHref(getCategoriesURI());
}
return Collections.singletonList(cats);
} | java | public List<Categories> getCategories(final boolean inline) {
final Categories cats = new Categories();
cats.setFixed(true);
cats.setScheme(contextURI + "/" + handle + "/" + singular);
if (inline) {
for (final String catName : catNames) {
final Category cat = new Category();
cat.setTerm(catName);
cats.addCategory(cat);
}
} else {
cats.setHref(getCategoriesURI());
}
return Collections.singletonList(cats);
} | [
"public",
"List",
"<",
"Categories",
">",
"getCategories",
"(",
"final",
"boolean",
"inline",
")",
"{",
"final",
"Categories",
"cats",
"=",
"new",
"Categories",
"(",
")",
";",
"cats",
".",
"setFixed",
"(",
"true",
")",
";",
"cats",
".",
"setScheme",
"(",... | Get list of one Categories object containing categories allowed by collection.
@param inline True if Categories object should contain collection of in-line Categories
objects or false if it should set the Href for out-of-line categories. | [
"Get",
"list",
"of",
"one",
"Categories",
"object",
"containing",
"categories",
"allowed",
"by",
"collection",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L153-L167 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.addEntry | public Entry addEntry(final Entry entry) throws Exception {
synchronized (FileStore.getFileStore()) {
final Feed f = getFeedDocument();
final String fsid = FileStore.getFileStore().getNextId();
updateTimestamps(entry);
// Save entry to file
final String entryPath = getEntryPath(fsid);
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateEntryAppLinks(entry, fsid, true);
Atom10Generator.serializeEntry(entry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
// Update feed file
updateEntryAppLinks(entry, fsid, false);
updateFeedDocumentWithNewEntry(f, entry);
return entry;
}
} | java | public Entry addEntry(final Entry entry) throws Exception {
synchronized (FileStore.getFileStore()) {
final Feed f = getFeedDocument();
final String fsid = FileStore.getFileStore().getNextId();
updateTimestamps(entry);
// Save entry to file
final String entryPath = getEntryPath(fsid);
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateEntryAppLinks(entry, fsid, true);
Atom10Generator.serializeEntry(entry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
// Update feed file
updateEntryAppLinks(entry, fsid, false);
updateFeedDocumentWithNewEntry(f, entry);
return entry;
}
} | [
"public",
"Entry",
"addEntry",
"(",
"final",
"Entry",
"entry",
")",
"throws",
"Exception",
"{",
"synchronized",
"(",
"FileStore",
".",
"getFileStore",
"(",
")",
")",
"{",
"final",
"Feed",
"f",
"=",
"getFeedDocument",
"(",
")",
";",
"final",
"String",
"fsid... | Add entry to collection.
@param entry Entry to be added to collection. Entry will be saved to disk in a directory
under the collection's directory and the path will follow the pattern
[collection-plural]/[entryid]/entry.xml. The entry will be added to the
collection's feed in [collection-plural]/feed.xml.
@throws java.lang.Exception On error.
@return Entry as it exists on the server. | [
"Add",
"entry",
"to",
"collection",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L188-L210 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.getEntry | public Entry getEntry(String fsid) throws Exception {
if (fsid.endsWith(".media-link")) {
fsid = fsid.substring(0, fsid.length() - ".media-link".length());
}
final String entryPath = getEntryPath(fsid);
checkExistence(entryPath);
final InputStream in = FileStore.getFileStore().getFileInputStream(entryPath);
final Entry entry;
final File resource = new File(fsid);
if (resource.exists()) {
entry = loadAtomResourceEntry(in, resource);
updateMediaEntryAppLinks(entry, fsid, true);
} else {
entry = loadAtomEntry(in);
updateEntryAppLinks(entry, fsid, true);
}
return entry;
} | java | public Entry getEntry(String fsid) throws Exception {
if (fsid.endsWith(".media-link")) {
fsid = fsid.substring(0, fsid.length() - ".media-link".length());
}
final String entryPath = getEntryPath(fsid);
checkExistence(entryPath);
final InputStream in = FileStore.getFileStore().getFileInputStream(entryPath);
final Entry entry;
final File resource = new File(fsid);
if (resource.exists()) {
entry = loadAtomResourceEntry(in, resource);
updateMediaEntryAppLinks(entry, fsid, true);
} else {
entry = loadAtomEntry(in);
updateEntryAppLinks(entry, fsid, true);
}
return entry;
} | [
"public",
"Entry",
"getEntry",
"(",
"String",
"fsid",
")",
"throws",
"Exception",
"{",
"if",
"(",
"fsid",
".",
"endsWith",
"(",
"\".media-link\"",
")",
")",
"{",
"fsid",
"=",
"fsid",
".",
"substring",
"(",
"0",
",",
"fsid",
".",
"length",
"(",
")",
"... | Get an entry from the collection.
@param fsid Internal ID of entry to be returned
@throws java.lang.Exception On error
@return Entry specified by fileName/ID | [
"Get",
"an",
"entry",
"from",
"the",
"collection",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L273-L293 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.getMediaResource | public AtomMediaResource getMediaResource(final String fileName) throws Exception {
final String filePath = getEntryMediaPath(fileName);
final File resource = new File(filePath);
return new AtomMediaResource(resource);
} | java | public AtomMediaResource getMediaResource(final String fileName) throws Exception {
final String filePath = getEntryMediaPath(fileName);
final File resource = new File(filePath);
return new AtomMediaResource(resource);
} | [
"public",
"AtomMediaResource",
"getMediaResource",
"(",
"final",
"String",
"fileName",
")",
"throws",
"Exception",
"{",
"final",
"String",
"filePath",
"=",
"getEntryMediaPath",
"(",
"fileName",
")",
";",
"final",
"File",
"resource",
"=",
"new",
"File",
"(",
"fil... | Get media resource wrapping a file. | [
"Get",
"media",
"resource",
"wrapping",
"a",
"file",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L298-L302 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.updateEntry | public void updateEntry(final Entry entry, String fsid) throws Exception {
synchronized (FileStore.getFileStore()) {
final Feed f = getFeedDocument();
if (fsid.endsWith(".media-link")) {
fsid = fsid.substring(0, fsid.length() - ".media-link".length());
}
updateTimestamps(entry);
updateEntryAppLinks(entry, fsid, false);
updateFeedDocumentWithExistingEntry(f, entry);
final String entryPath = getEntryPath(fsid);
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateEntryAppLinks(entry, fsid, true);
Atom10Generator.serializeEntry(entry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
}
} | java | public void updateEntry(final Entry entry, String fsid) throws Exception {
synchronized (FileStore.getFileStore()) {
final Feed f = getFeedDocument();
if (fsid.endsWith(".media-link")) {
fsid = fsid.substring(0, fsid.length() - ".media-link".length());
}
updateTimestamps(entry);
updateEntryAppLinks(entry, fsid, false);
updateFeedDocumentWithExistingEntry(f, entry);
final String entryPath = getEntryPath(fsid);
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateEntryAppLinks(entry, fsid, true);
Atom10Generator.serializeEntry(entry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
}
} | [
"public",
"void",
"updateEntry",
"(",
"final",
"Entry",
"entry",
",",
"String",
"fsid",
")",
"throws",
"Exception",
"{",
"synchronized",
"(",
"FileStore",
".",
"getFileStore",
"(",
")",
")",
"{",
"final",
"Feed",
"f",
"=",
"getFeedDocument",
"(",
")",
";",... | Update an entry in the collection.
@param entry Updated entry to be stored
@param fsid Internal ID of entry
@throws java.lang.Exception On error | [
"Update",
"an",
"entry",
"in",
"the",
"collection",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L311-L332 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.updateMediaEntry | public Entry updateMediaEntry(final String fileName, final String contentType, final InputStream is) throws Exception {
synchronized (FileStore.getFileStore()) {
final File tempFile = File.createTempFile(fileName, "tmp");
final FileOutputStream fos = new FileOutputStream(tempFile);
Utilities.copyInputToOutput(is, fos);
fos.close();
// Update media file
final FileInputStream fis = new FileInputStream(tempFile);
saveMediaFile(fileName, contentType, tempFile.length(), fis);
fis.close();
final File resourceFile = new File(getEntryMediaPath(fileName));
// Load media-link entry to return
final String entryPath = getEntryPath(fileName);
final InputStream in = FileStore.getFileStore().getFileInputStream(entryPath);
final Entry atomEntry = loadAtomResourceEntry(in, resourceFile);
updateTimestamps(atomEntry);
updateMediaEntryAppLinks(atomEntry, fileName, false);
// Update feed with new entry
final Feed f = getFeedDocument();
updateFeedDocumentWithExistingEntry(f, atomEntry);
// Save updated media-link entry
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateMediaEntryAppLinks(atomEntry, fileName, true);
Atom10Generator.serializeEntry(atomEntry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
return atomEntry;
}
} | java | public Entry updateMediaEntry(final String fileName, final String contentType, final InputStream is) throws Exception {
synchronized (FileStore.getFileStore()) {
final File tempFile = File.createTempFile(fileName, "tmp");
final FileOutputStream fos = new FileOutputStream(tempFile);
Utilities.copyInputToOutput(is, fos);
fos.close();
// Update media file
final FileInputStream fis = new FileInputStream(tempFile);
saveMediaFile(fileName, contentType, tempFile.length(), fis);
fis.close();
final File resourceFile = new File(getEntryMediaPath(fileName));
// Load media-link entry to return
final String entryPath = getEntryPath(fileName);
final InputStream in = FileStore.getFileStore().getFileInputStream(entryPath);
final Entry atomEntry = loadAtomResourceEntry(in, resourceFile);
updateTimestamps(atomEntry);
updateMediaEntryAppLinks(atomEntry, fileName, false);
// Update feed with new entry
final Feed f = getFeedDocument();
updateFeedDocumentWithExistingEntry(f, atomEntry);
// Save updated media-link entry
final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath);
updateMediaEntryAppLinks(atomEntry, fileName, true);
Atom10Generator.serializeEntry(atomEntry, new OutputStreamWriter(os, "UTF-8"));
os.flush();
os.close();
return atomEntry;
}
} | [
"public",
"Entry",
"updateMediaEntry",
"(",
"final",
"String",
"fileName",
",",
"final",
"String",
"contentType",
",",
"final",
"InputStream",
"is",
")",
"throws",
"Exception",
"{",
"synchronized",
"(",
"FileStore",
".",
"getFileStore",
"(",
")",
")",
"{",
"fi... | Update media associated with a media-link entry.
@param fileName Internal ID of entry being updated
@param contentType Content type of data
@param is Source of updated data
@throws java.lang.Exception On error
@return Updated Entry as it exists on server | [
"Update",
"media",
"associated",
"with",
"a",
"media",
"-",
"link",
"entry",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L343-L378 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.deleteEntry | public void deleteEntry(final String fsid) throws Exception {
synchronized (FileStore.getFileStore()) {
// Remove entry from Feed
final Feed feed = getFeedDocument();
updateFeedDocumentRemovingEntry(feed, fsid);
final String entryFilePath = getEntryPath(fsid);
FileStore.getFileStore().deleteFile(entryFilePath);
final String entryMediaPath = getEntryMediaPath(fsid);
if (entryMediaPath != null) {
FileStore.getFileStore().deleteFile(entryMediaPath);
}
final String entryDirPath = getEntryDirPath(fsid);
FileStore.getFileStore().deleteDirectory(entryDirPath);
try {
Thread.sleep(500L);
} catch (final Exception ignored) {
}
}
} | java | public void deleteEntry(final String fsid) throws Exception {
synchronized (FileStore.getFileStore()) {
// Remove entry from Feed
final Feed feed = getFeedDocument();
updateFeedDocumentRemovingEntry(feed, fsid);
final String entryFilePath = getEntryPath(fsid);
FileStore.getFileStore().deleteFile(entryFilePath);
final String entryMediaPath = getEntryMediaPath(fsid);
if (entryMediaPath != null) {
FileStore.getFileStore().deleteFile(entryMediaPath);
}
final String entryDirPath = getEntryDirPath(fsid);
FileStore.getFileStore().deleteDirectory(entryDirPath);
try {
Thread.sleep(500L);
} catch (final Exception ignored) {
}
}
} | [
"public",
"void",
"deleteEntry",
"(",
"final",
"String",
"fsid",
")",
"throws",
"Exception",
"{",
"synchronized",
"(",
"FileStore",
".",
"getFileStore",
"(",
")",
")",
"{",
"// Remove entry from Feed",
"final",
"Feed",
"feed",
"=",
"getFeedDocument",
"(",
")",
... | Delete an entry and any associated media file.
@param fsid Internal ID of entry
@throws java.lang.Exception On error | [
"Delete",
"an",
"entry",
"and",
"any",
"associated",
"media",
"file",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L386-L409 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.loadAtomEntry | private Entry loadAtomEntry(final InputStream in) {
try {
return Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in, "UTF-8")), null, Locale.US);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
} | java | private Entry loadAtomEntry(final InputStream in) {
try {
return Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in, "UTF-8")), null, Locale.US);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
} | [
"private",
"Entry",
"loadAtomEntry",
"(",
"final",
"InputStream",
"in",
")",
"{",
"try",
"{",
"return",
"Atom10Parser",
".",
"parseEntry",
"(",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"in",
",",
"\"UTF-8\"",
")",
")",
",",
"null",
",",... | Create a Rome Atom entry based on a Roller entry. Content is escaped. Link is stored as
rel=alternate link. | [
"Create",
"a",
"Rome",
"Atom",
"entry",
"based",
"on",
"a",
"Roller",
"entry",
".",
"Content",
"is",
"escaped",
".",
"Link",
"is",
"stored",
"as",
"rel",
"=",
"alternate",
"link",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L616-L623 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.saveMediaFile | private void saveMediaFile(final String name, final String contentType, final long size, final InputStream is) throws AtomException {
final byte[] buffer = new byte[8192];
int bytesRead = 0;
final File dirPath = new File(getEntryMediaPath(name));
if (!dirPath.getParentFile().exists()) {
dirPath.getParentFile().mkdirs();
}
OutputStream bos = null;
try {
bos = new FileOutputStream(dirPath.getAbsolutePath());
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
} catch (final Exception e) {
throw new AtomException("ERROR uploading file", e);
} finally {
try {
bos.flush();
bos.close();
} catch (final Exception ignored) {
}
}
} | java | private void saveMediaFile(final String name, final String contentType, final long size, final InputStream is) throws AtomException {
final byte[] buffer = new byte[8192];
int bytesRead = 0;
final File dirPath = new File(getEntryMediaPath(name));
if (!dirPath.getParentFile().exists()) {
dirPath.getParentFile().mkdirs();
}
OutputStream bos = null;
try {
bos = new FileOutputStream(dirPath.getAbsolutePath());
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
} catch (final Exception e) {
throw new AtomException("ERROR uploading file", e);
} finally {
try {
bos.flush();
bos.close();
} catch (final Exception ignored) {
}
}
} | [
"private",
"void",
"saveMediaFile",
"(",
"final",
"String",
"name",
",",
"final",
"String",
"contentType",
",",
"final",
"long",
"size",
",",
"final",
"InputStream",
"is",
")",
"throws",
"AtomException",
"{",
"final",
"byte",
"[",
"]",
"buffer",
"=",
"new",
... | Save file to website's resource directory.
@param handle Weblog handle to save to
@param name Name of file to save
@param size Size of file to be saved
@param is Read file from input stream | [
"Save",
"file",
"to",
"website",
"s",
"resource",
"directory",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L650-L675 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java | FileBasedCollection.createFileName | private String createFileName(final String title, final String contentType) {
if (handle == null) {
throw new IllegalArgumentException("weblog handle cannot be null");
}
if (contentType == null) {
throw new IllegalArgumentException("contentType cannot be null");
}
String fileName = null;
final SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMddHHssSSS");
// Determine the extension based on the contentType. This is a hack.
// The info we need to map from contentType to file extension is in
// JRE/lib/content-type.properties, but Java Activation doesn't provide
// a way to do a reverse mapping or to get at the data.
final String[] typeTokens = contentType.split("/");
final String ext = typeTokens[1];
if (title != null && !title.trim().equals("")) {
// We've got a title, so use it to build file name
final String base = Utilities.replaceNonAlphanumeric(title, ' ');
final StringTokenizer toker = new StringTokenizer(base);
String tmp = null;
int count = 0;
while (toker.hasMoreTokens() && count < 5) {
String s = toker.nextToken();
s = s.toLowerCase();
tmp = tmp == null ? s : tmp + "_" + s;
count++;
}
fileName = tmp + "-" + sdf.format(new Date()) + "." + ext;
} else {
// No title or text, so instead we'll use the item's date
// in YYYYMMDD format to form the file name
fileName = handle + "-" + sdf.format(new Date()) + "." + ext;
}
return fileName;
} | java | private String createFileName(final String title, final String contentType) {
if (handle == null) {
throw new IllegalArgumentException("weblog handle cannot be null");
}
if (contentType == null) {
throw new IllegalArgumentException("contentType cannot be null");
}
String fileName = null;
final SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMddHHssSSS");
// Determine the extension based on the contentType. This is a hack.
// The info we need to map from contentType to file extension is in
// JRE/lib/content-type.properties, but Java Activation doesn't provide
// a way to do a reverse mapping or to get at the data.
final String[] typeTokens = contentType.split("/");
final String ext = typeTokens[1];
if (title != null && !title.trim().equals("")) {
// We've got a title, so use it to build file name
final String base = Utilities.replaceNonAlphanumeric(title, ' ');
final StringTokenizer toker = new StringTokenizer(base);
String tmp = null;
int count = 0;
while (toker.hasMoreTokens() && count < 5) {
String s = toker.nextToken();
s = s.toLowerCase();
tmp = tmp == null ? s : tmp + "_" + s;
count++;
}
fileName = tmp + "-" + sdf.format(new Date()) + "." + ext;
} else {
// No title or text, so instead we'll use the item's date
// in YYYYMMDD format to form the file name
fileName = handle + "-" + sdf.format(new Date()) + "." + ext;
}
return fileName;
} | [
"private",
"String",
"createFileName",
"(",
"final",
"String",
"title",
",",
"final",
"String",
"contentType",
")",
"{",
"if",
"(",
"handle",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"weblog handle cannot be null\"",
")",
";",
"... | Creates a file name for a file based on a weblog handle, title string and a content-type.
@param handle Weblog handle
@param title Title to be used as basis for file name (or null)
@param contentType Content type of file (must not be null)
If a title is specified, the method will apply the same create-anchor logic we use
for weblog entries to create a file name based on the title.
If title is null, the base file name will be the weblog handle plus a YYYYMMDDHHSS
timestamp.
The extension will be formed by using the part of content type that comes after he
slash.
For example: weblog.handle = "daveblog" title = "Port Antonio" content-type =
"image/jpg" Would result in port_antonio.jpg
Another example: weblog.handle = "daveblog" title = null content-type =
"image/jpg" Might result in daveblog-200608201034.jpg | [
"Creates",
"a",
"file",
"name",
"for",
"a",
"file",
"based",
"on",
"a",
"weblog",
"handle",
"title",
"string",
"and",
"a",
"content",
"-",
"type",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/server/impl/FileBasedCollection.java#L699-L741 | train |
rometools/rome | rome-utils/src/main/java/com/rometools/utils/Alternatives.java | Alternatives.firstNotNull | public static <T> T firstNotNull(final T... objects) {
for (final T object : objects) {
if (object != null) {
return object;
}
}
return null;
} | java | public static <T> T firstNotNull(final T... objects) {
for (final T object : objects) {
if (object != null) {
return object;
}
}
return null;
} | [
"public",
"static",
"<",
"T",
">",
"T",
"firstNotNull",
"(",
"final",
"T",
"...",
"objects",
")",
"{",
"for",
"(",
"final",
"T",
"object",
":",
"objects",
")",
"{",
"if",
"(",
"object",
"!=",
"null",
")",
"{",
"return",
"object",
";",
"}",
"}",
"... | Returns the first object that is not null
@param objects The objects to process
@return The first value that is not null. null when there is no not-null value | [
"Returns",
"the",
"first",
"object",
"that",
"is",
"not",
"null"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-utils/src/main/java/com/rometools/utils/Alternatives.java#L28-L35 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/impl/PluginManager.java | PluginManager.loadPlugins | private void loadPlugins() {
final List<T> finalPluginsList = new ArrayList<T>();
pluginsList = new ArrayList<T>();
pluginsMap = new HashMap<String, T>();
String className = null;
try {
final Class<T>[] classes = getClasses();
for (final Class<T> clazz : classes) {
className = clazz.getName();
final T plugin = clazz.newInstance();
if (plugin instanceof DelegatingModuleParser) {
((DelegatingModuleParser) plugin).setFeedParser(parentParser);
}
if (plugin instanceof DelegatingModuleGenerator) {
((DelegatingModuleGenerator) plugin).setFeedGenerator(parentGenerator);
}
pluginsMap.put(getKey(plugin), plugin);
// to preserve the order of definition in the rome.properties files
pluginsList.add(plugin);
}
final Collection<T> plugins = pluginsMap.values();
for (final T plugin : plugins) {
// to remove overridden plugin impls
finalPluginsList.add(plugin);
}
final Iterator<T> iterator = pluginsList.iterator();
while (iterator.hasNext()) {
final T plugin = iterator.next();
if (!finalPluginsList.contains(plugin)) {
iterator.remove();
}
}
} catch (final Exception ex) {
throw new RuntimeException("could not instantiate plugin " + className, ex);
} catch (final ExceptionInInitializerError er) {
throw new RuntimeException("could not instantiate plugin " + className, er);
}
} | java | private void loadPlugins() {
final List<T> finalPluginsList = new ArrayList<T>();
pluginsList = new ArrayList<T>();
pluginsMap = new HashMap<String, T>();
String className = null;
try {
final Class<T>[] classes = getClasses();
for (final Class<T> clazz : classes) {
className = clazz.getName();
final T plugin = clazz.newInstance();
if (plugin instanceof DelegatingModuleParser) {
((DelegatingModuleParser) plugin).setFeedParser(parentParser);
}
if (plugin instanceof DelegatingModuleGenerator) {
((DelegatingModuleGenerator) plugin).setFeedGenerator(parentGenerator);
}
pluginsMap.put(getKey(plugin), plugin);
// to preserve the order of definition in the rome.properties files
pluginsList.add(plugin);
}
final Collection<T> plugins = pluginsMap.values();
for (final T plugin : plugins) {
// to remove overridden plugin impls
finalPluginsList.add(plugin);
}
final Iterator<T> iterator = pluginsList.iterator();
while (iterator.hasNext()) {
final T plugin = iterator.next();
if (!finalPluginsList.contains(plugin)) {
iterator.remove();
}
}
} catch (final Exception ex) {
throw new RuntimeException("could not instantiate plugin " + className, ex);
} catch (final ExceptionInInitializerError er) {
throw new RuntimeException("could not instantiate plugin " + className, er);
}
} | [
"private",
"void",
"loadPlugins",
"(",
")",
"{",
"final",
"List",
"<",
"T",
">",
"finalPluginsList",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
")",
";",
"pluginsList",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
")",
";",
"pluginsMap",
"=",
"new"... | PRIVATE - LOADER PART | [
"PRIVATE",
"-",
"LOADER",
"PART"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/impl/PluginManager.java#L83-L132 | train |
rometools/rome | rome-utils/src/main/java/com/rometools/utils/Strings.java | Strings.toLowerCase | public static String toLowerCase(final String s) {
if (s == null) {
return null;
} else {
return s.toLowerCase(Locale.ENGLISH);
}
} | java | public static String toLowerCase(final String s) {
if (s == null) {
return null;
} else {
return s.toLowerCase(Locale.ENGLISH);
}
} | [
"public",
"static",
"String",
"toLowerCase",
"(",
"final",
"String",
"s",
")",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"s",
".",
"toLowerCase",
"(",
"Locale",
".",
"ENGLISH",
")",
";",
"}",
"}... | null-safe lower-case conversion of a String.
@param s The String to process, may be null
@return null when the input String is null, the String in lower-case otherwise | [
"null",
"-",
"safe",
"lower",
"-",
"case",
"conversion",
"of",
"a",
"String",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-utils/src/main/java/com/rometools/utils/Strings.java#L118-L124 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java | Utilities.streamToString | public static String streamToString(final InputStream is) throws IOException {
final StringBuffer sb = new StringBuffer();
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
sb.append(LS);
}
return sb.toString();
} | java | public static String streamToString(final InputStream is) throws IOException {
final StringBuffer sb = new StringBuffer();
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
sb.append(LS);
}
return sb.toString();
} | [
"public",
"static",
"String",
"streamToString",
"(",
"final",
"InputStream",
"is",
")",
"throws",
"IOException",
"{",
"final",
"StringBuffer",
"sb",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"final",
"BufferedReader",
"in",
"=",
"new",
"BufferedReader",
"(",
... | Read input from stream and into string. | [
"Read",
"input",
"from",
"stream",
"and",
"into",
"string",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java#L88-L97 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java | Utilities.copyInputToOutput | public static void copyInputToOutput(final InputStream input, final OutputStream output) throws IOException {
final BufferedInputStream in = new BufferedInputStream(input);
final BufferedOutputStream out = new BufferedOutputStream(output);
final byte buffer[] = new byte[8192];
for (int count = 0; count != -1;) {
count = in.read(buffer, 0, 8192);
if (count != -1) {
out.write(buffer, 0, count);
}
}
try {
in.close();
out.close();
} catch (final IOException ex) {
throw new IOException("Closing file streams, " + ex.getMessage());
}
} | java | public static void copyInputToOutput(final InputStream input, final OutputStream output) throws IOException {
final BufferedInputStream in = new BufferedInputStream(input);
final BufferedOutputStream out = new BufferedOutputStream(output);
final byte buffer[] = new byte[8192];
for (int count = 0; count != -1;) {
count = in.read(buffer, 0, 8192);
if (count != -1) {
out.write(buffer, 0, count);
}
}
try {
in.close();
out.close();
} catch (final IOException ex) {
throw new IOException("Closing file streams, " + ex.getMessage());
}
} | [
"public",
"static",
"void",
"copyInputToOutput",
"(",
"final",
"InputStream",
"input",
",",
"final",
"OutputStream",
"output",
")",
"throws",
"IOException",
"{",
"final",
"BufferedInputStream",
"in",
"=",
"new",
"BufferedInputStream",
"(",
"input",
")",
";",
"fina... | Copy input stream to output stream using 8K buffer. | [
"Copy",
"input",
"stream",
"to",
"output",
"stream",
"using",
"8K",
"buffer",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java#L102-L119 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java | Utilities.replaceNonAlphanumeric | public static String replaceNonAlphanumeric(final String str, final char subst) {
final StringBuffer ret = new StringBuffer(str.length());
final char[] testChars = str.toCharArray();
for (final char testChar : testChars) {
if (Character.isLetterOrDigit(testChar)) {
ret.append(testChar);
} else {
ret.append(subst);
}
}
return ret.toString();
} | java | public static String replaceNonAlphanumeric(final String str, final char subst) {
final StringBuffer ret = new StringBuffer(str.length());
final char[] testChars = str.toCharArray();
for (final char testChar : testChars) {
if (Character.isLetterOrDigit(testChar)) {
ret.append(testChar);
} else {
ret.append(subst);
}
}
return ret.toString();
} | [
"public",
"static",
"String",
"replaceNonAlphanumeric",
"(",
"final",
"String",
"str",
",",
"final",
"char",
"subst",
")",
"{",
"final",
"StringBuffer",
"ret",
"=",
"new",
"StringBuffer",
"(",
"str",
".",
"length",
"(",
")",
")",
";",
"final",
"char",
"[",... | Replaces occurences of non-alphanumeric characters with a supplied char. | [
"Replaces",
"occurences",
"of",
"non",
"-",
"alphanumeric",
"characters",
"with",
"a",
"supplied",
"char",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java#L124-L135 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java | Utilities.stringToStringArray | public static String[] stringToStringArray(final String instr, final String delim) throws NoSuchElementException, NumberFormatException {
final StringTokenizer toker = new StringTokenizer(instr, delim);
final String stringArray[] = new String[toker.countTokens()];
int i = 0;
while (toker.hasMoreTokens()) {
stringArray[i++] = toker.nextToken();
}
return stringArray;
} | java | public static String[] stringToStringArray(final String instr, final String delim) throws NoSuchElementException, NumberFormatException {
final StringTokenizer toker = new StringTokenizer(instr, delim);
final String stringArray[] = new String[toker.countTokens()];
int i = 0;
while (toker.hasMoreTokens()) {
stringArray[i++] = toker.nextToken();
}
return stringArray;
} | [
"public",
"static",
"String",
"[",
"]",
"stringToStringArray",
"(",
"final",
"String",
"instr",
",",
"final",
"String",
"delim",
")",
"throws",
"NoSuchElementException",
",",
"NumberFormatException",
"{",
"final",
"StringTokenizer",
"toker",
"=",
"new",
"StringToken... | Convert string to string array. | [
"Convert",
"string",
"to",
"string",
"array",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java#L140-L148 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java | Utilities.stringArrayToString | public static String stringArrayToString(final String[] stringArray, final String delim) {
String ret = "";
for (final String element : stringArray) {
if (ret.length() > 0) {
ret = ret + delim + element;
} else {
ret = element;
}
}
return ret;
} | java | public static String stringArrayToString(final String[] stringArray, final String delim) {
String ret = "";
for (final String element : stringArray) {
if (ret.length() > 0) {
ret = ret + delim + element;
} else {
ret = element;
}
}
return ret;
} | [
"public",
"static",
"String",
"stringArrayToString",
"(",
"final",
"String",
"[",
"]",
"stringArray",
",",
"final",
"String",
"delim",
")",
"{",
"String",
"ret",
"=",
"\"\"",
";",
"for",
"(",
"final",
"String",
"element",
":",
"stringArray",
")",
"{",
"if"... | Convert string array to string. | [
"Convert",
"string",
"array",
"to",
"string",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/utils/Utilities.java#L153-L163 | train |
rometools/rome | rome-utils/src/main/java/com/rometools/utils/Integers.java | Integers.parse | public static Integer parse(final String s) {
try {
return Integer.parseInt(s);
} catch (final NumberFormatException e) {
return null;
}
} | java | public static Integer parse(final String s) {
try {
return Integer.parseInt(s);
} catch (final NumberFormatException e) {
return null;
}
} | [
"public",
"static",
"Integer",
"parse",
"(",
"final",
"String",
"s",
")",
"{",
"try",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"s",
")",
";",
"}",
"catch",
"(",
"final",
"NumberFormatException",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}"
] | Converts a String into an Integer.
@param s The String to convert, may be null
@return The parsed Integer or null when parsing is not possible | [
"Converts",
"a",
"String",
"into",
"an",
"Integer",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-utils/src/main/java/com/rometools/utils/Integers.java#L28-L34 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/sse/modules/History.java | History.addUpdate | public void addUpdate(final Update update) {
if (updates == null) {
updates = new ArrayList<Update>();
}
updates.add(update);
} | java | public void addUpdate(final Update update) {
if (updates == null) {
updates = new ArrayList<Update>();
}
updates.add(update);
} | [
"public",
"void",
"addUpdate",
"(",
"final",
"Update",
"update",
")",
"{",
"if",
"(",
"updates",
"==",
"null",
")",
"{",
"updates",
"=",
"new",
"ArrayList",
"<",
"Update",
">",
"(",
")",
";",
"}",
"updates",
".",
"add",
"(",
"update",
")",
";",
"}"... | Add an update to this history
@param update an update to add to the list of updates for this history. | [
"Add",
"an",
"update",
"to",
"this",
"history"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/sse/modules/History.java#L126-L131 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateThumbails | private void generateThumbails(final Metadata m, final Element e) {
for (final Thumbnail thumb : m.getThumbnail()) {
final Element t = new Element("thumbnail", NS);
addNotNullAttribute(t, "url", thumb.getUrl());
addNotNullAttribute(t, "width", thumb.getWidth());
addNotNullAttribute(t, "height", thumb.getHeight());
addNotNullAttribute(t, "time", thumb.getTime());
e.addContent(t);
}
} | java | private void generateThumbails(final Metadata m, final Element e) {
for (final Thumbnail thumb : m.getThumbnail()) {
final Element t = new Element("thumbnail", NS);
addNotNullAttribute(t, "url", thumb.getUrl());
addNotNullAttribute(t, "width", thumb.getWidth());
addNotNullAttribute(t, "height", thumb.getHeight());
addNotNullAttribute(t, "time", thumb.getTime());
e.addContent(t);
}
} | [
"private",
"void",
"generateThumbails",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"for",
"(",
"final",
"Thumbnail",
"thumb",
":",
"m",
".",
"getThumbnail",
"(",
")",
")",
"{",
"final",
"Element",
"t",
"=",
"new",
"Element",
... | Generation of thumbnail tags.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"thumbnail",
"tags",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L243-L252 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateComments | private void generateComments(final Metadata m, final Element e) {
final Element commentsElements = new Element("comments", NS);
for (final String comment : m.getComments()) {
addNotNullElement(commentsElements, "comment", comment);
}
if (!commentsElements.getChildren().isEmpty()) {
e.addContent(commentsElements);
}
} | java | private void generateComments(final Metadata m, final Element e) {
final Element commentsElements = new Element("comments", NS);
for (final String comment : m.getComments()) {
addNotNullElement(commentsElements, "comment", comment);
}
if (!commentsElements.getChildren().isEmpty()) {
e.addContent(commentsElements);
}
} | [
"private",
"void",
"generateComments",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"final",
"Element",
"commentsElements",
"=",
"new",
"Element",
"(",
"\"comments\"",
",",
"NS",
")",
";",
"for",
"(",
"final",
"String",
"comment",
... | Generation of comments tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"comments",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L276-L284 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateCommunity | private void generateCommunity(final Metadata m, final Element e) {
if (m.getCommunity() == null) {
return;
}
final Element communityElement = new Element("community", NS);
if (m.getCommunity().getStarRating() != null) {
final Element starRatingElement = new Element("starRating", NS);
addNotNullAttribute(starRatingElement, "average", m.getCommunity().getStarRating().getAverage());
addNotNullAttribute(starRatingElement, "count", m.getCommunity().getStarRating().getCount());
addNotNullAttribute(starRatingElement, "min", m.getCommunity().getStarRating().getMin());
addNotNullAttribute(starRatingElement, "max", m.getCommunity().getStarRating().getMax());
if (starRatingElement.hasAttributes()) {
communityElement.addContent(starRatingElement);
}
}
if (m.getCommunity().getStatistics() != null) {
final Element statisticsElement = new Element("statistics", NS);
addNotNullAttribute(statisticsElement, "views", m.getCommunity().getStatistics().getViews());
addNotNullAttribute(statisticsElement, "favorites", m.getCommunity().getStatistics().getFavorites());
if (statisticsElement.hasAttributes()) {
communityElement.addContent(statisticsElement);
}
}
if (m.getCommunity().getTags() != null && !m.getCommunity().getTags().isEmpty()) {
final Element tagsElement = new Element("tags", NS);
for (final Tag tag : m.getCommunity().getTags()) {
if (!tagsElement.getTextTrim().isEmpty()) {
tagsElement.addContent(", ");
}
if (tag.getWeight() == null) {
tagsElement.addContent(tag.getName());
} else {
tagsElement.addContent(tag.getName());
tagsElement.addContent(":");
tagsElement.addContent(String.valueOf(tag.getWeight()));
}
}
if (!tagsElement.getTextTrim().isEmpty()) {
communityElement.addContent(tagsElement);
}
}
if (!communityElement.getChildren().isEmpty()) {
e.addContent(communityElement);
}
} | java | private void generateCommunity(final Metadata m, final Element e) {
if (m.getCommunity() == null) {
return;
}
final Element communityElement = new Element("community", NS);
if (m.getCommunity().getStarRating() != null) {
final Element starRatingElement = new Element("starRating", NS);
addNotNullAttribute(starRatingElement, "average", m.getCommunity().getStarRating().getAverage());
addNotNullAttribute(starRatingElement, "count", m.getCommunity().getStarRating().getCount());
addNotNullAttribute(starRatingElement, "min", m.getCommunity().getStarRating().getMin());
addNotNullAttribute(starRatingElement, "max", m.getCommunity().getStarRating().getMax());
if (starRatingElement.hasAttributes()) {
communityElement.addContent(starRatingElement);
}
}
if (m.getCommunity().getStatistics() != null) {
final Element statisticsElement = new Element("statistics", NS);
addNotNullAttribute(statisticsElement, "views", m.getCommunity().getStatistics().getViews());
addNotNullAttribute(statisticsElement, "favorites", m.getCommunity().getStatistics().getFavorites());
if (statisticsElement.hasAttributes()) {
communityElement.addContent(statisticsElement);
}
}
if (m.getCommunity().getTags() != null && !m.getCommunity().getTags().isEmpty()) {
final Element tagsElement = new Element("tags", NS);
for (final Tag tag : m.getCommunity().getTags()) {
if (!tagsElement.getTextTrim().isEmpty()) {
tagsElement.addContent(", ");
}
if (tag.getWeight() == null) {
tagsElement.addContent(tag.getName());
} else {
tagsElement.addContent(tag.getName());
tagsElement.addContent(":");
tagsElement.addContent(String.valueOf(tag.getWeight()));
}
}
if (!tagsElement.getTextTrim().isEmpty()) {
communityElement.addContent(tagsElement);
}
}
if (!communityElement.getChildren().isEmpty()) {
e.addContent(communityElement);
}
} | [
"private",
"void",
"generateCommunity",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"if",
"(",
"m",
".",
"getCommunity",
"(",
")",
"==",
"null",
")",
"{",
"return",
";",
"}",
"final",
"Element",
"communityElement",
"=",
"new",
... | Generation of community tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"community",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L292-L336 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateEmbed | private void generateEmbed(final Metadata m, final Element e) {
if (m.getEmbed() == null) {
return;
}
final Element embedElement = new Element("embed", NS);
addNotNullAttribute(embedElement, "url", m.getEmbed().getUrl());
addNotNullAttribute(embedElement, "width", m.getEmbed().getWidth());
addNotNullAttribute(embedElement, "height", m.getEmbed().getHeight());
for (final Param param : m.getEmbed().getParams()) {
final Element paramElement = addNotNullElement(embedElement, "param", param.getValue());
if (paramElement != null) {
addNotNullAttribute(paramElement, "name", param.getName());
}
}
if (embedElement.hasAttributes() || !embedElement.getChildren().isEmpty()) {
e.addContent(embedElement);
}
} | java | private void generateEmbed(final Metadata m, final Element e) {
if (m.getEmbed() == null) {
return;
}
final Element embedElement = new Element("embed", NS);
addNotNullAttribute(embedElement, "url", m.getEmbed().getUrl());
addNotNullAttribute(embedElement, "width", m.getEmbed().getWidth());
addNotNullAttribute(embedElement, "height", m.getEmbed().getHeight());
for (final Param param : m.getEmbed().getParams()) {
final Element paramElement = addNotNullElement(embedElement, "param", param.getValue());
if (paramElement != null) {
addNotNullAttribute(paramElement, "name", param.getName());
}
}
if (embedElement.hasAttributes() || !embedElement.getChildren().isEmpty()) {
e.addContent(embedElement);
}
} | [
"private",
"void",
"generateEmbed",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"if",
"(",
"m",
".",
"getEmbed",
"(",
")",
"==",
"null",
")",
"{",
"return",
";",
"}",
"final",
"Element",
"embedElement",
"=",
"new",
"Element",... | Generation of embed tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"embed",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L344-L361 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateScenes | private void generateScenes(final Metadata m, final Element e) {
final Element scenesElement = new Element("scenes", NS);
for (final Scene scene : m.getScenes()) {
final Element sceneElement = new Element("scene", NS);
addNotNullElement(sceneElement, "sceneTitle", scene.getTitle());
addNotNullElement(sceneElement, "sceneDescription", scene.getDescription());
addNotNullElement(sceneElement, "sceneStartTime", scene.getStartTime());
addNotNullElement(sceneElement, "sceneEndTime", scene.getEndTime());
if (!sceneElement.getChildren().isEmpty()) {
scenesElement.addContent(sceneElement);
}
}
if (!scenesElement.getChildren().isEmpty()) {
e.addContent(scenesElement);
}
} | java | private void generateScenes(final Metadata m, final Element e) {
final Element scenesElement = new Element("scenes", NS);
for (final Scene scene : m.getScenes()) {
final Element sceneElement = new Element("scene", NS);
addNotNullElement(sceneElement, "sceneTitle", scene.getTitle());
addNotNullElement(sceneElement, "sceneDescription", scene.getDescription());
addNotNullElement(sceneElement, "sceneStartTime", scene.getStartTime());
addNotNullElement(sceneElement, "sceneEndTime", scene.getEndTime());
if (!sceneElement.getChildren().isEmpty()) {
scenesElement.addContent(sceneElement);
}
}
if (!scenesElement.getChildren().isEmpty()) {
e.addContent(scenesElement);
}
} | [
"private",
"void",
"generateScenes",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"final",
"Element",
"scenesElement",
"=",
"new",
"Element",
"(",
"\"scenes\"",
",",
"NS",
")",
";",
"for",
"(",
"final",
"Scene",
"scene",
":",
"m... | Generation of scenes tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"scenes",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L369-L384 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateLocations | private void generateLocations(final Metadata m, final Element e) {
final GMLGenerator geoRssGenerator = new GMLGenerator();
for (final Location location : m.getLocations()) {
final Element locationElement = new Element("location", NS);
addNotNullAttribute(locationElement, "description", location.getDescription());
addNotNullAttribute(locationElement, "start", location.getStart());
addNotNullAttribute(locationElement, "end", location.getEnd());
if (location.getGeoRss() != null) {
geoRssGenerator.generate(location.getGeoRss(), locationElement);
}
if (locationElement.hasAttributes() || !locationElement.getChildren().isEmpty()) {
e.addContent(locationElement);
}
}
} | java | private void generateLocations(final Metadata m, final Element e) {
final GMLGenerator geoRssGenerator = new GMLGenerator();
for (final Location location : m.getLocations()) {
final Element locationElement = new Element("location", NS);
addNotNullAttribute(locationElement, "description", location.getDescription());
addNotNullAttribute(locationElement, "start", location.getStart());
addNotNullAttribute(locationElement, "end", location.getEnd());
if (location.getGeoRss() != null) {
geoRssGenerator.generate(location.getGeoRss(), locationElement);
}
if (locationElement.hasAttributes() || !locationElement.getChildren().isEmpty()) {
e.addContent(locationElement);
}
}
} | [
"private",
"void",
"generateLocations",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"final",
"GMLGenerator",
"geoRssGenerator",
"=",
"new",
"GMLGenerator",
"(",
")",
";",
"for",
"(",
"final",
"Location",
"location",
":",
"m",
".",
... | Generation of location tags.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"location",
"tags",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L392-L406 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generatePeerLinks | private void generatePeerLinks(final Metadata m, final Element e) {
for (final PeerLink peerLink : m.getPeerLinks()) {
final Element peerLinkElement = new Element("peerLink", NS);
addNotNullAttribute(peerLinkElement, "type", peerLink.getType());
addNotNullAttribute(peerLinkElement, "href", peerLink.getHref());
if (peerLinkElement.hasAttributes()) {
e.addContent(peerLinkElement);
}
}
} | java | private void generatePeerLinks(final Metadata m, final Element e) {
for (final PeerLink peerLink : m.getPeerLinks()) {
final Element peerLinkElement = new Element("peerLink", NS);
addNotNullAttribute(peerLinkElement, "type", peerLink.getType());
addNotNullAttribute(peerLinkElement, "href", peerLink.getHref());
if (peerLinkElement.hasAttributes()) {
e.addContent(peerLinkElement);
}
}
} | [
"private",
"void",
"generatePeerLinks",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"for",
"(",
"final",
"PeerLink",
"peerLink",
":",
"m",
".",
"getPeerLinks",
"(",
")",
")",
"{",
"final",
"Element",
"peerLinkElement",
"=",
"new"... | Generation of peerLink tags.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"peerLink",
"tags",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L414-L423 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateSubTitles | private void generateSubTitles(final Metadata m, final Element e) {
for (final SubTitle subTitle : m.getSubTitles()) {
final Element subTitleElement = new Element("subTitle", NS);
addNotNullAttribute(subTitleElement, "type", subTitle.getType());
addNotNullAttribute(subTitleElement, "lang", subTitle.getLang());
addNotNullAttribute(subTitleElement, "href", subTitle.getHref());
if (subTitleElement.hasAttributes()) {
e.addContent(subTitleElement);
}
}
} | java | private void generateSubTitles(final Metadata m, final Element e) {
for (final SubTitle subTitle : m.getSubTitles()) {
final Element subTitleElement = new Element("subTitle", NS);
addNotNullAttribute(subTitleElement, "type", subTitle.getType());
addNotNullAttribute(subTitleElement, "lang", subTitle.getLang());
addNotNullAttribute(subTitleElement, "href", subTitle.getHref());
if (subTitleElement.hasAttributes()) {
e.addContent(subTitleElement);
}
}
} | [
"private",
"void",
"generateSubTitles",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"for",
"(",
"final",
"SubTitle",
"subTitle",
":",
"m",
".",
"getSubTitles",
"(",
")",
")",
"{",
"final",
"Element",
"subTitleElement",
"=",
"new"... | Generation of subTitle tags.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"subTitle",
"tags",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L431-L441 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateLicenses | private void generateLicenses(final Metadata m, final Element e) {
for (final License license : m.getLicenses()) {
final Element licenseElement = new Element("license", NS);
addNotNullAttribute(licenseElement, "type", license.getType());
addNotNullAttribute(licenseElement, "href", license.getHref());
if (license.getValue() != null) {
licenseElement.addContent(license.getValue());
}
if (licenseElement.hasAttributes() || !licenseElement.getTextTrim().isEmpty()) {
e.addContent(licenseElement);
}
}
} | java | private void generateLicenses(final Metadata m, final Element e) {
for (final License license : m.getLicenses()) {
final Element licenseElement = new Element("license", NS);
addNotNullAttribute(licenseElement, "type", license.getType());
addNotNullAttribute(licenseElement, "href", license.getHref());
if (license.getValue() != null) {
licenseElement.addContent(license.getValue());
}
if (licenseElement.hasAttributes() || !licenseElement.getTextTrim().isEmpty()) {
e.addContent(licenseElement);
}
}
} | [
"private",
"void",
"generateLicenses",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"for",
"(",
"final",
"License",
"license",
":",
"m",
".",
"getLicenses",
"(",
")",
")",
"{",
"final",
"Element",
"licenseElement",
"=",
"new",
"... | Generation of license tags.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"license",
"tags",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L449-L461 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateResponses | private void generateResponses(final Metadata m, final Element e) {
if (m.getResponses() == null || m.getResponses().length == 0) {
return;
}
final Element responsesElements = new Element("responses", NS);
for (final String response : m.getResponses()) {
addNotNullElement(responsesElements, "response", response);
}
e.addContent(responsesElements);
} | java | private void generateResponses(final Metadata m, final Element e) {
if (m.getResponses() == null || m.getResponses().length == 0) {
return;
}
final Element responsesElements = new Element("responses", NS);
for (final String response : m.getResponses()) {
addNotNullElement(responsesElements, "response", response);
}
e.addContent(responsesElements);
} | [
"private",
"void",
"generateResponses",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"if",
"(",
"m",
".",
"getResponses",
"(",
")",
"==",
"null",
"||",
"m",
".",
"getResponses",
"(",
")",
".",
"length",
"==",
"0",
")",
"{",
... | Generation of responses tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"responses",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L493-L502 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java | MediaModuleGenerator.generateStatus | private void generateStatus(final Metadata m, final Element e) {
if (m.getStatus() == null) {
return;
}
final Element statusElement = new Element("status", NS);
if (m.getStatus().getState() != null) {
statusElement.setAttribute("state", m.getStatus().getState().name());
}
addNotNullAttribute(statusElement, "reason", m.getStatus().getReason());
if (statusElement.hasAttributes()) {
e.addContent(statusElement);
}
} | java | private void generateStatus(final Metadata m, final Element e) {
if (m.getStatus() == null) {
return;
}
final Element statusElement = new Element("status", NS);
if (m.getStatus().getState() != null) {
statusElement.setAttribute("state", m.getStatus().getState().name());
}
addNotNullAttribute(statusElement, "reason", m.getStatus().getReason());
if (statusElement.hasAttributes()) {
e.addContent(statusElement);
}
} | [
"private",
"void",
"generateStatus",
"(",
"final",
"Metadata",
"m",
",",
"final",
"Element",
"e",
")",
"{",
"if",
"(",
"m",
".",
"getStatus",
"(",
")",
"==",
"null",
")",
"{",
"return",
";",
"}",
"final",
"Element",
"statusElement",
"=",
"new",
"Elemen... | Generation of status tag.
@param m source
@param e element to attach new element to | [
"Generation",
"of",
"status",
"tag",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/io/MediaModuleGenerator.java#L510-L522 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/common/rome/AppModuleImpl.java | AppModuleImpl.copyFrom | @Override
public void copyFrom(final CopyFrom obj) {
final AppModule m = (AppModule) obj;
setDraft(m.getDraft());
setEdited(m.getEdited());
} | java | @Override
public void copyFrom(final CopyFrom obj) {
final AppModule m = (AppModule) obj;
setDraft(m.getDraft());
setEdited(m.getEdited());
} | [
"@",
"Override",
"public",
"void",
"copyFrom",
"(",
"final",
"CopyFrom",
"obj",
")",
"{",
"final",
"AppModule",
"m",
"=",
"(",
"AppModule",
")",
"obj",
";",
"setDraft",
"(",
"m",
".",
"getDraft",
"(",
")",
")",
";",
"setEdited",
"(",
"m",
".",
"getEd... | Copy from other module | [
"Copy",
"from",
"other",
"module"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/common/rome/AppModuleImpl.java#L76-L81 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/XmlReader.java | XmlReader.getContentTypeMime | private static String getContentTypeMime(final String httpContentType) {
String mime = null;
if (httpContentType != null) {
final int i = httpContentType.indexOf(";");
if (i == -1) {
mime = httpContentType.trim();
} else {
mime = httpContentType.substring(0, i).trim();
}
}
return mime;
} | java | private static String getContentTypeMime(final String httpContentType) {
String mime = null;
if (httpContentType != null) {
final int i = httpContentType.indexOf(";");
if (i == -1) {
mime = httpContentType.trim();
} else {
mime = httpContentType.substring(0, i).trim();
}
}
return mime;
} | [
"private",
"static",
"String",
"getContentTypeMime",
"(",
"final",
"String",
"httpContentType",
")",
"{",
"String",
"mime",
"=",
"null",
";",
"if",
"(",
"httpContentType",
"!=",
"null",
")",
"{",
"final",
"int",
"i",
"=",
"httpContentType",
".",
"indexOf",
"... | returns MIME type or NULL if httpContentType is NULL | [
"returns",
"MIME",
"type",
"or",
"NULL",
"if",
"httpContentType",
"is",
"NULL"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/XmlReader.java#L610-L621 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/XmlReader.java | XmlReader.getContentTypeEncoding | private static String getContentTypeEncoding(final String httpContentType) {
String encoding = null;
if (httpContentType != null) {
final int i = httpContentType.indexOf(";");
if (i > -1) {
final String postMime = httpContentType.substring(i + 1);
final Matcher m = CHARSET_PATTERN.matcher(postMime);
if (m.find()) {
encoding = m.group(1);
}
if (encoding != null) {
encoding = encoding.toUpperCase(Locale.ENGLISH);
}
}
if (encoding != null && (encoding.startsWith("\"") && encoding.endsWith("\"") || encoding.startsWith("'") && encoding.endsWith("'"))) {
encoding = encoding.substring(1, encoding.length() - 1);
}
}
return encoding;
} | java | private static String getContentTypeEncoding(final String httpContentType) {
String encoding = null;
if (httpContentType != null) {
final int i = httpContentType.indexOf(";");
if (i > -1) {
final String postMime = httpContentType.substring(i + 1);
final Matcher m = CHARSET_PATTERN.matcher(postMime);
if (m.find()) {
encoding = m.group(1);
}
if (encoding != null) {
encoding = encoding.toUpperCase(Locale.ENGLISH);
}
}
if (encoding != null && (encoding.startsWith("\"") && encoding.endsWith("\"") || encoding.startsWith("'") && encoding.endsWith("'"))) {
encoding = encoding.substring(1, encoding.length() - 1);
}
}
return encoding;
} | [
"private",
"static",
"String",
"getContentTypeEncoding",
"(",
"final",
"String",
"httpContentType",
")",
"{",
"String",
"encoding",
"=",
"null",
";",
"if",
"(",
"httpContentType",
"!=",
"null",
")",
"{",
"final",
"int",
"i",
"=",
"httpContentType",
".",
"index... | httpContentType is NULL | [
"httpContentType",
"is",
"NULL"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/XmlReader.java#L625-L644 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/XmlReader.java | XmlReader.getBOMEncoding | private static String getBOMEncoding(final BufferedInputStream is) throws IOException {
String encoding = null;
final int[] bytes = new int[3];
is.mark(3);
bytes[0] = is.read();
bytes[1] = is.read();
bytes[2] = is.read();
if (bytes[0] == 0xFE && bytes[1] == 0xFF) {
encoding = UTF_16BE;
is.reset();
is.read();
is.read();
} else if (bytes[0] == 0xFF && bytes[1] == 0xFE) {
encoding = UTF_16LE;
is.reset();
is.read();
is.read();
} else if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
encoding = UTF_8;
} else {
is.reset();
}
return encoding;
} | java | private static String getBOMEncoding(final BufferedInputStream is) throws IOException {
String encoding = null;
final int[] bytes = new int[3];
is.mark(3);
bytes[0] = is.read();
bytes[1] = is.read();
bytes[2] = is.read();
if (bytes[0] == 0xFE && bytes[1] == 0xFF) {
encoding = UTF_16BE;
is.reset();
is.read();
is.read();
} else if (bytes[0] == 0xFF && bytes[1] == 0xFE) {
encoding = UTF_16LE;
is.reset();
is.read();
is.read();
} else if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
encoding = UTF_8;
} else {
is.reset();
}
return encoding;
} | [
"private",
"static",
"String",
"getBOMEncoding",
"(",
"final",
"BufferedInputStream",
"is",
")",
"throws",
"IOException",
"{",
"String",
"encoding",
"=",
"null",
";",
"final",
"int",
"[",
"]",
"bytes",
"=",
"new",
"int",
"[",
"3",
"]",
";",
"is",
".",
"m... | if there was BOM the in the stream it is consumed | [
"if",
"there",
"was",
"BOM",
"the",
"in",
"the",
"stream",
"it",
"is",
"consumed"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/XmlReader.java#L648-L672 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/XmlReader.java | XmlReader.isAppXml | private static boolean isAppXml(final String mime) {
return mime != null
&& (mime.equals("application/xml") || mime.equals("application/xml-dtd") || mime.equals("application/xml-external-parsed-entity") || mime
.startsWith("application/") && mime.endsWith("+xml"));
} | java | private static boolean isAppXml(final String mime) {
return mime != null
&& (mime.equals("application/xml") || mime.equals("application/xml-dtd") || mime.equals("application/xml-external-parsed-entity") || mime
.startsWith("application/") && mime.endsWith("+xml"));
} | [
"private",
"static",
"boolean",
"isAppXml",
"(",
"final",
"String",
"mime",
")",
"{",
"return",
"mime",
"!=",
"null",
"&&",
"(",
"mime",
".",
"equals",
"(",
"\"application/xml\"",
")",
"||",
"mime",
".",
"equals",
"(",
"\"application/xml-dtd\"",
")",
"||",
... | indicates if the MIME type belongs to the APPLICATION XML family | [
"indicates",
"if",
"the",
"MIME",
"type",
"belongs",
"to",
"the",
"APPLICATION",
"XML",
"family"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/XmlReader.java#L736-L740 | train |
rometools/rome | rome/src/main/java/com/rometools/rome/io/XmlReader.java | XmlReader.isTextXml | private static boolean isTextXml(final String mime) {
return mime != null && (mime.equals("text/xml") || mime.equals("text/xml-external-parsed-entity") || mime.startsWith("text/") && mime.endsWith("+xml"));
} | java | private static boolean isTextXml(final String mime) {
return mime != null && (mime.equals("text/xml") || mime.equals("text/xml-external-parsed-entity") || mime.startsWith("text/") && mime.endsWith("+xml"));
} | [
"private",
"static",
"boolean",
"isTextXml",
"(",
"final",
"String",
"mime",
")",
"{",
"return",
"mime",
"!=",
"null",
"&&",
"(",
"mime",
".",
"equals",
"(",
"\"text/xml\"",
")",
"||",
"mime",
".",
"equals",
"(",
"\"text/xml-external-parsed-entity\"",
")",
"... | indicates if the MIME type belongs to the TEXT XML family | [
"indicates",
"if",
"the",
"MIME",
"type",
"belongs",
"to",
"the",
"TEXT",
"XML",
"family"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome/src/main/java/com/rometools/rome/io/XmlReader.java#L743-L745 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java | SleUtility.group | public static <T extends Extendable> List<T> group(final List<T> values, final Group[] groups) {
final SortableList<T> list = getSortableList(values);
final GroupStrategy strategy = new GroupStrategy();
for (int i = groups.length - 1; i >= 0; i--) {
list.sortOnProperty(groups[i], true, strategy);
}
return list;
} | java | public static <T extends Extendable> List<T> group(final List<T> values, final Group[] groups) {
final SortableList<T> list = getSortableList(values);
final GroupStrategy strategy = new GroupStrategy();
for (int i = groups.length - 1; i >= 0; i--) {
list.sortOnProperty(groups[i], true, strategy);
}
return list;
} | [
"public",
"static",
"<",
"T",
"extends",
"Extendable",
">",
"List",
"<",
"T",
">",
"group",
"(",
"final",
"List",
"<",
"T",
">",
"values",
",",
"final",
"Group",
"[",
"]",
"groups",
")",
"{",
"final",
"SortableList",
"<",
"T",
">",
"list",
"=",
"ge... | Groups values by the groups from the SLE.
@param values List of Extendable implementations to group.
@param groups Group fields (from the SimpleListExtension module)
@return Grouped list of entries. | [
"Groups",
"values",
"by",
"the",
"groups",
"from",
"the",
"SLE",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java#L58-L65 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java | SleUtility.sort | public static <T extends Extendable> List<T> sort(final List<T> values, final Sort sort, final boolean ascending) {
final SortableList<T> list = getSortableList(values);
list.sortOnProperty(sort, ascending, new SortStrategy());
return list;
} | java | public static <T extends Extendable> List<T> sort(final List<T> values, final Sort sort, final boolean ascending) {
final SortableList<T> list = getSortableList(values);
list.sortOnProperty(sort, ascending, new SortStrategy());
return list;
} | [
"public",
"static",
"<",
"T",
"extends",
"Extendable",
">",
"List",
"<",
"T",
">",
"sort",
"(",
"final",
"List",
"<",
"T",
">",
"values",
",",
"final",
"Sort",
"sort",
",",
"final",
"boolean",
"ascending",
")",
"{",
"final",
"SortableList",
"<",
"T",
... | Sorts a list of values based on a given sort field using a selection sort.
@param values List of values (implements Extendable) to sort.
@param sort The sort field to sort on.
@param ascending Sort ascending/descending.
@return Sorted list of values | [
"Sorts",
"a",
"list",
"of",
"values",
"based",
"on",
"a",
"given",
"sort",
"field",
"using",
"a",
"selection",
"sort",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java#L75-L79 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java | SleUtility.sortAndGroup | public static <T extends Extendable> List<T> sortAndGroup(final List<T> values, final Group[] groups, final Sort sort, final boolean ascending) {
List<T> list = sort(values, sort, ascending);
list = group(list, groups);
return list;
} | java | public static <T extends Extendable> List<T> sortAndGroup(final List<T> values, final Group[] groups, final Sort sort, final boolean ascending) {
List<T> list = sort(values, sort, ascending);
list = group(list, groups);
return list;
} | [
"public",
"static",
"<",
"T",
"extends",
"Extendable",
">",
"List",
"<",
"T",
">",
"sortAndGroup",
"(",
"final",
"List",
"<",
"T",
">",
"values",
",",
"final",
"Group",
"[",
"]",
"groups",
",",
"final",
"Sort",
"sort",
",",
"final",
"boolean",
"ascendi... | Sorts and groups a set of entries.
@param values List of Extendable implementations.
@param groups Group items to group by.
@param sort Field to sort on.
@param ascending Sort ascending/descending
@return Grouped and sorted list of entries. | [
"Sorts",
"and",
"groups",
"a",
"set",
"of",
"entries",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/sle/SleUtility.java#L90-L94 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/client/AtomClientFactory.java | AtomClientFactory.getAtomService | public static ClientAtomService getAtomService(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientAtomService(uri, authStrategy);
} | java | public static ClientAtomService getAtomService(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientAtomService(uri, authStrategy);
} | [
"public",
"static",
"ClientAtomService",
"getAtomService",
"(",
"final",
"String",
"uri",
",",
"final",
"AuthStrategy",
"authStrategy",
")",
"throws",
"ProponoException",
"{",
"return",
"new",
"ClientAtomService",
"(",
"uri",
",",
"authStrategy",
")",
";",
"}"
] | Create AtomService by reading service doc from Atom Server. | [
"Create",
"AtomService",
"by",
"reading",
"service",
"doc",
"from",
"Atom",
"Server",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/client/AtomClientFactory.java#L40-L42 | train |
rometools/rome | rome-propono/src/main/java/com/rometools/propono/atom/client/AtomClientFactory.java | AtomClientFactory.getCollection | public static ClientCollection getCollection(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientCollection(uri, authStrategy);
} | java | public static ClientCollection getCollection(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientCollection(uri, authStrategy);
} | [
"public",
"static",
"ClientCollection",
"getCollection",
"(",
"final",
"String",
"uri",
",",
"final",
"AuthStrategy",
"authStrategy",
")",
"throws",
"ProponoException",
"{",
"return",
"new",
"ClientCollection",
"(",
"uri",
",",
"authStrategy",
")",
";",
"}"
] | Create ClientCollection bound to URI. | [
"Create",
"ClientCollection",
"bound",
"to",
"URI",
"."
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-propono/src/main/java/com/rometools/propono/atom/client/AtomClientFactory.java#L47-L49 | train |
rometools/rome | rome-modules/src/main/java/com/rometools/modules/mediarss/types/MediaContent.java | MediaContent.setReference | public void setReference(final Reference reference) {
this.reference = reference;
if (reference instanceof PlayerReference) {
setPlayer((PlayerReference) reference);
}
} | java | public void setReference(final Reference reference) {
this.reference = reference;
if (reference instanceof PlayerReference) {
setPlayer((PlayerReference) reference);
}
} | [
"public",
"void",
"setReference",
"(",
"final",
"Reference",
"reference",
")",
"{",
"this",
".",
"reference",
"=",
"reference",
";",
"if",
"(",
"reference",
"instanceof",
"PlayerReference",
")",
"{",
"setPlayer",
"(",
"(",
"PlayerReference",
")",
"reference",
... | The player or URL reference for the item
@param reference The player or URL reference for the item | [
"The",
"player",
"or",
"URL",
"reference",
"for",
"the",
"item"
] | 5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010 | https://github.com/rometools/rome/blob/5fcf0b1a9a6cdedbe253a45ad9468c54a0f97010/rome-modules/src/main/java/com/rometools/modules/mediarss/types/MediaContent.java#L481-L487 | train |
dequelabs/axe-selenium-java | src/main/java/com/deque/axe/AXE.java | AXE.inject | public static void inject(final WebDriver driver, final URL scriptUrl, Boolean skipFrames) {
final String script = getContents(scriptUrl);
if (!skipFrames) {
final ArrayList<WebElement> parents = new ArrayList<WebElement>();
injectIntoFrames(driver, script, parents);
}
JavascriptExecutor js = (JavascriptExecutor) driver;
driver.switchTo().defaultContent();
js.executeScript(script);
} | java | public static void inject(final WebDriver driver, final URL scriptUrl, Boolean skipFrames) {
final String script = getContents(scriptUrl);
if (!skipFrames) {
final ArrayList<WebElement> parents = new ArrayList<WebElement>();
injectIntoFrames(driver, script, parents);
}
JavascriptExecutor js = (JavascriptExecutor) driver;
driver.switchTo().defaultContent();
js.executeScript(script);
} | [
"public",
"static",
"void",
"inject",
"(",
"final",
"WebDriver",
"driver",
",",
"final",
"URL",
"scriptUrl",
",",
"Boolean",
"skipFrames",
")",
"{",
"final",
"String",
"script",
"=",
"getContents",
"(",
"scriptUrl",
")",
";",
"if",
"(",
"!",
"skipFrames",
... | Recursively injects a script to the top level document with the option to skip iframes.
@param driver WebDriver instance to inject into
@param scriptUrl URL to the script to inject
@param skipFrames True if the script should not be injected into iframes | [
"Recursively",
"injects",
"a",
"script",
"to",
"the",
"top",
"level",
"document",
"with",
"the",
"option",
"to",
"skip",
"iframes",
"."
] | 68b35ff46c59111b0e9a9f573380c3d250bcfd65 | https://github.com/dequelabs/axe-selenium-java/blob/68b35ff46c59111b0e9a9f573380c3d250bcfd65/src/main/java/com/deque/axe/AXE.java#L69-L80 | train |
dequelabs/axe-selenium-java | src/main/java/com/deque/axe/AXE.java | AXE.injectIntoFrames | private static void injectIntoFrames(final WebDriver driver, final String script, final ArrayList<WebElement> parents) {
final JavascriptExecutor js = (JavascriptExecutor) driver;
final List<WebElement> frames = driver.findElements(By.tagName("iframe"));
for (WebElement frame : frames) {
driver.switchTo().defaultContent();
if (parents != null) {
for (WebElement parent : parents) {
driver.switchTo().frame(parent);
}
}
driver.switchTo().frame(frame);
js.executeScript(script);
ArrayList<WebElement> localParents = (ArrayList<WebElement>) parents.clone();
localParents.add(frame);
injectIntoFrames(driver, script, localParents);
}
} | java | private static void injectIntoFrames(final WebDriver driver, final String script, final ArrayList<WebElement> parents) {
final JavascriptExecutor js = (JavascriptExecutor) driver;
final List<WebElement> frames = driver.findElements(By.tagName("iframe"));
for (WebElement frame : frames) {
driver.switchTo().defaultContent();
if (parents != null) {
for (WebElement parent : parents) {
driver.switchTo().frame(parent);
}
}
driver.switchTo().frame(frame);
js.executeScript(script);
ArrayList<WebElement> localParents = (ArrayList<WebElement>) parents.clone();
localParents.add(frame);
injectIntoFrames(driver, script, localParents);
}
} | [
"private",
"static",
"void",
"injectIntoFrames",
"(",
"final",
"WebDriver",
"driver",
",",
"final",
"String",
"script",
",",
"final",
"ArrayList",
"<",
"WebElement",
">",
"parents",
")",
"{",
"final",
"JavascriptExecutor",
"js",
"=",
"(",
"JavascriptExecutor",
"... | Recursively find frames and inject a script into them.
@param driver An initialized WebDriver
@param script Script to inject
@param parents A list of all toplevel frames | [
"Recursively",
"find",
"frames",
"and",
"inject",
"a",
"script",
"into",
"them",
"."
] | 68b35ff46c59111b0e9a9f573380c3d250bcfd65 | https://github.com/dequelabs/axe-selenium-java/blob/68b35ff46c59111b0e9a9f573380c3d250bcfd65/src/main/java/com/deque/axe/AXE.java#L97-L118 | train |
dequelabs/axe-selenium-java | src/main/java/com/deque/axe/AXE.java | AXE.writeResults | public static void writeResults(final String name, final Object output) {
Writer writer = null;
try {
writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(name + ".json"), "utf-8"));
writer.write(output.toString());
} catch (IOException ignored) {
} finally {
try {writer.close();}
catch (Exception ignored) {}
}
} | java | public static void writeResults(final String name, final Object output) {
Writer writer = null;
try {
writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(name + ".json"), "utf-8"));
writer.write(output.toString());
} catch (IOException ignored) {
} finally {
try {writer.close();}
catch (Exception ignored) {}
}
} | [
"public",
"static",
"void",
"writeResults",
"(",
"final",
"String",
"name",
",",
"final",
"Object",
"output",
")",
"{",
"Writer",
"writer",
"=",
"null",
";",
"try",
"{",
"writer",
"=",
"new",
"BufferedWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"new",
... | Writes a raw object out to a JSON file with the specified name.
@param name Desired filename, sans extension
@param output Object to write. Most useful if you pass in either the Builder.analyze() response or the
violations array it contains. | [
"Writes",
"a",
"raw",
"object",
"out",
"to",
"a",
"JSON",
"file",
"with",
"the",
"specified",
"name",
"."
] | 68b35ff46c59111b0e9a9f573380c3d250bcfd65 | https://github.com/dequelabs/axe-selenium-java/blob/68b35ff46c59111b0e9a9f573380c3d250bcfd65/src/main/java/com/deque/axe/AXE.java#L212-L226 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/SynonymsEntry.java | SynonymsEntry.add | public void add(IWord word)
{
//check and extends the entity from the base word
if ( word.getEntity() == null ) {
word.setEntity(rootWord.getEntity());
}
//check and extends the part of speech from the base word
if ( word.getPartSpeech() == null ) {
word.setPartSpeech(rootWord.getPartSpeech());
}
word.setSyn(this);
synsList.add(word);
} | java | public void add(IWord word)
{
//check and extends the entity from the base word
if ( word.getEntity() == null ) {
word.setEntity(rootWord.getEntity());
}
//check and extends the part of speech from the base word
if ( word.getPartSpeech() == null ) {
word.setPartSpeech(rootWord.getPartSpeech());
}
word.setSyn(this);
synsList.add(word);
} | [
"public",
"void",
"add",
"(",
"IWord",
"word",
")",
"{",
"//check and extends the entity from the base word",
"if",
"(",
"word",
".",
"getEntity",
"(",
")",
"==",
"null",
")",
"{",
"word",
".",
"setEntity",
"(",
"rootWord",
".",
"getEntity",
"(",
")",
")",
... | add a new synonyms word
and the newly added word will extends the part of speech and the entity
from the base word if there are not set
@param word | [
"add",
"a",
"new",
"synonyms",
"word",
"and",
"the",
"newly",
"added",
"word",
"will",
"extends",
"the",
"part",
"of",
"speech",
"and",
"the",
"entity",
"from",
"the",
"base",
"word",
"if",
"there",
"are",
"not",
"set"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/SynonymsEntry.java#L72-L86 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/NumericUtil.java | NumericUtil.isCNNumeric | public static int isCNNumeric( char c )
{
Integer i = cnNumeric.get(c);
if ( i == null ) return -1;
return i.intValue();
} | java | public static int isCNNumeric( char c )
{
Integer i = cnNumeric.get(c);
if ( i == null ) return -1;
return i.intValue();
} | [
"public",
"static",
"int",
"isCNNumeric",
"(",
"char",
"c",
")",
"{",
"Integer",
"i",
"=",
"cnNumeric",
".",
"get",
"(",
"c",
")",
";",
"if",
"(",
"i",
"==",
"null",
")",
"return",
"-",
"1",
";",
"return",
"i",
".",
"intValue",
"(",
")",
";",
"... | check if the given char is a Chinese numeric or not
@param c
@return int the numeric value | [
"check",
"if",
"the",
"given",
"char",
"is",
"a",
"Chinese",
"numeric",
"or",
"not"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/NumericUtil.java#L54-L59 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/NumericUtil.java | NumericUtil.isCNNumericString | public static boolean isCNNumericString(String str , int sIdx, int eIdx)
{
for ( int i = sIdx; i < eIdx; i++ ) {
if ( ! cnNumeric.containsKey(str.charAt(i)) ) {
return false;
}
}
return true;
} | java | public static boolean isCNNumericString(String str , int sIdx, int eIdx)
{
for ( int i = sIdx; i < eIdx; i++ ) {
if ( ! cnNumeric.containsKey(str.charAt(i)) ) {
return false;
}
}
return true;
} | [
"public",
"static",
"boolean",
"isCNNumericString",
"(",
"String",
"str",
",",
"int",
"sIdx",
",",
"int",
"eIdx",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"sIdx",
";",
"i",
"<",
"eIdx",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"cnNumeric",
".",
"c... | check if the specified string is a Chinese numeric string
@param str
@return boolean | [
"check",
"if",
"the",
"specified",
"string",
"is",
"a",
"Chinese",
"numeric",
"string"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/NumericUtil.java#L67-L75 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java | JcsegController.response | protected void response( int code, String data )
{
/*
* send the json content type and the charset
*/
response.setContentType("application/json;charset="+config.getCharset());
JSONWriter json = JSONWriter.create()
.put("code", code)
.put("data", data);
/*IStringBuffer sb = new IStringBuffer();
sb.append("{\n");
sb.append("\"status\": ").append(status).append(",\n");
sb.append("\"errcode\": ").append(errcode).append(",\n");
sb.append("\"data\": ");
if ( data.charAt(0) == '{' || data.charAt(0) == '[' ) {
sb.append(data).append('\n');
} else {
sb.append('"').append(data).append("\"\n");
}
sb.append("}\n");*/
output.println(json.toString());
output.flush();
//let the gc do its work
json = null;
} | java | protected void response( int code, String data )
{
/*
* send the json content type and the charset
*/
response.setContentType("application/json;charset="+config.getCharset());
JSONWriter json = JSONWriter.create()
.put("code", code)
.put("data", data);
/*IStringBuffer sb = new IStringBuffer();
sb.append("{\n");
sb.append("\"status\": ").append(status).append(",\n");
sb.append("\"errcode\": ").append(errcode).append(",\n");
sb.append("\"data\": ");
if ( data.charAt(0) == '{' || data.charAt(0) == '[' ) {
sb.append(data).append('\n');
} else {
sb.append('"').append(data).append("\"\n");
}
sb.append("}\n");*/
output.println(json.toString());
output.flush();
//let the gc do its work
json = null;
} | [
"protected",
"void",
"response",
"(",
"int",
"code",
",",
"String",
"data",
")",
"{",
"/*\n * send the json content type and the charset \n */",
"response",
".",
"setContentType",
"(",
"\"application/json;charset=\"",
"+",
"config",
".",
"getCharset",
"(",
... | global output protocol
@param code
@param data | [
"global",
"output",
"protocol"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java#L46-L74 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java | JcsegController.response | protected void response(int code, List<Object> data)
{
response(code, JSONWriter.list2JsonString(data));
} | java | protected void response(int code, List<Object> data)
{
response(code, JSONWriter.list2JsonString(data));
} | [
"protected",
"void",
"response",
"(",
"int",
"code",
",",
"List",
"<",
"Object",
">",
"data",
")",
"{",
"response",
"(",
"code",
",",
"JSONWriter",
".",
"list2JsonString",
"(",
"data",
")",
")",
";",
"}"
] | global list output protocol
@param code
@param data | [
"global",
"list",
"output",
"protocol"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java#L82-L85 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java | JcsegController.response | protected void response(int code, Map<String, Object> data)
{
response(code, JSONWriter.map2JsonString(data));
} | java | protected void response(int code, Map<String, Object> data)
{
response(code, JSONWriter.map2JsonString(data));
} | [
"protected",
"void",
"response",
"(",
"int",
"code",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"data",
")",
"{",
"response",
"(",
"code",
",",
"JSONWriter",
".",
"map2JsonString",
"(",
"data",
")",
")",
";",
"}"
] | global map output protocol
@param code
@param data | [
"global",
"map",
"output",
"protocol"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegController.java#L104-L107 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java | JSONWriter.put | public JSONWriter put(String key, Object obj)
{
data.put(key, obj);
return this;
} | java | public JSONWriter put(String key, Object obj)
{
data.put(key, obj);
return this;
} | [
"public",
"JSONWriter",
"put",
"(",
"String",
"key",
",",
"Object",
"obj",
")",
"{",
"data",
".",
"put",
"(",
"key",
",",
"obj",
")",
";",
"return",
"this",
";",
"}"
] | put a new mapping with a string
@param key
@param obj | [
"put",
"a",
"new",
"mapping",
"with",
"a",
"string"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java#L45-L49 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java | JSONWriter.put | public JSONWriter put(String key, Object[] vector)
{
data.put(key, vector2JsonString(vector));
return this;
} | java | public JSONWriter put(String key, Object[] vector)
{
data.put(key, vector2JsonString(vector));
return this;
} | [
"public",
"JSONWriter",
"put",
"(",
"String",
"key",
",",
"Object",
"[",
"]",
"vector",
")",
"{",
"data",
".",
"put",
"(",
"key",
",",
"vector2JsonString",
"(",
"vector",
")",
")",
";",
"return",
"this",
";",
"}"
] | put a new mapping with a vector
@param key
@param vector | [
"put",
"a",
"new",
"mapping",
"with",
"a",
"vector"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java#L57-L61 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java | JSONWriter.vector2JsonString | @SuppressWarnings("unchecked")
public static String vector2JsonString(Object[] vector)
{
IStringBuffer sb = new IStringBuffer();
sb.append('[');
for ( Object o : vector )
{
if ( o instanceof List<?> ) {
sb.append(list2JsonString((List<Object>)o)).append(',');
} else if (o instanceof Object[]) {
sb.append(vector2JsonString((Object[])o)).append(',');
} else if (o instanceof Map<?,?>) {
sb.append(map2JsonString((Map<String, Object>)o)).append(',');
} else if ((o instanceof Boolean)
|| (o instanceof Byte) || (o instanceof Short)
|| (o instanceof Integer) || (o instanceof Long)
|| (o instanceof Float) || (o instanceof Double)) {
sb.append(o.toString()).append(',');
} else {
String v = o.toString();
int last = v.length() - 1;
// Avoid string like "[Error] there is a problem" treat as a array
// and "{error}: there is a problem" treat as object
if ( v.length() > 1
&& ( (v.charAt(0) == '{' && v.charAt(last) == '}' )
|| (v.charAt(0) == '[' && v.charAt(last) == ']' ) )
) {
sb.append(v).append(',');
} else {
sb.append('"').append(v).append("\",");
}
}
}
if ( sb.length() > 1 ) {
sb.deleteCharAt(sb.length()-1);
}
sb.append(']');
return sb.toString();
} | java | @SuppressWarnings("unchecked")
public static String vector2JsonString(Object[] vector)
{
IStringBuffer sb = new IStringBuffer();
sb.append('[');
for ( Object o : vector )
{
if ( o instanceof List<?> ) {
sb.append(list2JsonString((List<Object>)o)).append(',');
} else if (o instanceof Object[]) {
sb.append(vector2JsonString((Object[])o)).append(',');
} else if (o instanceof Map<?,?>) {
sb.append(map2JsonString((Map<String, Object>)o)).append(',');
} else if ((o instanceof Boolean)
|| (o instanceof Byte) || (o instanceof Short)
|| (o instanceof Integer) || (o instanceof Long)
|| (o instanceof Float) || (o instanceof Double)) {
sb.append(o.toString()).append(',');
} else {
String v = o.toString();
int last = v.length() - 1;
// Avoid string like "[Error] there is a problem" treat as a array
// and "{error}: there is a problem" treat as object
if ( v.length() > 1
&& ( (v.charAt(0) == '{' && v.charAt(last) == '}' )
|| (v.charAt(0) == '[' && v.charAt(last) == ']' ) )
) {
sb.append(v).append(',');
} else {
sb.append('"').append(v).append("\",");
}
}
}
if ( sb.length() > 1 ) {
sb.deleteCharAt(sb.length()-1);
}
sb.append(']');
return sb.toString();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"String",
"vector2JsonString",
"(",
"Object",
"[",
"]",
"vector",
")",
"{",
"IStringBuffer",
"sb",
"=",
"new",
"IStringBuffer",
"(",
")",
";",
"sb",
".",
"append",
"(",
"'",
"'",
")",
... | vector to json string
@param vector
@return String | [
"vector",
"to",
"json",
"string"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java#L80-L121 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java | JSONWriter.map2JsonString | @SuppressWarnings("unchecked")
public static String map2JsonString(Map<String, Object> map)
{
IStringBuffer sb = new IStringBuffer();
sb.append('{');
for ( Map.Entry<String, Object> entry : map.entrySet() )
{
sb.append('"').append(entry.getKey().toString()).append("\": ");
Object obj = entry.getValue();
if ( obj instanceof List<?> ) {
sb.append(list2JsonString((List<Object>)obj)).append(',');
} else if (obj instanceof Object[]) {
sb.append(vector2JsonString((Object[])obj)).append(',');
} else if (obj instanceof Map<?,?>) {
sb.append(map2JsonString((Map<String, Object>)obj)).append(',');
} else if ((obj instanceof Boolean)
|| (obj instanceof Byte) || (obj instanceof Short)
|| (obj instanceof Integer) || (obj instanceof Long)
|| (obj instanceof Float) || (obj instanceof Double)) {
sb.append(obj.toString()).append(',');
} else {
String v = obj.toString();
int last = v.length() - 1;
if ( v.length() > 1
&& ( (v.charAt(0) == '{' && v.charAt(last) == '}' )
|| (v.charAt(0) == '[' && v.charAt(last) == ']' ) )
) {
sb.append(v).append(',');
} else {
sb.append('"').append(v).append("\",");
}
}
}
if ( sb.length() > 1 ) {
sb.deleteCharAt(sb.length()-1);
}
sb.append('}');
return sb.toString();
} | java | @SuppressWarnings("unchecked")
public static String map2JsonString(Map<String, Object> map)
{
IStringBuffer sb = new IStringBuffer();
sb.append('{');
for ( Map.Entry<String, Object> entry : map.entrySet() )
{
sb.append('"').append(entry.getKey().toString()).append("\": ");
Object obj = entry.getValue();
if ( obj instanceof List<?> ) {
sb.append(list2JsonString((List<Object>)obj)).append(',');
} else if (obj instanceof Object[]) {
sb.append(vector2JsonString((Object[])obj)).append(',');
} else if (obj instanceof Map<?,?>) {
sb.append(map2JsonString((Map<String, Object>)obj)).append(',');
} else if ((obj instanceof Boolean)
|| (obj instanceof Byte) || (obj instanceof Short)
|| (obj instanceof Integer) || (obj instanceof Long)
|| (obj instanceof Float) || (obj instanceof Double)) {
sb.append(obj.toString()).append(',');
} else {
String v = obj.toString();
int last = v.length() - 1;
if ( v.length() > 1
&& ( (v.charAt(0) == '{' && v.charAt(last) == '}' )
|| (v.charAt(0) == '[' && v.charAt(last) == ']' ) )
) {
sb.append(v).append(',');
} else {
sb.append('"').append(v).append("\",");
}
}
}
if ( sb.length() > 1 ) {
sb.deleteCharAt(sb.length()-1);
}
sb.append('}');
return sb.toString();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"String",
"map2JsonString",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"map",
")",
"{",
"IStringBuffer",
"sb",
"=",
"new",
"IStringBuffer",
"(",
")",
";",
"sb",
".",
"append",
"(",... | map to json string
@param map
@return String | [
"map",
"to",
"json",
"string"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/core/JSONWriter.java#L176-L217 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/json/XML.java | XML.stringToValue | public static Object stringToValue(String string) {
if ("true".equalsIgnoreCase(string)) {
return Boolean.TRUE;
}
if ("false".equalsIgnoreCase(string)) {
return Boolean.FALSE;
}
if ("null".equalsIgnoreCase(string)) {
return JSONObject.NULL;
}
// If it might be a number, try converting it, first as a Long, and then as a
// Double. If that doesn't work, return the string.
try {
char initial = string.charAt(0);
if (initial == '-' || (initial >= '0' && initial <= '9')) {
Long value = new Long(string);
if (value.toString().equals(string)) {
return value;
}
}
} catch (Exception ignore) {
try {
Double value = new Double(string);
if (value.toString().equals(string)) {
return value;
}
} catch (Exception ignoreAlso) {
}
}
return string;
} | java | public static Object stringToValue(String string) {
if ("true".equalsIgnoreCase(string)) {
return Boolean.TRUE;
}
if ("false".equalsIgnoreCase(string)) {
return Boolean.FALSE;
}
if ("null".equalsIgnoreCase(string)) {
return JSONObject.NULL;
}
// If it might be a number, try converting it, first as a Long, and then as a
// Double. If that doesn't work, return the string.
try {
char initial = string.charAt(0);
if (initial == '-' || (initial >= '0' && initial <= '9')) {
Long value = new Long(string);
if (value.toString().equals(string)) {
return value;
}
}
} catch (Exception ignore) {
try {
Double value = new Double(string);
if (value.toString().equals(string)) {
return value;
}
} catch (Exception ignoreAlso) {
}
}
return string;
} | [
"public",
"static",
"Object",
"stringToValue",
"(",
"String",
"string",
")",
"{",
"if",
"(",
"\"true\"",
".",
"equalsIgnoreCase",
"(",
"string",
")",
")",
"{",
"return",
"Boolean",
".",
"TRUE",
";",
"}",
"if",
"(",
"\"false\"",
".",
"equalsIgnoreCase",
"("... | Try to convert a string into a number, boolean, or null. If the string
can't be converted, return the string. This is much less ambitious than
JSONObject.stringToValue, especially because it does not attempt to
convert plus forms, octal forms, hex forms, or E forms lacking decimal
points.
@param string A String.
@return A simple JSON value. | [
"Try",
"to",
"convert",
"a",
"string",
"into",
"a",
"number",
"boolean",
"or",
"null",
".",
"If",
"the",
"string",
"can",
"t",
"be",
"converted",
"return",
"the",
"string",
".",
"This",
"is",
"much",
"less",
"ambitious",
"than",
"JSONObject",
".",
"strin... | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/json/XML.java#L302-L334 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitInputStream.java | BitInputStream.pad | public boolean pad(int width) throws IOException {
boolean result = true;
int gap = (int)this.nrBits % width;
if (gap < 0) {
gap += width;
}
if (gap != 0) {
int padding = width - gap;
while (padding > 0) {
if (bit()) {
result = false;
}
padding -= 1;
}
}
return result;
} | java | public boolean pad(int width) throws IOException {
boolean result = true;
int gap = (int)this.nrBits % width;
if (gap < 0) {
gap += width;
}
if (gap != 0) {
int padding = width - gap;
while (padding > 0) {
if (bit()) {
result = false;
}
padding -= 1;
}
}
return result;
} | [
"public",
"boolean",
"pad",
"(",
"int",
"width",
")",
"throws",
"IOException",
"{",
"boolean",
"result",
"=",
"true",
";",
"int",
"gap",
"=",
"(",
"int",
")",
"this",
".",
"nrBits",
"%",
"width",
";",
"if",
"(",
"gap",
"<",
"0",
")",
"{",
"gap",
... | Check that the rest of the block has been padded with zeroes.
@param width
The size of the block to pad in bits.
This will typically be 8, 16, 32, 64, 128, 256, etc.
@return true if the block was zero padded, or false if the the padding
contains any one bits.
@throws IOException | [
"Check",
"that",
"the",
"rest",
"of",
"the",
"block",
"has",
"been",
"padded",
"with",
"zeroes",
"."
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitInputStream.java#L99-L115 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitInputStream.java | BitInputStream.read | public int read(int width) throws IOException {
if (width == 0) {
return 0;
}
if (width < 0 || width > 32) {
throw new IOException("Bad read width.");
}
int result = 0;
while (width > 0) {
if (this.available == 0) {
this.unread = this.in.read();
if (this.unread < 0) {
throw new IOException("Attempt to read past end.");
}
this.available = 8;
}
int take = width;
if (take > this.available) {
take = this.available;
}
result |= ((this.unread >>> (this.available - take)) &
((1 << take) - 1)) << (width - take);
this.nrBits += take;
this.available -= take;
width -= take;
}
return result;
} | java | public int read(int width) throws IOException {
if (width == 0) {
return 0;
}
if (width < 0 || width > 32) {
throw new IOException("Bad read width.");
}
int result = 0;
while (width > 0) {
if (this.available == 0) {
this.unread = this.in.read();
if (this.unread < 0) {
throw new IOException("Attempt to read past end.");
}
this.available = 8;
}
int take = width;
if (take > this.available) {
take = this.available;
}
result |= ((this.unread >>> (this.available - take)) &
((1 << take) - 1)) << (width - take);
this.nrBits += take;
this.available -= take;
width -= take;
}
return result;
} | [
"public",
"int",
"read",
"(",
"int",
"width",
")",
"throws",
"IOException",
"{",
"if",
"(",
"width",
"==",
"0",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"width",
"<",
"0",
"||",
"width",
">",
"32",
")",
"{",
"throw",
"new",
"IOException",
"(... | Read some bits.
@param width
The number of bits to read. (0..32)
@throws IOException
@return the bits | [
"Read",
"some",
"bits",
"."
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitInputStream.java#L125-L152 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/IPushbackReader.java | IPushbackReader.read | public int read( char[] cbuf, int off, int len ) throws IOException
{
//check the buffer queue
int size = queue.size();
if ( size > 0 ) {
//TODO
//int num = size <= len ? size : len;
//System.arraycopy(src, srcPos, dest, destPos, length)
throw new IOException("Method not implemented yet");
}
return reader.read(cbuf, off, len);
} | java | public int read( char[] cbuf, int off, int len ) throws IOException
{
//check the buffer queue
int size = queue.size();
if ( size > 0 ) {
//TODO
//int num = size <= len ? size : len;
//System.arraycopy(src, srcPos, dest, destPos, length)
throw new IOException("Method not implemented yet");
}
return reader.read(cbuf, off, len);
} | [
"public",
"int",
"read",
"(",
"char",
"[",
"]",
"cbuf",
",",
"int",
"off",
",",
"int",
"len",
")",
"throws",
"IOException",
"{",
"//check the buffer queue",
"int",
"size",
"=",
"queue",
".",
"size",
"(",
")",
";",
"if",
"(",
"size",
">",
"0",
")",
... | read the specified block from the stream
@see #read()
@return int
@throws IOException | [
"read",
"the",
"specified",
"block",
"from",
"the",
"stream"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/IPushbackReader.java#L51-L63 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/IPushbackReader.java | IPushbackReader.unread | public void unread( char[] cbuf, int off, int len )
{
for ( int i = 0; i < len; i++ ) {
queue.enQueue(cbuf[off+i]);
}
} | java | public void unread( char[] cbuf, int off, int len )
{
for ( int i = 0; i < len; i++ ) {
queue.enQueue(cbuf[off+i]);
}
} | [
"public",
"void",
"unread",
"(",
"char",
"[",
"]",
"cbuf",
",",
"int",
"off",
",",
"int",
"len",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"queue",
".",
"enQueue",
"(",
"cbuf",
"[",
"off",
"... | unread a block from a char array to the stream
@see #unread(int) | [
"unread",
"a",
"block",
"from",
"a",
"char",
"array",
"to",
"the",
"stream"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/IPushbackReader.java#L89-L94 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.load | public void load( File file )
throws NumberFormatException, FileNotFoundException, IOException
{
loadWords(config, this, file, synBuffer);
} | java | public void load( File file )
throws NumberFormatException, FileNotFoundException, IOException
{
loadWords(config, this, file, synBuffer);
} | [
"public",
"void",
"load",
"(",
"File",
"file",
")",
"throws",
"NumberFormatException",
",",
"FileNotFoundException",
",",
"IOException",
"{",
"loadWords",
"(",
"config",
",",
"this",
",",
"file",
",",
"synBuffer",
")",
";",
"}"
] | load all the words from a specified lexicon file
@param file
@throws IOException
@throws FileNotFoundException
@throws NumberFormatException | [
"load",
"all",
"the",
"words",
"from",
"a",
"specified",
"lexicon",
"file"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L73-L77 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.loadDirectory | public void loadDirectory( String lexDir ) throws IOException
{
File path = new File(lexDir);
if ( ! path.exists() ) {
throw new IOException("Lexicon directory ["+lexDir+"] does'n exists.");
}
/*
* load all the lexicon file under the lexicon path
* that start with "lex-" and end with ".lex".
*/
File[] files = path.listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String name) {
return (name.startsWith("lex-") && name.endsWith(".lex"));
}
});
for ( File file : files ) {
load(file);
}
} | java | public void loadDirectory( String lexDir ) throws IOException
{
File path = new File(lexDir);
if ( ! path.exists() ) {
throw new IOException("Lexicon directory ["+lexDir+"] does'n exists.");
}
/*
* load all the lexicon file under the lexicon path
* that start with "lex-" and end with ".lex".
*/
File[] files = path.listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String name) {
return (name.startsWith("lex-") && name.endsWith(".lex"));
}
});
for ( File file : files ) {
load(file);
}
} | [
"public",
"void",
"loadDirectory",
"(",
"String",
"lexDir",
")",
"throws",
"IOException",
"{",
"File",
"path",
"=",
"new",
"File",
"(",
"lexDir",
")",
";",
"if",
"(",
"!",
"path",
".",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
... | load the all the words from all the files under a specified lexicon directory
@param lexDir
@throws IOException | [
"load",
"the",
"all",
"the",
"words",
"from",
"all",
"the",
"files",
"under",
"a",
"specified",
"lexicon",
"directory"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L111-L132 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.loadClassPath | public void loadClassPath() throws IOException
{
Class<?> dClass = this.getClass();
CodeSource codeSrc = this.getClass().getProtectionDomain().getCodeSource();
if ( codeSrc == null ) {
return;
}
String codePath = codeSrc.getLocation().getPath();
if ( codePath.toLowerCase().endsWith(".jar") ) {
ZipInputStream zip = new ZipInputStream(codeSrc.getLocation().openStream());
while ( true ) {
ZipEntry e = zip.getNextEntry();
if ( e == null ) {
break;
}
String fileName = e.getName();
if ( fileName.endsWith(".lex")
&& fileName.startsWith("lexicon/lex-") ) {
load(dClass.getResourceAsStream("/"+fileName));
}
}
} else {
//now, the classpath is an IDE directory
// like eclipse ./bin or maven ./target/classes/
loadDirectory(codePath+"/lexicon");
}
} | java | public void loadClassPath() throws IOException
{
Class<?> dClass = this.getClass();
CodeSource codeSrc = this.getClass().getProtectionDomain().getCodeSource();
if ( codeSrc == null ) {
return;
}
String codePath = codeSrc.getLocation().getPath();
if ( codePath.toLowerCase().endsWith(".jar") ) {
ZipInputStream zip = new ZipInputStream(codeSrc.getLocation().openStream());
while ( true ) {
ZipEntry e = zip.getNextEntry();
if ( e == null ) {
break;
}
String fileName = e.getName();
if ( fileName.endsWith(".lex")
&& fileName.startsWith("lexicon/lex-") ) {
load(dClass.getResourceAsStream("/"+fileName));
}
}
} else {
//now, the classpath is an IDE directory
// like eclipse ./bin or maven ./target/classes/
loadDirectory(codePath+"/lexicon");
}
} | [
"public",
"void",
"loadClassPath",
"(",
")",
"throws",
"IOException",
"{",
"Class",
"<",
"?",
">",
"dClass",
"=",
"this",
".",
"getClass",
"(",
")",
";",
"CodeSource",
"codeSrc",
"=",
"this",
".",
"getClass",
"(",
")",
".",
"getProtectionDomain",
"(",
")... | load all the words from all the files under the specified class path.
added at 2016/07/12:
only in the jar file could the ZipInputStream available
add IDE classpath supported here
@since 1.9.9
@throws IOException | [
"load",
"all",
"the",
"words",
"from",
"all",
"the",
"files",
"under",
"the",
"specified",
"class",
"path",
"."
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L144-L172 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.startAutoload | public void startAutoload()
{
if ( autoloadThread != null
|| config.getLexiconPath() == null ) {
return;
}
//create and start the lexicon auto load thread
autoloadThread = new Thread(new Runnable() {
@Override
public void run() {
String[] paths = config.getLexiconPath();
AutoLoadFile[] files = new AutoLoadFile[paths.length];
for ( int i = 0; i < files.length; i++ ) {
files[i] = new AutoLoadFile(paths[i] + "/" + AL_TODO_FILE);
files[i].setLastUpdateTime(files[i].getFile().lastModified());
}
while ( true ) {
//sleep for some time (seconds)
try {
Thread.sleep(config.getPollTime() * 1000);
} catch (InterruptedException e) {break;}
//check the update of all the reload todo files
File f = null;
AutoLoadFile af = null;
for ( int i = 0; i < files.length; i++ ) {
af = files[i];
f = files[i].getFile();
if ( ! f.exists() ) continue;
if ( f.lastModified() <= af.getLastUpdateTime() ) {
continue;
}
//load words form the lexicon files
try {
BufferedReader reader = new BufferedReader(new FileReader(f));
String line = null;
while ( ( line = reader.readLine() ) != null ) {
line = line.trim();
if ( line.indexOf('#') != -1 ) continue;
if ( "".equals(line) ) continue;
load(paths[i] + "/" + line);
}
reader.close();
FileWriter fw = new FileWriter(f);
fw.write("");
fw.close();
//update the last update time
//@Note: some file system may close the in-time last update time update
// in that case, this won't work normally.
//but, it will still work!!!
af.setLastUpdateTime(f.lastModified());
//System.out.println("newly added words loaded for path " + f.getParent());
} catch (IOException e) {
break;
}
}
//flush the synonyms buffer
resetSynonymsNet();
}
}
});
autoloadThread.setDaemon(true);
autoloadThread.start();
} | java | public void startAutoload()
{
if ( autoloadThread != null
|| config.getLexiconPath() == null ) {
return;
}
//create and start the lexicon auto load thread
autoloadThread = new Thread(new Runnable() {
@Override
public void run() {
String[] paths = config.getLexiconPath();
AutoLoadFile[] files = new AutoLoadFile[paths.length];
for ( int i = 0; i < files.length; i++ ) {
files[i] = new AutoLoadFile(paths[i] + "/" + AL_TODO_FILE);
files[i].setLastUpdateTime(files[i].getFile().lastModified());
}
while ( true ) {
//sleep for some time (seconds)
try {
Thread.sleep(config.getPollTime() * 1000);
} catch (InterruptedException e) {break;}
//check the update of all the reload todo files
File f = null;
AutoLoadFile af = null;
for ( int i = 0; i < files.length; i++ ) {
af = files[i];
f = files[i].getFile();
if ( ! f.exists() ) continue;
if ( f.lastModified() <= af.getLastUpdateTime() ) {
continue;
}
//load words form the lexicon files
try {
BufferedReader reader = new BufferedReader(new FileReader(f));
String line = null;
while ( ( line = reader.readLine() ) != null ) {
line = line.trim();
if ( line.indexOf('#') != -1 ) continue;
if ( "".equals(line) ) continue;
load(paths[i] + "/" + line);
}
reader.close();
FileWriter fw = new FileWriter(f);
fw.write("");
fw.close();
//update the last update time
//@Note: some file system may close the in-time last update time update
// in that case, this won't work normally.
//but, it will still work!!!
af.setLastUpdateTime(f.lastModified());
//System.out.println("newly added words loaded for path " + f.getParent());
} catch (IOException e) {
break;
}
}
//flush the synonyms buffer
resetSynonymsNet();
}
}
});
autoloadThread.setDaemon(true);
autoloadThread.start();
} | [
"public",
"void",
"startAutoload",
"(",
")",
"{",
"if",
"(",
"autoloadThread",
"!=",
"null",
"||",
"config",
".",
"getLexiconPath",
"(",
")",
"==",
"null",
")",
"{",
"return",
";",
"}",
"//create and start the lexicon auto load thread",
"autoloadThread",
"=",
"n... | start the lexicon autoload thread | [
"start",
"the",
"lexicon",
"autoload",
"thread"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L251-L326 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.getIndex | public static int getIndex( String key )
{
if ( key == null ) {
return -1;
}
key = key.toUpperCase();
if ( key.startsWith("CJK_WORD") ) {
return ILexicon.CJK_WORD;
} else if ( key.startsWith("CJK_CHAR") ) {
return ILexicon.CJK_CHAR;
} else if ( key.startsWith("CJK_UNIT") ) {
return ILexicon.CJK_UNIT;
} else if ( key.startsWith("CN_LNAME_ADORN") ) {
return ILexicon.CN_LNAME_ADORN;
} else if ( key.startsWith("CN_LNAME") ) {
return ILexicon.CN_LNAME;
} else if ( key.startsWith("CN_SNAME") ) {
return ILexicon.CN_SNAME;
} else if ( key.startsWith("CN_DNAME_1") ) {
return ILexicon.CN_DNAME_1;
} else if ( key.startsWith("CN_DNAME_2") ) {
return ILexicon.CN_DNAME_2;
} else if ( key.startsWith("STOP_WORD") ) {
return ILexicon.STOP_WORD;
} else if ( key.startsWith("DOMAIN_SUFFIX") ) {
return ILexicon.DOMAIN_SUFFIX;
} else if ( key.startsWith("NUMBER_UNIT") ) {
return ILexicon.NUMBER_UNIT;
} else if ( key.startsWith("CJK_SYN") ) {
return ILexicon.CJK_SYN;
}
return ILexicon.CJK_WORD;
} | java | public static int getIndex( String key )
{
if ( key == null ) {
return -1;
}
key = key.toUpperCase();
if ( key.startsWith("CJK_WORD") ) {
return ILexicon.CJK_WORD;
} else if ( key.startsWith("CJK_CHAR") ) {
return ILexicon.CJK_CHAR;
} else if ( key.startsWith("CJK_UNIT") ) {
return ILexicon.CJK_UNIT;
} else if ( key.startsWith("CN_LNAME_ADORN") ) {
return ILexicon.CN_LNAME_ADORN;
} else if ( key.startsWith("CN_LNAME") ) {
return ILexicon.CN_LNAME;
} else if ( key.startsWith("CN_SNAME") ) {
return ILexicon.CN_SNAME;
} else if ( key.startsWith("CN_DNAME_1") ) {
return ILexicon.CN_DNAME_1;
} else if ( key.startsWith("CN_DNAME_2") ) {
return ILexicon.CN_DNAME_2;
} else if ( key.startsWith("STOP_WORD") ) {
return ILexicon.STOP_WORD;
} else if ( key.startsWith("DOMAIN_SUFFIX") ) {
return ILexicon.DOMAIN_SUFFIX;
} else if ( key.startsWith("NUMBER_UNIT") ) {
return ILexicon.NUMBER_UNIT;
} else if ( key.startsWith("CJK_SYN") ) {
return ILexicon.CJK_SYN;
}
return ILexicon.CJK_WORD;
} | [
"public",
"static",
"int",
"getIndex",
"(",
"String",
"key",
")",
"{",
"if",
"(",
"key",
"==",
"null",
")",
"{",
"return",
"-",
"1",
";",
"}",
"key",
"=",
"key",
".",
"toUpperCase",
"(",
")",
";",
"if",
"(",
"key",
".",
"startsWith",
"(",
"\"CJK_... | get the key's type index located in ILexicon interface
@param key
@return int | [
"get",
"the",
"key",
"s",
"type",
"index",
"located",
"in",
"ILexicon",
"interface"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L434-L468 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java | ADictionary.loadWords | public static void loadWords(
JcsegTaskConfig config, ADictionary dic, File file, List<String[]> buffer )
throws NumberFormatException, FileNotFoundException, IOException
{
loadWords(config, dic, new FileInputStream(file), buffer);
} | java | public static void loadWords(
JcsegTaskConfig config, ADictionary dic, File file, List<String[]> buffer )
throws NumberFormatException, FileNotFoundException, IOException
{
loadWords(config, dic, new FileInputStream(file), buffer);
} | [
"public",
"static",
"void",
"loadWords",
"(",
"JcsegTaskConfig",
"config",
",",
"ADictionary",
"dic",
",",
"File",
"file",
",",
"List",
"<",
"String",
"[",
"]",
">",
"buffer",
")",
"throws",
"NumberFormatException",
",",
"FileNotFoundException",
",",
"IOExceptio... | load all the words in the specified lexicon file into the dictionary
@param config
@param dic
@param file
@param buffer
@throws IOException
@throws FileNotFoundException
@throws NumberFormatException | [
"load",
"all",
"the",
"words",
"in",
"the",
"specified",
"lexicon",
"file",
"into",
"the",
"dictionary"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/ADictionary.java#L491-L496 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/SegKit.java | SegKit.appendSynonyms | public final static void appendSynonyms(LinkedList<IWord> wordPool, IWord wd)
{
List<IWord> synList = wd.getSyn().getList();
synchronized (synList) {
for ( int j = 0; j < synList.size(); j++ ) {
IWord curWord = synList.get(j);
if ( curWord.getValue()
.equals(wd.getValue()) ) {
continue;
}
IWord synWord = synList.get(j).clone();
synWord.setPosition(wd.getPosition());
wordPool.add(synWord);
}
}
} | java | public final static void appendSynonyms(LinkedList<IWord> wordPool, IWord wd)
{
List<IWord> synList = wd.getSyn().getList();
synchronized (synList) {
for ( int j = 0; j < synList.size(); j++ ) {
IWord curWord = synList.get(j);
if ( curWord.getValue()
.equals(wd.getValue()) ) {
continue;
}
IWord synWord = synList.get(j).clone();
synWord.setPosition(wd.getPosition());
wordPool.add(synWord);
}
}
} | [
"public",
"final",
"static",
"void",
"appendSynonyms",
"(",
"LinkedList",
"<",
"IWord",
">",
"wordPool",
",",
"IWord",
"wd",
")",
"{",
"List",
"<",
"IWord",
">",
"synList",
"=",
"wd",
".",
"getSyn",
"(",
")",
".",
"getList",
"(",
")",
";",
"synchronize... | quick interface to do the synonyms append word
You got check if the specified has any synonyms first
@param wordPool
@param wd | [
"quick",
"interface",
"to",
"do",
"the",
"synonyms",
"append",
"word",
"You",
"got",
"check",
"if",
"the",
"specified",
"has",
"any",
"synonyms",
"first"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/SegKit.java#L20-L36 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java | LRUCache.get | public T get( E key )
{
Entry<E, T> entry = null;
synchronized(this) {
entry = map.get(key);
if (map.get(key) == null)
return null;
entry.prev.next = entry.next;
entry.next.prev = entry.prev;
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
}
return entry.value;
} | java | public T get( E key )
{
Entry<E, T> entry = null;
synchronized(this) {
entry = map.get(key);
if (map.get(key) == null)
return null;
entry.prev.next = entry.next;
entry.next.prev = entry.prev;
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
}
return entry.value;
} | [
"public",
"T",
"get",
"(",
"E",
"key",
")",
"{",
"Entry",
"<",
"E",
",",
"T",
">",
"entry",
"=",
"null",
";",
"synchronized",
"(",
"this",
")",
"{",
"entry",
"=",
"map",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"map",
".",
"get",
"(",
"... | get a element from map with specified key
@param key
@return value | [
"get",
"a",
"element",
"from",
"map",
"with",
"specified",
"key"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java#L67-L85 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java | LRUCache.set | public void set(E key, T value)
{
Entry<E, T> entry = new Entry<E, T>(key, value, null, null);
synchronized(this) {
if (map.get(key) == null) {
if (this.length >= this.capacity)
this.removeLeastUsedElements();
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
this.length++;
map.put(key, entry);
} else {
entry = map.get(key);
entry.value = value;
entry.prev.next = entry.next;
entry.next.prev = entry.prev;
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
}
}
} | java | public void set(E key, T value)
{
Entry<E, T> entry = new Entry<E, T>(key, value, null, null);
synchronized(this) {
if (map.get(key) == null) {
if (this.length >= this.capacity)
this.removeLeastUsedElements();
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
this.length++;
map.put(key, entry);
} else {
entry = map.get(key);
entry.value = value;
entry.prev.next = entry.next;
entry.next.prev = entry.prev;
entry.prev = this.head;
entry.next = this.head.next;
this.head.next.prev = entry;
this.head.next = entry;
}
}
} | [
"public",
"void",
"set",
"(",
"E",
"key",
",",
"T",
"value",
")",
"{",
"Entry",
"<",
"E",
",",
"T",
">",
"entry",
"=",
"new",
"Entry",
"<",
"E",
",",
"T",
">",
"(",
"key",
",",
"value",
",",
"null",
",",
"null",
")",
";",
"synchronized",
"(",... | set a element to list
@param key
@param value | [
"set",
"a",
"element",
"to",
"list"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java#L93-L124 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java | LRUCache.remove | public synchronized void remove(E key)
{
Entry<E, T> entry = map.get(key);
this.tail.prev = entry.prev;
entry.prev.next = this.tail;
map.remove(entry.key);
this.length--;
} | java | public synchronized void remove(E key)
{
Entry<E, T> entry = map.get(key);
this.tail.prev = entry.prev;
entry.prev.next = this.tail;
map.remove(entry.key);
this.length--;
} | [
"public",
"synchronized",
"void",
"remove",
"(",
"E",
"key",
")",
"{",
"Entry",
"<",
"E",
",",
"T",
">",
"entry",
"=",
"map",
".",
"get",
"(",
"key",
")",
";",
"this",
".",
"tail",
".",
"prev",
"=",
"entry",
".",
"prev",
";",
"entry",
".",
"pre... | remove a element from list
@param key | [
"remove",
"a",
"element",
"from",
"list"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java#L132-L139 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java | LRUCache.removeLeastUsedElements | public synchronized void removeLeastUsedElements()
{
int rows = this.removePercent / 100 * this.length;
rows = rows == 0 ? 1 : rows;
while(rows > 0 && this.length > 0) {
// remove the last element
Entry<E, T> entry = this.tail.prev;
this.tail.prev = entry.prev;
entry.prev.next = this.tail;
map.remove(entry.key);
this.length--;
rows--;
}
} | java | public synchronized void removeLeastUsedElements()
{
int rows = this.removePercent / 100 * this.length;
rows = rows == 0 ? 1 : rows;
while(rows > 0 && this.length > 0) {
// remove the last element
Entry<E, T> entry = this.tail.prev;
this.tail.prev = entry.prev;
entry.prev.next = this.tail;
map.remove(entry.key);
this.length--;
rows--;
}
} | [
"public",
"synchronized",
"void",
"removeLeastUsedElements",
"(",
")",
"{",
"int",
"rows",
"=",
"this",
".",
"removePercent",
"/",
"100",
"*",
"this",
".",
"length",
";",
"rows",
"=",
"rows",
"==",
"0",
"?",
"1",
":",
"rows",
";",
"while",
"(",
"rows",... | remove least used elements | [
"remove",
"least",
"used",
"elements"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java#L142-L157 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java | LRUCache.printList | public synchronized void printList(){
Entry<E, T> entry = this.head.next;
System.out.println("\n|----- key list----|");
while( entry != this.tail)
{
System.out.println(" -> " + entry.key );
entry = entry.next;
}
System.out.println("|------- end --------|\n");
} | java | public synchronized void printList(){
Entry<E, T> entry = this.head.next;
System.out.println("\n|----- key list----|");
while( entry != this.tail)
{
System.out.println(" -> " + entry.key );
entry = entry.next;
}
System.out.println("|------- end --------|\n");
} | [
"public",
"synchronized",
"void",
"printList",
"(",
")",
"{",
"Entry",
"<",
"E",
",",
"T",
">",
"entry",
"=",
"this",
".",
"head",
".",
"next",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"\\n|----- key list----|\"",
")",
";",
"while",
"(",
"entr... | print the list
NOTE: for test only | [
"print",
"the",
"list"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/util/LRUCache.java#L173-L183 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitOutputStream.java | BitOutputStream.write | public void write(int bits, int width) throws IOException {
if (bits == 0 && width == 0) {
return;
}
if (width <= 0 || width > 32) {
throw new IOException("Bad write width.");
}
while (width > 0) {
int actual = width;
if (actual > this.vacant) {
actual = this.vacant;
}
this.unwritten |= ((bits >>> (width - actual)) &
((1 << actual) - 1)) << (this.vacant - actual);
width -= actual;
nrBits += actual;
this.vacant -= actual;
if (this.vacant == 0) {
this.out.write(this.unwritten);
this.unwritten = 0;
this.vacant = 8;
}
}
} | java | public void write(int bits, int width) throws IOException {
if (bits == 0 && width == 0) {
return;
}
if (width <= 0 || width > 32) {
throw new IOException("Bad write width.");
}
while (width > 0) {
int actual = width;
if (actual > this.vacant) {
actual = this.vacant;
}
this.unwritten |= ((bits >>> (width - actual)) &
((1 << actual) - 1)) << (this.vacant - actual);
width -= actual;
nrBits += actual;
this.vacant -= actual;
if (this.vacant == 0) {
this.out.write(this.unwritten);
this.unwritten = 0;
this.vacant = 8;
}
}
} | [
"public",
"void",
"write",
"(",
"int",
"bits",
",",
"int",
"width",
")",
"throws",
"IOException",
"{",
"if",
"(",
"bits",
"==",
"0",
"&&",
"width",
"==",
"0",
")",
"{",
"return",
";",
"}",
"if",
"(",
"width",
"<=",
"0",
"||",
"width",
">",
"32",
... | Write some bits. Up to 32 bits can be written at a time.
@param bits
The bits to be written.
@param width
The number of bits to write. (0..32)
@throws IOException | [
"Write",
"some",
"bits",
".",
"Up",
"to",
"32",
"bits",
"can",
"be",
"written",
"at",
"a",
"time",
"."
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/json/zip/BitOutputStream.java#L120-L143 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/Word.java | Word.__toString | public String __toString()
{
StringBuilder sb = new StringBuilder();
sb.append(value);
sb.append('/');
//append the cx
if ( partspeech != null ) {
for ( int j = 0; j < partspeech.length; j++ ) {
if ( j == 0 ) {
sb.append(partspeech[j]);
} else {
sb.append(',');
sb.append(partspeech[j]);
}
}
} else {
sb.append("null");
}
sb.append('/');
sb.append(pinyin);
sb.append('/');
if ( syn != null ) {
List<IWord> synsList = syn.getList();
synchronized ( synsList ) {
for ( int i = 0; i < synsList.size(); i++ ) {
if ( i == 0 ) {
sb.append(synsList.get(i));
} else {
sb.append(',');
sb.append(synsList.get(i));
}
}
}
} else {
sb.append("null");
}
if ( value.length() == 1 ) {
sb.append('/');
sb.append(fre);
}
if ( entity != null ) {
sb.append('/');
sb.append(ArrayUtil.implode("|", entity));
}
if ( parameter != null ) {
sb.append('/');
sb.append(parameter);
}
return sb.toString();
} | java | public String __toString()
{
StringBuilder sb = new StringBuilder();
sb.append(value);
sb.append('/');
//append the cx
if ( partspeech != null ) {
for ( int j = 0; j < partspeech.length; j++ ) {
if ( j == 0 ) {
sb.append(partspeech[j]);
} else {
sb.append(',');
sb.append(partspeech[j]);
}
}
} else {
sb.append("null");
}
sb.append('/');
sb.append(pinyin);
sb.append('/');
if ( syn != null ) {
List<IWord> synsList = syn.getList();
synchronized ( synsList ) {
for ( int i = 0; i < synsList.size(); i++ ) {
if ( i == 0 ) {
sb.append(synsList.get(i));
} else {
sb.append(',');
sb.append(synsList.get(i));
}
}
}
} else {
sb.append("null");
}
if ( value.length() == 1 ) {
sb.append('/');
sb.append(fre);
}
if ( entity != null ) {
sb.append('/');
sb.append(ArrayUtil.implode("|", entity));
}
if ( parameter != null ) {
sb.append('/');
sb.append(parameter);
}
return sb.toString();
} | [
"public",
"String",
"__toString",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"sb",
".",
"append",
"(",
"value",
")",
";",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"//append the cx",
"if",
"(",
"partspeech",
... | for debug only | [
"for",
"debug",
"only"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/Word.java#L323-L378 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.insertionSort | public static <T extends Comparable<? super T>> void insertionSort( T[] arr )
{
int j;
for ( int i = 1; i < arr.length; i++ ) {
T tmp = arr[i];
for ( j = i; j > 0 && tmp.compareTo(arr[j-1]) < 0; j--) {
arr[j] = arr[j-1];
}
if ( j < i ) arr[j] = tmp;
}
} | java | public static <T extends Comparable<? super T>> void insertionSort( T[] arr )
{
int j;
for ( int i = 1; i < arr.length; i++ ) {
T tmp = arr[i];
for ( j = i; j > 0 && tmp.compareTo(arr[j-1]) < 0; j--) {
arr[j] = arr[j-1];
}
if ( j < i ) arr[j] = tmp;
}
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"insertionSort",
"(",
"T",
"[",
"]",
"arr",
")",
"{",
"int",
"j",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"arr",
".",
"length",
";",
... | insert sort method
@param arr an array of a comparable items | [
"insert",
"sort",
"method"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L46-L57 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.shellSort | public static <T extends Comparable<? super T>> void shellSort( T[] arr )
{
int j, k = 0, gap;
for ( ; GAPS[k] < arr.length; k++ ) ;
while ( k-- > 0 ) {
gap = GAPS[k];
for ( int i = gap; i < arr.length; i++ ) {
T tmp = arr[ i ];
for ( j = i;
j >= gap && tmp.compareTo( arr[ j - gap ] ) < 0; j -= gap ) {
arr[ j ] = arr[ j - gap ];
}
if ( j < i ) arr[ j ] = tmp;
}
}
} | java | public static <T extends Comparable<? super T>> void shellSort( T[] arr )
{
int j, k = 0, gap;
for ( ; GAPS[k] < arr.length; k++ ) ;
while ( k-- > 0 ) {
gap = GAPS[k];
for ( int i = gap; i < arr.length; i++ ) {
T tmp = arr[ i ];
for ( j = i;
j >= gap && tmp.compareTo( arr[ j - gap ] ) < 0; j -= gap ) {
arr[ j ] = arr[ j - gap ];
}
if ( j < i ) arr[ j ] = tmp;
}
}
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"shellSort",
"(",
"T",
"[",
"]",
"arr",
")",
"{",
"int",
"j",
",",
"k",
"=",
"0",
",",
"gap",
";",
"for",
"(",
";",
"GAPS",
"[",
"k",
"]",
"<",
... | shell sort algorithm
@param arr an array of Comparable items | [
"shell",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L64-L80 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.mergeSort | @SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> void mergeSort( T[] arr )
{
/*if ( arr.length < 15 ) {
insertionSort( arr );
return;
}*/
T[] tmpArr = (T[]) new Comparable[arr.length];
mergeSort(arr, tmpArr, 0, arr.length - 1);
} | java | @SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> void mergeSort( T[] arr )
{
/*if ( arr.length < 15 ) {
insertionSort( arr );
return;
}*/
T[] tmpArr = (T[]) new Comparable[arr.length];
mergeSort(arr, tmpArr, 0, arr.length - 1);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"mergeSort",
"(",
"T",
"[",
"]",
"arr",
")",
"{",
"/*if ( arr.length < 15 ) {\n insertionSort( arr );\n ... | merge sort algorithm
@param arr an array of Comparable item | [
"merge",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L90-L101 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.mergeSort | private static <T extends Comparable<? super T>>
void mergeSort( T[] arr, T[] tmpArr, int left, int right )
{
//recursive way
if ( left < right ) {
int center = ( left + right ) / 2;
mergeSort(arr, tmpArr, left, center);
mergeSort(arr, tmpArr, center + 1, right);
merge(arr, tmpArr, left, center + 1, right);
}
//loop instead
/* int len = 2, pos;
int rpos, offset, cut;
while ( len <= right ) {
pos = 0;
offset = len / 2;
while ( pos + len <= right ) {
rpos = pos + offset;
merge( arr, tmpArr, pos, rpos, rpos + offset - 1 );
pos += len;
}
//merge the rest
cut = pos + offset;
if ( cut <= right )
merge( arr, tmpArr, pos, cut, right );
len *= 2;
}
merge( arr, tmpArr, 0, len / 2, right );*/
} | java | private static <T extends Comparable<? super T>>
void mergeSort( T[] arr, T[] tmpArr, int left, int right )
{
//recursive way
if ( left < right ) {
int center = ( left + right ) / 2;
mergeSort(arr, tmpArr, left, center);
mergeSort(arr, tmpArr, center + 1, right);
merge(arr, tmpArr, left, center + 1, right);
}
//loop instead
/* int len = 2, pos;
int rpos, offset, cut;
while ( len <= right ) {
pos = 0;
offset = len / 2;
while ( pos + len <= right ) {
rpos = pos + offset;
merge( arr, tmpArr, pos, rpos, rpos + offset - 1 );
pos += len;
}
//merge the rest
cut = pos + offset;
if ( cut <= right )
merge( arr, tmpArr, pos, cut, right );
len *= 2;
}
merge( arr, tmpArr, 0, len / 2, right );*/
} | [
"private",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"mergeSort",
"(",
"T",
"[",
"]",
"arr",
",",
"T",
"[",
"]",
"tmpArr",
",",
"int",
"left",
",",
"int",
"right",
")",
"{",
"//recursive way",
"if",
"(",... | internal method to make a recursive call
@param arr an array of Comparable items
@param tmpArr temp array to placed the merged result
@param left left-most index of the subarray
@param right right-most index of the subarray | [
"internal",
"method",
"to",
"make",
"a",
"recursive",
"call"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L111-L142 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.merge | private static <T extends Comparable<? super T>>
void merge( T[] arr, T[] tmpArr, int lPos, int rPos, int rEnd )
{
int lEnd = rPos - 1;
int tPos = lPos;
int leftTmp = lPos;
while ( lPos <= lEnd && rPos <= rEnd ) {
if ( arr[lPos].compareTo( arr[rPos] ) <= 0 ) {
tmpArr[ tPos++ ] = arr[ lPos++ ];
} else {
tmpArr[ tPos++ ] = arr[ rPos++ ];
}
}
//copy the rest element of the left half subarray.
while ( lPos <= lEnd ) {
tmpArr[ tPos++ ] = arr[ lPos++ ];
}
//copy the rest elements of the right half subarray. (only one loop will be execute)
while ( rPos <= rEnd ) {
tmpArr[ tPos++ ] = arr[ rPos++ ];
}
//copy the tmpArr back cause we need to change the arr array items.
for ( ; rEnd >= leftTmp; rEnd-- ) {
arr[rEnd] = tmpArr[rEnd];
}
} | java | private static <T extends Comparable<? super T>>
void merge( T[] arr, T[] tmpArr, int lPos, int rPos, int rEnd )
{
int lEnd = rPos - 1;
int tPos = lPos;
int leftTmp = lPos;
while ( lPos <= lEnd && rPos <= rEnd ) {
if ( arr[lPos].compareTo( arr[rPos] ) <= 0 ) {
tmpArr[ tPos++ ] = arr[ lPos++ ];
} else {
tmpArr[ tPos++ ] = arr[ rPos++ ];
}
}
//copy the rest element of the left half subarray.
while ( lPos <= lEnd ) {
tmpArr[ tPos++ ] = arr[ lPos++ ];
}
//copy the rest elements of the right half subarray. (only one loop will be execute)
while ( rPos <= rEnd ) {
tmpArr[ tPos++ ] = arr[ rPos++ ];
}
//copy the tmpArr back cause we need to change the arr array items.
for ( ; rEnd >= leftTmp; rEnd-- ) {
arr[rEnd] = tmpArr[rEnd];
}
} | [
"private",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"merge",
"(",
"T",
"[",
"]",
"arr",
",",
"T",
"[",
"]",
"tmpArr",
",",
"int",
"lPos",
",",
"int",
"rPos",
",",
"int",
"rEnd",
")",
"{",
"int",
"lE... | internal method to merge the sorted halves of a subarray
@param arr an array of Comparable items
@param tmpArr temp array to placed the merged result
@param leftPos left-most index of the subarray
@param rightPos right start index of the subarray
@param endPos right-most index of the subarray | [
"internal",
"method",
"to",
"merge",
"the",
"sorted",
"halves",
"of",
"a",
"subarray"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L153-L182 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.swapReferences | private static <T> void swapReferences( T[] arr, int idx1, int idx2 )
{
T tmp = arr[idx1];
arr[idx1] = arr[idx2];
arr[idx2] = tmp;
} | java | private static <T> void swapReferences( T[] arr, int idx1, int idx2 )
{
T tmp = arr[idx1];
arr[idx1] = arr[idx2];
arr[idx2] = tmp;
} | [
"private",
"static",
"<",
"T",
">",
"void",
"swapReferences",
"(",
"T",
"[",
"]",
"arr",
",",
"int",
"idx1",
",",
"int",
"idx2",
")",
"{",
"T",
"tmp",
"=",
"arr",
"[",
"idx1",
"]",
";",
"arr",
"[",
"idx1",
"]",
"=",
"arr",
"[",
"idx2",
"]",
"... | method to swap elements in an array
@param arr an array of Objects
@param idx1 the index of the first element
@param idx2 the index of the second element | [
"method",
"to",
"swap",
"elements",
"in",
"an",
"array"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L194-L199 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.quicksort | public static <T extends Comparable<? super T>> void quicksort( T[] arr )
{
quicksort( arr, 0, arr.length - 1 );
} | java | public static <T extends Comparable<? super T>> void quicksort( T[] arr )
{
quicksort( arr, 0, arr.length - 1 );
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"quicksort",
"(",
"T",
"[",
"]",
"arr",
")",
"{",
"quicksort",
"(",
"arr",
",",
"0",
",",
"arr",
".",
"length",
"-",
"1",
")",
";",
"}"
] | quick sort algorithm
@param arr an array of Comparable items | [
"quick",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L207-L210 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.insertionSort | public static <T extends Comparable<? super T>>
void insertionSort( T[] arr, int start, int end )
{
int i;
for ( int j = start + 1; j <= end; j++ ) {
T tmp = arr[j];
for ( i = j; i > start && tmp.compareTo( arr[i - 1] ) < 0; i-- ) {
arr[ i ] = arr[ i - 1 ];
}
if ( i < j ) arr[ i ] = tmp;
}
} | java | public static <T extends Comparable<? super T>>
void insertionSort( T[] arr, int start, int end )
{
int i;
for ( int j = start + 1; j <= end; j++ ) {
T tmp = arr[j];
for ( i = j; i > start && tmp.compareTo( arr[i - 1] ) < 0; i-- ) {
arr[ i ] = arr[ i - 1 ];
}
if ( i < j ) arr[ i ] = tmp;
}
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"insertionSort",
"(",
"T",
"[",
"]",
"arr",
",",
"int",
"start",
",",
"int",
"end",
")",
"{",
"int",
"i",
";",
"for",
"(",
"int",
"j",
"=",
"start",
... | method to sort an subarray from start to end with insertion sort algorithm
@param arr an array of Comparable items
@param start the begining position
@param end the end position | [
"method",
"to",
"sort",
"an",
"subarray",
"from",
"start",
"to",
"end",
"with",
"insertion",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L246-L257 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.quicksort | private static <T extends Comparable<? super T>>
void quicksort( T[] arr, int left, int right )
{
if ( left + CUTOFF <= right ) {
//find the pivot
T pivot = median( arr, left, right );
//start partitioning
int i = left, j = right - 1;
for ( ; ; ) {
while ( arr[++i].compareTo( pivot ) < 0 ) ;
while ( arr[--j].compareTo( pivot ) > 0 ) ;
if ( i < j ) {
swapReferences( arr, i, j );
} else {
break;
}
}
//swap the pivot reference back to the small collection.
swapReferences( arr, i, right - 1 );
quicksort( arr, left, i - 1 ); //sort the small collection.
quicksort( arr, i + 1, right ); //sort the large collection.
} else {
//if the total number is less than CUTOFF we use insertion sort instead.
insertionSort( arr, left, right );
}
} | java | private static <T extends Comparable<? super T>>
void quicksort( T[] arr, int left, int right )
{
if ( left + CUTOFF <= right ) {
//find the pivot
T pivot = median( arr, left, right );
//start partitioning
int i = left, j = right - 1;
for ( ; ; ) {
while ( arr[++i].compareTo( pivot ) < 0 ) ;
while ( arr[--j].compareTo( pivot ) > 0 ) ;
if ( i < j ) {
swapReferences( arr, i, j );
} else {
break;
}
}
//swap the pivot reference back to the small collection.
swapReferences( arr, i, right - 1 );
quicksort( arr, left, i - 1 ); //sort the small collection.
quicksort( arr, i + 1, right ); //sort the large collection.
} else {
//if the total number is less than CUTOFF we use insertion sort instead.
insertionSort( arr, left, right );
}
} | [
"private",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"quicksort",
"(",
"T",
"[",
"]",
"arr",
",",
"int",
"left",
",",
"int",
"right",
")",
"{",
"if",
"(",
"left",
"+",
"CUTOFF",
"<=",
"right",
")",
"{"... | internal method to sort the array with quick sort algorithm
@param arr an array of Comparable Items
@param left the left-most index of the subarray
@param right the right-most index of the subarray | [
"internal",
"method",
"to",
"sort",
"the",
"array",
"with",
"quick",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L266-L295 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.quickSelect | public static <T extends Comparable<? super T>>
void quickSelect( T[] arr, int k )
{
quickSelect( arr, 0, arr.length - 1, k );
} | java | public static <T extends Comparable<? super T>>
void quickSelect( T[] arr, int k )
{
quickSelect( arr, 0, arr.length - 1, k );
} | [
"public",
"static",
"<",
"T",
"extends",
"Comparable",
"<",
"?",
"super",
"T",
">",
">",
"void",
"quickSelect",
"(",
"T",
"[",
"]",
"arr",
",",
"int",
"k",
")",
"{",
"quickSelect",
"(",
"arr",
",",
"0",
",",
"arr",
".",
"length",
"-",
"1",
",",
... | quick select algorithm
@param arr an array of Comparable items
@param k the k-th small index | [
"quick",
"select",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L306-L310 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java | Sort.bucketSort | public static void bucketSort( int[] arr, int m )
{
int[] count = new int[m];
int j, i = 0;
//System.out.println(count[0]==0?"true":"false");
for ( j = 0; j < arr.length; j++ ) {
count[ arr[j] ]++;
}
//loop and filter the elements
for ( j = 0; j < m; j++ ) {
if ( count[j] > 0 ) {
while ( count[j]-- > 0 ) {
arr[i++] = j;
}
}
}
} | java | public static void bucketSort( int[] arr, int m )
{
int[] count = new int[m];
int j, i = 0;
//System.out.println(count[0]==0?"true":"false");
for ( j = 0; j < arr.length; j++ ) {
count[ arr[j] ]++;
}
//loop and filter the elements
for ( j = 0; j < m; j++ ) {
if ( count[j] > 0 ) {
while ( count[j]-- > 0 ) {
arr[i++] = j;
}
}
}
} | [
"public",
"static",
"void",
"bucketSort",
"(",
"int",
"[",
"]",
"arr",
",",
"int",
"m",
")",
"{",
"int",
"[",
"]",
"count",
"=",
"new",
"int",
"[",
"m",
"]",
";",
"int",
"j",
",",
"i",
"=",
"0",
";",
"//System.out.println(count[0]==0?\"true\":\"false\"... | bucket sort algorithm
@param arr an int array
@param m the large-most one for all the Integers in arr | [
"bucket",
"sort",
"algorithm"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Sort.java#L356-L373 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Util.java | Util.getJarHome | public static String getJarHome(Object o)
{
String path = o.getClass().getProtectionDomain()
.getCodeSource().getLocation().getFile();
File jarFile = new File(path);
return jarFile.getParentFile().getAbsolutePath();
} | java | public static String getJarHome(Object o)
{
String path = o.getClass().getProtectionDomain()
.getCodeSource().getLocation().getFile();
File jarFile = new File(path);
return jarFile.getParentFile().getAbsolutePath();
} | [
"public",
"static",
"String",
"getJarHome",
"(",
"Object",
"o",
")",
"{",
"String",
"path",
"=",
"o",
".",
"getClass",
"(",
")",
".",
"getProtectionDomain",
"(",
")",
".",
"getCodeSource",
"(",
")",
".",
"getLocation",
"(",
")",
".",
"getFile",
"(",
")... | get the absolute parent path for the jar file.
@param o
@return String | [
"get",
"the",
"absolute",
"parent",
"path",
"for",
"the",
"jar",
"file",
"."
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Util.java#L19-L25 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/Util.java | Util.printMatrix | public static void printMatrix(double[][] matrix)
{
StringBuffer sb = new StringBuffer();
sb.append('[').append('\n');
for ( double[] line : matrix ) {
for ( double column : line ) {
sb.append(column).append(", ");
}
sb.append('\n');
}
sb.append(']');
System.out.println(sb.toString());
} | java | public static void printMatrix(double[][] matrix)
{
StringBuffer sb = new StringBuffer();
sb.append('[').append('\n');
for ( double[] line : matrix ) {
for ( double column : line ) {
sb.append(column).append(", ");
}
sb.append('\n');
}
sb.append(']');
System.out.println(sb.toString());
} | [
"public",
"static",
"void",
"printMatrix",
"(",
"double",
"[",
"]",
"[",
"]",
"matrix",
")",
"{",
"StringBuffer",
"sb",
"=",
"new",
"StringBuffer",
"(",
")",
";",
"sb",
".",
"append",
"(",
"'",
"'",
")",
".",
"append",
"(",
"'",
"'",
")",
";",
"f... | print the specified matrix
@param matrix | [
"print",
"the",
"specified",
"matrix"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/Util.java#L32-L44 | train |
lionsoul2014/jcseg | jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegServerConfig.java | JcsegServerConfig.resetFromFile | public void resetFromFile(String configFile) throws IOException
{
IStringBuffer isb = new IStringBuffer();
String line = null;
BufferedReader reader = new BufferedReader(new FileReader(configFile));
while ( (line = reader.readLine()) != null ) {
line = line.trim();
if (line.equals("")) continue;
if (line.charAt(0) == '#') continue;
isb.append(line).append('\n');
line = null; //let gc do its work
}
globalConfig = new JSONObject(isb.toString());
//let gc do its work
isb = null;
reader.close();
reader = null;
} | java | public void resetFromFile(String configFile) throws IOException
{
IStringBuffer isb = new IStringBuffer();
String line = null;
BufferedReader reader = new BufferedReader(new FileReader(configFile));
while ( (line = reader.readLine()) != null ) {
line = line.trim();
if (line.equals("")) continue;
if (line.charAt(0) == '#') continue;
isb.append(line).append('\n');
line = null; //let gc do its work
}
globalConfig = new JSONObject(isb.toString());
//let gc do its work
isb = null;
reader.close();
reader = null;
} | [
"public",
"void",
"resetFromFile",
"(",
"String",
"configFile",
")",
"throws",
"IOException",
"{",
"IStringBuffer",
"isb",
"=",
"new",
"IStringBuffer",
"(",
")",
";",
"String",
"line",
"=",
"null",
";",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
... | initialize it from the specified config file
@param configFile
@throws IOException | [
"initialize",
"it",
"from",
"the",
"specified",
"config",
"file"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-server/src/main/java/org/lionsoul/jcseg/server/JcsegServerConfig.java#L47-L67 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/util/IIntFIFO.java | IIntFIFO.enQueue | public boolean enQueue( int data )
{
Entry o = new Entry(data, head.next);
head.next = o;
size++;
return true;
} | java | public boolean enQueue( int data )
{
Entry o = new Entry(data, head.next);
head.next = o;
size++;
return true;
} | [
"public",
"boolean",
"enQueue",
"(",
"int",
"data",
")",
"{",
"Entry",
"o",
"=",
"new",
"Entry",
"(",
"data",
",",
"head",
".",
"next",
")",
";",
"head",
".",
"next",
"=",
"o",
";",
"size",
"++",
";",
"return",
"true",
";",
"}"
] | add a new item to the queue
@param data
@return boolean | [
"add",
"a",
"new",
"item",
"to",
"the",
"queue"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/util/IIntFIFO.java#L28-L35 | train |
lionsoul2014/jcseg | jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/DictionaryFactory.java | DictionaryFactory.createDictionary | public static ADictionary createDictionary(
Class<? extends ADictionary> _class, Class<?>[] paramType, Object[] args)
{
try {
Constructor<?> cons = _class.getConstructor(paramType);
return ( ( ADictionary ) cons.newInstance(args) );
} catch ( Exception e ) {
System.err.println("can't create the ADictionary instance " +
"with classpath ["+_class.getName()+"]");
e.printStackTrace();
}
return null;
} | java | public static ADictionary createDictionary(
Class<? extends ADictionary> _class, Class<?>[] paramType, Object[] args)
{
try {
Constructor<?> cons = _class.getConstructor(paramType);
return ( ( ADictionary ) cons.newInstance(args) );
} catch ( Exception e ) {
System.err.println("can't create the ADictionary instance " +
"with classpath ["+_class.getName()+"]");
e.printStackTrace();
}
return null;
} | [
"public",
"static",
"ADictionary",
"createDictionary",
"(",
"Class",
"<",
"?",
"extends",
"ADictionary",
">",
"_class",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"paramType",
",",
"Object",
"[",
"]",
"args",
")",
"{",
"try",
"{",
"Constructor",
"<",
"?",
... | create a new ADictionary instance
@param _class
@return ADictionary | [
"create",
"a",
"new",
"ADictionary",
"instance"
] | 7c8a912e3bbcaf4f8de701180b9c24e2e444a94b | https://github.com/lionsoul2014/jcseg/blob/7c8a912e3bbcaf4f8de701180b9c24e2e444a94b/jcseg-core/src/main/java/org/lionsoul/jcseg/tokenizer/core/DictionaryFactory.java#L37-L50 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.