code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public static final void selectAll(Spannable text) { setSelection(text, 0, text.length()); }
Select the entire text.
Selection::selectAll
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/Selection.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/Selection.java
Apache-2.0
public static final void extendSelection(Spannable text, int index) { if (text.getSpanStart(SELECTION_END) != index) text.setSpan(SELECTION_END, index, index, Spanned.SPAN_POINT_POINT); }
Move the selection edge to offset <code>index</code>.
Selection::extendSelection
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/Selection.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/Selection.java
Apache-2.0
public static final void removeSelection(Spannable text) { text.removeSpan(SELECTION_START); text.removeSpan(SELECTION_END); }
Remove the selection or cursor, if any, from the text.
Selection::removeSelection
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/Selection.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/Selection.java
Apache-2.0
public static CharSequence join(Iterable<CharSequence> list) { // final CharSequence delimiter = Resources.getSystem().getText(R.string.list_delimeter); CharSequence delimiter = ","; return join(delimiter, list); }
Returns list of multiple {@link CharSequence} joined into a single {@link CharSequence} separated by localized delimiter such as ", ". @hide
return::join
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
public static String join(CharSequence delimiter, Object[] tokens) { StringBuilder sb = new StringBuilder(); boolean firstTime = true; for (Object token: tokens) { if (firstTime) { firstTime = false; } else { sb.append(delimiter); } sb.append(token); } return sb.toString(); }
Returns a string containing the tokens joined by delimiters. @param tokens an array objects to be joined. Strings will be formed from the objects by calling object.toString().
return::join
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
static boolean doesNotNeedBidi(CharSequence s, int start, int end) { for (int i = start; i < end; i++) { if (s.charAt(i) >= FIRST_RIGHT_TO_LEFT) { return false; } } return true; }
@hide public static CharSequence commaEllipsize(CharSequence text, TextPaint p, float avail, String oneMore, String more, TextDirectionHeuristic textDir) { MeasuredText mt = MeasuredText.obtain(); try { int len = text.length(); float width = setPara(mt, p, text, 0, len, textDir); if (width <= avail) { return text; } char[] buf = mt.mChars; int commaCount = 0; for (int i = 0; i < len; i++) { if (buf[i] == ',') { commaCount++; } } int remaining = commaCount + 1; int ok = 0; String okFormat = ""; int w = 0; int count = 0; float[] widths = mt.mWidths; MeasuredText tempMt = MeasuredText.obtain(); for (int i = 0; i < len; i++) { w += widths[i]; if (buf[i] == ',') { count++; String format; // XXX should not insert spaces, should be part of string // XXX should use plural rules and not assume English plurals if (--remaining == 1) { format = " " + oneMore; } else { format = " " + String.format(more, remaining); } // XXX this is probably ok, but need to look at it more tempMt.setPara(format, 0, format.length(), textDir); float moreWid = tempMt.addStyleRun(p, tempMt.mLen, null); if (w + moreWid <= avail) { ok = i + 1; okFormat = format; } } } MeasuredText.recycle(tempMt); SpannableStringBuilder out = new SpannableStringBuilder(okFormat); out.insert(0, text, 0, ok); return out; } finally { MeasuredText.recycle(mt); } } private static float setPara(MeasuredText mt, TextPaint paint, CharSequence text, int start, int end, TextDirectionHeuristic textDir) { mt.setPara(text, start, end, textDir); float width; Spanned sp = text instanceof Spanned ? (Spanned) text : null; int len = end - start; if (sp == null) { width = mt.addStyleRun(paint, len, null); } else { width = 0; int spanEnd; for (int spanStart = 0; spanStart < len; spanStart = spanEnd) { spanEnd = sp.nextSpanTransition(spanStart, len, MetricAffectingSpan.class); MetricAffectingSpan[] spans = sp.getSpans( spanStart, spanEnd, MetricAffectingSpan.class); spans = TextUtils.removeEmptySpans(spans, sp, MetricAffectingSpan.class); width += mt.addStyleRun(paint, spans, spanEnd - spanStart, null); } } return width; } private static final char FIRST_RIGHT_TO_LEFT = '\u0590'; /* package
Object::doesNotNeedBidi
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
static boolean doesNotNeedBidi(char[] text, int start, int len) { for (int i = start, e = i + len; i < e; i++) { if (text[i] >= FIRST_RIGHT_TO_LEFT) { return false; } } return true; }
@hide public static CharSequence commaEllipsize(CharSequence text, TextPaint p, float avail, String oneMore, String more, TextDirectionHeuristic textDir) { MeasuredText mt = MeasuredText.obtain(); try { int len = text.length(); float width = setPara(mt, p, text, 0, len, textDir); if (width <= avail) { return text; } char[] buf = mt.mChars; int commaCount = 0; for (int i = 0; i < len; i++) { if (buf[i] == ',') { commaCount++; } } int remaining = commaCount + 1; int ok = 0; String okFormat = ""; int w = 0; int count = 0; float[] widths = mt.mWidths; MeasuredText tempMt = MeasuredText.obtain(); for (int i = 0; i < len; i++) { w += widths[i]; if (buf[i] == ',') { count++; String format; // XXX should not insert spaces, should be part of string // XXX should use plural rules and not assume English plurals if (--remaining == 1) { format = " " + oneMore; } else { format = " " + String.format(more, remaining); } // XXX this is probably ok, but need to look at it more tempMt.setPara(format, 0, format.length(), textDir); float moreWid = tempMt.addStyleRun(p, tempMt.mLen, null); if (w + moreWid <= avail) { ok = i + 1; okFormat = format; } } } MeasuredText.recycle(tempMt); SpannableStringBuilder out = new SpannableStringBuilder(okFormat); out.insert(0, text, 0, ok); return out; } finally { MeasuredText.recycle(mt); } } private static float setPara(MeasuredText mt, TextPaint paint, CharSequence text, int start, int end, TextDirectionHeuristic textDir) { mt.setPara(text, start, end, textDir); float width; Spanned sp = text instanceof Spanned ? (Spanned) text : null; int len = end - start; if (sp == null) { width = mt.addStyleRun(paint, len, null); } else { width = 0; int spanEnd; for (int spanStart = 0; spanStart < len; spanStart = spanEnd) { spanEnd = sp.nextSpanTransition(spanStart, len, MetricAffectingSpan.class); MetricAffectingSpan[] spans = sp.getSpans( spanStart, spanEnd, MetricAffectingSpan.class); spans = TextUtils.removeEmptySpans(spans, sp, MetricAffectingSpan.class); width += mt.addStyleRun(paint, spans, spanEnd - spanStart, null); } } return width; } private static final char FIRST_RIGHT_TO_LEFT = '\u0590'; /* package static boolean doesNotNeedBidi(CharSequence s, int start, int end) { for (int i = start; i < end; i++) { if (s.charAt(i) >= FIRST_RIGHT_TO_LEFT) { return false; } } return true; } /* package
Object::doesNotNeedBidi
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
public static String htmlEncode(String s) { StringBuilder sb = new StringBuilder(); char c; for (int i = 0; i < s.length(); i++) { c = s.charAt(i); switch (c) { case '<': sb.append("&lt;"); //$NON-NLS-1$ break; case '>': sb.append("&gt;"); //$NON-NLS-1$ break; case '&': sb.append("&amp;"); //$NON-NLS-1$ break; case '\'': //http://www.w3.org/TR/xhtml1 // The named character reference &apos; (the apostrophe, U+0027) was introduced in // XML 1.0 but does not appear in HTML. Authors should therefore use &#39; instead // of &apos; to work as expected in HTML 4 user agents. sb.append("&#39;"); //$NON-NLS-1$ break; case '"': sb.append("&quot;"); //$NON-NLS-1$ break; default: sb.append(c); } } return sb.toString(); }
Html-encode the string. @param s the string to be encoded @return the encoded string
Object::htmlEncode
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
public static CharSequence concat(CharSequence... text) { if (text.length == 0) { return ""; } if (text.length == 1) { return text[0]; } boolean spanned = false; for (int i = 0; i < text.length; i++) { if (text[i] instanceof Spanned) { spanned = true; break; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length; i++) { sb.append(text[i]); } if (!spanned) { return sb.toString(); } SpannableString ss = new SpannableString(sb); int off = 0; for (int i = 0; i < text.length; i++) { int len = text[i].length(); if (text[i] instanceof Spanned) { copySpansFrom((Spanned) text[i], 0, len, Object.class, ss, off); } off += len; } return new SpannedString(ss); }
Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any.
Object::concat
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/TextUtils.java
Apache-2.0
public String getAddress() { return mAddress; }
Returns the address part.
Rfc822Token::getAddress
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/util/Rfc822Token.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/util/Rfc822Token.java
Apache-2.0
public String getComment() { return mComment; }
Returns the comment part.
Rfc822Token::getComment
java
google/j2objc
jre_emul/android/frameworks/base/core/java/android/text/util/Rfc822Token.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/android/text/util/Rfc822Token.java
Apache-2.0
public static <E> ArrayList<E> newArrayList() { return new ArrayList<E>(); }
Creates an empty {@code ArrayList} instance. <p><b>Note:</b> if you only need an <i>immutable</i> empty List, use {@link Collections#emptyList} instead. @return a newly-created, initially-empty {@code ArrayList}
Lists::newArrayList
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Lists.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Lists.java
Apache-2.0
public static <E> ArrayList<E> newArrayList(E... elements) { int capacity = (elements.length * 110) / 100 + 5; ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
Creates a resizable {@code ArrayList} instance containing the given elements. <p><b>Note:</b> due to a bug in javac 1.5.0_06, we cannot support the following: <p>{@code List<Base> list = Lists.newArrayList(sub1, sub2);} <p>where {@code sub1} and {@code sub2} are references to subtypes of {@code Base}, not of {@code Base} itself. To get around this, you must use: <p>{@code List<Base> list = Lists.<Base>newArrayList(sub1, sub2);} @param elements the elements that the list should contain, in order @return a newly-created {@code ArrayList} containing those elements
Lists::newArrayList
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Lists.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Lists.java
Apache-2.0
public static <K> HashSet<K> newHashSet() { return new HashSet<K>(); }
Creates an empty {@code HashSet} instance. <p><b>Note:</b> if {@code E} is an {@link Enum} type, use {@link EnumSet#noneOf} instead. <p><b>Note:</b> if you only need an <i>immutable</i> empty Set, use {@link Collections#emptySet} instead. @return a newly-created, initially-empty {@code HashSet}
Sets::newHashSet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <E> HashSet<E> newHashSet(E... elements) { int capacity = elements.length * 4 / 3 + 1; HashSet<E> set = new HashSet<E>(capacity); Collections.addAll(set, elements); return set; }
Creates a {@code HashSet} instance containing the given elements. <p><b>Note:</b> due to a bug in javac 1.5.0_06, we cannot support the following: <p>{@code Set<Base> set = Sets.newHashSet(sub1, sub2);} <p>where {@code sub1} and {@code sub2} are references to subtypes of {@code Base}, not of {@code Base} itself. To get around this, you must use: <p>{@code Set<Base> set = Sets.<Base>newHashSet(sub1, sub2);} @param elements the elements that the set should contain @return a newly-created {@code HashSet} containing those elements (minus duplicates)
Sets::newHashSet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <E> SortedSet<E> newSortedSet() { return new TreeSet<E>(); }
Creates an empty {@code SortedSet} instance. @return a newly-created, initially-empty {@code SortedSet}.
Sets::newSortedSet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <E> SortedSet<E> newSortedSet(E... elements) { SortedSet<E> set = new TreeSet<E>(); Collections.addAll(set, elements); return set; }
Creates a {@code SortedSet} instance containing the given elements. @param elements the elements that the set should contain @return a newly-created {@code SortedSet} containing those elements (minus duplicates)
Sets::newSortedSet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <E> ArraySet<E> newArraySet() { return new ArraySet<E>(); }
Creates a {@code ArraySet} instance.
Sets::newArraySet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <E> ArraySet<E> newArraySet(E... elements) { int capacity = elements.length * 4 / 3 + 1; ArraySet<E> set = new ArraySet<E>(capacity); Collections.addAll(set, elements); return set; }
Creates a {@code ArraySet} instance containing the given elements.
Sets::newArraySet
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Sets.java
Apache-2.0
public static <K, V> HashMap<K, V> newHashMap() { return new HashMap<K, V>(); }
Creates a {@code HashMap} instance. @return a newly-created, initially-empty {@code HashMap}
Maps::newHashMap
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Maps.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Maps.java
Apache-2.0
public static <K, V> ArrayMap<K, V> newArrayMap() { return new ArrayMap<K, V>(); }
Creates a {@code ArrayMap} instance.
Maps::newArrayMap
java
google/j2objc
jre_emul/android/frameworks/base/core/java/com/google/android/collect/Maps.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/java/com/google/android/collect/Maps.java
Apache-2.0
private String decodeString(String in) throws Exception { byte[] out = Base64.decode(in, 0); return new String(out); }
/* Copyright (C) 2010 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. package android.util; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import junit.framework.TestCase; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Random; public class Base64Test extends TestCase { private static final String TAG = "Base64Test"; /** Decodes a string, returning a string.
Base64Test::decodeString
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private String encodeToString(String in, int flags) throws Exception { String b64 = Base64.encodeToString(in.getBytes(), flags); String dec = decodeString(b64); assertEquals(in, dec); return b64; }
Encodes the string 'in' using 'flags'. Asserts that decoding gives the same string. Returns the encoded string.
Base64Test::encodeToString
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private void assertBad(String in) throws Exception { try { byte[] out = Base64.decode(in, 0); fail("should have failed to decode"); } catch (IllegalArgumentException e) { } }
Encodes the string 'in' using 'flags'. Asserts that decoding gives the same string. Returns the encoded string. private String encodeToString(String in, int flags) throws Exception { String b64 = Base64.encodeToString(in.getBytes(), flags); String dec = decodeString(b64); assertEquals(in, dec); return b64; } /** Assert that decoding 'in' throws IllegalArgumentException.
Base64Test::assertBad
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private void assertEquals(byte[] expected, int len, byte[] actual) { assertEquals(len, actual.length); for (int i = 0; i < len; ++i) { assertEquals(expected[i], actual[i]); } }
Encodes the string 'in' using 'flags'. Asserts that decoding gives the same string. Returns the encoded string. private String encodeToString(String in, int flags) throws Exception { String b64 = Base64.encodeToString(in.getBytes(), flags); String dec = decodeString(b64); assertEquals(in, dec); return b64; } /** Assert that decoding 'in' throws IllegalArgumentException. private void assertBad(String in) throws Exception { try { byte[] out = Base64.decode(in, 0); fail("should have failed to decode"); } catch (IllegalArgumentException e) { } } /** Assert that actual equals the first len bytes of expected.
Base64Test::assertEquals
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private void assertEquals(byte[] expected, int len, byte[] actual, int alen) { assertEquals(len, alen); for (int i = 0; i < len; ++i) { assertEquals(expected[i], actual[i]); } }
Encodes the string 'in' using 'flags'. Asserts that decoding gives the same string. Returns the encoded string. private String encodeToString(String in, int flags) throws Exception { String b64 = Base64.encodeToString(in.getBytes(), flags); String dec = decodeString(b64); assertEquals(in, dec); return b64; } /** Assert that decoding 'in' throws IllegalArgumentException. private void assertBad(String in) throws Exception { try { byte[] out = Base64.decode(in, 0); fail("should have failed to decode"); } catch (IllegalArgumentException e) { } } /** Assert that actual equals the first len bytes of expected. private void assertEquals(byte[] expected, int len, byte[] actual) { assertEquals(len, actual.length); for (int i = 0; i < len; ++i) { assertEquals(expected[i], actual[i]); } } /** Assert that actual equals the first len bytes of expected.
Base64Test::assertEquals
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private void assertEquals(byte[] expected, byte[] actual) { assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; ++i) { assertEquals(expected[i], actual[i]); } }
Encodes the string 'in' using 'flags'. Asserts that decoding gives the same string. Returns the encoded string. private String encodeToString(String in, int flags) throws Exception { String b64 = Base64.encodeToString(in.getBytes(), flags); String dec = decodeString(b64); assertEquals(in, dec); return b64; } /** Assert that decoding 'in' throws IllegalArgumentException. private void assertBad(String in) throws Exception { try { byte[] out = Base64.decode(in, 0); fail("should have failed to decode"); } catch (IllegalArgumentException e) { } } /** Assert that actual equals the first len bytes of expected. private void assertEquals(byte[] expected, int len, byte[] actual) { assertEquals(len, actual.length); for (int i = 0; i < len; ++i) { assertEquals(expected[i], actual[i]); } } /** Assert that actual equals the first len bytes of expected. private void assertEquals(byte[] expected, int len, byte[] actual, int alen) { assertEquals(len, alen); for (int i = 0; i < len; ++i) { assertEquals(expected[i], actual[i]); } } /** Assert that actual equals the first len bytes of expected.
Base64Test::assertEquals
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
public void XXXtestEncodeInternal() throws Exception { byte[] input = { (byte) 0x61, (byte) 0x62, (byte) 0x63 }; byte[] output = new byte[100]; Base64.Encoder encoder = new Base64.Encoder(Base64.NO_PADDING | Base64.NO_WRAP, output); encoder.process(input, 0, 3, false); assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 3, false); assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals(0, encoder.op); assertEquals(1, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals(0, encoder.op); assertEquals(2, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals("YWFh".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals(0, encoder.op); assertEquals(2, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals("YWJh".getBytes(), 4, encoder.output, encoder.op); assertEquals(1, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals("YmFi".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 1, true); assertEquals("YQ".getBytes(), 2, encoder.output, encoder.op); }
Tests that Base64.Encoder.encode() does correct handling of the tail for each call. This test is disabled because while it passes if you can get it to run, android's test infrastructure currently doesn't allow us to get at package-private members (Base64.Encoder in this case).
Base64Test::XXXtestEncodeInternal
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
public void testSingleByteReads() throws IOException { InputStream in = new Base64InputStream( new ByteArrayInputStream("/v8=".getBytes()), Base64.DEFAULT); assertEquals(254, in.read()); assertEquals(255, in.read()); }
Tests that Base64.Encoder.encode() does correct handling of the tail for each call. This test is disabled because while it passes if you can get it to run, android's test infrastructure currently doesn't allow us to get at package-private members (Base64.Encoder in this case). public void XXXtestEncodeInternal() throws Exception { byte[] input = { (byte) 0x61, (byte) 0x62, (byte) 0x63 }; byte[] output = new byte[100]; Base64.Encoder encoder = new Base64.Encoder(Base64.NO_PADDING | Base64.NO_WRAP, output); encoder.process(input, 0, 3, false); assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 3, false); assertEquals("YWJj".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals(0, encoder.op); assertEquals(1, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals(0, encoder.op); assertEquals(2, encoder.tailLen); encoder.process(input, 0, 1, false); assertEquals("YWFh".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals(0, encoder.op); assertEquals(2, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals("YWJh".getBytes(), 4, encoder.output, encoder.op); assertEquals(1, encoder.tailLen); encoder.process(input, 0, 2, false); assertEquals("YmFi".getBytes(), 4, encoder.output, encoder.op); assertEquals(0, encoder.tailLen); encoder.process(input, 0, 1, true); assertEquals("YQ".getBytes(), 2, encoder.output, encoder.op); } private static final String lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Quisque congue eleifend odio, eu ornare nulla facilisis eget. " + "Integer eget elit diam, sit amet laoreet nibh. Quisque enim " + "urna, pharetra vitae consequat eget, adipiscing eu ante. " + "Aliquam venenatis arcu nec nibh imperdiet tempor. In id dui " + "eget lorem aliquam rutrum vel vitae eros. In placerat ornare " + "pretium. Curabitur non fringilla mi. Fusce ultricies, turpis " + "eu ultrices suscipit, ligula nisi consectetur eros, dapibus " + "aliquet dui sapien a turpis. Donec ultricies varius ligula, " + "ut hendrerit arcu malesuada at. Praesent sed elit pretium " + "eros luctus gravida. In ac dolor lorem. Cras condimentum " + "convallis elementum. Phasellus vel felis in nulla ultrices " + "venenatis. Nam non tortor non orci convallis convallis. " + "Nam tristique lacinia hendrerit. Pellentesque habitant morbi " + "tristique senectus et netus et malesuada fames ac turpis " + "egestas. Vivamus cursus, nibh eu imperdiet porta, magna " + "ipsum mollis mauris, sit amet fringilla mi nisl eu mi. " + "Phasellus posuere, leo at ultricies vehicula, massa risus " + "volutpat sapien, eu tincidunt diam ipsum eget nulla. Cras " + "molestie dapibus commodo. Ut vel tellus at massa gravida " + "semper non sed orci."; public void testInputStream() throws Exception { int[] flagses = { Base64.DEFAULT, Base64.NO_PADDING, Base64.NO_WRAP, Base64.NO_PADDING | Base64.NO_WRAP, Base64.CRLF, Base64.URL_SAFE }; int[] writeLengths = { -10, -5, -1, 0, 1, 1, 2, 2, 3, 10, 100 }; Random rng = new Random(32176L); // Test input needs to be at least 2048 bytes to fill up the // read buffer of Base64InputStream. byte[] plain = (lipsum + lipsum + lipsum + lipsum + lipsum).getBytes(); for (int flags: flagses) { byte[] encoded = Base64.encode(plain, flags); ByteArrayInputStream bais; Base64InputStream b64is; byte[] actual = new byte[plain.length * 2]; int ap; int b; // ----- test decoding ("encoded" -> "plain") ----- // read as much as it will give us in one chunk bais = new ByteArrayInputStream(encoded); b64is = new Base64InputStream(bais, flags); ap = 0; while ((b = b64is.read(actual, ap, actual.length-ap)) != -1) { ap += b; } assertEquals(actual, ap, plain); // read individual bytes bais = new ByteArrayInputStream(encoded); b64is = new Base64InputStream(bais, flags); ap = 0; while ((b = b64is.read()) != -1) { actual[ap++] = (byte) b; } assertEquals(actual, ap, plain); // mix reads of variously-sized arrays with one-byte reads bais = new ByteArrayInputStream(encoded); b64is = new Base64InputStream(bais, flags); ap = 0; readloop: while (true) { int l = writeLengths[rng.nextInt(writeLengths.length)]; if (l >= 0) { b = b64is.read(actual, ap, l); if (b == -1) break readloop; ap += b; } else { for (int i = 0; i < -l; ++i) { if ((b = b64is.read()) == -1) break readloop; actual[ap++] = (byte) b; } } } assertEquals(actual, ap, plain); // ----- test encoding ("plain" -> "encoded") ----- // read as much as it will give us in one chunk bais = new ByteArrayInputStream(plain); b64is = new Base64InputStream(bais, flags, true); ap = 0; while ((b = b64is.read(actual, ap, actual.length-ap)) != -1) { ap += b; } assertEquals(actual, ap, encoded); // read individual bytes bais = new ByteArrayInputStream(plain); b64is = new Base64InputStream(bais, flags, true); ap = 0; while ((b = b64is.read()) != -1) { actual[ap++] = (byte) b; } assertEquals(actual, ap, encoded); // mix reads of variously-sized arrays with one-byte reads bais = new ByteArrayInputStream(plain); b64is = new Base64InputStream(bais, flags, true); ap = 0; readloop: while (true) { int l = writeLengths[rng.nextInt(writeLengths.length)]; if (l >= 0) { b = b64is.read(actual, ap, l); if (b == -1) break readloop; ap += b; } else { for (int i = 0; i < -l; ++i) { if ((b = b64is.read()) == -1) break readloop; actual[ap++] = (byte) b; } } } assertEquals(actual, ap, encoded); } } /** http://b/3026478
Base64Test::testSingleByteReads
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
public void testOutputStream() throws Exception { int[] flagses = { Base64.DEFAULT, Base64.NO_PADDING, Base64.NO_WRAP, Base64.NO_PADDING | Base64.NO_WRAP, Base64.CRLF, Base64.URL_SAFE }; int[] writeLengths = { -10, -5, -1, 0, 1, 1, 2, 2, 3, 10, 100 }; Random rng = new Random(32176L); // Test input needs to be at least 1024 bytes to test filling // up the write(int) buffer of Base64OutputStream. byte[] plain = (lipsum + lipsum).getBytes(); for (int flags: flagses) { byte[] encoded = Base64.encode(plain, flags); ByteArrayOutputStream baos; Base64OutputStream b64os; byte[] actual; int p; // ----- test encoding ("plain" -> "encoded") ----- // one large write(byte[]) of the whole input baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags); b64os.write(plain); b64os.close(); actual = baos.toByteArray(); assertEquals(encoded, actual); // many calls to write(int) baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags); for (int i = 0; i < plain.length; ++i) { b64os.write(plain[i]); } b64os.close(); actual = baos.toByteArray(); assertEquals(encoded, actual); // intermixed sequences of write(int) with // write(byte[],int,int) of various lengths. baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags); p = 0; while (p < plain.length) { int l = writeLengths[rng.nextInt(writeLengths.length)]; l = Math.min(l, plain.length-p); if (l >= 0) { b64os.write(plain, p, l); p += l; } else { l = Math.min(-l, plain.length-p); for (int i = 0; i < l; ++i) { b64os.write(plain[p+i]); } p += l; } } b64os.close(); actual = baos.toByteArray(); assertEquals(encoded, actual); // ----- test decoding ("encoded" -> "plain") ----- // one large write(byte[]) of the whole input baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags, false); b64os.write(encoded); b64os.close(); actual = baos.toByteArray(); assertEquals(plain, actual); // many calls to write(int) baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags, false); for (int i = 0; i < encoded.length; ++i) { b64os.write(encoded[i]); } b64os.close(); actual = baos.toByteArray(); assertEquals(plain, actual); // intermixed sequences of write(int) with // write(byte[],int,int) of various lengths. baos = new ByteArrayOutputStream(); b64os = new Base64OutputStream(baos, flags, false); p = 0; while (p < encoded.length) { int l = writeLengths[rng.nextInt(writeLengths.length)]; l = Math.min(l, encoded.length-p); if (l >= 0) { b64os.write(encoded, p, l); p += l; } else { l = Math.min(-l, encoded.length-p); for (int i = 0; i < l; ++i) { b64os.write(encoded[p+i]); } p += l; } } b64os.close(); actual = baos.toByteArray(); assertEquals(plain, actual); } }
Tests that Base64OutputStream produces exactly the same results as calling Base64.encode/.decode on an in-memory array.
Base64Test::testOutputStream
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/util/Base64Test.java
Apache-2.0
private void checkContains(Spanned text, String[] spans, String spanName, int start, int end) throws Exception { for (String i: spans) { if (i.equals(spanName)) { assertEquals(start, text.getSpanStart(i)); assertEquals(end, text.getSpanEnd(i)); return; } } fail(); }
TextUtilsTest tests {@link TextUtils}. public class TextUtilsTest extends TestCase { @SmallTest public void testBasic() throws Exception { assertEquals("", TextUtils.concat()); assertEquals("foo", TextUtils.concat("foo")); assertEquals("foobar", TextUtils.concat("foo", "bar")); assertEquals("foobarbaz", TextUtils.concat("foo", "bar", "baz")); SpannableString foo = new SpannableString("foo"); foo.setSpan("foo", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); SpannableString bar = new SpannableString("bar"); bar.setSpan("bar", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); SpannableString baz = new SpannableString("baz"); baz.setSpan("baz", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); assertEquals("foo", TextUtils.concat(foo).toString()); assertEquals("foobar", TextUtils.concat(foo, bar).toString()); assertEquals("foobarbaz", TextUtils.concat(foo, bar, baz).toString()); assertEquals(1, ((Spanned) TextUtils.concat(foo)).getSpanStart("foo")); assertEquals(1, ((Spanned) TextUtils.concat(foo, bar)).getSpanStart("foo")); assertEquals(4, ((Spanned) TextUtils.concat(foo, bar)).getSpanStart("bar")); assertEquals(1, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("foo")); assertEquals(4, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("bar")); assertEquals(7, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("baz")); assertTrue(TextUtils.concat("foo", "bar") instanceof String); assertTrue(TextUtils.concat(foo, bar) instanceof SpannedString); } @SmallTest public void testTemplateString() throws Exception { CharSequence result; result = TextUtils.expandTemplate("This is a ^1 of the ^2 broadcast ^3.", "test", "emergency", "system"); assertEquals("This is a test of the emergency broadcast system.", result.toString()); result = TextUtils.expandTemplate("^^^1^^^2^3^a^1^^b^^^c", "one", "two", "three"); assertEquals("^one^twothree^aone^b^^c", result.toString()); result = TextUtils.expandTemplate("^"); assertEquals("^", result.toString()); result = TextUtils.expandTemplate("^^"); assertEquals("^", result.toString()); result = TextUtils.expandTemplate("^^^"); assertEquals("^^", result.toString()); result = TextUtils.expandTemplate("shorter ^1 values ^2.", "a", ""); assertEquals("shorter a values .", result.toString()); try { TextUtils.expandTemplate("Only ^1 value given, but ^2 used.", "foo"); fail(); } catch (IllegalArgumentException e) { } try { TextUtils.expandTemplate("^1 value given, and ^0 used.", "foo"); fail(); } catch (IllegalArgumentException e) { } result = TextUtils.expandTemplate("^1 value given, and ^9 used.", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); assertEquals("one value given, and nine used.", result.toString()); try { TextUtils.expandTemplate("^1 value given, and ^10 used.", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); fail(); } catch (IllegalArgumentException e) { } // putting carets in the values: expansion is not recursive. result = TextUtils.expandTemplate("^2", "foo", "^^"); assertEquals("^^", result.toString()); result = TextUtils.expandTemplate("^^2", "foo", "1"); assertEquals("^2", result.toString()); result = TextUtils.expandTemplate("^1", "value with ^2 in it", "foo"); assertEquals("value with ^2 in it", result.toString()); } /** Fail unless text+spans contains a span 'spanName' with the given start and end.
TextUtilsTest::checkContains
java
google/j2objc
jre_emul/android/frameworks/base/core/tests/coretests/src/android/text/TextUtilsTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/frameworks/base/core/tests/coretests/src/android/text/TextUtilsTest.java
Apache-2.0
public Thread() { this(null, null, THREAD, 0, null); }
Constructs a new Thread with no runnable object and a newly generated name. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor. @see java.lang.ThreadGroup
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(Runnable runnable) { this(null, runnable, THREAD, 0, null); }
Constructs a new Thread with a runnable object and a newly generated name. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor. @param runnable a java.lang.Runnable whose method <code>run</code> will be executed by the new Thread @see java.lang.ThreadGroup @see java.lang.Runnable
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(Runnable runnable, String threadName) { this(null, runnable, threadName, 0, null); }
Constructs a new Thread with a runnable object and name provided. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor. @param runnable a java.lang.Runnable whose method <code>run</code> will be executed by the new Thread @param threadName Name for the Thread being created @see java.lang.ThreadGroup @see java.lang.Runnable
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(String threadName) { this(null, null, threadName, 0, null); }
Constructs a new Thread with no runnable object and the name provided. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor. @param threadName Name for the Thread being created @see java.lang.ThreadGroup @see java.lang.Runnable
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(ThreadGroup group, Runnable runnable) { this(group, runnable, THREAD, 0, null); }
Constructs a new Thread with a runnable object and a newly generated name. The new Thread will belong to the ThreadGroup passed as parameter. @param group ThreadGroup to which the new Thread will belong @param runnable a java.lang.Runnable whose method <code>run</code> will be executed by the new Thread @throws SecurityException if <code>group.checkAccess()</code> fails with a SecurityException @throws IllegalThreadStateException if <code>group.destroy()</code> has already been done @see java.lang.ThreadGroup @see java.lang.Runnable @see java.lang.SecurityException @see java.lang.SecurityManager
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(ThreadGroup group, Runnable runnable, String threadName, long stack) { this(group, runnable, threadName, stack, null); }
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter. @param group ThreadGroup to which the new Thread will belong @param runnable a java.lang.Runnable whose method <code>run</code> will be executed by the new Thread @param threadName Name for the Thread being created @param stack Platform dependent stack size @throws SecurityException if <code>group.checkAccess()</code> fails with a SecurityException @throws IllegalThreadStateException if <code>group.destroy()</code> has already been done @see java.lang.ThreadGroup @see java.lang.Runnable @see java.lang.SecurityException @see java.lang.SecurityManager
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(ThreadGroup group, Runnable runnable, String threadName) { this(group, runnable, threadName, 0, null); }
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter. @param group ThreadGroup to which the new Thread will belong @param runnable a java.lang.Runnable whose method <code>run</code> will be executed by the new Thread @param threadName Name for the Thread being created @throws SecurityException if <code>group.checkAccess()</code> fails with a SecurityException @throws IllegalThreadStateException if <code>group.destroy()</code> has already been done @see java.lang.ThreadGroup @see java.lang.Runnable @see java.lang.SecurityException @see java.lang.SecurityManager
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public Thread(ThreadGroup group, String threadName) { this(group, null, threadName, 0, null); }
Constructs a new Thread with no runnable object, the given name and belonging to the ThreadGroup passed as parameter. @param group ThreadGroup to which the new Thread will belong @param threadName Name for the Thread being created @throws SecurityException if <code>group.checkAccess()</code> fails with a SecurityException @throws IllegalThreadStateException if <code>group.destroy()</code> has already been done @see java.lang.ThreadGroup @see java.lang.SecurityException @see java.lang.SecurityManager
Thread::Thread
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public static void dumpStack() { new Throwable("stack dump").printStackTrace(); }
Prints to the standard error stream a text representation of the current stack for this Thread. @see Throwable#printStackTrace()
Thread::dumpStack
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public void blockedOn(Interruptible b) { synchronized (IOBlockerLock) { IOBlocker = b; } }
Prints to the standard error stream a text representation of the current stack for this Thread. @see Throwable#printStackTrace() public static void dumpStack() { new Throwable("stack dump").printStackTrace(); } public static int enumerate(Thread[] threads) { Thread thread = Thread.currentThread(); return thread.getThreadGroup().enumerate(threads); } public long getId() { return threadId; } public final String getName() { return name; } public final void setName(String name) { checkAccess(); if (name == null) { throw new NullPointerException("name == null"); } this.name = name; } public final int getPriority() { return priority; } public final void setPriority(int newPriority) { ThreadGroup g; checkAccess(); if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) { throw new IllegalArgumentException(); } if ((g = getThreadGroup()) != null) { if (newPriority > g.getMaxPriority()) { newPriority = g.getMaxPriority(); } synchronized (this) { this.priority = newPriority; if (isAlive()) { nativeSetPriority(newPriority); } } } } private native void nativeSetPriority(int priority) /*-[ struct sched_param param; param.sched_priority = (priority * 64 / JavaLangThread_MAX_PRIORITY) - 1; NativeThread *nt = (NativeThread *)self->nativeThread_; pthread_setschedparam(nt->t, SCHED_OTHER, &param); ]-*/; public State getState() { switch (state) { case STATE_NEW: return State.NEW; case STATE_RUNNABLE: return State.RUNNABLE; case STATE_BLOCKED: return State.BLOCKED; case STATE_WAITING: return State.WAITING; case STATE_TIMED_WAITING: return State.TIMED_WAITING; case STATE_TERMINATED: return State.TERMINATED; } // Unreachable. return null; } public ThreadGroup getThreadGroup() { return state == STATE_TERMINATED ? null : threadGroup; } public StackTraceElement[] getStackTrace() { // Get the stack trace for a new exception, stripping the exception's // and preamble's (runtime startup) frames. StackTraceElement[] exceptionTrace = new Throwable().getStackTrace(); int firstElement = 0; int lastElement = exceptionTrace.length; for (int i = 0; i < exceptionTrace.length; i++) { String methodName = exceptionTrace[i].getMethodName(); if (methodName.contains("getStackTrace")) { firstElement = i; continue; } if (methodName.contains("mainWithNSStringArray:")) { lastElement = i; break; } } int nFrames = lastElement - firstElement + 1; if (nFrames < 0) { // Something failed, return the whole stack trace. return exceptionTrace; } if (firstElement + nFrames > exceptionTrace.length) { nFrames = exceptionTrace.length - firstElement; } StackTraceElement[] result = new StackTraceElement[nFrames]; System.arraycopy(exceptionTrace, firstElement, result, 0, nFrames); return result; } @Deprecated public int countStackFrames() { return getStackTrace().length; } /** Set the IOBlocker field; invoked from java.nio code.
Thread::blockedOn
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public void interrupt() { synchronized(nativeThread) { synchronized (interruptActions) { for (int i = interruptActions.size() - 1; i >= 0; i--) { interruptActions.get(i).run(); } } synchronized (IOBlockerLock) { Interruptible b = IOBlocker; if (b != null) { b.interrupt(this); } } if (interrupted) { return; // No further action needed. } interrupted = true; if (blocker != null) { synchronized(blocker) { blocker.notify(); } } } }
Posts an interrupt request to this {@code Thread}. Unless the caller is the {@link #currentThread()}, the method {@code checkAccess()} is called for the installed {@code SecurityManager}, if any. This may result in a {@code SecurityException} being thrown. The further behavior depends on the state of this {@code Thread}: <ul> <li> {@code Thread}s blocked in one of {@code Object}'s {@code wait()} methods or one of {@code Thread}'s {@code join()} or {@code sleep()} methods will be woken up, their interrupt status will be cleared, and they receive an {@link InterruptedException}. <li> {@code Thread}s blocked in an I/O operation of an {@link java.nio.channels.InterruptibleChannel} will have their interrupt status set and receive an {@link java.nio.channels.ClosedByInterruptException}. Also, the channel will be closed. <li> {@code Thread}s blocked in a {@link java.nio.channels.Selector} will have their interrupt status set and return immediately. They don't receive an exception in this case. <ul> @throws SecurityException if <code>checkAccess()</code> fails with a SecurityException @see java.lang.SecurityException @see java.lang.SecurityManager @see Thread#interrupted @see Thread#isInterrupted
Thread::interrupt
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public boolean isInterrupted() { return interrupted; }
Returns a <code>boolean</code> indicating whether the receiver has a pending interrupt request (<code>true</code>) or not ( <code>false</code>) @return a <code>boolean</code> indicating the interrupt status @see Thread#interrupt @see Thread#interrupted
Thread::isInterrupted
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public final void join() throws InterruptedException { if (!isAlive()) { return; } Object lock = currentThread().nativeThread; synchronized (lock) { while (isAlive()) { lock.wait(POLL_INTERVAL); } } }
Blocks the current Thread (<code>Thread.currentThread()</code>) until the receiver finishes its execution and dies. @throws InterruptedException if <code>interrupt()</code> was called for the receiver while it was in the <code>join()</code> call @see Object#notifyAll @see java.lang.ThreadDeath
Thread::join
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public final void join(long millis) throws InterruptedException { join(millis, 0); }
Blocks the current Thread (<code>Thread.currentThread()</code>) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first. @param millis The maximum time to wait (in milliseconds). @throws InterruptedException if <code>interrupt()</code> was called for the receiver while it was in the <code>join()</code> call @see Object#notifyAll @see java.lang.ThreadDeath
Thread::join
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public final void join(long millis, int nanos) throws InterruptedException { if (millis < 0 || nanos < 0 || nanos >= NANOS_PER_MILLI) { throw new IllegalArgumentException("bad timeout: millis=" + millis + ",nanos=" + nanos); } // avoid overflow: if total > 292,277 years, just wait forever boolean overflow = millis >= (Long.MAX_VALUE - nanos) / NANOS_PER_MILLI; boolean forever = (millis | nanos) == 0; if (forever | overflow) { join(); return; } if (!isAlive()) { return; } Object lock = currentThread().nativeThread; synchronized (lock) { if (!isAlive()) { return; } // guaranteed not to overflow long nanosToWait = millis * NANOS_PER_MILLI + nanos; // wait until this thread completes or the timeout has elapsed long start = System.nanoTime(); while (true) { if (millis > POLL_INTERVAL) { lock.wait(POLL_INTERVAL); } else { lock.wait(millis, nanos); } if (!isAlive()) { break; } long nanosElapsed = System.nanoTime() - start; long nanosRemaining = nanosToWait - nanosElapsed; if (nanosRemaining <= 0) { break; } millis = nanosRemaining / NANOS_PER_MILLI; nanos = (int) (nanosRemaining - millis * NANOS_PER_MILLI); } } }
Blocks the current Thread (<code>Thread.currentThread()</code>) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first. @param millis The maximum time to wait (in milliseconds). @param nanos Extra nanosecond precision @throws InterruptedException if <code>interrupt()</code> was called for the receiver while it was in the <code>join()</code> call @see Object#notifyAll @see java.lang.ThreadDeath
Thread::join
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public ClassLoader getContextClassLoader() { return contextClassLoader != null ? contextClassLoader : ClassLoader.getSystemClassLoader(); }
Returns the context ClassLoader for this Thread. @return ClassLoader The context ClassLoader @see java.lang.ClassLoader
Thread::getContextClassLoader
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() { return defaultUncaughtHandler; }
Returns the default exception handler that's executed when uncaught exception terminates a thread. @return an {@link UncaughtExceptionHandler} or <code>null</code> if none exists.
Thread::getDefaultUncaughtExceptionHandler
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler handler) { Thread.defaultUncaughtHandler = handler; }
Sets the default uncaught exception handler. This handler is invoked in case any Thread dies due to an unhandled exception. @param handler The handler to set or null.
Thread::setDefaultUncaughtExceptionHandler
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public UncaughtExceptionHandler getUncaughtExceptionHandler() { UncaughtExceptionHandler h = uncaughtExceptionHandler; return h != null ? h : threadGroup; }
Returns the handler invoked when this thread abruptly terminates due to an uncaught exception. If this thread has not had an uncaught exception handler explicitly set then this thread's <tt>ThreadGroup</tt> object is returned, unless this thread has terminated, in which case <tt>null</tt> is returned. @since 1.5
Thread::getUncaughtExceptionHandler
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh) { checkAccess(); uncaughtExceptionHandler = eh; }
Set the handler invoked when this thread abruptly terminates due to an uncaught exception. <p>A thread can take full control of how it responds to uncaught exceptions by having its uncaught exception handler explicitly set. If no such handler is set then the thread's <tt>ThreadGroup</tt> object acts as its handler. @param eh the object to use as this thread's uncaught exception handler. If <tt>null</tt> then this thread has no explicit handler. @throws SecurityException if the current thread is not allowed to modify this thread. @see #setDefaultUncaughtExceptionHandler @see ThreadGroup#uncaughtException @since 1.5
Thread::setUncaughtExceptionHandler
java
google/j2objc
jre_emul/Classes/java/lang/Thread.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Thread.java
Apache-2.0
public static SecurityManager getSecurityManager() { return null; }
Returns null. Android does not use {@code SecurityManager}. This method is only provided for source compatibility. @return null
System::getSecurityManager
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static String lineSeparator() { return "\n"; // Always return OSX/iOS value. }
Returns the system's line separator. @since 1.7
System::lineSeparator
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static void load(String pathName) { Runtime.getRuntime().load(pathName); }
See {@link Runtime#load}.
System::load
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static void loadLibrary(String libName) { Runtime.getRuntime().loadLibrary(libName); }
See {@link Runtime#loadLibrary}.
System::loadLibrary
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static void runFinalization() {}
No-op on iOS, since it doesn't use garbage collection.
System::runFinalization
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static Console console() { return Console.getConsole(); }
Returns the {@link java.io.Console} associated with this VM, or null. Not all VMs will have an associated console. A console is typically only available for programs run from the command line. @since 1.6
System::console
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public static Channel inheritedChannel() throws IOException { // j2objc: Android always returns null, so avoid calling // SelectorProvider to keep library subsets separate. return null; }
Returns the channel inherited from the entity that created this Java virtual machine. <p> This method returns the channel obtained by invoking the {@link java.nio.channels.spi.SelectorProvider#inheritedChannel inheritedChannel} method of the system-wide default {@link java.nio.channels.spi.SelectorProvider} object. </p> <p> In addition to the network-oriented channels described in {@link java.nio.channels.spi.SelectorProvider#inheritedChannel inheritedChannel}, this method may return other kinds of channels in the future. @return The inherited channel, if any, otherwise <tt>null</tt>. @throws IOException If an I/O error occurs @throws SecurityException If a security manager is present and it does not permit access to the channel. @since 1.5
System::inheritedChannel
java
google/j2objc
jre_emul/Classes/java/lang/System.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/System.java
Apache-2.0
public void load(String absolutePath) {}
No-op on iOS, since all code must be linked into app bundle.
Runtime::load
java
google/j2objc
jre_emul/Classes/java/lang/Runtime.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Runtime.java
Apache-2.0
public void traceInstructions(boolean enable) {}
No-op on iOS.
Runtime::traceInstructions
java
google/j2objc
jre_emul/Classes/java/lang/Runtime.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/Runtime.java
Apache-2.0
public static FileSystemProvider create() { return new MacOSXFileSystemProvider(); }
Returns the default FileSystemProvider.
DefaultFileSystemProvider::create
java
google/j2objc
jre_emul/Classes/sun/nio/fs/DefaultFileSystemProvider.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/sun/nio/fs/DefaultFileSystemProvider.java
Apache-2.0
public LibraryNotLinkedError( String functionalName, String libraryName, String dependencyClassName) { super( String.format( EXCEPTION_MESSAGE, functionalName, libraryName, dependencyClassName, dependencyClassName)); }
Create a new LibraryNotLinkedException. @param functionalName the Java functionality that was requested @param libraryName the name of the J2ObjC JRE library that was not linked @param dependencyClassName the class to statically reference to force linking
LibraryNotLinkedError::LibraryNotLinkedError
java
google/j2objc
jre_emul/Classes/com/google/j2objc/LibraryNotLinkedError.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/LibraryNotLinkedError.java
Apache-2.0
public LibraryNotLinkedError( String functionalName, String libraryName, String dependencyClassName, String addedText, Object... args) { super( String.format( EXCEPTION_MESSAGE, functionalName, libraryName, dependencyClassName, dependencyClassName) + '\n' + String.format(addedText, args)); }
Create a new LibraryNotLinkedException. @param functionalName the Java functionality that was requested @param libraryName the name of the J2ObjC JRE library that was not linked @param dependencyClassName the class to statically reference to force linking @param addedText text to be appended to the exception message @param args any values to be used when formatting the addedText string.
LibraryNotLinkedError::LibraryNotLinkedError
java
google/j2objc
jre_emul/Classes/com/google/j2objc/LibraryNotLinkedError.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/LibraryNotLinkedError.java
Apache-2.0
public ReflectionStrippedError(Class<?> cls) { super(cls.getName() + EXCEPTION_MESSAGE); }
Create a new ReflectionStrippedError.
ReflectionStrippedError::ReflectionStrippedError
java
google/j2objc
jre_emul/Classes/com/google/j2objc/ReflectionStrippedError.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/ReflectionStrippedError.java
Apache-2.0
public Object getNSError() { return nsError; }
Returns the native NSError instance.
NSErrorException::getNSError
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/NSErrorException.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/NSErrorException.java
Apache-2.0
private void loadRequestCookies() throws IOException { CookieHandler cookieHandler = CookieHandler.getDefault(); if (cookieHandler != null) { try { URI uri = getURL().toURI(); Map<String, List<String>> cookieHeaders = cookieHandler.get(uri, getHeaderFieldsDoNotForceResponse()); for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) { String key = entry.getKey(); if (("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key)) && !entry.getValue().isEmpty()) { List<String> cookies = entry.getValue(); StringBuilder sb = new StringBuilder(); for (int i = 0, size = cookies.size(); i < size; i++) { if (i > 0) { sb.append("; "); } sb.append(cookies.get(i)); } setHeader(key, sb.toString()); } } } catch (URISyntaxException e) { throw new IOException(e); } } }
Add any cookies for this URI to the request headers.
IosHttpURLConnection::loadRequestCookies
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/IosHttpURLConnection.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/IosHttpURLConnection.java
Apache-2.0
private void saveResponseCookies() throws IOException { saveResponseCookies(getURL(), getHeaderFieldsDoNotForceResponse()); }
Store any returned cookies.
IosHttpURLConnection::saveResponseCookies
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/IosHttpURLConnection.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/IosHttpURLConnection.java
Apache-2.0
DataEnqueuedInputStream(long timeoutMillis) { this.timeoutMillis = timeoutMillis; }
Create an InputStream with timeout. @param timeoutMillis timeout in millis. If it's negative, the reads will never time out.
DataEnqueuedInputStream::DataEnqueuedInputStream
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
Apache-2.0
void offerData(byte[] chunk) { if (chunk == null || chunk.length == 0) { throw new IllegalArgumentException("chunk must have at least one byte of data"); } if (closed) { return; } // Since this is an unbounded queue, offer() always succeeds. In addition, we don't make a copy // of the chunk, as the data source (NSURLSessionDataTask) does not reuse the underlying byte // array of a chunk when the chunk is alive. queue.offer(chunk); }
Create an InputStream with timeout. @param timeoutMillis timeout in millis. If it's negative, the reads will never time out. DataEnqueuedInputStream(long timeoutMillis) { this.timeoutMillis = timeoutMillis; } /** Offers a chunk of data to the queue.
DataEnqueuedInputStream::offerData
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
Apache-2.0
void endOffering() { endOffering(null); }
Signals that no more data is available without errors. It is ok to call this multiple times.
DataEnqueuedInputStream::endOffering
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
Apache-2.0
void endOffering(IOException exception) { if (closed) { return; } // closed should never be set by this method--only the polling side should do it, as it means // that the CLOSED marker has been encountered. if (this.exception == null) { this.exception = exception; } // Since this is an unbounded queue, offer() always succeeds. queue.offer(CLOSED); }
Signals that no more data is available without errors. It is ok to call this multiple times. void endOffering() { endOffering(null); } /** Signals that no more data is available and an exception should be thrown.
DataEnqueuedInputStream::endOffering
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/DataEnqueuedInputStream.java
Apache-2.0
DataEnqueuedOutputStream(long timeoutMillis) { this.timeoutMillis = timeoutMillis; }
Create an OutputStream with timeout. @param timeoutMillis timeout in millis. If it's negative, the writes will never time out.
DataEnqueuedOutputStream::DataEnqueuedOutputStream
java
google/j2objc
jre_emul/Classes/com/google/j2objc/net/DataEnqueuedOutputStream.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/net/DataEnqueuedOutputStream.java
Apache-2.0
private NativeTimeZone(Object nativeTimeZone, String name, int rawOffset, int dstSavings, boolean useDaylightTime) { if (name.startsWith("GMT-")) { int offsetMillis = rawOffset; if (useDaylightTime) { offsetMillis += dstSavings; } setID(createGmtOffsetString(true, true, offsetMillis)); } else { setID(name); } this.nativeTimeZone = nativeTimeZone; this.rawOffset = rawOffset; this.dstSavings = dstSavings; this.useDaylightTime = useDaylightTime; }
Create an NSTimeZone-backed TimeZone instance. @param nativeTimeZone the NSTimeZone instance. @param name the native time zone's name. @param rawOffset the pre-calculated raw offset (in millis) from UTC. When TimeZone was designed, the assumption was that the rawOffset would be a constant at all times. We pre-compute this offset using the instant when the instance is created. @param useDaylightTime whether this time zone observes DST at the moment this instance is created.
NativeTimeZone::NativeTimeZone
java
google/j2objc
jre_emul/Classes/com/google/j2objc/util/NativeTimeZone.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/util/NativeTimeZone.java
Apache-2.0
public static boolean matchClassNamePrefix(String actual, String expected) { return actual.equals(expected) || actual.equals(getCamelCase(expected)); }
When reflection is stripped, the transpiled code uses NSStringFromClass to return the name of a class. For example, instead of getting something like java.lang.Throwable, we get JavaLangThrowable. <p>This method assumes that {@code actual} and {@code expected} contain a class name as prefix. Firts, it compares directly {@code actual} to {@code expected}; if it fails, then it compares {@actual} to the cammel case version of {@code expected}.
ReflectionUtil::matchClassNamePrefix
java
google/j2objc
jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
Apache-2.0
public static long getSerialVersionUID(Class<? extends Serializable> clazz) { try { return clazz.getField("serialVersionUID").getLong(null); } catch (NoSuchFieldException | IllegalAccessException ex) { // ignored. return 0; } }
Transpiled code that directly acccess the serialVersionUID field when reflection is stripped won't compile because this field is also stripped. <p>Accessing it via reflection allows the non-stripped code to keep the same behavior and allows the stripped code to compile. Note that in the later case, a ReflectionStrippedError will be thrown, this is OK because serialization code is not supported when reflection is stripped.
ReflectionUtil::getSerialVersionUID
java
google/j2objc
jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/util/ReflectionUtil.java
Apache-2.0
private byte[] maybeDecodeBase64(byte[] byteArray) { try { String pem = new String(byteArray); // Remove required begin/end lines. pem = pem.substring(BEGIN_CERT_LINE_LENGTH, pem.length() - END_CERT_LINE_LENGTH); return Base64.getDecoder().decode(pem); } catch (Exception e) { // Not a valid PEM encoded certificate, return original array. return byteArray; } }
Test whether array is a Base64-encoded certificate. If so, return the decoded content instead of the specified array. @see CertificateFactorySpi#engineGenerateCertificate(InputStream)
IosCertificateFactory::maybeDecodeBase64
java
google/j2objc
jre_emul/Classes/com/google/j2objc/security/cert/IosCertificateFactory.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/security/cert/IosCertificateFactory.java
Apache-2.0
public static Object create(Delegate delegate, int bufferSize) { if (bufferSize < 1) { throw new IllegalArgumentException("Invalid buffer size: " + bufferSize); } if (delegate == null) { throw new IllegalArgumentException("Delegate must not be null"); } return nativeCreate(delegate, bufferSize); }
Creates a native NSInputStream that is piped to a NSOutpuStream, which in turn requests data from the supplied delegate asynchronously. <p>Please note that the returned NSInputStream is not yet open. This is to allow the stream to be used by other Foundation API (such as NSMutableURLRequest) and is consistent with other NSInputStream initializers. @param delegate the delegate. @param bufferSize the size of the internal buffer used to pipe the NSOutputStream to the NSInputStream. @return a native NSInputStream.
OutputStreamAdapter::create
java
google/j2objc
jre_emul/Classes/com/google/j2objc/io/AsyncPipedNSInputStreamAdapter.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/com/google/j2objc/io/AsyncPipedNSInputStreamAdapter.java
Apache-2.0
public static ClassLoader getClosestUserClassLoader() { return null; }
Stub implementation of getClosestUserClassLoader() Returns the first ClassLoader on the call stack that isn't the bootstrap class loader.
VMStack::getClosestUserClassLoader
java
google/j2objc
jre_emul/Classes/dalvik/system/VMStack.java
https://github.com/google/j2objc/blob/master/jre_emul/Classes/dalvik/system/VMStack.java
Apache-2.0
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass, String getterName, String setterName, String indexedGetterName, String indexedSetterName) throws IntrospectionException { super(propertyName, beanClass, getterName, setterName); setIndexedByName(beanClass, indexedGetterName, indexedSetterName); }
Constructs a new instance of <code>IndexedPropertyDescriptor</code>. @param propertyName the specified indexed property's name. @param beanClass the bean class @param getterName the name of the array getter @param setterName the name of the array setter @param indexedGetterName the name of the indexed getter. @param indexedSetterName the name of the indexed setter. @throws IntrospectionException
IndexedPropertyDescriptor::IndexedPropertyDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter, Method indexedGetter, Method indexedSetter) throws IntrospectionException { super(propertyName, getter, setter); if (indexedGetter != null) { internalSetIndexedReadMethod(indexedGetter); internalSetIndexedWriteMethod(indexedSetter, true); } else { internalSetIndexedWriteMethod(indexedSetter, true); internalSetIndexedReadMethod(indexedGetter); } if (!isCompatible()) { throw new IntrospectionException( "Property type is incompatible with the indexed property type"); } }
Constructs a new instance of <code>IndexedPropertyDescriptor</code>. @param propertyName the specified indexed property's name. @param getter the array getter @param setter the array setter @param indexedGetter the indexed getter @param indexedSetter the indexed setter @throws IntrospectionException
IndexedPropertyDescriptor::IndexedPropertyDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass) throws IntrospectionException { super(propertyName, beanClass); setIndexedByName(beanClass, "get" //$NON-NLS-1$ .concat(initialUpperCase(propertyName)), "set" //$NON-NLS-1$ .concat(initialUpperCase(propertyName))); }
Constructs a new instance of <code>IndexedPropertyDescriptor</code>. @param propertyName the specified indexed property's name. @param beanClass the bean class. @throws IntrospectionException
IndexedPropertyDescriptor::IndexedPropertyDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public void setIndexedReadMethod(Method indexedGetter) throws IntrospectionException { this.internalSetIndexedReadMethod(indexedGetter); }
Sets the indexed getter as the specified method. @param indexedGetter the specified indexed getter. @throws IntrospectionException
IndexedPropertyDescriptor::setIndexedReadMethod
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public void setIndexedWriteMethod(Method indexedSetter) throws IntrospectionException { this.internalSetIndexedWriteMethod(indexedSetter, false); }
Sets the indexed setter as the specified method. @param indexedSetter the specified indexed setter. @throws IntrospectionException
IndexedPropertyDescriptor::setIndexedWriteMethod
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public Method getIndexedWriteMethod() { return indexedSetter; }
Obtains the indexed setter. @return the indexed setter.
IndexedPropertyDescriptor::getIndexedWriteMethod
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public Method getIndexedReadMethod() { return indexedGetter; }
Obtains the indexed getter. @return the indexed getter.
IndexedPropertyDescriptor::getIndexedReadMethod
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public Class<?> getIndexedPropertyType() { return indexedPropertyType; }
Obtains the Class object of the indexed property type. @return the Class object of the indexed property type.
IndexedPropertyDescriptor::getIndexedPropertyType
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
Apache-2.0
public static String decapitalize(String name) { if (name == null) return null; // The rule for decapitalize is that: // If the first letter of the string is Upper Case, make it lower case // UNLESS the second letter of the string is also Upper Case, in which case no // changes are made. if (name.length() == 0 || (name.length() > 1 && Character.isUpperCase(name.charAt(1)))) { return name; } char[] chars = name.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return new String(chars); }
Decapitalizes a given string according to the rule: <ul> <li>If the first or only character is Upper Case, it is made Lower Case <li>UNLESS the second character is also Upper Case, when the String is returned unchanged <eul> @param name - the String to decapitalize @return the decapitalized version of the String
Introspector::decapitalize
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static void flushCaches() { // Flush the cache by throwing away the cache HashMap and creating a // new empty one theCache.clear(); }
Flushes all <code>BeanInfo</code> caches.
Introspector::flushCaches
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static void flushFromCaches(Class<?> clazz) { if(clazz == null){ throw new NullPointerException(); } theCache.remove(clazz); }
Flushes the <code>BeanInfo</code> caches of the specified bean class @param clazz the specified bean class
Introspector::flushFromCaches
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException { StandardBeanInfo beanInfo = theCache.get(beanClass); if (beanInfo == null) { beanInfo = getBeanInfoImplAndInit(beanClass, null, USE_ALL_BEANINFO); theCache.put(beanClass, beanInfo); } return beanInfo; }
Gets the <code>BeanInfo</code> object which contains the information of the properties, events and methods of the specified bean class. <p> The <code>Introspector</code> will cache the <code>BeanInfo</code> object. Subsequent calls to this method will be answered with the cached data. </p> @param beanClass the specified bean class. @return the <code>BeanInfo</code> of the bean class. @throws IntrospectionException
Introspector::getBeanInfo
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass) throws IntrospectionException { if(stopClass == null){ //try to use cache return getBeanInfo(beanClass); } return getBeanInfoImplAndInit(beanClass, stopClass, USE_ALL_BEANINFO); }
Gets the <code>BeanInfo</code> object which contains the information of the properties, events and methods of the specified bean class. It will not introspect the "stopclass" and its super class. <p> The <code>Introspector</code> will cache the <code>BeanInfo</code> object. Subsequent calls to this method will be answered with the cached data. </p> @param beanClass the specified beanClass. @param stopClass the sopt class which should be super class of the bean class. May be null. @return the <code>BeanInfo</code> of the bean class. @throws IntrospectionException
Introspector::getBeanInfo
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static BeanInfo getBeanInfo(Class<?> beanClass, int flags) throws IntrospectionException { if(flags == USE_ALL_BEANINFO){ //try to use cache return getBeanInfo(beanClass); } return getBeanInfoImplAndInit(beanClass, null, flags); }
Gets the <code>BeanInfo</code> object which contains the information of the properties, events and methods of the specified bean class. <ol> <li>If <code>flag==IGNORE_ALL_BEANINFO</code>, the <code>Introspector</code> will ignore all <code>BeanInfo</code> class.</li> <li>If <code>flag==IGNORE_IMMEDIATE_BEANINFO</code>, the <code>Introspector</code> will ignore the <code>BeanInfo</code> class of the current bean class.</li> <li>If <code>flag==USE_ALL_BEANINFO</code>, the <code>Introspector</code> will use all <code>BeanInfo</code> class which have been found.</li> </ol> <p> The <code>Introspector</code> will cache the <code>BeanInfo</code> object. Subsequent calls to this method will be answered with the cached data. </p> @param beanClass the specified bean class. @param flags the flag to control the usage of the explicit <code>BeanInfo</code> class. @return the <code>BeanInfo</code> of the bean class. @throws IntrospectionException
Introspector::getBeanInfo
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static String[] getBeanInfoSearchPath() { String[] path = new String[searchPath.length]; System.arraycopy(searchPath, 0, path, 0, searchPath.length); return path; }
Gets an array of search packages. @return an array of search packages.
Introspector::getBeanInfoSearchPath
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public static void setBeanInfoSearchPath(String[] path) { // if (System.getSecurityManager() != null) { // System.getSecurityManager().checkPropertiesAccess(); // } searchPath = path; }
Sets the search packages. @param path the new search packages to be set.
Introspector::setBeanInfoSearchPath
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
private static BeanInfo loadBeanInfo(String beanInfoClassName, Class<?> beanClass) throws Exception{ try { ClassLoader cl = beanClass.getClassLoader(); if(cl != null){ return (BeanInfo) Class.forName(beanInfoClassName, true, beanClass.getClassLoader()).newInstance(); } } catch (Exception e) { // fall through } try { return (BeanInfo) Class.forName(beanInfoClassName, true, ClassLoader.getSystemClassLoader()).newInstance(); } catch (Exception e) { // fall through } return (BeanInfo) Class.forName(beanInfoClassName, true, Thread.currentThread().getContextClassLoader()).newInstance(); }
Sets the search packages. @param path the new search packages to be set. public static void setBeanInfoSearchPath(String[] path) { // if (System.getSecurityManager() != null) { // System.getSecurityManager().checkPropertiesAccess(); // } searchPath = path; } private static StandardBeanInfo getBeanInfoImpl(Class<?> beanClass, Class<?> stopClass, int flags) throws IntrospectionException { BeanInfo explicitInfo = null; if (flags == USE_ALL_BEANINFO) { explicitInfo = getExplicitBeanInfo(beanClass); } StandardBeanInfo beanInfo = new StandardBeanInfo(beanClass, explicitInfo, stopClass); if (beanInfo.additionalBeanInfo != null) { for (int i = beanInfo.additionalBeanInfo.length-1; i >=0; i--) { BeanInfo info = beanInfo.additionalBeanInfo[i]; beanInfo.mergeBeanInfo(info, true); } } // recursive get beaninfo for super classes Class<?> beanSuperClass = beanClass.getSuperclass(); if (beanSuperClass != stopClass) { if (beanSuperClass == null) throw new IntrospectionException( "Stop class is not super class of bean class"); //$NON-NLS-1$ int superflags = flags == IGNORE_IMMEDIATE_BEANINFO ? USE_ALL_BEANINFO : flags; BeanInfo superBeanInfo = getBeanInfoImpl(beanSuperClass, stopClass, superflags); if (superBeanInfo != null) { beanInfo.mergeBeanInfo(superBeanInfo, false); } } return beanInfo; } private static BeanInfo getExplicitBeanInfo(Class<?> beanClass) { String beanInfoClassName = beanClass.getName() + "BeanInfo"; //$NON-NLS-1$ try { return loadBeanInfo(beanInfoClassName, beanClass); } catch (Exception e) { // fall through } int index = beanInfoClassName.lastIndexOf('.'); String beanInfoName = index >= 0 ? beanInfoClassName .substring(index + 1) : beanInfoClassName; BeanInfo theBeanInfo = null; BeanDescriptor beanDescriptor = null; for (int i = 0; i < searchPath.length; i++) { beanInfoClassName = searchPath[i] + "." + beanInfoName; //$NON-NLS-1$ try { theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass); } catch (Exception e) { // ignore, try next one continue; } beanDescriptor = theBeanInfo.getBeanDescriptor(); if (beanDescriptor != null && beanClass == beanDescriptor.getBeanClass()) { return theBeanInfo; } } if (BeanInfo.class.isAssignableFrom(beanClass)) { try { return loadBeanInfo(beanClass.getName(), beanClass); } catch (Exception e) { // fall through } } return null; } /* Method which attempts to instantiate a BeanInfo object of the supplied classname @param theBeanInfoClassName - the Class Name of the class of which the BeanInfo is an instance @param classLoader @return A BeanInfo object which is an instance of the Class named theBeanInfoClassName null if the Class does not exist or if there are problems instantiating the instance
Introspector::loadBeanInfo
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Apache-2.0
public MethodDescriptor(Method method, ParameterDescriptor[] parameterDescriptors) { super(); if (method == null) { throw new NullPointerException(); } this.method = method; this.parameterDescriptors = parameterDescriptors; setName(method.getName()); }
<p> Constructs an instance with the given {@link Method} and {@link ParameterDescriptor}s. The {@link #getName()} is set as the name of the <code>method</code> passed. </p> @param method The Method to set. @param parameterDescriptors An array of parameter descriptors.
MethodDescriptor::MethodDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
Apache-2.0
public MethodDescriptor(Method method) { super(); if (method == null) { throw new NullPointerException(); } this.method = method; setName(method.getName()); }
<p> Constructs an instance with the given {@link Method}. The {@link #getName()} is set as the name of the <code>method</code> passed. </p> @param method The Method to set.
MethodDescriptor::MethodDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
Apache-2.0
public ParameterDescriptor[] getParameterDescriptors() { return parameterDescriptors; }
<p> Gets the parameter descriptors. </p> @return An array of {@link ParameterDescriptor} instance or <code>null</code>.
MethodDescriptor::getParameterDescriptors
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/MethodDescriptor.java
Apache-2.0
public FeatureDescriptor() { this.values = new HashMap<String, Object>(); }
<p> Constructs an instance. </p>
FeatureDescriptor::FeatureDescriptor
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
Apache-2.0
public void setValue(String attributeName, Object value) { if (attributeName == null || value == null) { throw new NullPointerException(); } values.put(attributeName, value); }
<p> Sets the value for the named attribute. </p> @param attributeName The name of the attribute to set a value with. @param value The value to set.
FeatureDescriptor::setValue
java
google/j2objc
jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
https://github.com/google/j2objc/blob/master/jre_emul/apache_harmony/classlib/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
Apache-2.0