id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
65538552-5459-4594-a726-1d351c2b3183 | public static void writeSingleFile(Integer docId, String url, String path, String parentUrl, String title, String h1, String h2, String h3, String bold,
String strong, String em, String anchorText, String parsedData) throws IOException {
FileWriter fstream = new FileWriter("combinedwebpages", true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(docId.toString() + "^" + url + "^" + path + "^" + parentUrl + "^" + title + "^" + h1 + "^" + h2 + "^" + h3 + "^" + bold
+ "^" + strong + "^" + em + "^" + anchorText + "^" + parsedData);
out.newLine();
out.close();
} |
9736fd9c-95fd-43fd-860d-ec0017cc6f7d | public static ArrayList<String> tokenizeFile(File input) throws IOException {
BufferedReader inputBR = null;
ArrayList<String> tokanizedWords = new ArrayList<String>();
ArrayList<String> tempArrList = new ArrayList<String>();
try {
String inputString = "";
// Storing all stop words in a HashSet
HashSet<String> stopWords = new HashSet<String>();
// Reading the Stop Words
String line = null;
File file = new File("src/ir/assignments/UtilFiles/StopWords");
inputBR = new BufferedReader(new FileReader(file));
while (( line = inputBR.readLine()) != null) {
stopWords.add(line.trim());
}
int i=0;
// Reading and processing the file passes as argument to this method
inputBR = new BufferedReader(new FileReader(input));
while (( inputString = inputBR.readLine()) != null) {
if(inputString.trim().length() != 0 || !inputString.equals(" +")) {
// inputString += line + " ";
// Removing extra white spaces between characters with a single white space
inputString = inputString.replaceAll(" +", " ");
// Reference: http://stackoverflow.com/questions/7552253/how-to-remove-special-characters-from-an-string
inputString = inputString.replaceAll("[^\\w\\s]","");
inputString = inputString.replaceAll("[^\\p{L}\\p{N}]"," ");
inputString = inputString.trim();
inputString = inputString.toLowerCase();
// Removing extra white spaces between characters
inputString = inputString.replaceAll(" +", " ");
tempArrList.clear();
tempArrList.addAll(Arrays.asList(inputString.split(" ")));
// Removing stop words
tempArrList = removeStopWords(tempArrList, stopWords);
// Splitting the line based on spaces
tokanizedWords.addAll(tempArrList);
i++;
if(i%500==0) {
Calendar cal = Calendar.getInstance();
cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println( i + " : " + sdf.format(cal.getTime()) + " ---------------- " + tokanizedWords.size() );
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
inputBR.close();
}
if(tokanizedWords.size() == 1 && tokanizedWords.get(0).equals("")) {
return new ArrayList<String>();
} else {
return tokanizedWords;
}
} |
5fa98125-efa9-46fe-9d11-60b70f68929f | public static ArrayList<String> removeStopWords(List<String> wordList, HashSet<String> stopWords) {
ArrayList<String> modifiedWordList = new ArrayList<String>(wordList);
for(String word: wordList) {
if(stopWords.contains(word)) {
modifiedWordList.remove(word);
}
}
return modifiedWordList;
} |
63088b29-c570-4ef8-a667-eab6e2767aab | public static void printFrequencies(List<Frequency> frequencies) {
int totTwoGrmCnt = 0;
Boolean isTwoGram = false;
for (Frequency frequency : frequencies) {
totTwoGrmCnt += frequency.getFrequency();
if(frequency.getText().split(" ").length > 1) isTwoGram = true;
}
if(isTwoGram) {
System.out.println("Total 2-gram count: " + totTwoGrmCnt);
System.out.println("Unique 2-gram count: " + frequencies.size());
} else {
System.out.println("Total item count: " + totTwoGrmCnt);
System.out.println("Unique item count: " + frequencies.size());
}
System.out.println();
for (Frequency frequency : frequencies) {
System.out.println(frequency.toString());
}
System.out.println();
System.out.println("===============");
System.out.println();
} |
96087077-3452-46c3-ad74-2fa1e806673e | public static List<Frequency> computeFourGramFrequencies(ArrayList<String> words) {
List<Frequency> fourGramList = new ArrayList<Frequency>();
Map<String, Integer> fourGramMap = new TreeMap<String, Integer>();
// Adding a pair of words and its corresponding frequency in a TreeMap.
for (int i=0;i<words.size()-3;i++) {
if(fourGramMap.get(words.get(i) + " " + words.get(i+1) + " " + words.get(i+2) + " " + words.get(i+3)) == null) {
fourGramMap.put(words.get(i) + " " + words.get(i+1) + " " + words.get(i+2) + " " + words.get(i+3), 1);
} else {
fourGramMap.put(words.get(i) + " " + words.get(i+1) + " " + words.get(i+2) + " " + words.get(i+3),fourGramMap.get(words.get(i) + " " + words.get(i+1) + " " + words.get(i+2) + " " + words.get(i+3)) + 1);
}
}
for (Map.Entry<String, Integer> entry : fourGramMap.entrySet()) {
fourGramList.add(new Frequency(entry.getKey(), entry.getValue()));
}
return fourGramList;
} |
e248a0fb-d353-4a9a-b58e-c006eb98e638 | public Frequency(String word) {
this.word = word;
this.frequency = 0;
} |
8c3eeb3c-6958-4e32-a39a-79d4c093a6e0 | public Frequency(String word, int frequency) {
this.word = word;
this.frequency = frequency;
} |
f8081d44-558e-417f-a946-6a834cdec418 | public String getText() {
return word;
} |
b4edce29-2d3f-4b02-a08e-0a6667be7966 | public int getFrequency() {
return frequency;
} |
14cb7ea9-710e-4bc7-9a87-3f111f79c8a7 | public void incrementFrequency() {
frequency++;
} |
1946767a-119c-45e0-b88c-aef649fe72fd | @Override
public String toString() {
return word + "\t" + frequency;
} |
4aa8d601-334e-4848-b234-061d4a487897 | public JSONArray() {
this.myArrayList = new ArrayList();
} |
b7747783-9d50-47a2-8a22-23bf6b00c9c7 | public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['");
}
if (x.nextClean() != ']') {
x.back();
for (;;) {
if (x.nextClean() == ',') {
x.back();
this.myArrayList.add(JSONObject.NULL);
} else {
x.back();
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == ']') {
return;
}
x.back();
break;
case ']':
return;
default:
throw x.syntaxError("Expected a ',' or ']'");
}
}
}
} |
62674857-a438-4b89-b68d-8c908f886425 | public JSONArray(String source) throws JSONException {
this(new JSONTokener(source));
} |
935f2051-0e9f-4aa0-85cb-bb22729c5d43 | public JSONArray(Collection collection) {
this.myArrayList = new ArrayList();
if (collection != null) {
Iterator iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
}
}
} |
1c1abc55-68ab-4a65-926a-bd473a8ced52 | public JSONArray(Object array) throws JSONException {
this();
if (array.getClass().isArray()) {
int length = Array.getLength(array);
for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i)));
}
} else {
throw new JSONException(
"JSONArray initial value should be a string or collection or array.");
}
} |
c544aaf9-c0f5-4863-8693-c779cc68b3db | public Object get(int index) throws JSONException {
Object object = this.opt(index);
if (object == null) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
return object;
} |
a589e148-b79a-4e2e-a694-c17770e27e26 | public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (object.equals(Boolean.FALSE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("false"))) {
return false;
} else if (object.equals(Boolean.TRUE)
|| (object instanceof String && ((String) object)
.equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
} |
d3fc6aa8-16b7-444b-8254-298167fe3c52 | public double getDouble(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
} |
12094b41-710e-45db-be85-92a8e7dcb7a7 | public int getInt(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
} |
ec59fb95-f191-4720-8d0f-4e2f60f7ca02 | public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONArray) {
return (JSONArray) object;
}
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
} |
bb951574-9e93-4c8d-8402-9ec60215058a | public JSONObject getJSONObject(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONObject) {
return (JSONObject) object;
}
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
} |
159609c7-d780-46bb-8780-d14397c7a1e4 | public long getLong(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
} |
428e0383-3926-43fc-a275-52123d955027 | public String getString(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof String) {
return (String) object;
}
throw new JSONException("JSONArray[" + index + "] not a string.");
} |
21911af7-d127-40a3-b754-461d0bb4e9ee | public boolean isNull(int index) {
return JSONObject.NULL.equals(this.opt(index));
} |
4adfc109-6df0-4956-89f8-d5f43e80ebdc | public String join(String separator) throws JSONException {
int len = this.length();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
}
return sb.toString();
} |
e66ceb1e-29f9-4828-b825-b2b37a88a6d1 | public int length() {
return this.myArrayList.size();
} |
c6daf1ef-3f72-406e-9ec8-57cfc4beab36 | public Object opt(int index) {
return (index < 0 || index >= this.length()) ? null : this.myArrayList
.get(index);
} |
77a68ff7-ba2b-4472-81a1-facb1e0cc997 | public boolean optBoolean(int index) {
return this.optBoolean(index, false);
} |
cde4cbe6-44b4-4e05-9644-1a49e56fe0e8 | public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
} |
3f7058f7-3fe0-4a1a-9756-c00f1308d854 | public double optDouble(int index) {
return this.optDouble(index, Double.NaN);
} |
89b9db90-3b90-4468-9271-56dfe05a2597 | public double optDouble(int index, double defaultValue) {
try {
return this.getDouble(index);
} catch (Exception e) {
return defaultValue;
}
} |
be3d973e-c898-4539-a690-6e3429df89bc | public int optInt(int index) {
return this.optInt(index, 0);
} |
e33d8ce8-9e57-46f3-9fb1-396789265172 | public int optInt(int index, int defaultValue) {
try {
return this.getInt(index);
} catch (Exception e) {
return defaultValue;
}
} |
7bd008a1-dc96-44b1-85ff-d66bb67bded2 | public JSONArray optJSONArray(int index) {
Object o = this.opt(index);
return o instanceof JSONArray ? (JSONArray) o : null;
} |
f6f40395-0af3-446e-9483-56a530415f2a | public JSONObject optJSONObject(int index) {
Object o = this.opt(index);
return o instanceof JSONObject ? (JSONObject) o : null;
} |
fecde42a-f059-4b29-9a0f-4f7011e190ad | public long optLong(int index) {
return this.optLong(index, 0);
} |
832ab319-dfe0-40be-95ad-6729cfcba304 | public long optLong(int index, long defaultValue) {
try {
return this.getLong(index);
} catch (Exception e) {
return defaultValue;
}
} |
51ab1326-e247-47c3-ac55-f4b6a2139369 | public String optString(int index) {
return this.optString(index, "");
} |
e3d1424b-707c-48d9-84ea-4924b1e0a025 | public String optString(int index, String defaultValue) {
Object object = this.opt(index);
return JSONObject.NULL.equals(object) ? defaultValue : object
.toString();
} |
ccd72706-e4f3-4a09-990e-3a22ad0bf3dc | public JSONArray put(boolean value) {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
} |
c50fdea9-76fa-478f-93f3-2fb84755f497 | public JSONArray put(Collection value) {
this.put(new JSONArray(value));
return this;
} |
bea63e19-bed5-46d1-90ac-f1157241e1ee | public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
JSONObject.testValidity(d);
this.put(d);
return this;
} |
d6777dff-304b-46b6-85ea-bc6a54c0c2e6 | public JSONArray put(int value) {
this.put(new Integer(value));
return this;
} |
0f776ce6-e73b-45fb-ad0c-d79445521d4a | public JSONArray put(long value) {
this.put(new Long(value));
return this;
} |
e731a3e4-807b-45be-9ac8-e266fc93a97f | public JSONArray put(Map value) {
this.put(new JSONObject(value));
return this;
} |
e106e65d-c571-44db-858b-d1ff443fecb0 | public JSONArray put(Object value) {
this.myArrayList.add(value);
return this;
} |
e80f4ca0-1e76-44d1-bd17-82cff59de8cf | public JSONArray put(int index, boolean value) throws JSONException {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
} |
111cb9a4-8c5f-4480-8724-eda0abffcad1 | public JSONArray put(int index, Collection value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
} |
f61b6c41-0e3a-4407-a03e-4fc8f0570fd6 | public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
return this;
} |
ca23c008-4a71-4aca-a95c-bc3aaee1d913 | public JSONArray put(int index, int value) throws JSONException {
this.put(index, new Integer(value));
return this;
} |
c18ef24e-563e-4b75-9d86-4e4478634abe | public JSONArray put(int index, long value) throws JSONException {
this.put(index, new Long(value));
return this;
} |
41223875-0639-45c3-90db-be11eaf4cf47 | public JSONArray put(int index, Map value) throws JSONException {
this.put(index, new JSONObject(value));
return this;
} |
c0360233-deee-4544-b73e-40c7ddb1a7fe | public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < this.length()) {
this.myArrayList.set(index, value);
} else {
while (index != this.length()) {
this.put(JSONObject.NULL);
}
this.put(value);
}
return this;
} |
eb8fa82f-77fb-4330-ac77-3a69560c3815 | public Object remove(int index) {
Object o = this.opt(index);
this.myArrayList.remove(index);
return o;
} |
3640f70b-c0fd-4b9d-9908-9eb95f6055e4 | public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0) {
return null;
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
} |
74d3ce00-ac5c-4b5e-ae45-6f022dfee67c | public String toString() {
try {
return this.toString(0);
} catch (Exception e) {
return null;
}
} |
a1bb83b3-88a8-42e3-800b-f7a13f1ef9fa | public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
return this.write(sw, indentFactor, 0).toString();
}
} |
bdaf0e1a-3c63-4c66-b3e0-9732f6bb331f | public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
} |
1939a13e-8d06-40e3-99da-664ace171320 | Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
try {
boolean commanate = false;
int length = this.length();
writer.write('[');
if (length == 1) {
JSONObject.writeValue(writer, this.myArrayList.get(0),
indentFactor, indent);
} else if (length != 0) {
final int newindent = indent + indentFactor;
for (int i = 0; i < length; i += 1) {
if (commanate) {
writer.write(',');
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
JSONObject.writeValue(writer, this.myArrayList.get(i),
indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, indent);
}
writer.write(']');
return writer;
} catch (IOException e) {
throw new JSONException(e);
}
} |
cb704a8c-7660-4d52-b48e-aec6ff72afa8 | public String toJSONString(); |
69b2ff64-fb7c-47f2-af4a-90ffb0d72172 | public JSONException(String message) {
super(message);
} |
9343d980-eec3-4a87-83a3-6d59f0c0cf86 | public JSONException(Throwable cause) {
super(cause.getMessage());
this.cause = cause;
} |
c351ddd3-1643-46ec-b27b-8e1af600bd33 | public Throwable getCause() {
return this.cause;
} |
a74dcfba-bb64-4a45-98aa-f3cf3d829922 | protected final Object clone() {
return this;
} |
0ba74c93-8e10-45fc-b094-c059f16ebcc7 | public boolean equals(Object object) {
return object == null || object == this;
} |
2edbe270-4ba1-458f-af2a-febee6d2a806 | public String toString() {
return "null";
} |
ae4a8e79-a7b9-47e2-8923-48ed870c9772 | public JSONObject() {
this.map = new HashMap();
} |
8fc74cb0-aa12-48af-b44b-6c36bbb71d83 | public JSONObject(JSONObject jo, String[] names) {
this();
for (int i = 0; i < names.length; i += 1) {
try {
this.putOnce(names[i], jo.opt(names[i]));
} catch (Exception ignore) {
}
}
} |
5b51e2fc-3961-487b-9aa6-a0c9ddba2cd7 | public JSONObject(JSONTokener x) throws JSONException {
this();
char c;
String key;
if (x.nextClean() != '{') {
throw x.syntaxError("A JSONObject text must begin with '{'");
}
for (;;) {
c = x.nextClean();
switch (c) {
case 0:
throw x.syntaxError("A JSONObject text must end with '}'");
case '}':
return;
default:
x.back();
key = x.nextValue().toString();
}
// The key is followed by ':'. We will also tolerate '=' or '=>'.
c = x.nextClean();
if (c == '=') {
if (x.next() != '>') {
x.back();
}
} else if (c != ':') {
throw x.syntaxError("Expected a ':' after a key");
}
this.putOnce(key, x.nextValue());
// Pairs are separated by ','. We will also tolerate ';'.
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == '}') {
return;
}
x.back();
break;
case '}':
return;
default:
throw x.syntaxError("Expected a ',' or '}'");
}
}
} |
703a23e2-c7be-43eb-bd08-a1e974cdfd55 | public JSONObject(Map map) {
this.map = new HashMap();
if (map != null) {
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = (Map.Entry)i.next();
Object value = e.getValue();
if (value != null) {
this.map.put(e.getKey(), wrap(value));
}
}
}
} |
3fa0d811-3d3e-42f9-9d01-3d590f483f23 | public JSONObject(Object bean) {
this();
this.populateMap(bean);
} |
3ae1bb2b-2e5c-4db3-8945-6ca6a140112a | public JSONObject(Object object, String names[]) {
this();
Class c = object.getClass();
for (int i = 0; i < names.length; i += 1) {
String name = names[i];
try {
this.putOpt(name, c.getField(name).get(object));
} catch (Exception ignore) {
}
}
} |
459f40e3-8bb0-4364-8025-0991a50f94b9 | public JSONObject(String source) throws JSONException {
this(new JSONTokener(source));
} |
bee9b4a3-b042-41ec-88c4-48c9253bbb80 | public JSONObject(String baseName, Locale locale) throws JSONException {
this();
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
Thread.currentThread().getContextClassLoader());
// Iterate through the keys in the bundle.
Enumeration keys = bundle.getKeys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof String) {
// Go through the path, ensuring that there is a nested JSONObject for each
// segment except the last. Add the value using the last segment's name into
// the deepest nested JSONObject.
String[] path = ((String)key).split("\\.");
int last = path.length - 1;
JSONObject target = this;
for (int i = 0; i < last; i += 1) {
String segment = path[i];
JSONObject nextTarget = target.optJSONObject(segment);
if (nextTarget == null) {
nextTarget = new JSONObject();
target.put(segment, nextTarget);
}
target = nextTarget;
}
target.put(path[last], bundle.getString((String)key));
}
}
} |
d5e43057-10a6-47e4-874f-757f5cebefe0 | public JSONObject accumulate(
String key,
Object value
) throws JSONException {
testValidity(value);
Object object = this.opt(key);
if (object == null) {
this.put(key, value instanceof JSONArray
? new JSONArray().put(value)
: value);
} else if (object instanceof JSONArray) {
((JSONArray)object).put(value);
} else {
this.put(key, new JSONArray().put(object).put(value));
}
return this;
} |
c36c1674-2e99-435c-8136-b3a628a5c025 | public JSONObject append(String key, Object value) throws JSONException {
testValidity(value);
Object object = this.opt(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray)object).put(value));
} else {
throw new JSONException("JSONObject[" + key +
"] is not a JSONArray.");
}
return this;
} |
8d4c0fa2-9c44-4083-8456-537326f48670 | public static String doubleToString(double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return "null";
}
// Shave off trailing zeros and decimal point, if possible.
String string = Double.toString(d);
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
} |
8bd06d64-615c-497a-a51f-0d92ddae08e8 | public Object get(String key) throws JSONException {
if (key == null) {
throw new JSONException("Null key.");
}
Object object = this.opt(key);
if (object == null) {
throw new JSONException("JSONObject[" + quote(key) +
"] not found.");
}
return object;
} |
53d71034-45eb-4255-bb1e-5238ba10ee37 | public boolean getBoolean(String key) throws JSONException {
Object object = this.get(key);
if (object.equals(Boolean.FALSE) ||
(object instanceof String &&
((String)object).equalsIgnoreCase("false"))) {
return false;
} else if (object.equals(Boolean.TRUE) ||
(object instanceof String &&
((String)object).equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a Boolean.");
} |
323a71d5-5fc5-458e-818d-8ffc87528508 | public double getDouble(String key) throws JSONException {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number)object).doubleValue()
: Double.parseDouble((String)object);
} catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) +
"] is not a number.");
}
} |
f1e09e4b-9963-4ad8-8a72-e3a2dac0ea8a | public int getInt(String key) throws JSONException {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number)object).intValue()
: Integer.parseInt((String)object);
} catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) +
"] is not an int.");
}
} |
0fc0a76e-b09e-42a7-bbaf-5d8d8eda3224 | public JSONArray getJSONArray(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof JSONArray) {
return (JSONArray)object;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a JSONArray.");
} |
6723ce1d-94c2-472e-a1ca-7e2e7f691b22 | public JSONObject getJSONObject(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof JSONObject) {
return (JSONObject)object;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a JSONObject.");
} |
eeb062ed-0b2e-4874-b1f3-befedd885e6e | public long getLong(String key) throws JSONException {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number)object).longValue()
: Long.parseLong((String)object);
} catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) +
"] is not a long.");
}
} |
7c7f9770-18ab-44cd-ac43-51efc8420b79 | public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
return null;
}
Iterator iterator = jo.keys();
String[] names = new String[length];
int i = 0;
while (iterator.hasNext()) {
names[i] = (String)iterator.next();
i += 1;
}
return names;
} |
e1859db7-f283-42ac-81c8-1a9e20eacdc1 | public static String[] getNames(Object object) {
if (object == null) {
return null;
}
Class klass = object.getClass();
Field[] fields = klass.getFields();
int length = fields.length;
if (length == 0) {
return null;
}
String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
} |
d88e52b1-f7d4-4fc2-94bc-649892feeb99 | public String getString(String key) throws JSONException {
Object object = this.get(key);
if (object instanceof String) {
return (String)object;
}
throw new JSONException("JSONObject[" + quote(key) +
"] not a string.");
} |
b4f77a8c-6bb0-49b2-8f7d-73e47ce49ebe | public boolean has(String key) {
return this.map.containsKey(key);
} |
b6d9df2e-f353-41db-82be-df0f23b06f46 | public JSONObject increment(String key) throws JSONException {
Object value = this.opt(key);
if (value == null) {
this.put(key, 1);
} else if (value instanceof Integer) {
this.put(key, ((Integer)value).intValue() + 1);
} else if (value instanceof Long) {
this.put(key, ((Long)value).longValue() + 1);
} else if (value instanceof Double) {
this.put(key, ((Double)value).doubleValue() + 1);
} else if (value instanceof Float) {
this.put(key, ((Float)value).floatValue() + 1);
} else {
throw new JSONException("Unable to increment [" + quote(key) + "].");
}
return this;
} |
48b8d934-4f99-43ee-ada6-cc4938675c52 | public boolean isNull(String key) {
return JSONObject.NULL.equals(this.opt(key));
} |
69eaf96f-0856-45f0-938d-0b605cfb01b1 | public Iterator keys() {
return this.keySet().iterator();
} |
c96c6709-428a-4c26-9cef-69318134b081 | public Set keySet() {
return this.map.keySet();
} |
6c7e97a6-59da-4e37-a005-088d347a21d7 | public int length() {
return this.map.size();
} |
649931bd-6291-4b6f-b875-d1eff09fd244 | public JSONArray names() {
JSONArray ja = new JSONArray();
Iterator keys = this.keys();
while (keys.hasNext()) {
ja.put(keys.next());
}
return ja.length() == 0 ? null : ja;
} |
d321cc22-9270-41b5-a149-98d40243ec65 | public static String numberToString(Number number)
throws JSONException {
if (number == null) {
throw new JSONException("Null pointer");
}
testValidity(number);
// Shave off trailing zeros and decimal point, if possible.
String string = number.toString();
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
} |
211a82c2-ac3b-436e-8021-4678aa1c6b7d | public Object opt(String key) {
return key == null ? null : this.map.get(key);
} |
f1b7f81d-cd5a-469e-8d2a-c0e0c7f1f2e6 | public boolean optBoolean(String key) {
return this.optBoolean(key, false);
} |
93abc96c-8785-46d0-9778-e9480a318c33 | public boolean optBoolean(String key, boolean defaultValue) {
try {
return this.getBoolean(key);
} catch (Exception e) {
return defaultValue;
}
} |
85752b22-cbee-40c8-9a05-2e4d407975a3 | public double optDouble(String key) {
return this.optDouble(key, Double.NaN);
} |