code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public void replace(final int pos, final double latitude, final double longitude) {
this.longitude[pos] = longitude;
this.latitude[pos] = latitude;
} | 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;
} | 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.inde... | 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;
... | 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(par... | java |
private static String stripStartingSlash(String s) {
if (s != null && s.startsWith("/")) {
s = s.substring(1, s.length());
}
return s;
} | java |
private static String stripTrailingSlash(String s) {
if (s != null && s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
}
return s;
} | 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(... | java |
public Feed getFeedDocument() throws AtomException {
InputStream in = null;
synchronized (FileStore.getFileStore()) {
in = FileStore.getFileStore().getFileInputStream(getFeedPath());
if (in == null) {
in = createDefaultFeedDocument(contextURI + servletPath + "/" +... | 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 = ... | 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 Str... | 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.get... | java |
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 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());
}
... | 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);
... | 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);
... | 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;
}
} | 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()) ... | 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");
... | java |
public static <T> T firstNotNull(final T... objects) {
for (final T object : objects) {
if (object != null) {
return object;
}
}
return null;
} | 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 :... | java |
public static String toLowerCase(final String s) {
if (s == null) {
return null;
} else {
return s.toLowerCase(Locale.ENGLISH);
}
} | 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);
... | 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 c... | 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)) {
re... | 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... | 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;
}
... | java |
public static Integer parse(final String s) {
try {
return Integer.parseInt(s);
} catch (final NumberFormatException e) {
return null;
}
} | java |
public void addUpdate(final Update update) {
if (updates == null) {
updates = new ArrayList<Update>();
}
updates.add(update);
} | 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());
a... | 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().isEmp... | 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 Eleme... | 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.g... | 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(... | 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, "descr... | 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(peerLinkEl... | 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(subTitleEl... | 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, "h... | 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()) {
addNotNul... | 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().na... | java |
@Override
public void copyFrom(final CopyFrom obj) {
final AppModule m = (AppModule) obj;
setDraft(m.getDraft());
setEdited(m.getEdited());
} | 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 = httpCo... | 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);
... | 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)... | 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"));
} | 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"));
} | 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], tru... | 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;
} | 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;
} | java |
public static ClientAtomService getAtomService(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientAtomService(uri, authStrategy);
} | java |
public static ClientCollection getCollection(final String uri, final AuthStrategy authStrategy) throws ProponoException {
return new ClientCollection(uri, authStrategy);
} | java |
public void setReference(final Reference reference) {
this.reference = reference;
if (reference instanceof PlayerReference) {
setPlayer((PlayerReference) reference);
}
} | 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 = (Javascrip... | 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().def... | 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 {write... | 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 ) {
... | java |
public static int isCNNumeric( char c )
{
Integer i = cnNumeric.get(c);
if ( i == null ) return -1;
return i.intValue();
} | 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;
} | 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)
... | java |
protected void response(int code, List<Object> data)
{
response(code, JSONWriter.list2JsonString(data));
} | java |
protected void response(int code, Map<String, Object> data)
{
response(code, JSONWriter.map2JsonString(data));
} | java |
public JSONWriter put(String key, Object obj)
{
data.put(key, obj);
return this;
} | java |
public JSONWriter put(String key, Object[] vector)
{
data.put(key, vector2JsonString(vector));
return this;
} | 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)).appen... | 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("\"... | 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;
... | 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()) {
... | 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... | 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 ... | java |
public void unread( char[] cbuf, int off, int len )
{
for ( int i = 0; i < len; i++ ) {
queue.enQueue(cbuf[off+i]);
}
} | java |
public void load( File file )
throws NumberFormatException, FileNotFoundException, IOException
{
loadWords(config, this, file, synBuffer);
} | 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
... | 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();
... | 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... | 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... | 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);
} | 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()
... | 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... | 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();
... | 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--;
} | 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;
... | 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("|------... | 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 > t... | 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(partsp... | 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];
}
... | 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 ];
... | 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, ... | 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, rig... | 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 )... | java |
private static <T> void swapReferences( T[] arr, int idx1, int idx2 )
{
T tmp = arr[idx1];
arr[idx1] = arr[idx2];
arr[idx2] = tmp;
} | java |
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 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 ... | 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;
... | java |
public static <T extends Comparable<? super T>>
void quickSelect( T[] arr, int k )
{
quickSelect( arr, 0, arr.length - 1, k );
} | 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 ... | java |
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 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');
... | 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();
... | java |
public boolean enQueue( int data )
{
Entry o = new Entry(data, head.next);
head.next = o;
size++;
return true;
} | 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 ) {
... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.