id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
8,100
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/raw/CustomStorableCodec.java
CustomStorableCodec.getStorableClass
@SuppressWarnings("unchecked") static <S extends Storable> Class<? extends S> getStorableClass(Class<S> type, boolean isMaster) throws SupportException { synchronized (cCache) { Class<? extends S> storableClass; RawStorableGenerator.Flavors<S> flavors = (RawStorableGenerator.Flavors<S>) cCache.get(type); if (flavors == null) { flavors = new RawStorableGenerator.Flavors<S>(); cCache.put(type, flavors); } else if ((storableClass = flavors.getClass(isMaster)) != null) { return storableClass; } storableClass = generateStorableClass(type, isMaster); flavors.setClass(storableClass, isMaster); return storableClass; } }
java
@SuppressWarnings("unchecked") static <S extends Storable> Class<? extends S> getStorableClass(Class<S> type, boolean isMaster) throws SupportException { synchronized (cCache) { Class<? extends S> storableClass; RawStorableGenerator.Flavors<S> flavors = (RawStorableGenerator.Flavors<S>) cCache.get(type); if (flavors == null) { flavors = new RawStorableGenerator.Flavors<S>(); cCache.put(type, flavors); } else if ((storableClass = flavors.getClass(isMaster)) != null) { return storableClass; } storableClass = generateStorableClass(type, isMaster); flavors.setClass(storableClass, isMaster); return storableClass; } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "static", "<", "S", "extends", "Storable", ">", "Class", "<", "?", "extends", "S", ">", "getStorableClass", "(", "Class", "<", "S", ">", "type", ",", "boolean", "isMaster", ")", "throws", "SupportException", "{", "synchronized", "(", "cCache", ")", "{", "Class", "<", "?", "extends", "S", ">", "storableClass", ";", "RawStorableGenerator", ".", "Flavors", "<", "S", ">", "flavors", "=", "(", "RawStorableGenerator", ".", "Flavors", "<", "S", ">", ")", "cCache", ".", "get", "(", "type", ")", ";", "if", "(", "flavors", "==", "null", ")", "{", "flavors", "=", "new", "RawStorableGenerator", ".", "Flavors", "<", "S", ">", "(", ")", ";", "cCache", ".", "put", "(", "type", ",", "flavors", ")", ";", "}", "else", "if", "(", "(", "storableClass", "=", "flavors", ".", "getClass", "(", "isMaster", ")", ")", "!=", "null", ")", "{", "return", "storableClass", ";", "}", "storableClass", "=", "generateStorableClass", "(", "type", ",", "isMaster", ")", ";", "flavors", ".", "setClass", "(", "storableClass", ",", "isMaster", ")", ";", "return", "storableClass", ";", "}", "}" ]
Returns a storable implementation that calls into CustomStorableCodec implementation for encoding and decoding.
[ "Returns", "a", "storable", "implementation", "that", "calls", "into", "CustomStorableCodec", "implementation", "for", "encoding", "and", "decoding", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/raw/CustomStorableCodec.java#L62-L85
8,101
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/raw/CustomStorableCodec.java
CustomStorableCodec.buildPkIndex
@SuppressWarnings("unchecked") public StorableIndex<S> buildPkIndex(String... propertyNames) { Map<String, ? extends StorableProperty<S>> map = getAllProperties(); int length = propertyNames.length; StorableProperty<S>[] properties = new StorableProperty[length]; Direction[] directions = new Direction[length]; for (int i=0; i<length; i++) { String name = propertyNames[i]; char c = name.charAt(0); Direction dir = Direction.fromCharacter(c); if (dir != Direction.UNSPECIFIED || c == Direction.UNSPECIFIED.toCharacter()) { name = name.substring(1); } else { // Default to ascending if not specified. dir = Direction.ASCENDING; } if ((properties[i] = map.get(name)) == null) { throw new IllegalArgumentException("Unknown property: " + name); } directions[i] = dir; } return new StorableIndex<S>(properties, directions, true, true); }
java
@SuppressWarnings("unchecked") public StorableIndex<S> buildPkIndex(String... propertyNames) { Map<String, ? extends StorableProperty<S>> map = getAllProperties(); int length = propertyNames.length; StorableProperty<S>[] properties = new StorableProperty[length]; Direction[] directions = new Direction[length]; for (int i=0; i<length; i++) { String name = propertyNames[i]; char c = name.charAt(0); Direction dir = Direction.fromCharacter(c); if (dir != Direction.UNSPECIFIED || c == Direction.UNSPECIFIED.toCharacter()) { name = name.substring(1); } else { // Default to ascending if not specified. dir = Direction.ASCENDING; } if ((properties[i] = map.get(name)) == null) { throw new IllegalArgumentException("Unknown property: " + name); } directions[i] = dir; } return new StorableIndex<S>(properties, directions, true, true); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "StorableIndex", "<", "S", ">", "buildPkIndex", "(", "String", "...", "propertyNames", ")", "{", "Map", "<", "String", ",", "?", "extends", "StorableProperty", "<", "S", ">", ">", "map", "=", "getAllProperties", "(", ")", ";", "int", "length", "=", "propertyNames", ".", "length", ";", "StorableProperty", "<", "S", ">", "[", "]", "properties", "=", "new", "StorableProperty", "[", "length", "]", ";", "Direction", "[", "]", "directions", "=", "new", "Direction", "[", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "String", "name", "=", "propertyNames", "[", "i", "]", ";", "char", "c", "=", "name", ".", "charAt", "(", "0", ")", ";", "Direction", "dir", "=", "Direction", ".", "fromCharacter", "(", "c", ")", ";", "if", "(", "dir", "!=", "Direction", ".", "UNSPECIFIED", "||", "c", "==", "Direction", ".", "UNSPECIFIED", ".", "toCharacter", "(", ")", ")", "{", "name", "=", "name", ".", "substring", "(", "1", ")", ";", "}", "else", "{", "// Default to ascending if not specified.\r", "dir", "=", "Direction", ".", "ASCENDING", ";", "}", "if", "(", "(", "properties", "[", "i", "]", "=", "map", ".", "get", "(", "name", ")", ")", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unknown property: \"", "+", "name", ")", ";", "}", "directions", "[", "i", "]", "=", "dir", ";", "}", "return", "new", "StorableIndex", "<", "S", ">", "(", "properties", ",", "directions", ",", "true", ",", "true", ")", ";", "}" ]
Convenient way to define the clustered primary key index descriptor. Direction can be specified by prefixing the property name with a '+' or '-'. If unspecified, direction is assumed to be ascending.
[ "Convenient", "way", "to", "define", "the", "clustered", "primary", "key", "index", "descriptor", ".", "Direction", "can", "be", "specified", "by", "prefixing", "the", "property", "name", "with", "a", "+", "or", "-", ".", "If", "unspecified", "direction", "is", "assumed", "to", "be", "ascending", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/raw/CustomStorableCodec.java#L340-L362
8,102
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java
PropertyFilterList.getPreviousRemaining
public int getPreviousRemaining() { int remaining = mPrevRemaining; if (remaining < 0) { mPrevRemaining = remaining = ((mPrev == null) ? 0 : (mPrev.getPreviousRemaining() + 1)); } return remaining; }
java
public int getPreviousRemaining() { int remaining = mPrevRemaining; if (remaining < 0) { mPrevRemaining = remaining = ((mPrev == null) ? 0 : (mPrev.getPreviousRemaining() + 1)); } return remaining; }
[ "public", "int", "getPreviousRemaining", "(", ")", "{", "int", "remaining", "=", "mPrevRemaining", ";", "if", "(", "remaining", "<", "0", ")", "{", "mPrevRemaining", "=", "remaining", "=", "(", "(", "mPrev", "==", "null", ")", "?", "0", ":", "(", "mPrev", ".", "getPreviousRemaining", "(", ")", "+", "1", ")", ")", ";", "}", "return", "remaining", ";", "}" ]
Returns the amount of previous remaining list nodes.
[ "Returns", "the", "amount", "of", "previous", "remaining", "list", "nodes", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java#L97-L104
8,103
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java
PropertyFilterList.getBlankCount
public int getBlankCount() { int count = mBlankCount; if (count < 0) { mBlankCount = count = (mPropFilter.isConstant() ? 0 : 1) + ((mPrev == null) ? 0 : mPrev.getBlankCount()); } return count; }
java
public int getBlankCount() { int count = mBlankCount; if (count < 0) { mBlankCount = count = (mPropFilter.isConstant() ? 0 : 1) + ((mPrev == null) ? 0 : mPrev.getBlankCount()); } return count; }
[ "public", "int", "getBlankCount", "(", ")", "{", "int", "count", "=", "mBlankCount", ";", "if", "(", "count", "<", "0", ")", "{", "mBlankCount", "=", "count", "=", "(", "mPropFilter", ".", "isConstant", "(", ")", "?", "0", ":", "1", ")", "+", "(", "(", "mPrev", "==", "null", ")", "?", "0", ":", "mPrev", ".", "getBlankCount", "(", ")", ")", ";", "}", "return", "count", ";", "}" ]
Returns the amount of non-constant list nodes up to this node.
[ "Returns", "the", "amount", "of", "non", "-", "constant", "list", "nodes", "up", "to", "this", "node", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java#L109-L116
8,104
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java
PropertyFilterList.contains
public boolean contains(PropertyFilter<S> propFilter) { if (mPropFilter == propFilter) { return true; } if (mNext == null) { return false; } // Tail recursion. return mNext.contains(propFilter); }
java
public boolean contains(PropertyFilter<S> propFilter) { if (mPropFilter == propFilter) { return true; } if (mNext == null) { return false; } // Tail recursion. return mNext.contains(propFilter); }
[ "public", "boolean", "contains", "(", "PropertyFilter", "<", "S", ">", "propFilter", ")", "{", "if", "(", "mPropFilter", "==", "propFilter", ")", "{", "return", "true", ";", "}", "if", "(", "mNext", "==", "null", ")", "{", "return", "false", ";", "}", "// Tail recursion.\r", "return", "mNext", ".", "contains", "(", "propFilter", ")", ";", "}" ]
Searches list for given PropertyFilter.
[ "Searches", "list", "for", "given", "PropertyFilter", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java#L145-L154
8,105
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java
PropertyFilterList.prepend
PropertyFilterList<S> prepend(PropertyFilter<S> propFilter) { PropertyFilterList<S> head = new PropertyFilterList<S>(propFilter, this); mPrev = head; return head; }
java
PropertyFilterList<S> prepend(PropertyFilter<S> propFilter) { PropertyFilterList<S> head = new PropertyFilterList<S>(propFilter, this); mPrev = head; return head; }
[ "PropertyFilterList", "<", "S", ">", "prepend", "(", "PropertyFilter", "<", "S", ">", "propFilter", ")", "{", "PropertyFilterList", "<", "S", ">", "head", "=", "new", "PropertyFilterList", "<", "S", ">", "(", "propFilter", ",", "this", ")", ";", "mPrev", "=", "head", ";", "return", "head", ";", "}" ]
Prepend a node to the head of the list.
[ "Prepend", "a", "node", "to", "the", "head", "of", "the", "list", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/PropertyFilterList.java#L159-L163
8,106
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java
SortedQueryExecutor.printNative
@Override public boolean printNative(Appendable app, int indentLevel, FilterValues<S> values) throws IOException { return mExecutor.printNative(app, indentLevel, values); }
java
@Override public boolean printNative(Appendable app, int indentLevel, FilterValues<S> values) throws IOException { return mExecutor.printNative(app, indentLevel, values); }
[ "@", "Override", "public", "boolean", "printNative", "(", "Appendable", "app", ",", "int", "indentLevel", ",", "FilterValues", "<", "S", ">", "values", ")", "throws", "IOException", "{", "return", "mExecutor", ".", "printNative", "(", "app", ",", "indentLevel", ",", "values", ")", ";", "}" ]
Prints native query of the wrapped executor.
[ "Prints", "native", "query", "of", "the", "wrapped", "executor", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/SortedQueryExecutor.java#L144-L149
8,107
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java
FilteredCursorGenerator.getFactory
@SuppressWarnings("unchecked") static <S extends Storable> Factory<S> getFactory(Filter<S> filter) { if (filter == null) { throw new IllegalArgumentException(); } synchronized (cCache) { Factory<S> factory = (Factory<S>) cCache.get(filter); if (factory != null) { return factory; } Class<Cursor<S>> clazz = generateClass(filter); factory = QuickConstructorGenerator.getInstance(clazz, Factory.class); cCache.put(filter, factory); return factory; } }
java
@SuppressWarnings("unchecked") static <S extends Storable> Factory<S> getFactory(Filter<S> filter) { if (filter == null) { throw new IllegalArgumentException(); } synchronized (cCache) { Factory<S> factory = (Factory<S>) cCache.get(filter); if (factory != null) { return factory; } Class<Cursor<S>> clazz = generateClass(filter); factory = QuickConstructorGenerator.getInstance(clazz, Factory.class); cCache.put(filter, factory); return factory; } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "static", "<", "S", "extends", "Storable", ">", "Factory", "<", "S", ">", "getFactory", "(", "Filter", "<", "S", ">", "filter", ")", "{", "if", "(", "filter", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "synchronized", "(", "cCache", ")", "{", "Factory", "<", "S", ">", "factory", "=", "(", "Factory", "<", "S", ">", ")", "cCache", ".", "get", "(", "filter", ")", ";", "if", "(", "factory", "!=", "null", ")", "{", "return", "factory", ";", "}", "Class", "<", "Cursor", "<", "S", ">", ">", "clazz", "=", "generateClass", "(", "filter", ")", ";", "factory", "=", "QuickConstructorGenerator", ".", "getInstance", "(", "clazz", ",", "Factory", ".", "class", ")", ";", "cCache", ".", "put", "(", "filter", ",", "factory", ")", ";", "return", "factory", ";", "}", "}" ]
Returns a factory for creating new filtered cursor instances. @param filter filter specification @throws IllegalArgumentException if filter is null @throws UnsupportedOperationException if filter is not supported
[ "Returns", "a", "factory", "for", "creating", "new", "filtered", "cursor", "instances", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java#L87-L102
8,108
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JoinNode.java
JoinNode.appendTableNameAndAliasTo
public void appendTableNameAndAliasTo(SQLStatementBuilder fromClause) { appendTableNameTo(fromClause); fromClause.append(' '); fromClause.append(mAlias); }
java
public void appendTableNameAndAliasTo(SQLStatementBuilder fromClause) { appendTableNameTo(fromClause); fromClause.append(' '); fromClause.append(mAlias); }
[ "public", "void", "appendTableNameAndAliasTo", "(", "SQLStatementBuilder", "fromClause", ")", "{", "appendTableNameTo", "(", "fromClause", ")", ";", "fromClause", ".", "append", "(", "'", "'", ")", ";", "fromClause", ".", "append", "(", "mAlias", ")", ";", "}" ]
Appends table name and alias to the given FROM clause builder.
[ "Appends", "table", "name", "and", "alias", "to", "the", "given", "FROM", "clause", "builder", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JoinNode.java#L112-L116
8,109
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java
IndexedQueryExecutor.compareWithNullHigh
static int compareWithNullHigh(Object a, Object b) { return a == null ? (b == null ? 0 : -1) : (b == null ? 1 : ((Comparable) a).compareTo(b)); }
java
static int compareWithNullHigh(Object a, Object b) { return a == null ? (b == null ? 0 : -1) : (b == null ? 1 : ((Comparable) a).compareTo(b)); }
[ "static", "int", "compareWithNullHigh", "(", "Object", "a", ",", "Object", "b", ")", "{", "return", "a", "==", "null", "?", "(", "b", "==", "null", "?", "0", ":", "-", "1", ")", ":", "(", "b", "==", "null", "?", "1", ":", "(", "(", "Comparable", ")", "a", ")", ".", "compareTo", "(", "b", ")", ")", ";", "}" ]
Compares two objects which are assumed to be Comparable. If one value is null, it is treated as being higher. This consistent with all other property value comparisons in carbonado.
[ "Compares", "two", "objects", "which", "are", "assumed", "to", "be", "Comparable", ".", "If", "one", "value", "is", "null", "it", "is", "treated", "as", "being", "higher", ".", "This", "consistent", "with", "all", "other", "property", "value", "comparisons", "in", "carbonado", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/IndexedQueryExecutor.java#L49-L51
8,110
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.inflateView
private void inflateView() { parentView = createParentView(); view = createView(); view.setOnFocusChangeListener(createFocusChangeListener()); view.setBackgroundResource(R.drawable.validateable_view_background); setLineColor(getAccentColor()); if (parentView != null) { parentView.addView(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); addView(parentView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } else { addView(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } }
java
private void inflateView() { parentView = createParentView(); view = createView(); view.setOnFocusChangeListener(createFocusChangeListener()); view.setBackgroundResource(R.drawable.validateable_view_background); setLineColor(getAccentColor()); if (parentView != null) { parentView.addView(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); addView(parentView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } else { addView(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); } }
[ "private", "void", "inflateView", "(", ")", "{", "parentView", "=", "createParentView", "(", ")", ";", "view", "=", "createView", "(", ")", ";", "view", ".", "setOnFocusChangeListener", "(", "createFocusChangeListener", "(", ")", ")", ";", "view", ".", "setBackgroundResource", "(", "R", ".", "drawable", ".", "validateable_view_background", ")", ";", "setLineColor", "(", "getAccentColor", "(", ")", ")", ";", "if", "(", "parentView", "!=", "null", ")", "{", "parentView", ".", "addView", "(", "view", ",", "LayoutParams", ".", "MATCH_PARENT", ",", "LayoutParams", ".", "WRAP_CONTENT", ")", ";", "addView", "(", "parentView", ",", "LayoutParams", ".", "MATCH_PARENT", ",", "LayoutParams", ".", "WRAP_CONTENT", ")", ";", "}", "else", "{", "addView", "(", "view", ",", "LayoutParams", ".", "MATCH_PARENT", ",", "LayoutParams", ".", "WRAP_CONTENT", ")", ";", "}", "}" ]
Inflates the view, whose value should be able to be validated.
[ "Inflates", "the", "view", "whose", "value", "should", "be", "able", "to", "be", "validated", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L315-L328
8,111
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.inflateErrorMessageTextViews
private void inflateErrorMessageTextViews() { View parent = View.inflate(getContext(), R.layout.error_messages, null); addView(parent, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); leftMessage = parent.findViewById(R.id.left_error_message); leftMessage.setTag(false); rightMessage = parent.findViewById(R.id.right_error_message); rightMessage.setTag(false); }
java
private void inflateErrorMessageTextViews() { View parent = View.inflate(getContext(), R.layout.error_messages, null); addView(parent, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); leftMessage = parent.findViewById(R.id.left_error_message); leftMessage.setTag(false); rightMessage = parent.findViewById(R.id.right_error_message); rightMessage.setTag(false); }
[ "private", "void", "inflateErrorMessageTextViews", "(", ")", "{", "View", "parent", "=", "View", ".", "inflate", "(", "getContext", "(", ")", ",", "R", ".", "layout", ".", "error_messages", ",", "null", ")", ";", "addView", "(", "parent", ",", "LayoutParams", ".", "MATCH_PARENT", ",", "LayoutParams", ".", "WRAP_CONTENT", ")", ";", "leftMessage", "=", "parent", ".", "findViewById", "(", "R", ".", "id", ".", "left_error_message", ")", ";", "leftMessage", ".", "setTag", "(", "false", ")", ";", "rightMessage", "=", "parent", ".", "findViewById", "(", "R", ".", "id", ".", "right_error_message", ")", ";", "rightMessage", ".", "setTag", "(", "false", ")", ";", "}" ]
Inflates the text views, which are used to show validation errors.
[ "Inflates", "the", "text", "views", "which", "are", "used", "to", "show", "validation", "errors", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L333-L340
8,112
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.createFocusChangeListener
private OnFocusChangeListener createFocusChangeListener() { return new OnFocusChangeListener() { @Override public final void onFocusChange(final View view, final boolean hasFocus) { if (!hasFocus && isValidatedOnFocusLost()) { validate(); } } }; }
java
private OnFocusChangeListener createFocusChangeListener() { return new OnFocusChangeListener() { @Override public final void onFocusChange(final View view, final boolean hasFocus) { if (!hasFocus && isValidatedOnFocusLost()) { validate(); } } }; }
[ "private", "OnFocusChangeListener", "createFocusChangeListener", "(", ")", "{", "return", "new", "OnFocusChangeListener", "(", ")", "{", "@", "Override", "public", "final", "void", "onFocusChange", "(", "final", "View", "view", ",", "final", "boolean", "hasFocus", ")", "{", "if", "(", "!", "hasFocus", "&&", "isValidatedOnFocusLost", "(", ")", ")", "{", "validate", "(", ")", ";", "}", "}", "}", ";", "}" ]
Creates and returns a listener, which allows to validate the value of the view, when the view loses its focus. @return The listener, which has been created, as an instance of the type {@link OnFocusChangeListener}
[ "Creates", "and", "returns", "a", "listener", "which", "allows", "to", "validate", "the", "value", "of", "the", "view", "when", "the", "view", "loses", "its", "focus", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L349-L360
8,113
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.notifyOnValidationFailure
private void notifyOnValidationFailure(@NonNull final Validator<ValueType> validator) { for (ValidationListener<ValueType> listener : listeners) { listener.onValidationFailure(this, validator); } }
java
private void notifyOnValidationFailure(@NonNull final Validator<ValueType> validator) { for (ValidationListener<ValueType> listener : listeners) { listener.onValidationFailure(this, validator); } }
[ "private", "void", "notifyOnValidationFailure", "(", "@", "NonNull", "final", "Validator", "<", "ValueType", ">", "validator", ")", "{", "for", "(", "ValidationListener", "<", "ValueType", ">", "listener", ":", "listeners", ")", "{", "listener", ".", "onValidationFailure", "(", "this", ",", "validator", ")", ";", "}", "}" ]
Notifies all registered listeners, that a validation failed. @param validator The validator, which failed, as an instance of the type {@link Validator}. The validator may not be null
[ "Notifies", "all", "registered", "listeners", "that", "a", "validation", "failed", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L378-L382
8,114
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.validateLeft
private Validator<ValueType> validateLeft() { Validator<ValueType> result = null; Collection<Validator<ValueType>> subValidators = onGetLeftErrorMessage(); if (subValidators != null) { for (Validator<ValueType> validator : subValidators) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } for (Validator<ValueType> validator : validators) { if (!validator.validate(getValue())) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } return result; }
java
private Validator<ValueType> validateLeft() { Validator<ValueType> result = null; Collection<Validator<ValueType>> subValidators = onGetLeftErrorMessage(); if (subValidators != null) { for (Validator<ValueType> validator : subValidators) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } for (Validator<ValueType> validator : validators) { if (!validator.validate(getValue())) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } return result; }
[ "private", "Validator", "<", "ValueType", ">", "validateLeft", "(", ")", "{", "Validator", "<", "ValueType", ">", "result", "=", "null", ";", "Collection", "<", "Validator", "<", "ValueType", ">", ">", "subValidators", "=", "onGetLeftErrorMessage", "(", ")", ";", "if", "(", "subValidators", "!=", "null", ")", "{", "for", "(", "Validator", "<", "ValueType", ">", "validator", ":", "subValidators", ")", "{", "notifyOnValidationFailure", "(", "validator", ")", ";", "if", "(", "result", "==", "null", ")", "{", "result", "=", "validator", ";", "}", "}", "}", "for", "(", "Validator", "<", "ValueType", ">", "validator", ":", "validators", ")", "{", "if", "(", "!", "validator", ".", "validate", "(", "getValue", "(", ")", ")", ")", "{", "notifyOnValidationFailure", "(", "validator", ")", ";", "if", "(", "result", "==", "null", ")", "{", "result", "=", "validator", ";", "}", "}", "}", "return", "result", ";", "}" ]
Validates the current value of the view in order to retrieve the error message and icon, which should be shown at the left edge of the view, if a validation fails. @return The validator, which failed or null, if the validation succeeded
[ "Validates", "the", "current", "value", "of", "the", "view", "in", "order", "to", "retrieve", "the", "error", "message", "and", "icon", "which", "should", "be", "shown", "at", "the", "left", "edge", "of", "the", "view", "if", "a", "validation", "fails", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L390-L415
8,115
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.validateRight
private Validator<ValueType> validateRight() { Validator<ValueType> result = null; Collection<Validator<ValueType>> subValidators = onGetRightErrorMessage(); if (subValidators != null) { for (Validator<ValueType> validator : subValidators) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } return result; }
java
private Validator<ValueType> validateRight() { Validator<ValueType> result = null; Collection<Validator<ValueType>> subValidators = onGetRightErrorMessage(); if (subValidators != null) { for (Validator<ValueType> validator : subValidators) { notifyOnValidationFailure(validator); if (result == null) { result = validator; } } } return result; }
[ "private", "Validator", "<", "ValueType", ">", "validateRight", "(", ")", "{", "Validator", "<", "ValueType", ">", "result", "=", "null", ";", "Collection", "<", "Validator", "<", "ValueType", ">", ">", "subValidators", "=", "onGetRightErrorMessage", "(", ")", ";", "if", "(", "subValidators", "!=", "null", ")", "{", "for", "(", "Validator", "<", "ValueType", ">", "validator", ":", "subValidators", ")", "{", "notifyOnValidationFailure", "(", "validator", ")", ";", "if", "(", "result", "==", "null", ")", "{", "result", "=", "validator", ";", "}", "}", "}", "return", "result", ";", "}" ]
Validates the current value of the view in order to retrieve the error message and icon, which should be shown at the right edge of the view, if a validation fails. @return The validator, which failed or null, if the validation succeeded
[ "Validates", "the", "current", "value", "of", "the", "view", "in", "order", "to", "retrieve", "the", "error", "message", "and", "icon", "which", "should", "be", "shown", "at", "the", "right", "edge", "of", "the", "view", "if", "a", "validation", "fails", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L423-L438
8,116
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setLineColor
private void setLineColor(@ColorInt final int color) { view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP); }
java
private void setLineColor(@ColorInt final int color) { view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP); }
[ "private", "void", "setLineColor", "(", "@", "ColorInt", "final", "int", "color", ")", "{", "view", ".", "getBackground", "(", ")", ".", "setColorFilter", "(", "color", ",", "PorterDuff", ".", "Mode", ".", "SRC_ATOP", ")", ";", "}" ]
Sets the color of the view's line. @param color The color, which should be set, as an {@link Integer} value
[ "Sets", "the", "color", "of", "the", "view", "s", "line", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L457-L459
8,117
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setEnabledOnViewGroup
private void setEnabledOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean enabled) { viewGroup.setEnabled(enabled); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setEnabledOnViewGroup((ViewGroup) child, enabled); } else { child.setEnabled(enabled); } } }
java
private void setEnabledOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean enabled) { viewGroup.setEnabled(enabled); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setEnabledOnViewGroup((ViewGroup) child, enabled); } else { child.setEnabled(enabled); } } }
[ "private", "void", "setEnabledOnViewGroup", "(", "@", "NonNull", "final", "ViewGroup", "viewGroup", ",", "final", "boolean", "enabled", ")", "{", "viewGroup", ".", "setEnabled", "(", "enabled", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "viewGroup", ".", "getChildCount", "(", ")", ";", "i", "++", ")", "{", "View", "child", "=", "viewGroup", ".", "getChildAt", "(", "i", ")", ";", "if", "(", "child", "instanceof", "ViewGroup", ")", "{", "setEnabledOnViewGroup", "(", "(", "ViewGroup", ")", "child", ",", "enabled", ")", ";", "}", "else", "{", "child", ".", "setEnabled", "(", "enabled", ")", ";", "}", "}", "}" ]
Adapts the enable state of all children of a specific view group. @param viewGroup The view group, whose children's enabled states should be adapted, as an instance of the class {@link ViewGroup}. The view group may not be null @param enabled True, if the children should be enabled, false otherwise
[ "Adapts", "the", "enable", "state", "of", "all", "children", "of", "a", "specific", "view", "group", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L470-L482
8,118
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setActivatedOnViewGroup
private void setActivatedOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean activated) { viewGroup.setActivated(activated); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setActivatedOnViewGroup((ViewGroup) child, activated); } else { child.setActivated(activated); } } }
java
private void setActivatedOnViewGroup(@NonNull final ViewGroup viewGroup, final boolean activated) { viewGroup.setActivated(activated); for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setActivatedOnViewGroup((ViewGroup) child, activated); } else { child.setActivated(activated); } } }
[ "private", "void", "setActivatedOnViewGroup", "(", "@", "NonNull", "final", "ViewGroup", "viewGroup", ",", "final", "boolean", "activated", ")", "{", "viewGroup", ".", "setActivated", "(", "activated", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "viewGroup", ".", "getChildCount", "(", ")", ";", "i", "++", ")", "{", "View", "child", "=", "viewGroup", ".", "getChildAt", "(", "i", ")", ";", "if", "(", "child", "instanceof", "ViewGroup", ")", "{", "setActivatedOnViewGroup", "(", "(", "ViewGroup", ")", "child", ",", "activated", ")", ";", "}", "else", "{", "child", ".", "setActivated", "(", "activated", ")", ";", "}", "}", "}" ]
Adapts the activated state of all children of a specific view group. @param viewGroup The view group, whose children's activated states should be adapted, as an instance of the class {@link ViewGroup}. The view group may not be null @param activated True, if the children should be activated, false otherwise
[ "Adapts", "the", "activated", "state", "of", "all", "children", "of", "a", "specific", "view", "group", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L493-L506
8,119
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setLeftMessage
protected final void setLeftMessage(@Nullable final CharSequence message, @Nullable final Drawable icon) { setLeftMessage(message, icon, true); }
java
protected final void setLeftMessage(@Nullable final CharSequence message, @Nullable final Drawable icon) { setLeftMessage(message, icon, true); }
[ "protected", "final", "void", "setLeftMessage", "(", "@", "Nullable", "final", "CharSequence", "message", ",", "@", "Nullable", "final", "Drawable", "icon", ")", "{", "setLeftMessage", "(", "message", ",", "icon", ",", "true", ")", ";", "}" ]
Shows a specific message, which is marked as an error, at the left edge of the view. @param message The message, which should be shown, as an instance of the type {@link CharSequence} or null, if no message should be shown @param icon The icon, which should be shown, as an instance of the type {@link Drawable} or null, if no icon should be shown
[ "Shows", "a", "specific", "message", "which", "is", "marked", "as", "an", "error", "at", "the", "left", "edge", "of", "the", "view", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L528-L531
8,120
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setLeftMessage
protected final void setLeftMessage(@Nullable final CharSequence message, @Nullable final Drawable icon, final boolean error) { if (message != null) { leftMessage.setText(message); leftMessage.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); leftMessage.setTextColor(error ? getErrorColor() : getHelperTextColor()); leftMessage.setTag(error); leftMessage.setVisibility(View.VISIBLE); } else if (getHelperText() != null) { setLeftMessage(getHelperText(), null, false); } else { leftMessage.setTag(false); leftMessage.setVisibility(View.GONE); } }
java
protected final void setLeftMessage(@Nullable final CharSequence message, @Nullable final Drawable icon, final boolean error) { if (message != null) { leftMessage.setText(message); leftMessage.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); leftMessage.setTextColor(error ? getErrorColor() : getHelperTextColor()); leftMessage.setTag(error); leftMessage.setVisibility(View.VISIBLE); } else if (getHelperText() != null) { setLeftMessage(getHelperText(), null, false); } else { leftMessage.setTag(false); leftMessage.setVisibility(View.GONE); } }
[ "protected", "final", "void", "setLeftMessage", "(", "@", "Nullable", "final", "CharSequence", "message", ",", "@", "Nullable", "final", "Drawable", "icon", ",", "final", "boolean", "error", ")", "{", "if", "(", "message", "!=", "null", ")", "{", "leftMessage", ".", "setText", "(", "message", ")", ";", "leftMessage", ".", "setCompoundDrawablesWithIntrinsicBounds", "(", "icon", ",", "null", ",", "null", ",", "null", ")", ";", "leftMessage", ".", "setTextColor", "(", "error", "?", "getErrorColor", "(", ")", ":", "getHelperTextColor", "(", ")", ")", ";", "leftMessage", ".", "setTag", "(", "error", ")", ";", "leftMessage", ".", "setVisibility", "(", "View", ".", "VISIBLE", ")", ";", "}", "else", "if", "(", "getHelperText", "(", ")", "!=", "null", ")", "{", "setLeftMessage", "(", "getHelperText", "(", ")", ",", "null", ",", "false", ")", ";", "}", "else", "{", "leftMessage", ".", "setTag", "(", "false", ")", ";", "leftMessage", ".", "setVisibility", "(", "View", ".", "GONE", ")", ";", "}", "}" ]
Shows a specific message at the left edge of the view. @param message The message, which should be shown, as an instance of the type {@link CharSequence} or null, if no message should be shown @param icon The icon, which should be shown, as an instance of the type {@link Drawable} or null, if no icon should be shown @param error True, if the message should be highlighted as an error, false otherwise
[ "Shows", "a", "specific", "message", "at", "the", "left", "edge", "of", "the", "view", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L545-L559
8,121
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setRightMessage
protected final void setRightMessage(@Nullable final CharSequence message, final boolean error) { if (message != null) { rightMessage.setVisibility(View.VISIBLE); rightMessage.setText(message); rightMessage.setTextColor(error ? getErrorColor() : getHelperTextColor()); rightMessage.setTag(error); } else { rightMessage.setTag(false); rightMessage.setVisibility(View.GONE); } }
java
protected final void setRightMessage(@Nullable final CharSequence message, final boolean error) { if (message != null) { rightMessage.setVisibility(View.VISIBLE); rightMessage.setText(message); rightMessage.setTextColor(error ? getErrorColor() : getHelperTextColor()); rightMessage.setTag(error); } else { rightMessage.setTag(false); rightMessage.setVisibility(View.GONE); } }
[ "protected", "final", "void", "setRightMessage", "(", "@", "Nullable", "final", "CharSequence", "message", ",", "final", "boolean", "error", ")", "{", "if", "(", "message", "!=", "null", ")", "{", "rightMessage", ".", "setVisibility", "(", "View", ".", "VISIBLE", ")", ";", "rightMessage", ".", "setText", "(", "message", ")", ";", "rightMessage", ".", "setTextColor", "(", "error", "?", "getErrorColor", "(", ")", ":", "getHelperTextColor", "(", ")", ")", ";", "rightMessage", ".", "setTag", "(", "error", ")", ";", "}", "else", "{", "rightMessage", ".", "setTag", "(", "false", ")", ";", "rightMessage", ".", "setVisibility", "(", "View", ".", "GONE", ")", ";", "}", "}" ]
Shows a specific message at the right edge of the view. @param message The message, which should be shown, as an instance of the type {@link CharSequence} or null, if no message should be shown @param error True, if the message should be highlighted as an error, false otherwise
[ "Shows", "a", "specific", "message", "at", "the", "right", "edge", "of", "the", "view", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L581-L592
8,122
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setHelperText
public final void setHelperText(@Nullable final CharSequence helperText) { this.helperText = helperText; if (getError() == null) { setLeftMessage(helperText, null, false); } }
java
public final void setHelperText(@Nullable final CharSequence helperText) { this.helperText = helperText; if (getError() == null) { setLeftMessage(helperText, null, false); } }
[ "public", "final", "void", "setHelperText", "(", "@", "Nullable", "final", "CharSequence", "helperText", ")", "{", "this", ".", "helperText", "=", "helperText", ";", "if", "(", "getError", "(", ")", "==", "null", ")", "{", "setLeftMessage", "(", "helperText", ",", "null", ",", "false", ")", ";", "}", "}" ]
Sets the helper text, which should be shown, when no validation error is currently shown. @param helperText The helper text, which should be set, as an instance of the type {@link CharSequence} or null, if no helper text should be shown
[ "Sets", "the", "helper", "text", "which", "should", "be", "shown", "when", "no", "validation", "error", "is", "currently", "shown", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L806-L812
8,123
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setErrorColor
public final void setErrorColor(@ColorInt final int color) { this.errorColor = color; if ((Boolean) leftMessage.getTag()) { leftMessage.setTextColor(color); } if ((Boolean) rightMessage.getTag()) { rightMessage.setTextColor(color); } }
java
public final void setErrorColor(@ColorInt final int color) { this.errorColor = color; if ((Boolean) leftMessage.getTag()) { leftMessage.setTextColor(color); } if ((Boolean) rightMessage.getTag()) { rightMessage.setTextColor(color); } }
[ "public", "final", "void", "setErrorColor", "(", "@", "ColorInt", "final", "int", "color", ")", "{", "this", ".", "errorColor", "=", "color", ";", "if", "(", "(", "Boolean", ")", "leftMessage", ".", "getTag", "(", ")", ")", "{", "leftMessage", ".", "setTextColor", "(", "color", ")", ";", "}", "if", "(", "(", "Boolean", ")", "rightMessage", ".", "getTag", "(", ")", ")", "{", "rightMessage", ".", "setTextColor", "(", "color", ")", ";", "}", "}" ]
Sets the color, which should be used to indicate validation errors. @param color The color, which should be set, as an {@link Integer} value
[ "Sets", "the", "color", "which", "should", "be", "used", "to", "indicate", "validation", "errors", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L841-L851
8,124
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setHelperTextColor
public final void setHelperTextColor(@ColorInt final int color) { this.helperTextColor = color; if (!(Boolean) leftMessage.getTag()) { leftMessage.setTextColor(color); } if (!(Boolean) rightMessage.getTag()) { rightMessage.setTextColor(color); } }
java
public final void setHelperTextColor(@ColorInt final int color) { this.helperTextColor = color; if (!(Boolean) leftMessage.getTag()) { leftMessage.setTextColor(color); } if (!(Boolean) rightMessage.getTag()) { rightMessage.setTextColor(color); } }
[ "public", "final", "void", "setHelperTextColor", "(", "@", "ColorInt", "final", "int", "color", ")", "{", "this", ".", "helperTextColor", "=", "color", ";", "if", "(", "!", "(", "Boolean", ")", "leftMessage", ".", "getTag", "(", ")", ")", "{", "leftMessage", ".", "setTextColor", "(", "color", ")", ";", "}", "if", "(", "!", "(", "Boolean", ")", "rightMessage", ".", "getTag", "(", ")", ")", "{", "rightMessage", ".", "setTextColor", "(", "color", ")", ";", "}", "}" ]
Sets the color of the helper text. @param color The color, which should be set, as an {@link Integer} value
[ "Sets", "the", "color", "of", "the", "helper", "text", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L868-L878
8,125
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.getError
public final CharSequence getError() { if (leftMessage.getVisibility() == View.VISIBLE && (Boolean) leftMessage.getTag()) { return leftMessage.getText(); } return null; }
java
public final CharSequence getError() { if (leftMessage.getVisibility() == View.VISIBLE && (Boolean) leftMessage.getTag()) { return leftMessage.getText(); } return null; }
[ "public", "final", "CharSequence", "getError", "(", ")", "{", "if", "(", "leftMessage", ".", "getVisibility", "(", ")", "==", "View", ".", "VISIBLE", "&&", "(", "Boolean", ")", "leftMessage", ".", "getTag", "(", ")", ")", "{", "return", "leftMessage", ".", "getText", "(", ")", ";", "}", "return", "null", ";", "}" ]
Returns the error message, which has been previously set to be displayed. @return The error message, which has been previously set to be displayed, as an instance of the type {@link CharSequence} or null, if no error has been set or if it has already been cleared by the widget
[ "Returns", "the", "error", "message", "which", "has", "been", "previously", "set", "to", "be", "displayed", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L887-L893
8,126
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java
AbstractValidateableView.setError
public void setError(@Nullable final CharSequence error, @Nullable final Drawable icon) { setLeftMessage(error, icon); setActivated(error != null); }
java
public void setError(@Nullable final CharSequence error, @Nullable final Drawable icon) { setLeftMessage(error, icon); setActivated(error != null); }
[ "public", "void", "setError", "(", "@", "Nullable", "final", "CharSequence", "error", ",", "@", "Nullable", "final", "Drawable", "icon", ")", "{", "setLeftMessage", "(", "error", ",", "icon", ")", ";", "setActivated", "(", "error", "!=", "null", ")", ";", "}" ]
Sets an error message and an icon, which should be displayed. @param error The error message, which should be displayed, as an instance of the type {@link CharSequence} or null, if a previously set error message should be cleared be cleared @param icon The icon, which should be displayed,as an instance of the type {@link Drawable} or null, if no icon should be displayed
[ "Sets", "an", "error", "message", "and", "an", "icon", "which", "should", "be", "displayed", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/AbstractValidateableView.java#L918-L921
8,127
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
JDBCRepository.closeDataSource
public static boolean closeDataSource(DataSource ds) throws SQLException { try { Method closeMethod = ds.getClass().getMethod("close"); try { closeMethod.invoke(ds); } catch (Throwable e) { ThrowUnchecked.fireFirstDeclaredCause(e, SQLException.class); } return true; } catch (NoSuchMethodException e) { return false; } }
java
public static boolean closeDataSource(DataSource ds) throws SQLException { try { Method closeMethod = ds.getClass().getMethod("close"); try { closeMethod.invoke(ds); } catch (Throwable e) { ThrowUnchecked.fireFirstDeclaredCause(e, SQLException.class); } return true; } catch (NoSuchMethodException e) { return false; } }
[ "public", "static", "boolean", "closeDataSource", "(", "DataSource", "ds", ")", "throws", "SQLException", "{", "try", "{", "Method", "closeMethod", "=", "ds", ".", "getClass", "(", ")", ".", "getMethod", "(", "\"close\"", ")", ";", "try", "{", "closeMethod", ".", "invoke", "(", "ds", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "ThrowUnchecked", ".", "fireFirstDeclaredCause", "(", "e", ",", "SQLException", ".", "class", ")", ";", "}", "return", "true", ";", "}", "catch", "(", "NoSuchMethodException", "e", ")", "{", "return", "false", ";", "}", "}" ]
Attempts to close a DataSource by searching for a "close" method. For some reason, there's no standard way to close a DataSource. @return false if DataSource doesn't have a close method.
[ "Attempts", "to", "close", "a", "DataSource", "by", "searching", "for", "a", "close", "method", ".", "For", "some", "reason", "there", "s", "no", "standard", "way", "to", "close", "a", "DataSource", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java#L90-L102
8,128
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
JDBCRepository.getJDBCStorableProperty
<S extends Storable> JDBCStorableProperty<S> getJDBCStorableProperty(StorableProperty<S> property) throws RepositoryException, SupportException { JDBCStorableInfo<S> info = examineStorable(property.getEnclosingType()); JDBCStorableProperty<S> jProperty = info.getAllProperties().get(property.getName()); if (!jProperty.isSupported()) { throw new UnsupportedOperationException ("Property is not supported: " + property.getName()); } return jProperty; }
java
<S extends Storable> JDBCStorableProperty<S> getJDBCStorableProperty(StorableProperty<S> property) throws RepositoryException, SupportException { JDBCStorableInfo<S> info = examineStorable(property.getEnclosingType()); JDBCStorableProperty<S> jProperty = info.getAllProperties().get(property.getName()); if (!jProperty.isSupported()) { throw new UnsupportedOperationException ("Property is not supported: " + property.getName()); } return jProperty; }
[ "<", "S", "extends", "Storable", ">", "JDBCStorableProperty", "<", "S", ">", "getJDBCStorableProperty", "(", "StorableProperty", "<", "S", ">", "property", ")", "throws", "RepositoryException", ",", "SupportException", "{", "JDBCStorableInfo", "<", "S", ">", "info", "=", "examineStorable", "(", "property", ".", "getEnclosingType", "(", ")", ")", ";", "JDBCStorableProperty", "<", "S", ">", "jProperty", "=", "info", ".", "getAllProperties", "(", ")", ".", "get", "(", "property", ".", "getName", "(", ")", ")", ";", "if", "(", "!", "jProperty", ".", "isSupported", "(", ")", ")", "{", "throw", "new", "UnsupportedOperationException", "(", "\"Property is not supported: \"", "+", "property", ".", "getName", "(", ")", ")", ";", "}", "return", "jProperty", ";", "}" ]
Convenience method to convert a regular StorableProperty into a JDBCStorableProperty. @throws UnsupportedOperationException if JDBCStorableProperty is not supported
[ "Convenience", "method", "to", "convert", "a", "regular", "StorableProperty", "into", "a", "JDBCStorableProperty", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java#L410-L421
8,129
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
JDBCRepository.getConnection
public Connection getConnection() throws FetchException { try { if (mOpenConnections == null) { throw new FetchException("Repository is closed"); } JDBCTransaction txn = localTransactionScope().getTxn(); if (txn != null) { // Return the connection used by the current transaction. return txn.getConnection(); } // Get connection outside lock section since it may block. Connection con = mDataSource.getConnection(); con.setAutoCommit(true); mOpenConnectionsLock.lock(); try { if (mOpenConnections == null) { con.close(); throw new FetchException("Repository is closed"); } mOpenConnections.put(con, null); } finally { mOpenConnectionsLock.unlock(); } return con; } catch (Exception e) { throw toFetchException(e); } }
java
public Connection getConnection() throws FetchException { try { if (mOpenConnections == null) { throw new FetchException("Repository is closed"); } JDBCTransaction txn = localTransactionScope().getTxn(); if (txn != null) { // Return the connection used by the current transaction. return txn.getConnection(); } // Get connection outside lock section since it may block. Connection con = mDataSource.getConnection(); con.setAutoCommit(true); mOpenConnectionsLock.lock(); try { if (mOpenConnections == null) { con.close(); throw new FetchException("Repository is closed"); } mOpenConnections.put(con, null); } finally { mOpenConnectionsLock.unlock(); } return con; } catch (Exception e) { throw toFetchException(e); } }
[ "public", "Connection", "getConnection", "(", ")", "throws", "FetchException", "{", "try", "{", "if", "(", "mOpenConnections", "==", "null", ")", "{", "throw", "new", "FetchException", "(", "\"Repository is closed\"", ")", ";", "}", "JDBCTransaction", "txn", "=", "localTransactionScope", "(", ")", ".", "getTxn", "(", ")", ";", "if", "(", "txn", "!=", "null", ")", "{", "// Return the connection used by the current transaction.\r", "return", "txn", ".", "getConnection", "(", ")", ";", "}", "// Get connection outside lock section since it may block.\r", "Connection", "con", "=", "mDataSource", ".", "getConnection", "(", ")", ";", "con", ".", "setAutoCommit", "(", "true", ")", ";", "mOpenConnectionsLock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "mOpenConnections", "==", "null", ")", "{", "con", ".", "close", "(", ")", ";", "throw", "new", "FetchException", "(", "\"Repository is closed\"", ")", ";", "}", "mOpenConnections", ".", "put", "(", "con", ",", "null", ")", ";", "}", "finally", "{", "mOpenConnectionsLock", ".", "unlock", "(", ")", ";", "}", "return", "con", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "toFetchException", "(", "e", ")", ";", "}", "}" ]
Any connection returned by this method must be closed by calling yieldConnection on this repository.
[ "Any", "connection", "returned", "by", "this", "method", "must", "be", "closed", "by", "calling", "yieldConnection", "on", "this", "repository", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java#L431-L462
8,130
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
JDBCRepository.getConnectionForTxn
Connection getConnectionForTxn(IsolationLevel level) throws FetchException { try { if (mOpenConnections == null) { throw new FetchException("Repository is closed"); } // Get connection outside lock section since it may block. Connection con = mDataSource.getConnection(); if (level == IsolationLevel.NONE) { con.setAutoCommit(true); } else { con.setAutoCommit(false); if (level != mDefaultIsolationLevel) { con.setTransactionIsolation(mapIsolationLevelToJdbc(level)); } } mOpenConnectionsLock.lock(); try { if (mOpenConnections == null) { con.close(); throw new FetchException("Repository is closed"); } mOpenConnections.put(con, null); } finally { mOpenConnectionsLock.unlock(); } return con; } catch (Exception e) { throw toFetchException(e); } }
java
Connection getConnectionForTxn(IsolationLevel level) throws FetchException { try { if (mOpenConnections == null) { throw new FetchException("Repository is closed"); } // Get connection outside lock section since it may block. Connection con = mDataSource.getConnection(); if (level == IsolationLevel.NONE) { con.setAutoCommit(true); } else { con.setAutoCommit(false); if (level != mDefaultIsolationLevel) { con.setTransactionIsolation(mapIsolationLevelToJdbc(level)); } } mOpenConnectionsLock.lock(); try { if (mOpenConnections == null) { con.close(); throw new FetchException("Repository is closed"); } mOpenConnections.put(con, null); } finally { mOpenConnectionsLock.unlock(); } return con; } catch (Exception e) { throw toFetchException(e); } }
[ "Connection", "getConnectionForTxn", "(", "IsolationLevel", "level", ")", "throws", "FetchException", "{", "try", "{", "if", "(", "mOpenConnections", "==", "null", ")", "{", "throw", "new", "FetchException", "(", "\"Repository is closed\"", ")", ";", "}", "// Get connection outside lock section since it may block.\r", "Connection", "con", "=", "mDataSource", ".", "getConnection", "(", ")", ";", "if", "(", "level", "==", "IsolationLevel", ".", "NONE", ")", "{", "con", ".", "setAutoCommit", "(", "true", ")", ";", "}", "else", "{", "con", ".", "setAutoCommit", "(", "false", ")", ";", "if", "(", "level", "!=", "mDefaultIsolationLevel", ")", "{", "con", ".", "setTransactionIsolation", "(", "mapIsolationLevelToJdbc", "(", "level", ")", ")", ";", "}", "}", "mOpenConnectionsLock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "mOpenConnections", "==", "null", ")", "{", "con", ".", "close", "(", ")", ";", "throw", "new", "FetchException", "(", "\"Repository is closed\"", ")", ";", "}", "mOpenConnections", ".", "put", "(", "con", ",", "null", ")", ";", "}", "finally", "{", "mOpenConnectionsLock", ".", "unlock", "(", ")", ";", "}", "return", "con", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "toFetchException", "(", "e", ")", ";", "}", "}" ]
Called by JDBCTransactionManager.
[ "Called", "by", "JDBCTransactionManager", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java#L467-L500
8,131
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
JDBCRepository.yieldConnection
public void yieldConnection(Connection con) throws FetchException { try { if (con.getAutoCommit()) { closeConnection(con); } // Connections which aren't auto-commit are in a transaction. Keep // them around instead of closing them. } catch (Exception e) { throw toFetchException(e); } }
java
public void yieldConnection(Connection con) throws FetchException { try { if (con.getAutoCommit()) { closeConnection(con); } // Connections which aren't auto-commit are in a transaction. Keep // them around instead of closing them. } catch (Exception e) { throw toFetchException(e); } }
[ "public", "void", "yieldConnection", "(", "Connection", "con", ")", "throws", "FetchException", "{", "try", "{", "if", "(", "con", ".", "getAutoCommit", "(", ")", ")", "{", "closeConnection", "(", "con", ")", ";", "}", "// Connections which aren't auto-commit are in a transaction. Keep\r", "// them around instead of closing them.\r", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "toFetchException", "(", "e", ")", ";", "}", "}" ]
Gives up a connection returned from getConnection. Connection must be yielded in same thread that retrieved it.
[ "Gives", "up", "a", "connection", "returned", "from", "getConnection", ".", "Connection", "must", "be", "yielded", "in", "same", "thread", "that", "retrieved", "it", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java#L506-L516
8,132
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngineTrigger.java
LobEngineTrigger.beforeInsert
@Override public Object beforeInsert(S storable) throws PersistException { // Capture user lob values for later and replace with new locators. int length = mLobProperties.length; Object[] userLobs = new Object[length]; for (int i=0; i<length; i++) { LobProperty<Lob> prop = mLobProperties[i]; Object userLob = storable.getPropertyValue(prop.mName); userLobs[i] = userLob; if (userLob != null) { Object lob = prop.createNewLob(mBlockSize); storable.setPropertyValue(prop.mName, lob); } } return userLobs; }
java
@Override public Object beforeInsert(S storable) throws PersistException { // Capture user lob values for later and replace with new locators. int length = mLobProperties.length; Object[] userLobs = new Object[length]; for (int i=0; i<length; i++) { LobProperty<Lob> prop = mLobProperties[i]; Object userLob = storable.getPropertyValue(prop.mName); userLobs[i] = userLob; if (userLob != null) { Object lob = prop.createNewLob(mBlockSize); storable.setPropertyValue(prop.mName, lob); } } return userLobs; }
[ "@", "Override", "public", "Object", "beforeInsert", "(", "S", "storable", ")", "throws", "PersistException", "{", "// Capture user lob values for later and replace with new locators.\r", "int", "length", "=", "mLobProperties", ".", "length", ";", "Object", "[", "]", "userLobs", "=", "new", "Object", "[", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "length", ";", "i", "++", ")", "{", "LobProperty", "<", "Lob", ">", "prop", "=", "mLobProperties", "[", "i", "]", ";", "Object", "userLob", "=", "storable", ".", "getPropertyValue", "(", "prop", ".", "mName", ")", ";", "userLobs", "[", "i", "]", "=", "userLob", ";", "if", "(", "userLob", "!=", "null", ")", "{", "Object", "lob", "=", "prop", ".", "createNewLob", "(", "mBlockSize", ")", ";", "storable", ".", "setPropertyValue", "(", "prop", ".", "mName", ",", "lob", ")", ";", "}", "}", "return", "userLobs", ";", "}" ]
Returns user specified Lob values
[ "Returns", "user", "specified", "Lob", "values" ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngineTrigger.java#L52-L67
8,133
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngineTrigger.java
LobEngineTrigger.beforeDelete
@Override public Object beforeDelete(S storable) throws PersistException { S existing = (S) storable.copy(); try { if (!existing.tryLoad()) { existing = null; } return existing; } catch (FetchException e) { throw e.toPersistException(); } }
java
@Override public Object beforeDelete(S storable) throws PersistException { S existing = (S) storable.copy(); try { if (!existing.tryLoad()) { existing = null; } return existing; } catch (FetchException e) { throw e.toPersistException(); } }
[ "@", "Override", "public", "Object", "beforeDelete", "(", "S", "storable", ")", "throws", "PersistException", "{", "S", "existing", "=", "(", "S", ")", "storable", ".", "copy", "(", ")", ";", "try", "{", "if", "(", "!", "existing", ".", "tryLoad", "(", ")", ")", "{", "existing", "=", "null", ";", "}", "return", "existing", ";", "}", "catch", "(", "FetchException", "e", ")", "{", "throw", "e", ".", "toPersistException", "(", ")", ";", "}", "}" ]
Returns existing Storable or null
[ "Returns", "existing", "Storable", "or", "null" ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngineTrigger.java#L142-L153
8,134
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/constraints/text/RegexConstraint.java
RegexConstraint.setRegex
public final void setRegex(@NonNull final Pattern regex) { Condition.INSTANCE.ensureNotNull(regex, "The regular expression may not be null"); this.regex = regex; }
java
public final void setRegex(@NonNull final Pattern regex) { Condition.INSTANCE.ensureNotNull(regex, "The regular expression may not be null"); this.regex = regex; }
[ "public", "final", "void", "setRegex", "(", "@", "NonNull", "final", "Pattern", "regex", ")", "{", "Condition", ".", "INSTANCE", ".", "ensureNotNull", "(", "regex", ",", "\"The regular expression may not be null\"", ")", ";", "this", ".", "regex", "=", "regex", ";", "}" ]
Sets the regular expression, which should be used to verify the texts. @param regex The regular expression, which should be set, as an instance of the class {@link Pattern}. The regular expression may not be null
[ "Sets", "the", "regular", "expression", "which", "should", "be", "used", "to", "verify", "the", "texts", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/constraints/text/RegexConstraint.java#L66-L69
8,135
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/FilterParser.java
FilterParser.parseRoot
Filter<S> parseRoot() { Filter<S> filter = parseFilter(); int c = nextCharIgnoreWhitespace(); if (c >= 0) { mPos--; throw error("Unexpected trailing characters"); } return filter; }
java
Filter<S> parseRoot() { Filter<S> filter = parseFilter(); int c = nextCharIgnoreWhitespace(); if (c >= 0) { mPos--; throw error("Unexpected trailing characters"); } return filter; }
[ "Filter", "<", "S", ">", "parseRoot", "(", ")", "{", "Filter", "<", "S", ">", "filter", "=", "parseFilter", "(", ")", ";", "int", "c", "=", "nextCharIgnoreWhitespace", "(", ")", ";", "if", "(", "c", ">=", "0", ")", "{", "mPos", "--", ";", "throw", "error", "(", "\"Unexpected trailing characters\"", ")", ";", "}", "return", "filter", ";", "}" ]
all rolled into one. This is okay since the grammar is so simple.
[ "all", "rolled", "into", "one", ".", "This", "is", "okay", "since", "the", "grammar", "is", "so", "simple", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/FilterParser.java#L62-L70
8,136
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/filter/FilterParser.java
FilterParser.nextChar
private int nextChar() { String filter = mFilter; int pos = mPos; int c = (pos >= filter.length()) ? -1 : mFilter.charAt(pos); mPos = pos + 1; return c; }
java
private int nextChar() { String filter = mFilter; int pos = mPos; int c = (pos >= filter.length()) ? -1 : mFilter.charAt(pos); mPos = pos + 1; return c; }
[ "private", "int", "nextChar", "(", ")", "{", "String", "filter", "=", "mFilter", ";", "int", "pos", "=", "mPos", ";", "int", "c", "=", "(", "pos", ">=", "filter", ".", "length", "(", ")", ")", "?", "-", "1", ":", "mFilter", ".", "charAt", "(", "pos", ")", ";", "mPos", "=", "pos", "+", "1", ";", "return", "c", ";", "}" ]
Returns -1 if no more characters.
[ "Returns", "-", "1", "if", "no", "more", "characters", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/filter/FilterParser.java#L409-L415
8,137
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/sleepycat/BDBCursor.java
BDBCursor.getData
protected static byte[] getData(byte[] data, int size) { if (data == null) { return NO_DATA; } if (data.length <= size) { return data; } byte[] newData = new byte[size]; System.arraycopy(data, 0, newData, 0, size); return newData; }
java
protected static byte[] getData(byte[] data, int size) { if (data == null) { return NO_DATA; } if (data.length <= size) { return data; } byte[] newData = new byte[size]; System.arraycopy(data, 0, newData, 0, size); return newData; }
[ "protected", "static", "byte", "[", "]", "getData", "(", "byte", "[", "]", "data", ",", "int", "size", ")", "{", "if", "(", "data", "==", "null", ")", "{", "return", "NO_DATA", ";", "}", "if", "(", "data", ".", "length", "<=", "size", ")", "{", "return", "data", ";", "}", "byte", "[", "]", "newData", "=", "new", "byte", "[", "size", "]", ";", "System", ".", "arraycopy", "(", "data", ",", "0", ",", "newData", ",", "0", ",", "size", ")", ";", "return", "newData", ";", "}" ]
If the given byte array is less than or equal to given size, it is simply returned. Otherwise, a new array is allocated and the data is copied.
[ "If", "the", "given", "byte", "array", "is", "less", "than", "or", "equal", "to", "given", "size", "it", "is", "simply", "returned", ".", "Otherwise", "a", "new", "array", "is", "allocated", "and", "the", "data", "is", "copied", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBCursor.java#L247-L257
8,138
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/sleepycat/BDBCursor.java
BDBCursor.getDataCopy
protected static byte[] getDataCopy(byte[] data, int size) { if (data == null) { return NO_DATA; } byte[] newData = new byte[size]; System.arraycopy(data, 0, newData, 0, size); return newData; }
java
protected static byte[] getDataCopy(byte[] data, int size) { if (data == null) { return NO_DATA; } byte[] newData = new byte[size]; System.arraycopy(data, 0, newData, 0, size); return newData; }
[ "protected", "static", "byte", "[", "]", "getDataCopy", "(", "byte", "[", "]", "data", ",", "int", "size", ")", "{", "if", "(", "data", "==", "null", ")", "{", "return", "NO_DATA", ";", "}", "byte", "[", "]", "newData", "=", "new", "byte", "[", "size", "]", ";", "System", ".", "arraycopy", "(", "data", ",", "0", ",", "newData", ",", "0", ",", "size", ")", ";", "return", "newData", ";", "}" ]
Returns a copy of the data array.
[ "Returns", "a", "copy", "of", "the", "data", "array", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBCursor.java#L262-L269
8,139
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/validators/text/EqualValidator.java
EqualValidator.setEditText
public final void setEditText(@NonNull final EditText editText) { Condition.INSTANCE.ensureNotNull(editText, "The edit text widget may not be null"); this.editText = editText; }
java
public final void setEditText(@NonNull final EditText editText) { Condition.INSTANCE.ensureNotNull(editText, "The edit text widget may not be null"); this.editText = editText; }
[ "public", "final", "void", "setEditText", "(", "@", "NonNull", "final", "EditText", "editText", ")", "{", "Condition", ".", "INSTANCE", ".", "ensureNotNull", "(", "editText", ",", "\"The edit text widget may not be null\"", ")", ";", "this", ".", "editText", "=", "editText", ";", "}" ]
Sets the edit text widget, which contains the content, the texts should be equal to. @param editText The edit text widget, which should be set, as an instance of the class {@link EditText}. The widget may not be null
[ "Sets", "the", "edit", "text", "widget", "which", "contains", "the", "content", "the", "texts", "should", "be", "equal", "to", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/validators/text/EqualValidator.java#L93-L96
8,140
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/raw/RawUtil.java
RawUtil.increment
public static boolean increment(byte[] value) { for (int i=value.length; --i>=0; ) { byte newValue = (byte) ((value[i] & 0xff) + 1); value[i] = newValue; if (newValue != 0) { // No carry bit, so done adding. return true; } } // This point is reached upon overflow. return false; }
java
public static boolean increment(byte[] value) { for (int i=value.length; --i>=0; ) { byte newValue = (byte) ((value[i] & 0xff) + 1); value[i] = newValue; if (newValue != 0) { // No carry bit, so done adding. return true; } } // This point is reached upon overflow. return false; }
[ "public", "static", "boolean", "increment", "(", "byte", "[", "]", "value", ")", "{", "for", "(", "int", "i", "=", "value", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "byte", "newValue", "=", "(", "byte", ")", "(", "(", "value", "[", "i", "]", "&", "0xff", ")", "+", "1", ")", ";", "value", "[", "i", "]", "=", "newValue", ";", "if", "(", "newValue", "!=", "0", ")", "{", "// No carry bit, so done adding.\r", "return", "true", ";", "}", "}", "// This point is reached upon overflow.\r", "return", "false", ";", "}" ]
Adds one to an unsigned integer, represented as a byte array. If overflowed, value in byte array is 0x00, 0x00, 0x00... @param value unsigned integer to increment @return false if overflowed
[ "Adds", "one", "to", "an", "unsigned", "integer", "represented", "as", "a", "byte", "array", ".", "If", "overflowed", "value", "in", "byte", "array", "is", "0x00", "0x00", "0x00", "..." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/raw/RawUtil.java#L34-L45
8,141
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/raw/RawUtil.java
RawUtil.decrement
public static boolean decrement(byte[] value) { for (int i=value.length; --i>=0; ) { byte newValue = (byte) ((value[i] & 0xff) + -1); value[i] = newValue; if (newValue != -1) { // No borrow bit, so done subtracting. return true; } } // This point is reached upon overflow. return false; }
java
public static boolean decrement(byte[] value) { for (int i=value.length; --i>=0; ) { byte newValue = (byte) ((value[i] & 0xff) + -1); value[i] = newValue; if (newValue != -1) { // No borrow bit, so done subtracting. return true; } } // This point is reached upon overflow. return false; }
[ "public", "static", "boolean", "decrement", "(", "byte", "[", "]", "value", ")", "{", "for", "(", "int", "i", "=", "value", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "byte", "newValue", "=", "(", "byte", ")", "(", "(", "value", "[", "i", "]", "&", "0xff", ")", "+", "-", "1", ")", ";", "value", "[", "i", "]", "=", "newValue", ";", "if", "(", "newValue", "!=", "-", "1", ")", "{", "// No borrow bit, so done subtracting.\r", "return", "true", ";", "}", "}", "// This point is reached upon overflow.\r", "return", "false", ";", "}" ]
Subtracts one from an unsigned integer, represented as a byte array. If overflowed, value in byte array is 0xff, 0xff, 0xff... @param value unsigned integer to decrement @return false if overflowed
[ "Subtracts", "one", "from", "an", "unsigned", "integer", "represented", "as", "a", "byte", "array", ".", "If", "overflowed", "value", "in", "byte", "array", "is", "0xff", "0xff", "0xff", "..." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/raw/RawUtil.java#L54-L65
8,142
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.evaluate
public static <S extends Storable> CompositeScore<S> evaluate (StorableIndex<S> index, Filter<S> filter, OrderingList<S> ordering) { if (index == null) { throw new IllegalArgumentException("Index required"); } return evaluate(index.getOrderedProperties(), index.isUnique(), index.isClustered(), filter, ordering); }
java
public static <S extends Storable> CompositeScore<S> evaluate (StorableIndex<S> index, Filter<S> filter, OrderingList<S> ordering) { if (index == null) { throw new IllegalArgumentException("Index required"); } return evaluate(index.getOrderedProperties(), index.isUnique(), index.isClustered(), filter, ordering); }
[ "public", "static", "<", "S", "extends", "Storable", ">", "CompositeScore", "<", "S", ">", "evaluate", "(", "StorableIndex", "<", "S", ">", "index", ",", "Filter", "<", "S", ">", "filter", ",", "OrderingList", "<", "S", ">", "ordering", ")", "{", "if", "(", "index", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Index required\"", ")", ";", "}", "return", "evaluate", "(", "index", ".", "getOrderedProperties", "(", ")", ",", "index", ".", "isUnique", "(", ")", ",", "index", ".", "isClustered", "(", ")", ",", "filter", ",", "ordering", ")", ";", "}" ]
Evaluates the given index for its filtering and ordering capabilities against the given filter and order-by properties. @param index index to evaluate @param filter optional filter which cannot contain any logical 'or' operations. @param ordering optional properties which define desired ordering @throws IllegalArgumentException if index is null or filter is not supported
[ "Evaluates", "the", "given", "index", "for", "its", "filtering", "and", "ordering", "capabilities", "against", "the", "given", "filter", "and", "order", "-", "by", "properties", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L48-L62
8,143
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.evaluate
public static <S extends Storable> CompositeScore<S> evaluate (OrderedProperty<S>[] indexProperties, boolean unique, boolean clustered, Filter<S> filter, OrderingList<S> ordering) { FilteringScore<S> filteringScore = FilteringScore .evaluate(indexProperties, unique, clustered, filter); OrderingScore<S> orderingScore = OrderingScore .evaluate(indexProperties, unique, clustered, filter, ordering); return new CompositeScore<S>(filteringScore, orderingScore); }
java
public static <S extends Storable> CompositeScore<S> evaluate (OrderedProperty<S>[] indexProperties, boolean unique, boolean clustered, Filter<S> filter, OrderingList<S> ordering) { FilteringScore<S> filteringScore = FilteringScore .evaluate(indexProperties, unique, clustered, filter); OrderingScore<S> orderingScore = OrderingScore .evaluate(indexProperties, unique, clustered, filter, ordering); return new CompositeScore<S>(filteringScore, orderingScore); }
[ "public", "static", "<", "S", "extends", "Storable", ">", "CompositeScore", "<", "S", ">", "evaluate", "(", "OrderedProperty", "<", "S", ">", "[", "]", "indexProperties", ",", "boolean", "unique", ",", "boolean", "clustered", ",", "Filter", "<", "S", ">", "filter", ",", "OrderingList", "<", "S", ">", "ordering", ")", "{", "FilteringScore", "<", "S", ">", "filteringScore", "=", "FilteringScore", ".", "evaluate", "(", "indexProperties", ",", "unique", ",", "clustered", ",", "filter", ")", ";", "OrderingScore", "<", "S", ">", "orderingScore", "=", "OrderingScore", ".", "evaluate", "(", "indexProperties", ",", "unique", ",", "clustered", ",", "filter", ",", "ordering", ")", ";", "return", "new", "CompositeScore", "<", "S", ">", "(", "filteringScore", ",", "orderingScore", ")", ";", "}" ]
Evaluates the given index properties for its filtering and ordering capabilities against the given filter and order-by properties. @param indexProperties index properties to evaluate @param unique true if index is unique @param clustered true if index is clustered @param filter optional filter which cannot contain any logical 'or' operations. @param ordering optional properties which define desired ordering @throws IllegalArgumentException if index is null or filter is not supported
[ "Evaluates", "the", "given", "index", "properties", "for", "its", "filtering", "and", "ordering", "capabilities", "against", "the", "given", "filter", "and", "order", "-", "by", "properties", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L75-L89
8,144
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.canMergeRemainder
public boolean canMergeRemainder(CompositeScore<S> other) { return getFilteringScore().canMergeRemainderFilter(other.getFilteringScore()) && getOrderingScore().canMergeRemainderOrdering(other.getOrderingScore()); }
java
public boolean canMergeRemainder(CompositeScore<S> other) { return getFilteringScore().canMergeRemainderFilter(other.getFilteringScore()) && getOrderingScore().canMergeRemainderOrdering(other.getOrderingScore()); }
[ "public", "boolean", "canMergeRemainder", "(", "CompositeScore", "<", "S", ">", "other", ")", "{", "return", "getFilteringScore", "(", ")", ".", "canMergeRemainderFilter", "(", "other", ".", "getFilteringScore", "(", ")", ")", "&&", "getOrderingScore", "(", ")", ".", "canMergeRemainderOrdering", "(", "other", ".", "getOrderingScore", "(", ")", ")", ";", "}" ]
Returns true if the filtering score can merge its remainder filter and the ordering score can merge its remainder orderings.
[ "Returns", "true", "if", "the", "filtering", "score", "can", "merge", "its", "remainder", "filter", "and", "the", "ordering", "score", "can", "merge", "its", "remainder", "orderings", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L177-L180
8,145
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.mergeRemainderFilter
public Filter<S> mergeRemainderFilter(CompositeScore<S> other) { return getFilteringScore().mergeRemainderFilter(other.getFilteringScore()); }
java
public Filter<S> mergeRemainderFilter(CompositeScore<S> other) { return getFilteringScore().mergeRemainderFilter(other.getFilteringScore()); }
[ "public", "Filter", "<", "S", ">", "mergeRemainderFilter", "(", "CompositeScore", "<", "S", ">", "other", ")", "{", "return", "getFilteringScore", "(", ")", ".", "mergeRemainderFilter", "(", "other", ".", "getFilteringScore", "(", ")", ")", ";", "}" ]
Merges the remainder filter of this score with the one given using an 'or' operation. Call canMergeRemainder first to verify if the merge makes any sense.
[ "Merges", "the", "remainder", "filter", "of", "this", "score", "with", "the", "one", "given", "using", "an", "or", "operation", ".", "Call", "canMergeRemainder", "first", "to", "verify", "if", "the", "merge", "makes", "any", "sense", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L187-L189
8,146
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.mergeRemainderOrdering
public OrderingList<S> mergeRemainderOrdering(CompositeScore<S> other) { return getOrderingScore().mergeRemainderOrdering(other.getOrderingScore()); }
java
public OrderingList<S> mergeRemainderOrdering(CompositeScore<S> other) { return getOrderingScore().mergeRemainderOrdering(other.getOrderingScore()); }
[ "public", "OrderingList", "<", "S", ">", "mergeRemainderOrdering", "(", "CompositeScore", "<", "S", ">", "other", ")", "{", "return", "getOrderingScore", "(", ")", ".", "mergeRemainderOrdering", "(", "other", ".", "getOrderingScore", "(", ")", ")", ";", "}" ]
Merges the remainder orderings of this score with the one given. Call canMergeRemainder first to verify if the merge makes any sense.
[ "Merges", "the", "remainder", "orderings", "of", "this", "score", "with", "the", "one", "given", ".", "Call", "canMergeRemainder", "first", "to", "verify", "if", "the", "merge", "makes", "any", "sense", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L195-L197
8,147
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.withRemainderFilter
public CompositeScore<S> withRemainderFilter(Filter<S> filter) { return new CompositeScore<S>(mFilteringScore.withRemainderFilter(filter), mOrderingScore); }
java
public CompositeScore<S> withRemainderFilter(Filter<S> filter) { return new CompositeScore<S>(mFilteringScore.withRemainderFilter(filter), mOrderingScore); }
[ "public", "CompositeScore", "<", "S", ">", "withRemainderFilter", "(", "Filter", "<", "S", ">", "filter", ")", "{", "return", "new", "CompositeScore", "<", "S", ">", "(", "mFilteringScore", ".", "withRemainderFilter", "(", "filter", ")", ",", "mOrderingScore", ")", ";", "}" ]
Returns a new CompositeScore with the filtering remainder replaced and covering matches recalculated. Other matches are not recalculated. @since 1.2
[ "Returns", "a", "new", "CompositeScore", "with", "the", "filtering", "remainder", "replaced", "and", "covering", "matches", "recalculated", ".", "Other", "matches", "are", "not", "recalculated", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L205-L208
8,148
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/CompositeScore.java
CompositeScore.withRemainderOrdering
public CompositeScore<S> withRemainderOrdering(OrderingList<S> ordering) { return new CompositeScore<S>(mFilteringScore, mOrderingScore.withRemainderOrdering(ordering)); }
java
public CompositeScore<S> withRemainderOrdering(OrderingList<S> ordering) { return new CompositeScore<S>(mFilteringScore, mOrderingScore.withRemainderOrdering(ordering)); }
[ "public", "CompositeScore", "<", "S", ">", "withRemainderOrdering", "(", "OrderingList", "<", "S", ">", "ordering", ")", "{", "return", "new", "CompositeScore", "<", "S", ">", "(", "mFilteringScore", ",", "mOrderingScore", ".", "withRemainderOrdering", "(", "ordering", ")", ")", ";", "}" ]
Returns a new CompositeScore with the ordering remainder replaced. Handled count is not recalculated. @since 1.2
[ "Returns", "a", "new", "CompositeScore", "with", "the", "ordering", "remainder", "replaced", ".", "Handled", "count", "is", "not", "recalculated", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/CompositeScore.java#L216-L219
8,149
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/StandardQuery.java
StandardQuery.executor
protected QueryExecutor<S> executor() throws RepositoryException { QueryExecutor<S> executor = mExecutor; if (executor == null) { mExecutor = executor = executorFactory().executor(mFilter, mOrdering, null); } return executor; }
java
protected QueryExecutor<S> executor() throws RepositoryException { QueryExecutor<S> executor = mExecutor; if (executor == null) { mExecutor = executor = executorFactory().executor(mFilter, mOrdering, null); } return executor; }
[ "protected", "QueryExecutor", "<", "S", ">", "executor", "(", ")", "throws", "RepositoryException", "{", "QueryExecutor", "<", "S", ">", "executor", "=", "mExecutor", ";", "if", "(", "executor", "==", "null", ")", "{", "mExecutor", "=", "executor", "=", "executorFactory", "(", ")", ".", "executor", "(", "mFilter", ",", "mOrdering", ",", "null", ")", ";", "}", "return", "executor", ";", "}" ]
Returns the executor in use by this query.
[ "Returns", "the", "executor", "in", "use", "by", "this", "query", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/StandardQuery.java#L508-L514
8,150
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/StandardQuery.java
StandardQuery.resetExecutor
protected void resetExecutor() throws RepositoryException { if (mExecutor != null) { mExecutor = executorFactory().executor(mFilter, mOrdering, null); } }
java
protected void resetExecutor() throws RepositoryException { if (mExecutor != null) { mExecutor = executorFactory().executor(mFilter, mOrdering, null); } }
[ "protected", "void", "resetExecutor", "(", ")", "throws", "RepositoryException", "{", "if", "(", "mExecutor", "!=", "null", ")", "{", "mExecutor", "=", "executorFactory", "(", ")", ".", "executor", "(", "mFilter", ",", "mOrdering", ",", "null", ")", ";", "}", "}" ]
Resets any cached reference to a query executor. If a reference is available, it is replaced, but a clear reference is not set.
[ "Resets", "any", "cached", "reference", "to", "a", "query", "executor", ".", "If", "a", "reference", "is", "available", "it", "is", "replaced", "but", "a", "clear", "reference", "is", "not", "set", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/StandardQuery.java#L528-L532
8,151
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java
AbstractQueryExecutor.fetchSlice
public Cursor<S> fetchSlice(FilterValues<S> values, long from, Long to) throws FetchException { Cursor<S> cursor = fetch(values); if (from > 0) { cursor = new SkipCursor<S>(cursor, from); } if (to != null) { cursor = new LimitCursor<S>(cursor, to - from); } return cursor; }
java
public Cursor<S> fetchSlice(FilterValues<S> values, long from, Long to) throws FetchException { Cursor<S> cursor = fetch(values); if (from > 0) { cursor = new SkipCursor<S>(cursor, from); } if (to != null) { cursor = new LimitCursor<S>(cursor, to - from); } return cursor; }
[ "public", "Cursor", "<", "S", ">", "fetchSlice", "(", "FilterValues", "<", "S", ">", "values", ",", "long", "from", ",", "Long", "to", ")", "throws", "FetchException", "{", "Cursor", "<", "S", ">", "cursor", "=", "fetch", "(", "values", ")", ";", "if", "(", "from", ">", "0", ")", "{", "cursor", "=", "new", "SkipCursor", "<", "S", ">", "(", "cursor", ",", "from", ")", ";", "}", "if", "(", "to", "!=", "null", ")", "{", "cursor", "=", "new", "LimitCursor", "<", "S", ">", "(", "cursor", ",", "to", "-", "from", ")", ";", "}", "return", "cursor", ";", "}" ]
Produces a slice via skip and limit cursors. Subclasses are encouraged to override with a more efficient implementation. @since 1.2
[ "Produces", "a", "slice", "via", "skip", "and", "limit", "cursors", ".", "Subclasses", "are", "encouraged", "to", "override", "with", "a", "more", "efficient", "implementation", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java#L49-L58
8,152
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java
AbstractQueryExecutor.count
public long count(FilterValues<S> values) throws FetchException { Cursor<S> cursor = fetch(values); try { long count = cursor.skipNext(Integer.MAX_VALUE); if (count == Integer.MAX_VALUE) { int amt; while ((amt = cursor.skipNext(Integer.MAX_VALUE)) > 0) { count += amt; } } return count; } finally { cursor.close(); } }
java
public long count(FilterValues<S> values) throws FetchException { Cursor<S> cursor = fetch(values); try { long count = cursor.skipNext(Integer.MAX_VALUE); if (count == Integer.MAX_VALUE) { int amt; while ((amt = cursor.skipNext(Integer.MAX_VALUE)) > 0) { count += amt; } } return count; } finally { cursor.close(); } }
[ "public", "long", "count", "(", "FilterValues", "<", "S", ">", "values", ")", "throws", "FetchException", "{", "Cursor", "<", "S", ">", "cursor", "=", "fetch", "(", "values", ")", ";", "try", "{", "long", "count", "=", "cursor", ".", "skipNext", "(", "Integer", ".", "MAX_VALUE", ")", ";", "if", "(", "count", "==", "Integer", ".", "MAX_VALUE", ")", "{", "int", "amt", ";", "while", "(", "(", "amt", "=", "cursor", ".", "skipNext", "(", "Integer", ".", "MAX_VALUE", ")", ")", ">", "0", ")", "{", "count", "+=", "amt", ";", "}", "}", "return", "count", ";", "}", "finally", "{", "cursor", ".", "close", "(", ")", ";", "}", "}" ]
Counts results by opening a cursor and skipping entries. Subclasses are encouraged to override with a more efficient implementation.
[ "Counts", "results", "by", "opening", "a", "cursor", "and", "skipping", "entries", ".", "Subclasses", "are", "encouraged", "to", "override", "with", "a", "more", "efficient", "implementation", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java#L84-L98
8,153
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java
AbstractQueryExecutor.indent
protected void indent(Appendable app, int indentLevel) throws IOException { for (int i=0; i<indentLevel; i++) { app.append(' '); } }
java
protected void indent(Appendable app, int indentLevel) throws IOException { for (int i=0; i<indentLevel; i++) { app.append(' '); } }
[ "protected", "void", "indent", "(", "Appendable", "app", ",", "int", "indentLevel", ")", "throws", "IOException", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "indentLevel", ";", "i", "++", ")", "{", "app", ".", "append", "(", "'", "'", ")", ";", "}", "}" ]
Appends spaces to the given appendable. Useful for implementing printNative and printPlan.
[ "Appends", "spaces", "to", "the", "given", "appendable", ".", "Useful", "for", "implementing", "printNative", "and", "printPlan", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/qe/AbstractQueryExecutor.java#L133-L137
8,154
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.lockForReadInterruptibly
public final void lockForReadInterruptibly(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForRead(locker)) { lockForReadQueuedInterruptibly(locker, addReadWaiter()); } }
java
public final void lockForReadInterruptibly(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForRead(locker)) { lockForReadQueuedInterruptibly(locker, addReadWaiter()); } }
[ "public", "final", "void", "lockForReadInterruptibly", "(", "L", "locker", ")", "throws", "InterruptedException", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "if", "(", "!", "tryLockForRead", "(", "locker", ")", ")", "{", "lockForReadQueuedInterruptibly", "(", "locker", ",", "addReadWaiter", "(", ")", ")", ";", "}", "}" ]
Acquire a shared read lock, possibly blocking until interrupted. @param locker object which might be write or upgrade lock owner
[ "Acquire", "a", "shared", "read", "lock", "possibly", "blocking", "until", "interrupted", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L158-L165
8,155
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.tryLockForRead
public final boolean tryLockForRead(L locker) { int state = mState; if (state >= 0) { // no write lock is held if (isReadWriteFirst() || isReadLockHeld(locker)) { do { if (incrementReadLocks(state)) { adjustReadLockCount(locker, 1); return true; } // keep looping on CAS failure if a reader or upgrader mucked with the state } while ((state = mState) >= 0); } } else if (mOwner == locker) { // keep looping on CAS failure if a reader or upgrader mucked with the state while (!incrementReadLocks(state)) { state = mState; } adjustReadLockCount(locker, 1); return true; } return false; }
java
public final boolean tryLockForRead(L locker) { int state = mState; if (state >= 0) { // no write lock is held if (isReadWriteFirst() || isReadLockHeld(locker)) { do { if (incrementReadLocks(state)) { adjustReadLockCount(locker, 1); return true; } // keep looping on CAS failure if a reader or upgrader mucked with the state } while ((state = mState) >= 0); } } else if (mOwner == locker) { // keep looping on CAS failure if a reader or upgrader mucked with the state while (!incrementReadLocks(state)) { state = mState; } adjustReadLockCount(locker, 1); return true; } return false; }
[ "public", "final", "boolean", "tryLockForRead", "(", "L", "locker", ")", "{", "int", "state", "=", "mState", ";", "if", "(", "state", ">=", "0", ")", "{", "// no write lock is held\r", "if", "(", "isReadWriteFirst", "(", ")", "||", "isReadLockHeld", "(", "locker", ")", ")", "{", "do", "{", "if", "(", "incrementReadLocks", "(", "state", ")", ")", "{", "adjustReadLockCount", "(", "locker", ",", "1", ")", ";", "return", "true", ";", "}", "// keep looping on CAS failure if a reader or upgrader mucked with the state\r", "}", "while", "(", "(", "state", "=", "mState", ")", ">=", "0", ")", ";", "}", "}", "else", "if", "(", "mOwner", "==", "locker", ")", "{", "// keep looping on CAS failure if a reader or upgrader mucked with the state\r", "while", "(", "!", "incrementReadLocks", "(", "state", ")", ")", "{", "state", "=", "mState", ";", "}", "adjustReadLockCount", "(", "locker", ",", "1", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Attempt to immediately acquire a shared read lock. @param locker object which might be write or upgrade lock owner @return true if acquired
[ "Attempt", "to", "immediately", "acquire", "a", "shared", "read", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L173-L194
8,156
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.tryLockForRead
public final boolean tryLockForRead(L locker, long timeout, TimeUnit unit) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForRead(locker)) { return lockForReadQueuedInterruptibly(locker, addReadWaiter(), unit.toNanos(timeout)); } return true; }
java
public final boolean tryLockForRead(L locker, long timeout, TimeUnit unit) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForRead(locker)) { return lockForReadQueuedInterruptibly(locker, addReadWaiter(), unit.toNanos(timeout)); } return true; }
[ "public", "final", "boolean", "tryLockForRead", "(", "L", "locker", ",", "long", "timeout", ",", "TimeUnit", "unit", ")", "throws", "InterruptedException", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "if", "(", "!", "tryLockForRead", "(", "locker", ")", ")", "{", "return", "lockForReadQueuedInterruptibly", "(", "locker", ",", "addReadWaiter", "(", ")", ",", "unit", ".", "toNanos", "(", "timeout", ")", ")", ";", "}", "return", "true", ";", "}" ]
Attempt to acquire a shared read lock, waiting a maximum amount of time. @param locker object which might be write or upgrade lock owner @return true if acquired
[ "Attempt", "to", "acquire", "a", "shared", "read", "lock", "waiting", "a", "maximum", "amount", "of", "time", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L203-L213
8,157
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.unlockFromRead
public final void unlockFromRead(L locker) { adjustReadLockCount(locker, -1); int readLocks; while ((readLocks = decrementReadLocks(mState)) < 0) {} if (readLocks == 0) { Node h = mRWHead; if (h != null && h.mWaitStatus != 0) { unparkReadWriteSuccessor(h); } } }
java
public final void unlockFromRead(L locker) { adjustReadLockCount(locker, -1); int readLocks; while ((readLocks = decrementReadLocks(mState)) < 0) {} if (readLocks == 0) { Node h = mRWHead; if (h != null && h.mWaitStatus != 0) { unparkReadWriteSuccessor(h); } } }
[ "public", "final", "void", "unlockFromRead", "(", "L", "locker", ")", "{", "adjustReadLockCount", "(", "locker", ",", "-", "1", ")", ";", "int", "readLocks", ";", "while", "(", "(", "readLocks", "=", "decrementReadLocks", "(", "mState", ")", ")", "<", "0", ")", "{", "}", "if", "(", "readLocks", "==", "0", ")", "{", "Node", "h", "=", "mRWHead", ";", "if", "(", "h", "!=", "null", "&&", "h", ".", "mWaitStatus", "!=", "0", ")", "{", "unparkReadWriteSuccessor", "(", "h", ")", ";", "}", "}", "}" ]
Release a previously acquired read lock.
[ "Release", "a", "previously", "acquired", "read", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L218-L230
8,158
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.lockForUpgrade_
private final Result lockForUpgrade_(L locker) { Result result; if ((result = tryLockForUpgrade_(locker)) == Result.FAILED) { result = lockForUpgradeQueued(locker, addUpgradeWaiter()); } return result; }
java
private final Result lockForUpgrade_(L locker) { Result result; if ((result = tryLockForUpgrade_(locker)) == Result.FAILED) { result = lockForUpgradeQueued(locker, addUpgradeWaiter()); } return result; }
[ "private", "final", "Result", "lockForUpgrade_", "(", "L", "locker", ")", "{", "Result", "result", ";", "if", "(", "(", "result", "=", "tryLockForUpgrade_", "(", "locker", ")", ")", "==", "Result", ".", "FAILED", ")", "{", "result", "=", "lockForUpgradeQueued", "(", "locker", ",", "addUpgradeWaiter", "(", ")", ")", ";", "}", "return", "result", ";", "}" ]
Acquire an upgrade lock, possibly blocking indefinitely. @param locker object trying to become lock owner @return ACQUIRED or OWNED
[ "Acquire", "an", "upgrade", "lock", "possibly", "blocking", "indefinitely", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L248-L254
8,159
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.lockForUpgradeInterruptibly_
private final Result lockForUpgradeInterruptibly_(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } Result result; if ((result = tryLockForUpgrade_(locker)) == Result.FAILED) { result = lockForUpgradeQueuedInterruptibly(locker, addUpgradeWaiter()); } return result; }
java
private final Result lockForUpgradeInterruptibly_(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } Result result; if ((result = tryLockForUpgrade_(locker)) == Result.FAILED) { result = lockForUpgradeQueuedInterruptibly(locker, addUpgradeWaiter()); } return result; }
[ "private", "final", "Result", "lockForUpgradeInterruptibly_", "(", "L", "locker", ")", "throws", "InterruptedException", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "Result", "result", ";", "if", "(", "(", "result", "=", "tryLockForUpgrade_", "(", "locker", ")", ")", "==", "Result", ".", "FAILED", ")", "{", "result", "=", "lockForUpgradeQueuedInterruptibly", "(", "locker", ",", "addUpgradeWaiter", "(", ")", ")", ";", "}", "return", "result", ";", "}" ]
Acquire an upgrade lock, possibly blocking until interrupted. @param locker object trying to become lock owner @return ACQUIRED or OWNED
[ "Acquire", "an", "upgrade", "lock", "possibly", "blocking", "until", "interrupted", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L272-L281
8,160
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.tryLockForUpgrade_
private final Result tryLockForUpgrade_(L locker) { int state = mState; if ((state & LOCK_STATE_MASK) == 0) { // no write or upgrade lock is held if (isUpgradeFirst()) { do { if (setUpgradeLock(state)) { mOwner = locker; incrementUpgradeCount(); return Result.ACQUIRED; } // keep looping on CAS failure if a reader mucked with the state } while (((state = mState) & LOCK_STATE_MASK) == 0); } } else if (mOwner == locker) { incrementUpgradeCount(); return Result.OWNED; } return Result.FAILED; }
java
private final Result tryLockForUpgrade_(L locker) { int state = mState; if ((state & LOCK_STATE_MASK) == 0) { // no write or upgrade lock is held if (isUpgradeFirst()) { do { if (setUpgradeLock(state)) { mOwner = locker; incrementUpgradeCount(); return Result.ACQUIRED; } // keep looping on CAS failure if a reader mucked with the state } while (((state = mState) & LOCK_STATE_MASK) == 0); } } else if (mOwner == locker) { incrementUpgradeCount(); return Result.OWNED; } return Result.FAILED; }
[ "private", "final", "Result", "tryLockForUpgrade_", "(", "L", "locker", ")", "{", "int", "state", "=", "mState", ";", "if", "(", "(", "state", "&", "LOCK_STATE_MASK", ")", "==", "0", ")", "{", "// no write or upgrade lock is held\r", "if", "(", "isUpgradeFirst", "(", ")", ")", "{", "do", "{", "if", "(", "setUpgradeLock", "(", "state", ")", ")", "{", "mOwner", "=", "locker", ";", "incrementUpgradeCount", "(", ")", ";", "return", "Result", ".", "ACQUIRED", ";", "}", "// keep looping on CAS failure if a reader mucked with the state\r", "}", "while", "(", "(", "(", "state", "=", "mState", ")", "&", "LOCK_STATE_MASK", ")", "==", "0", ")", ";", "}", "}", "else", "if", "(", "mOwner", "==", "locker", ")", "{", "incrementUpgradeCount", "(", ")", ";", "return", "Result", ".", "OWNED", ";", "}", "return", "Result", ".", "FAILED", ";", "}" ]
Attempt to immediately acquire an upgrade lock. @param locker object trying to become lock owner @return FAILED, ACQUIRED or OWNED
[ "Attempt", "to", "immediately", "acquire", "an", "upgrade", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L299-L317
8,161
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.unlockFromUpgrade
public final void unlockFromUpgrade(L locker) { int upgradeCount = mUpgradeCount - 1; if (upgradeCount < 0) { throw new IllegalMonitorStateException("Too many upgrade locks released"); } if (upgradeCount == 0 && mWriteCount > 0) { // Don't release last upgrade lock and switch write lock to // automatic upgrade mode. clearUpgradeLock(mState); return; } mUpgradeCount = upgradeCount; if (upgradeCount > 0) { return; } mOwner = null; // keep looping on CAS failure if reader mucked with state while (!clearUpgradeLock(mState)) {} Node h = mUHead; if (h != null && h.mWaitStatus != 0) { unparkUpgradeSuccessor(h); } }
java
public final void unlockFromUpgrade(L locker) { int upgradeCount = mUpgradeCount - 1; if (upgradeCount < 0) { throw new IllegalMonitorStateException("Too many upgrade locks released"); } if (upgradeCount == 0 && mWriteCount > 0) { // Don't release last upgrade lock and switch write lock to // automatic upgrade mode. clearUpgradeLock(mState); return; } mUpgradeCount = upgradeCount; if (upgradeCount > 0) { return; } mOwner = null; // keep looping on CAS failure if reader mucked with state while (!clearUpgradeLock(mState)) {} Node h = mUHead; if (h != null && h.mWaitStatus != 0) { unparkUpgradeSuccessor(h); } }
[ "public", "final", "void", "unlockFromUpgrade", "(", "L", "locker", ")", "{", "int", "upgradeCount", "=", "mUpgradeCount", "-", "1", ";", "if", "(", "upgradeCount", "<", "0", ")", "{", "throw", "new", "IllegalMonitorStateException", "(", "\"Too many upgrade locks released\"", ")", ";", "}", "if", "(", "upgradeCount", "==", "0", "&&", "mWriteCount", ">", "0", ")", "{", "// Don't release last upgrade lock and switch write lock to\r", "// automatic upgrade mode.\r", "clearUpgradeLock", "(", "mState", ")", ";", "return", ";", "}", "mUpgradeCount", "=", "upgradeCount", ";", "if", "(", "upgradeCount", ">", "0", ")", "{", "return", ";", "}", "mOwner", "=", "null", ";", "// keep looping on CAS failure if reader mucked with state\r", "while", "(", "!", "clearUpgradeLock", "(", "mState", ")", ")", "{", "}", "Node", "h", "=", "mUHead", ";", "if", "(", "h", "!=", "null", "&&", "h", ".", "mWaitStatus", "!=", "0", ")", "{", "unparkUpgradeSuccessor", "(", "h", ")", ";", "}", "}" ]
Release a previously acquired upgrade lock.
[ "Release", "a", "previously", "acquired", "upgrade", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L354-L379
8,162
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.lockForWrite
public final void lockForWrite(L locker) { if (!tryLockForWrite(locker)) { Result upgradeResult = lockForUpgrade_(locker); if (!tryLockForWrite(locker)) { lockForWriteQueued(locker, addWriteWaiter()); } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } }
java
public final void lockForWrite(L locker) { if (!tryLockForWrite(locker)) { Result upgradeResult = lockForUpgrade_(locker); if (!tryLockForWrite(locker)) { lockForWriteQueued(locker, addWriteWaiter()); } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } }
[ "public", "final", "void", "lockForWrite", "(", "L", "locker", ")", "{", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "Result", "upgradeResult", "=", "lockForUpgrade_", "(", "locker", ")", ";", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "lockForWriteQueued", "(", "locker", ",", "addWriteWaiter", "(", ")", ")", ";", "}", "if", "(", "upgradeResult", "==", "Result", ".", "ACQUIRED", ")", "{", "// clear upgrade state bit to indicate automatic upgrade\r", "while", "(", "!", "clearUpgradeLock", "(", "mState", ")", ")", "{", "}", "}", "else", "{", "// undo automatic upgrade count increment\r", "mUpgradeCount", "--", ";", "}", "}", "}" ]
Acquire an exclusive write lock, possibly blocking indefinitely. @param locker object trying to become lock owner
[ "Acquire", "an", "exclusive", "write", "lock", "possibly", "blocking", "indefinitely", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L386-L400
8,163
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.lockForWriteInterruptibly
public final void lockForWriteInterruptibly(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForWrite(locker)) { Result upgradeResult = lockForUpgradeInterruptibly_(locker); if (!tryLockForWrite(locker)) { lockForWriteQueuedInterruptibly(locker, addWriteWaiter()); } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } }
java
public final void lockForWriteInterruptibly(L locker) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForWrite(locker)) { Result upgradeResult = lockForUpgradeInterruptibly_(locker); if (!tryLockForWrite(locker)) { lockForWriteQueuedInterruptibly(locker, addWriteWaiter()); } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } }
[ "public", "final", "void", "lockForWriteInterruptibly", "(", "L", "locker", ")", "throws", "InterruptedException", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "Result", "upgradeResult", "=", "lockForUpgradeInterruptibly_", "(", "locker", ")", ";", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "lockForWriteQueuedInterruptibly", "(", "locker", ",", "addWriteWaiter", "(", ")", ")", ";", "}", "if", "(", "upgradeResult", "==", "Result", ".", "ACQUIRED", ")", "{", "// clear upgrade state bit to indicate automatic upgrade\r", "while", "(", "!", "clearUpgradeLock", "(", "mState", ")", ")", "{", "}", "}", "else", "{", "// undo automatic upgrade count increment\r", "mUpgradeCount", "--", ";", "}", "}", "}" ]
Acquire an exclusive write lock, possibly blocking until interrupted. @param locker object trying to become lock owner
[ "Acquire", "an", "exclusive", "write", "lock", "possibly", "blocking", "until", "interrupted", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L407-L424
8,164
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.tryLockForWrite
public final boolean tryLockForWrite(L locker) { int state = mState; if (state == 0) { // no locks are held if (isUpgradeOrReadWriteFirst() && setWriteLock(state)) { // keep upgrade state bit clear to indicate automatic upgrade mOwner = locker; incrementUpgradeCount(); incrementWriteCount(); return true; } } else if (state == LOCK_STATE_UPGRADE) { // only upgrade lock is held; upgrade to full write lock if (mOwner == locker && setWriteLock(state)) { incrementWriteCount(); return true; } } else if (state < 0) { // write lock is held, and upgrade lock might be held too if (mOwner == locker) { incrementWriteCount(); return true; } } return false; }
java
public final boolean tryLockForWrite(L locker) { int state = mState; if (state == 0) { // no locks are held if (isUpgradeOrReadWriteFirst() && setWriteLock(state)) { // keep upgrade state bit clear to indicate automatic upgrade mOwner = locker; incrementUpgradeCount(); incrementWriteCount(); return true; } } else if (state == LOCK_STATE_UPGRADE) { // only upgrade lock is held; upgrade to full write lock if (mOwner == locker && setWriteLock(state)) { incrementWriteCount(); return true; } } else if (state < 0) { // write lock is held, and upgrade lock might be held too if (mOwner == locker) { incrementWriteCount(); return true; } } return false; }
[ "public", "final", "boolean", "tryLockForWrite", "(", "L", "locker", ")", "{", "int", "state", "=", "mState", ";", "if", "(", "state", "==", "0", ")", "{", "// no locks are held\r", "if", "(", "isUpgradeOrReadWriteFirst", "(", ")", "&&", "setWriteLock", "(", "state", ")", ")", "{", "// keep upgrade state bit clear to indicate automatic upgrade\r", "mOwner", "=", "locker", ";", "incrementUpgradeCount", "(", ")", ";", "incrementWriteCount", "(", ")", ";", "return", "true", ";", "}", "}", "else", "if", "(", "state", "==", "LOCK_STATE_UPGRADE", ")", "{", "// only upgrade lock is held; upgrade to full write lock\r", "if", "(", "mOwner", "==", "locker", "&&", "setWriteLock", "(", "state", ")", ")", "{", "incrementWriteCount", "(", ")", ";", "return", "true", ";", "}", "}", "else", "if", "(", "state", "<", "0", ")", "{", "// write lock is held, and upgrade lock might be held too\r", "if", "(", "mOwner", "==", "locker", ")", "{", "incrementWriteCount", "(", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Attempt to immediately acquire an exclusive lock. @param locker object trying to become lock owner @return true if acquired
[ "Attempt", "to", "immediately", "acquire", "an", "exclusive", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L432-L457
8,165
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.tryLockForWrite
public final boolean tryLockForWrite(L locker, long timeout, TimeUnit unit) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForWrite(locker)) { long start = System.nanoTime(); Result upgradeResult = tryLockForUpgrade_(locker, timeout, unit); if (upgradeResult == Result.FAILED) { return false; } if (!tryLockForWrite(locker)) { unlockFromUpgrade(locker); if ((timeout = unit.toNanos(timeout) - (System.nanoTime() - start)) <= 0) { return false; } if (!lockForWriteQueuedInterruptibly(locker, addWriteWaiter(), timeout)) { return false; } } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } return true; }
java
public final boolean tryLockForWrite(L locker, long timeout, TimeUnit unit) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } if (!tryLockForWrite(locker)) { long start = System.nanoTime(); Result upgradeResult = tryLockForUpgrade_(locker, timeout, unit); if (upgradeResult == Result.FAILED) { return false; } if (!tryLockForWrite(locker)) { unlockFromUpgrade(locker); if ((timeout = unit.toNanos(timeout) - (System.nanoTime() - start)) <= 0) { return false; } if (!lockForWriteQueuedInterruptibly(locker, addWriteWaiter(), timeout)) { return false; } } if (upgradeResult == Result.ACQUIRED) { // clear upgrade state bit to indicate automatic upgrade while (!clearUpgradeLock(mState)) {} } else { // undo automatic upgrade count increment mUpgradeCount--; } } return true; }
[ "public", "final", "boolean", "tryLockForWrite", "(", "L", "locker", ",", "long", "timeout", ",", "TimeUnit", "unit", ")", "throws", "InterruptedException", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "long", "start", "=", "System", ".", "nanoTime", "(", ")", ";", "Result", "upgradeResult", "=", "tryLockForUpgrade_", "(", "locker", ",", "timeout", ",", "unit", ")", ";", "if", "(", "upgradeResult", "==", "Result", ".", "FAILED", ")", "{", "return", "false", ";", "}", "if", "(", "!", "tryLockForWrite", "(", "locker", ")", ")", "{", "unlockFromUpgrade", "(", "locker", ")", ";", "if", "(", "(", "timeout", "=", "unit", ".", "toNanos", "(", "timeout", ")", "-", "(", "System", ".", "nanoTime", "(", ")", "-", "start", ")", ")", "<=", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "lockForWriteQueuedInterruptibly", "(", "locker", ",", "addWriteWaiter", "(", ")", ",", "timeout", ")", ")", "{", "return", "false", ";", "}", "}", "if", "(", "upgradeResult", "==", "Result", ".", "ACQUIRED", ")", "{", "// clear upgrade state bit to indicate automatic upgrade\r", "while", "(", "!", "clearUpgradeLock", "(", "mState", ")", ")", "{", "}", "}", "else", "{", "// undo automatic upgrade count increment\r", "mUpgradeCount", "--", ";", "}", "}", "return", "true", ";", "}" ]
Attempt to acquire an exclusive lock, waiting a maximum amount of time. @param locker object trying to become lock owner @return true if acquired
[ "Attempt", "to", "acquire", "an", "exclusive", "lock", "waiting", "a", "maximum", "amount", "of", "time", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L465-L495
8,166
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java
UpgradableLock.unlockFromWrite
public final void unlockFromWrite(L locker) { int writeCount = mWriteCount - 1; if (writeCount < 0) { throw new IllegalMonitorStateException("Too many write locks released"); } mWriteCount = writeCount; if (writeCount > 0) { return; } // copy original state to check if upgrade lock was automatic final int state = mState; // make sure upgrade lock is still held after releasing write lock mState = LOCK_STATE_UPGRADE; Node h = mRWHead; if (h != null && h.mWaitStatus != 0) { unparkReadWriteSuccessor(h); } if (state == LOCK_STATE_WRITE) { // upgrade owner was automatically set, so automatically clear it unlockFromUpgrade(locker); } }
java
public final void unlockFromWrite(L locker) { int writeCount = mWriteCount - 1; if (writeCount < 0) { throw new IllegalMonitorStateException("Too many write locks released"); } mWriteCount = writeCount; if (writeCount > 0) { return; } // copy original state to check if upgrade lock was automatic final int state = mState; // make sure upgrade lock is still held after releasing write lock mState = LOCK_STATE_UPGRADE; Node h = mRWHead; if (h != null && h.mWaitStatus != 0) { unparkReadWriteSuccessor(h); } if (state == LOCK_STATE_WRITE) { // upgrade owner was automatically set, so automatically clear it unlockFromUpgrade(locker); } }
[ "public", "final", "void", "unlockFromWrite", "(", "L", "locker", ")", "{", "int", "writeCount", "=", "mWriteCount", "-", "1", ";", "if", "(", "writeCount", "<", "0", ")", "{", "throw", "new", "IllegalMonitorStateException", "(", "\"Too many write locks released\"", ")", ";", "}", "mWriteCount", "=", "writeCount", ";", "if", "(", "writeCount", ">", "0", ")", "{", "return", ";", "}", "// copy original state to check if upgrade lock was automatic\r", "final", "int", "state", "=", "mState", ";", "// make sure upgrade lock is still held after releasing write lock\r", "mState", "=", "LOCK_STATE_UPGRADE", ";", "Node", "h", "=", "mRWHead", ";", "if", "(", "h", "!=", "null", "&&", "h", ".", "mWaitStatus", "!=", "0", ")", "{", "unparkReadWriteSuccessor", "(", "h", ")", ";", "}", "if", "(", "state", "==", "LOCK_STATE_WRITE", ")", "{", "// upgrade owner was automatically set, so automatically clear it\r", "unlockFromUpgrade", "(", "locker", ")", ";", "}", "}" ]
Release a previously acquired write lock.
[ "Release", "a", "previously", "acquired", "write", "lock", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/map/UpgradableLock.java#L500-L525
8,167
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.loadPropertyAnnotation
private void loadPropertyAnnotation(CodeBuilder b, StorableProperty property, StorablePropertyAnnotation annotation) { /* Example UserInfo.class.getMethod("setFirstName", new Class[] {String.class}) .getAnnotation(LengthConstraint.class) */ String methodName = annotation.getAnnotatedMethod().getName(); boolean isAccessor = !methodName.startsWith("set"); b.loadConstant(TypeDesc.forClass(property.getEnclosingType())); b.loadConstant(methodName); if (isAccessor) { // Accessor method has no parameters. b.loadNull(); } else { // Mutator method has one parameter. b.loadConstant(1); b.newObject(TypeDesc.forClass(Class[].class)); b.dup(); b.loadConstant(0); b.loadConstant(TypeDesc.forClass(property.getType())); b.storeToArray(TypeDesc.forClass(Class[].class)); } b.invokeVirtual(Class.class.getName(), "getMethod", TypeDesc.forClass(Method.class), new TypeDesc[] { TypeDesc.STRING, TypeDesc.forClass(Class[].class) }); b.loadConstant(TypeDesc.forClass(annotation.getAnnotationType())); b.invokeVirtual(Method.class.getName(), "getAnnotation", TypeDesc.forClass(Annotation.class), new TypeDesc[] { TypeDesc.forClass(Class.class) }); b.checkCast(TypeDesc.forClass(annotation.getAnnotationType())); }
java
private void loadPropertyAnnotation(CodeBuilder b, StorableProperty property, StorablePropertyAnnotation annotation) { /* Example UserInfo.class.getMethod("setFirstName", new Class[] {String.class}) .getAnnotation(LengthConstraint.class) */ String methodName = annotation.getAnnotatedMethod().getName(); boolean isAccessor = !methodName.startsWith("set"); b.loadConstant(TypeDesc.forClass(property.getEnclosingType())); b.loadConstant(methodName); if (isAccessor) { // Accessor method has no parameters. b.loadNull(); } else { // Mutator method has one parameter. b.loadConstant(1); b.newObject(TypeDesc.forClass(Class[].class)); b.dup(); b.loadConstant(0); b.loadConstant(TypeDesc.forClass(property.getType())); b.storeToArray(TypeDesc.forClass(Class[].class)); } b.invokeVirtual(Class.class.getName(), "getMethod", TypeDesc.forClass(Method.class), new TypeDesc[] { TypeDesc.STRING, TypeDesc.forClass(Class[].class) }); b.loadConstant(TypeDesc.forClass(annotation.getAnnotationType())); b.invokeVirtual(Method.class.getName(), "getAnnotation", TypeDesc.forClass(Annotation.class), new TypeDesc[] { TypeDesc.forClass(Class.class) }); b.checkCast(TypeDesc.forClass(annotation.getAnnotationType())); }
[ "private", "void", "loadPropertyAnnotation", "(", "CodeBuilder", "b", ",", "StorableProperty", "property", ",", "StorablePropertyAnnotation", "annotation", ")", "{", "/* Example\r\n UserInfo.class.getMethod(\"setFirstName\", new Class[] {String.class})\r\n .getAnnotation(LengthConstraint.class)\r\n */", "String", "methodName", "=", "annotation", ".", "getAnnotatedMethod", "(", ")", ".", "getName", "(", ")", ";", "boolean", "isAccessor", "=", "!", "methodName", ".", "startsWith", "(", "\"set\"", ")", ";", "b", ".", "loadConstant", "(", "TypeDesc", ".", "forClass", "(", "property", ".", "getEnclosingType", "(", ")", ")", ")", ";", "b", ".", "loadConstant", "(", "methodName", ")", ";", "if", "(", "isAccessor", ")", "{", "// Accessor method has no parameters.\r", "b", ".", "loadNull", "(", ")", ";", "}", "else", "{", "// Mutator method has one parameter.\r", "b", ".", "loadConstant", "(", "1", ")", ";", "b", ".", "newObject", "(", "TypeDesc", ".", "forClass", "(", "Class", "[", "]", ".", "class", ")", ")", ";", "b", ".", "dup", "(", ")", ";", "b", ".", "loadConstant", "(", "0", ")", ";", "b", ".", "loadConstant", "(", "TypeDesc", ".", "forClass", "(", "property", ".", "getType", "(", ")", ")", ")", ";", "b", ".", "storeToArray", "(", "TypeDesc", ".", "forClass", "(", "Class", "[", "]", ".", "class", ")", ")", ";", "}", "b", ".", "invokeVirtual", "(", "Class", ".", "class", ".", "getName", "(", ")", ",", "\"getMethod\"", ",", "TypeDesc", ".", "forClass", "(", "Method", ".", "class", ")", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "STRING", ",", "TypeDesc", ".", "forClass", "(", "Class", "[", "]", ".", "class", ")", "}", ")", ";", "b", ".", "loadConstant", "(", "TypeDesc", ".", "forClass", "(", "annotation", ".", "getAnnotationType", "(", ")", ")", ")", ";", "b", ".", "invokeVirtual", "(", "Method", ".", "class", ".", "getName", "(", ")", ",", "\"getAnnotation\"", ",", "TypeDesc", ".", "forClass", "(", "Annotation", ".", "class", ")", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "forClass", "(", "Class", ".", "class", ")", "}", ")", ";", "b", ".", "checkCast", "(", "TypeDesc", ".", "forClass", "(", "annotation", ".", "getAnnotationType", "(", ")", ")", ")", ";", "}" ]
Generates code that loads a property annotation to the stack.
[ "Generates", "code", "that", "loads", "a", "property", "annotation", "to", "the", "stack", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2089-L2124
8,168
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.loadStorageForFetch
private void loadStorageForFetch(CodeBuilder b, TypeDesc type) { b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); TypeDesc storageType = TypeDesc.forClass(Storage.class); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); b.invokeInterface (mSupportType, "getRootRepository", repositoryType, null); b.loadConstant(type); // This may throw a RepositoryException. Label tryStart = b.createLabel().setLocation(); b.invokeInterface(repositoryType, STORAGE_FOR_METHOD_NAME, storageType, new TypeDesc[]{TypeDesc.forClass(Class.class)}); Label tryEnd = b.createLabel().setLocation(); Label noException = b.createLabel(); b.branch(noException); b.exceptionHandler(tryStart, tryEnd, RepositoryException.class.getName()); b.invokeVirtual (RepositoryException.class.getName(), "toFetchException", TypeDesc.forClass(FetchException.class), null); b.throwObject(); noException.setLocation(); }
java
private void loadStorageForFetch(CodeBuilder b, TypeDesc type) { b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); TypeDesc storageType = TypeDesc.forClass(Storage.class); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); b.invokeInterface (mSupportType, "getRootRepository", repositoryType, null); b.loadConstant(type); // This may throw a RepositoryException. Label tryStart = b.createLabel().setLocation(); b.invokeInterface(repositoryType, STORAGE_FOR_METHOD_NAME, storageType, new TypeDesc[]{TypeDesc.forClass(Class.class)}); Label tryEnd = b.createLabel().setLocation(); Label noException = b.createLabel(); b.branch(noException); b.exceptionHandler(tryStart, tryEnd, RepositoryException.class.getName()); b.invokeVirtual (RepositoryException.class.getName(), "toFetchException", TypeDesc.forClass(FetchException.class), null); b.throwObject(); noException.setLocation(); }
[ "private", "void", "loadStorageForFetch", "(", "CodeBuilder", "b", ",", "TypeDesc", "type", ")", "{", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "SUPPORT_FIELD_NAME", ",", "mSupportType", ")", ";", "TypeDesc", "storageType", "=", "TypeDesc", ".", "forClass", "(", "Storage", ".", "class", ")", ";", "TypeDesc", "repositoryType", "=", "TypeDesc", ".", "forClass", "(", "Repository", ".", "class", ")", ";", "b", ".", "invokeInterface", "(", "mSupportType", ",", "\"getRootRepository\"", ",", "repositoryType", ",", "null", ")", ";", "b", ".", "loadConstant", "(", "type", ")", ";", "// This may throw a RepositoryException.\r", "Label", "tryStart", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "b", ".", "invokeInterface", "(", "repositoryType", ",", "STORAGE_FOR_METHOD_NAME", ",", "storageType", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "forClass", "(", "Class", ".", "class", ")", "}", ")", ";", "Label", "tryEnd", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "Label", "noException", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "branch", "(", "noException", ")", ";", "b", ".", "exceptionHandler", "(", "tryStart", ",", "tryEnd", ",", "RepositoryException", ".", "class", ".", "getName", "(", ")", ")", ";", "b", ".", "invokeVirtual", "(", "RepositoryException", ".", "class", ".", "getName", "(", ")", ",", "\"toFetchException\"", ",", "TypeDesc", ".", "forClass", "(", "FetchException", ".", "class", ")", ",", "null", ")", ";", "b", ".", "throwObject", "(", ")", ";", "noException", ".", "setLocation", "(", ")", ";", "}" ]
Generates code that loads a Storage instance on the stack, throwing a FetchException if Storage request fails. @param type type of Storage to request
[ "Generates", "code", "that", "loads", "a", "Storage", "instance", "on", "the", "stack", "throwing", "a", "FetchException", "if", "Storage", "request", "fails", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2132-L2158
8,169
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.markOrdinaryPropertyDirty
private void markOrdinaryPropertyDirty (CodeBuilder b, StorableProperty ordinaryProperty) { int count = mAllProperties.size(); int ordinal = 0; int andMask = 0xffffffff; int orMask = 0; boolean anyNonDerived = false; for (StorableProperty property : mAllProperties.values()) { if (!property.isDerived()) { anyNonDerived = true; if (property == ordinaryProperty) { orMask |= PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2); } else if (property.isJoin()) { // Check to see if ordinary is an internal member of join property. for (int i=property.getJoinElementCount(); --i>=0; ) { if (ordinaryProperty == property.getInternalJoinElement(i)) { andMask &= ~(PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2)); } } } } ordinal++; if ((ordinal & 0xf) == 0 || ordinal >= count) { if (anyNonDerived && (andMask != 0xffffffff || orMask != 0)) { String stateFieldName = PROPERTY_STATE_FIELD_NAME + ((ordinal - 1) >> 4); b.loadThis(); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); if (andMask != 0xffffffff) { b.loadConstant(andMask); b.math(Opcode.IAND); } if (orMask != 0) { b.loadConstant(orMask); b.math(Opcode.IOR); } b.storeField(stateFieldName, TypeDesc.INT); } andMask = 0xffffffff; orMask = 0; anyNonDerived = false; } } }
java
private void markOrdinaryPropertyDirty (CodeBuilder b, StorableProperty ordinaryProperty) { int count = mAllProperties.size(); int ordinal = 0; int andMask = 0xffffffff; int orMask = 0; boolean anyNonDerived = false; for (StorableProperty property : mAllProperties.values()) { if (!property.isDerived()) { anyNonDerived = true; if (property == ordinaryProperty) { orMask |= PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2); } else if (property.isJoin()) { // Check to see if ordinary is an internal member of join property. for (int i=property.getJoinElementCount(); --i>=0; ) { if (ordinaryProperty == property.getInternalJoinElement(i)) { andMask &= ~(PROPERTY_STATE_DIRTY << ((ordinal & 0xf) * 2)); } } } } ordinal++; if ((ordinal & 0xf) == 0 || ordinal >= count) { if (anyNonDerived && (andMask != 0xffffffff || orMask != 0)) { String stateFieldName = PROPERTY_STATE_FIELD_NAME + ((ordinal - 1) >> 4); b.loadThis(); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); if (andMask != 0xffffffff) { b.loadConstant(andMask); b.math(Opcode.IAND); } if (orMask != 0) { b.loadConstant(orMask); b.math(Opcode.IOR); } b.storeField(stateFieldName, TypeDesc.INT); } andMask = 0xffffffff; orMask = 0; anyNonDerived = false; } } }
[ "private", "void", "markOrdinaryPropertyDirty", "(", "CodeBuilder", "b", ",", "StorableProperty", "ordinaryProperty", ")", "{", "int", "count", "=", "mAllProperties", ".", "size", "(", ")", ";", "int", "ordinal", "=", "0", ";", "int", "andMask", "=", "0xffffffff", ";", "int", "orMask", "=", "0", ";", "boolean", "anyNonDerived", "=", "false", ";", "for", "(", "StorableProperty", "property", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "if", "(", "!", "property", ".", "isDerived", "(", ")", ")", "{", "anyNonDerived", "=", "true", ";", "if", "(", "property", "==", "ordinaryProperty", ")", "{", "orMask", "|=", "PROPERTY_STATE_DIRTY", "<<", "(", "(", "ordinal", "&", "0xf", ")", "*", "2", ")", ";", "}", "else", "if", "(", "property", ".", "isJoin", "(", ")", ")", "{", "// Check to see if ordinary is an internal member of join property.\r", "for", "(", "int", "i", "=", "property", ".", "getJoinElementCount", "(", ")", ";", "--", "i", ">=", "0", ";", ")", "{", "if", "(", "ordinaryProperty", "==", "property", ".", "getInternalJoinElement", "(", "i", ")", ")", "{", "andMask", "&=", "~", "(", "PROPERTY_STATE_DIRTY", "<<", "(", "(", "ordinal", "&", "0xf", ")", "*", "2", ")", ")", ";", "}", "}", "}", "}", "ordinal", "++", ";", "if", "(", "(", "ordinal", "&", "0xf", ")", "==", "0", "||", "ordinal", ">=", "count", ")", "{", "if", "(", "anyNonDerived", "&&", "(", "andMask", "!=", "0xffffffff", "||", "orMask", "!=", "0", ")", ")", "{", "String", "stateFieldName", "=", "PROPERTY_STATE_FIELD_NAME", "+", "(", "(", "ordinal", "-", "1", ")", ">>", "4", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "stateFieldName", ",", "TypeDesc", ".", "INT", ")", ";", "if", "(", "andMask", "!=", "0xffffffff", ")", "{", "b", ".", "loadConstant", "(", "andMask", ")", ";", "b", ".", "math", "(", "Opcode", ".", "IAND", ")", ";", "}", "if", "(", "orMask", "!=", "0", ")", "{", "b", ".", "loadConstant", "(", "orMask", ")", ";", "b", ".", "math", "(", "Opcode", ".", "IOR", ")", ";", "}", "b", ".", "storeField", "(", "stateFieldName", ",", "TypeDesc", ".", "INT", ")", ";", "}", "andMask", "=", "0xffffffff", ";", "orMask", "=", "0", ";", "anyNonDerived", "=", "false", ";", "}", "}", "}" ]
For the given ordinary key property, marks all of its dependent join element properties as uninitialized, and marks given property as dirty.
[ "For", "the", "given", "ordinary", "key", "property", "marks", "all", "of", "its", "dependent", "join", "element", "properties", "as", "uninitialized", "and", "marks", "given", "property", "as", "dirty", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2372-L2420
8,170
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.branchIfDirty
private void branchIfDirty(CodeBuilder b, boolean includePk, Label label) { int count = mAllProperties.size(); int ordinal = 0; int andMask = 0; boolean anyNonDerived = false; for (StorableProperty property : mAllProperties.values()) { if (!property.isDerived()) { anyNonDerived = true; if (!property.isJoin() && (!property.isPrimaryKeyMember() || includePk)) { // Logical 'and' will convert state 1 (clean) to state 0, so // that it will be ignored. State 3 (dirty) is what we're // looking for, and it turns into 2. Essentially, we leave the // high order bit on, since there is no state which has the // high order bit on unless the low order bit is also on. andMask |= 2 << ((ordinal & 0xf) * 2); } } ordinal++; if ((ordinal & 0xf) == 0 || ordinal >= count) { if (anyNonDerived) { String stateFieldName = PROPERTY_STATE_FIELD_NAME + ((ordinal - 1) >> 4); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); b.loadConstant(andMask); b.math(Opcode.IAND); // At least one property is dirty, so short circuit. b.ifZeroComparisonBranch(label, "!="); } andMask = 0; anyNonDerived = false; } } }
java
private void branchIfDirty(CodeBuilder b, boolean includePk, Label label) { int count = mAllProperties.size(); int ordinal = 0; int andMask = 0; boolean anyNonDerived = false; for (StorableProperty property : mAllProperties.values()) { if (!property.isDerived()) { anyNonDerived = true; if (!property.isJoin() && (!property.isPrimaryKeyMember() || includePk)) { // Logical 'and' will convert state 1 (clean) to state 0, so // that it will be ignored. State 3 (dirty) is what we're // looking for, and it turns into 2. Essentially, we leave the // high order bit on, since there is no state which has the // high order bit on unless the low order bit is also on. andMask |= 2 << ((ordinal & 0xf) * 2); } } ordinal++; if ((ordinal & 0xf) == 0 || ordinal >= count) { if (anyNonDerived) { String stateFieldName = PROPERTY_STATE_FIELD_NAME + ((ordinal - 1) >> 4); b.loadThis(); b.loadField(stateFieldName, TypeDesc.INT); b.loadConstant(andMask); b.math(Opcode.IAND); // At least one property is dirty, so short circuit. b.ifZeroComparisonBranch(label, "!="); } andMask = 0; anyNonDerived = false; } } }
[ "private", "void", "branchIfDirty", "(", "CodeBuilder", "b", ",", "boolean", "includePk", ",", "Label", "label", ")", "{", "int", "count", "=", "mAllProperties", ".", "size", "(", ")", ";", "int", "ordinal", "=", "0", ";", "int", "andMask", "=", "0", ";", "boolean", "anyNonDerived", "=", "false", ";", "for", "(", "StorableProperty", "property", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "if", "(", "!", "property", ".", "isDerived", "(", ")", ")", "{", "anyNonDerived", "=", "true", ";", "if", "(", "!", "property", ".", "isJoin", "(", ")", "&&", "(", "!", "property", ".", "isPrimaryKeyMember", "(", ")", "||", "includePk", ")", ")", "{", "// Logical 'and' will convert state 1 (clean) to state 0, so\r", "// that it will be ignored. State 3 (dirty) is what we're\r", "// looking for, and it turns into 2. Essentially, we leave the\r", "// high order bit on, since there is no state which has the\r", "// high order bit on unless the low order bit is also on.\r", "andMask", "|=", "2", "<<", "(", "(", "ordinal", "&", "0xf", ")", "*", "2", ")", ";", "}", "}", "ordinal", "++", ";", "if", "(", "(", "ordinal", "&", "0xf", ")", "==", "0", "||", "ordinal", ">=", "count", ")", "{", "if", "(", "anyNonDerived", ")", "{", "String", "stateFieldName", "=", "PROPERTY_STATE_FIELD_NAME", "+", "(", "(", "ordinal", "-", "1", ")", ">>", "4", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "stateFieldName", ",", "TypeDesc", ".", "INT", ")", ";", "b", ".", "loadConstant", "(", "andMask", ")", ";", "b", ".", "math", "(", "Opcode", ".", "IAND", ")", ";", "// At least one property is dirty, so short circuit.\r", "b", ".", "ifZeroComparisonBranch", "(", "label", ",", "\"!=\"", ")", ";", "}", "andMask", "=", "0", ";", "anyNonDerived", "=", "false", ";", "}", "}", "}" ]
Generates code that branches to the given label if any properties are dirty.
[ "Generates", "code", "that", "branches", "to", "the", "given", "label", "if", "any", "properties", "are", "dirty", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2423-L2458
8,171
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.requirePkInitialized
private void requirePkInitialized(CodeBuilder b, String methodName) { // Add code to call method which we are about to define. b.loadThis(); b.invokeVirtual(methodName, null, null); // Now define new method, discarding original builder object. b = new CodeBuilder(mClassFile.addMethod(Modifiers.PROTECTED, methodName, null, null)); b.loadThis(); b.invokeVirtual(IS_REQUIRED_PK_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label pkInitialized = b.createLabel(); b.ifZeroComparisonBranch(pkInitialized, "!="); CodeBuilderUtil.throwException (b, IllegalStateException.class, "Primary key not fully specified"); pkInitialized.setLocation(); b.returnVoid(); }
java
private void requirePkInitialized(CodeBuilder b, String methodName) { // Add code to call method which we are about to define. b.loadThis(); b.invokeVirtual(methodName, null, null); // Now define new method, discarding original builder object. b = new CodeBuilder(mClassFile.addMethod(Modifiers.PROTECTED, methodName, null, null)); b.loadThis(); b.invokeVirtual(IS_REQUIRED_PK_INITIALIZED_METHOD_NAME, TypeDesc.BOOLEAN, null); Label pkInitialized = b.createLabel(); b.ifZeroComparisonBranch(pkInitialized, "!="); CodeBuilderUtil.throwException (b, IllegalStateException.class, "Primary key not fully specified"); pkInitialized.setLocation(); b.returnVoid(); }
[ "private", "void", "requirePkInitialized", "(", "CodeBuilder", "b", ",", "String", "methodName", ")", "{", "// Add code to call method which we are about to define.\r", "b", ".", "loadThis", "(", ")", ";", "b", ".", "invokeVirtual", "(", "methodName", ",", "null", ",", "null", ")", ";", "// Now define new method, discarding original builder object.\r", "b", "=", "new", "CodeBuilder", "(", "mClassFile", ".", "addMethod", "(", "Modifiers", ".", "PROTECTED", ",", "methodName", ",", "null", ",", "null", ")", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "invokeVirtual", "(", "IS_REQUIRED_PK_INITIALIZED_METHOD_NAME", ",", "TypeDesc", ".", "BOOLEAN", ",", "null", ")", ";", "Label", "pkInitialized", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "pkInitialized", ",", "\"!=\"", ")", ";", "CodeBuilderUtil", ".", "throwException", "(", "b", ",", "IllegalStateException", ".", "class", ",", "\"Primary key not fully specified\"", ")", ";", "pkInitialized", ".", "setLocation", "(", ")", ";", "b", ".", "returnVoid", "(", ")", ";", "}" ]
Generates code that verifies that all primary keys are initialized. @param b builder that will invoke generated method @param methodName name to give to generated method
[ "Generates", "code", "that", "verifies", "that", "all", "primary", "keys", "are", "initialized", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2577-L2592
8,172
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addPropertyStateExtractMethod
private void addPropertyStateExtractMethod() { MethodInfo mi = mClassFile.addMethod(Modifiers.PRIVATE, PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); addPropertySwitch(new CodeBuilder(mi), SWITCH_FOR_STATE); }
java
private void addPropertyStateExtractMethod() { MethodInfo mi = mClassFile.addMethod(Modifiers.PRIVATE, PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); addPropertySwitch(new CodeBuilder(mi), SWITCH_FOR_STATE); }
[ "private", "void", "addPropertyStateExtractMethod", "(", ")", "{", "MethodInfo", "mi", "=", "mClassFile", ".", "addMethod", "(", "Modifiers", ".", "PRIVATE", ",", "PROPERTY_STATE_EXTRACT_METHOD_NAME", ",", "TypeDesc", ".", "INT", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "STRING", "}", ")", ";", "addPropertySwitch", "(", "new", "CodeBuilder", "(", "mi", ")", ",", "SWITCH_FOR_STATE", ")", ";", "}" ]
Generates a private method which accepts a property name and returns PROPERTY_STATE_UNINITIALIZED, PROPERTY_STATE_DIRTY, or PROPERTY_STATE_CLEAN.
[ "Generates", "a", "private", "method", "which", "accepts", "a", "property", "name", "and", "returns", "PROPERTY_STATE_UNINITIALIZED", "PROPERTY_STATE_DIRTY", "or", "PROPERTY_STATE_CLEAN", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2599-L2604
8,173
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.caseMatches
private List<StorableProperty<?>>[] caseMatches(int caseCount) { List<StorableProperty<?>>[] cases = new List[caseCount]; for (StorableProperty<?> prop : mAllProperties.values()) { int hashCode = prop.getName().hashCode(); int caseValue = (hashCode & 0x7fffffff) % caseCount; List matches = cases[caseValue]; if (matches == null) { matches = cases[caseValue] = new ArrayList<StorableProperty<?>>(); } matches.add(prop); } return cases; }
java
private List<StorableProperty<?>>[] caseMatches(int caseCount) { List<StorableProperty<?>>[] cases = new List[caseCount]; for (StorableProperty<?> prop : mAllProperties.values()) { int hashCode = prop.getName().hashCode(); int caseValue = (hashCode & 0x7fffffff) % caseCount; List matches = cases[caseValue]; if (matches == null) { matches = cases[caseValue] = new ArrayList<StorableProperty<?>>(); } matches.add(prop); } return cases; }
[ "private", "List", "<", "StorableProperty", "<", "?", ">", ">", "[", "]", "caseMatches", "(", "int", "caseCount", ")", "{", "List", "<", "StorableProperty", "<", "?", ">", ">", "[", "]", "cases", "=", "new", "List", "[", "caseCount", "]", ";", "for", "(", "StorableProperty", "<", "?", ">", "prop", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "int", "hashCode", "=", "prop", ".", "getName", "(", ")", ".", "hashCode", "(", ")", ";", "int", "caseValue", "=", "(", "hashCode", "&", "0x7fffffff", ")", "%", "caseCount", ";", "List", "matches", "=", "cases", "[", "caseValue", "]", ";", "if", "(", "matches", "==", "null", ")", "{", "matches", "=", "cases", "[", "caseValue", "]", "=", "new", "ArrayList", "<", "StorableProperty", "<", "?", ">", ">", "(", ")", ";", "}", "matches", ".", "add", "(", "prop", ")", ";", "}", "return", "cases", ";", "}" ]
Returns the properties that match on a given case. The array length is the same as the case count. Each list represents the matches. The lists themselves may be null if no matches for that case.
[ "Returns", "the", "properties", "that", "match", "on", "a", "given", "case", ".", "The", "array", "length", "is", "the", "same", "as", "the", "case", "count", ".", "Each", "list", "represents", "the", "matches", ".", "The", "lists", "themselves", "may", "be", "null", "if", "no", "matches", "for", "that", "case", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2837-L2851
8,174
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addPropertyStateCheckMethod
private void addPropertyStateCheckMethod(String name, int state) { MethodInfo mi = addMethodIfNotFinal(Modifiers.PUBLIC, name, TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.STRING}); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); // Call private method to extract state and compare. b.loadThis(); b.loadLocal(b.getParameter(0)); b.invokePrivate(PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); Label isFalse = b.createLabel(); if (state == 0) { b.ifZeroComparisonBranch(isFalse, "!="); } else { b.loadConstant(state); b.ifComparisonBranch(isFalse, "!="); } b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); isFalse.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); }
java
private void addPropertyStateCheckMethod(String name, int state) { MethodInfo mi = addMethodIfNotFinal(Modifiers.PUBLIC, name, TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.STRING}); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); // Call private method to extract state and compare. b.loadThis(); b.loadLocal(b.getParameter(0)); b.invokePrivate(PROPERTY_STATE_EXTRACT_METHOD_NAME, TypeDesc.INT, new TypeDesc[] {TypeDesc.STRING}); Label isFalse = b.createLabel(); if (state == 0) { b.ifZeroComparisonBranch(isFalse, "!="); } else { b.loadConstant(state); b.ifComparisonBranch(isFalse, "!="); } b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); isFalse.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); }
[ "private", "void", "addPropertyStateCheckMethod", "(", "String", "name", ",", "int", "state", ")", "{", "MethodInfo", "mi", "=", "addMethodIfNotFinal", "(", "Modifiers", ".", "PUBLIC", ",", "name", ",", "TypeDesc", ".", "BOOLEAN", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "STRING", "}", ")", ";", "if", "(", "mi", "==", "null", ")", "{", "return", ";", "}", "CodeBuilder", "b", "=", "new", "CodeBuilder", "(", "mi", ")", ";", "// Call private method to extract state and compare.\r", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadLocal", "(", "b", ".", "getParameter", "(", "0", ")", ")", ";", "b", ".", "invokePrivate", "(", "PROPERTY_STATE_EXTRACT_METHOD_NAME", ",", "TypeDesc", ".", "INT", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "STRING", "}", ")", ";", "Label", "isFalse", "=", "b", ".", "createLabel", "(", ")", ";", "if", "(", "state", "==", "0", ")", "{", "b", ".", "ifZeroComparisonBranch", "(", "isFalse", ",", "\"!=\"", ")", ";", "}", "else", "{", "b", ".", "loadConstant", "(", "state", ")", ";", "b", ".", "ifComparisonBranch", "(", "isFalse", ",", "\"!=\"", ")", ";", "}", "b", ".", "loadConstant", "(", "true", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "isFalse", ".", "setLocation", "(", ")", ";", "b", ".", "loadConstant", "(", "false", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "}" ]
Generates public method which accepts a property name and returns a boolean true, if the given state matches the property's actual state. @param name name of method @param state property state to check
[ "Generates", "public", "method", "which", "accepts", "a", "property", "name", "and", "returns", "a", "boolean", "true", "if", "the", "given", "state", "matches", "the", "property", "s", "actual", "state", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L2860-L2887
8,175
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addHashCodeMethod
private void addHashCodeMethod() { Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal(modifiers, "hashCode", TypeDesc.INT, null); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); boolean mixIn = false; for (StorableProperty property : mAllProperties.values()) { if (property.isDerived() || property.isJoin()) { continue; } TypeDesc fieldType = TypeDesc.forClass(property.getType()); b.loadThis(); b.loadField(property.getName(), fieldType); CodeBuilderUtil.addValueHashCodeCall(b, fieldType, true, mixIn); mixIn = true; } b.returnValue(TypeDesc.INT); }
java
private void addHashCodeMethod() { Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal(modifiers, "hashCode", TypeDesc.INT, null); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); boolean mixIn = false; for (StorableProperty property : mAllProperties.values()) { if (property.isDerived() || property.isJoin()) { continue; } TypeDesc fieldType = TypeDesc.forClass(property.getType()); b.loadThis(); b.loadField(property.getName(), fieldType); CodeBuilderUtil.addValueHashCodeCall(b, fieldType, true, mixIn); mixIn = true; } b.returnValue(TypeDesc.INT); }
[ "private", "void", "addHashCodeMethod", "(", ")", "{", "Modifiers", "modifiers", "=", "Modifiers", ".", "PUBLIC", ".", "toSynchronized", "(", "true", ")", ";", "MethodInfo", "mi", "=", "addMethodIfNotFinal", "(", "modifiers", ",", "\"hashCode\"", ",", "TypeDesc", ".", "INT", ",", "null", ")", ";", "if", "(", "mi", "==", "null", ")", "{", "return", ";", "}", "CodeBuilder", "b", "=", "new", "CodeBuilder", "(", "mi", ")", ";", "boolean", "mixIn", "=", "false", ";", "for", "(", "StorableProperty", "property", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "if", "(", "property", ".", "isDerived", "(", ")", "||", "property", ".", "isJoin", "(", ")", ")", "{", "continue", ";", "}", "TypeDesc", "fieldType", "=", "TypeDesc", ".", "forClass", "(", "property", ".", "getType", "(", ")", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "property", ".", "getName", "(", ")", ",", "fieldType", ")", ";", "CodeBuilderUtil", ".", "addValueHashCodeCall", "(", "b", ",", "fieldType", ",", "true", ",", "mixIn", ")", ";", "mixIn", "=", "true", ";", "}", "b", ".", "returnValue", "(", "TypeDesc", ".", "INT", ")", ";", "}" ]
Defines a hashCode method.
[ "Defines", "a", "hashCode", "method", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3016-L3039
8,176
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addEqualsMethod
private void addEqualsMethod(int equalityType) { TypeDesc[] objectParam = {TypeDesc.OBJECT}; String equalsMethodName; switch (equalityType) { default: throw new IllegalArgumentException(); case EQUAL_KEYS: equalsMethodName = EQUAL_PRIMARY_KEYS_METHOD_NAME; break; case EQUAL_PROPERTIES: equalsMethodName = EQUAL_PROPERTIES_METHOD_NAME; break; case EQUAL_FULL: equalsMethodName = EQUALS_METHOD_NAME; } Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal (modifiers, equalsMethodName, TypeDesc.BOOLEAN, objectParam); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); // if (this == target) return true; b.loadThis(); b.loadLocal(b.getParameter(0)); Label notEqual = b.createLabel(); b.ifEqualBranch(notEqual, false); b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); notEqual.setLocation(); // FIXME: Using instanceof means that equals is not symmetric. // if (! target instanceof this) return false; TypeDesc userStorableTypeDesc = TypeDesc.forClass(mStorableType); b.loadLocal(b.getParameter(0)); b.instanceOf(userStorableTypeDesc); Label fail = b.createLabel(); b.ifZeroComparisonBranch(fail, "=="); // this.class other = (this.class)target; LocalVariable other = b.createLocalVariable(null, userStorableTypeDesc); b.loadLocal(b.getParameter(0)); b.checkCast(userStorableTypeDesc); b.storeLocal(other); for (StorableProperty property : mAllProperties.values()) { if (property.isDerived() || property.isJoin()) { continue; } // If we're only comparing keys, and this isn't a key, skip it if ((equalityType == EQUAL_KEYS) && !property.isPrimaryKeyMember()) { continue; } // Check if independent property is supported, and skip if not. Label skipCheck = b.createLabel(); if (equalityType != EQUAL_KEYS && property.isIndependent()) { addSkipIndependent(b, other, property, skipCheck); } TypeDesc fieldType = TypeDesc.forClass(property.getType()); loadThisProperty(b, property); b.loadLocal(other); b.invoke(property.getReadMethod()); CodeBuilderUtil.addValuesEqualCall(b, fieldType, true, fail, false); skipCheck.setLocation(); } b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); fail.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); }
java
private void addEqualsMethod(int equalityType) { TypeDesc[] objectParam = {TypeDesc.OBJECT}; String equalsMethodName; switch (equalityType) { default: throw new IllegalArgumentException(); case EQUAL_KEYS: equalsMethodName = EQUAL_PRIMARY_KEYS_METHOD_NAME; break; case EQUAL_PROPERTIES: equalsMethodName = EQUAL_PROPERTIES_METHOD_NAME; break; case EQUAL_FULL: equalsMethodName = EQUALS_METHOD_NAME; } Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal (modifiers, equalsMethodName, TypeDesc.BOOLEAN, objectParam); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); // if (this == target) return true; b.loadThis(); b.loadLocal(b.getParameter(0)); Label notEqual = b.createLabel(); b.ifEqualBranch(notEqual, false); b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); notEqual.setLocation(); // FIXME: Using instanceof means that equals is not symmetric. // if (! target instanceof this) return false; TypeDesc userStorableTypeDesc = TypeDesc.forClass(mStorableType); b.loadLocal(b.getParameter(0)); b.instanceOf(userStorableTypeDesc); Label fail = b.createLabel(); b.ifZeroComparisonBranch(fail, "=="); // this.class other = (this.class)target; LocalVariable other = b.createLocalVariable(null, userStorableTypeDesc); b.loadLocal(b.getParameter(0)); b.checkCast(userStorableTypeDesc); b.storeLocal(other); for (StorableProperty property : mAllProperties.values()) { if (property.isDerived() || property.isJoin()) { continue; } // If we're only comparing keys, and this isn't a key, skip it if ((equalityType == EQUAL_KEYS) && !property.isPrimaryKeyMember()) { continue; } // Check if independent property is supported, and skip if not. Label skipCheck = b.createLabel(); if (equalityType != EQUAL_KEYS && property.isIndependent()) { addSkipIndependent(b, other, property, skipCheck); } TypeDesc fieldType = TypeDesc.forClass(property.getType()); loadThisProperty(b, property); b.loadLocal(other); b.invoke(property.getReadMethod()); CodeBuilderUtil.addValuesEqualCall(b, fieldType, true, fail, false); skipCheck.setLocation(); } b.loadConstant(true); b.returnValue(TypeDesc.BOOLEAN); fail.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); }
[ "private", "void", "addEqualsMethod", "(", "int", "equalityType", ")", "{", "TypeDesc", "[", "]", "objectParam", "=", "{", "TypeDesc", ".", "OBJECT", "}", ";", "String", "equalsMethodName", ";", "switch", "(", "equalityType", ")", "{", "default", ":", "throw", "new", "IllegalArgumentException", "(", ")", ";", "case", "EQUAL_KEYS", ":", "equalsMethodName", "=", "EQUAL_PRIMARY_KEYS_METHOD_NAME", ";", "break", ";", "case", "EQUAL_PROPERTIES", ":", "equalsMethodName", "=", "EQUAL_PROPERTIES_METHOD_NAME", ";", "break", ";", "case", "EQUAL_FULL", ":", "equalsMethodName", "=", "EQUALS_METHOD_NAME", ";", "}", "Modifiers", "modifiers", "=", "Modifiers", ".", "PUBLIC", ".", "toSynchronized", "(", "true", ")", ";", "MethodInfo", "mi", "=", "addMethodIfNotFinal", "(", "modifiers", ",", "equalsMethodName", ",", "TypeDesc", ".", "BOOLEAN", ",", "objectParam", ")", ";", "if", "(", "mi", "==", "null", ")", "{", "return", ";", "}", "CodeBuilder", "b", "=", "new", "CodeBuilder", "(", "mi", ")", ";", "// if (this == target) return true;\r", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadLocal", "(", "b", ".", "getParameter", "(", "0", ")", ")", ";", "Label", "notEqual", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifEqualBranch", "(", "notEqual", ",", "false", ")", ";", "b", ".", "loadConstant", "(", "true", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "notEqual", ".", "setLocation", "(", ")", ";", "// FIXME: Using instanceof means that equals is not symmetric.\r", "// if (! target instanceof this) return false;\r", "TypeDesc", "userStorableTypeDesc", "=", "TypeDesc", ".", "forClass", "(", "mStorableType", ")", ";", "b", ".", "loadLocal", "(", "b", ".", "getParameter", "(", "0", ")", ")", ";", "b", ".", "instanceOf", "(", "userStorableTypeDesc", ")", ";", "Label", "fail", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "fail", ",", "\"==\"", ")", ";", "// this.class other = (this.class)target;\r", "LocalVariable", "other", "=", "b", ".", "createLocalVariable", "(", "null", ",", "userStorableTypeDesc", ")", ";", "b", ".", "loadLocal", "(", "b", ".", "getParameter", "(", "0", ")", ")", ";", "b", ".", "checkCast", "(", "userStorableTypeDesc", ")", ";", "b", ".", "storeLocal", "(", "other", ")", ";", "for", "(", "StorableProperty", "property", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "if", "(", "property", ".", "isDerived", "(", ")", "||", "property", ".", "isJoin", "(", ")", ")", "{", "continue", ";", "}", "// If we're only comparing keys, and this isn't a key, skip it\r", "if", "(", "(", "equalityType", "==", "EQUAL_KEYS", ")", "&&", "!", "property", ".", "isPrimaryKeyMember", "(", ")", ")", "{", "continue", ";", "}", "// Check if independent property is supported, and skip if not.\r", "Label", "skipCheck", "=", "b", ".", "createLabel", "(", ")", ";", "if", "(", "equalityType", "!=", "EQUAL_KEYS", "&&", "property", ".", "isIndependent", "(", ")", ")", "{", "addSkipIndependent", "(", "b", ",", "other", ",", "property", ",", "skipCheck", ")", ";", "}", "TypeDesc", "fieldType", "=", "TypeDesc", ".", "forClass", "(", "property", ".", "getType", "(", ")", ")", ";", "loadThisProperty", "(", "b", ",", "property", ")", ";", "b", ".", "loadLocal", "(", "other", ")", ";", "b", ".", "invoke", "(", "property", ".", "getReadMethod", "(", ")", ")", ";", "CodeBuilderUtil", ".", "addValuesEqualCall", "(", "b", ",", "fieldType", ",", "true", ",", "fail", ",", "false", ")", ";", "skipCheck", ".", "setLocation", "(", ")", ";", "}", "b", ".", "loadConstant", "(", "true", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "fail", ".", "setLocation", "(", ")", ";", "b", ".", "loadConstant", "(", "false", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "}" ]
Defines an equals method. @param equalityType Type of equality to define - {@link EQUAL_KEYS} for "equalKeys", {@link EQUAL_PROPERTIES} for "equalProperties", and {@link EQUAL_FULL} for "equals"
[ "Defines", "an", "equals", "method", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3047-L3128
8,177
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addToStringMethod
private void addToStringMethod(boolean keyOnly) { TypeDesc stringBuilder = TypeDesc.forClass(StringBuilder.class); Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal(modifiers, keyOnly ? TO_STRING_KEY_ONLY_METHOD_NAME : TO_STRING_METHOD_NAME, TypeDesc.STRING, null); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); b.newObject(stringBuilder); b.dup(); b.invokeConstructor(stringBuilder, null); b.loadConstant(mStorableType.getName()); invokeAppend(b, TypeDesc.STRING); String detail; if (keyOnly) { detail = " (key only) {"; } else { detail = " {"; } b.loadConstant(detail); invokeAppend(b, TypeDesc.STRING); // First pass, just print primary keys. LocalVariable commaCountVar = b.createLocalVariable(null, TypeDesc.INT); b.loadConstant(-1); b.storeLocal(commaCountVar); for (StorableProperty property : mInfo.getPrimaryKeyProperties().values()) { addPropertyAppendCall(b, property, commaCountVar); } // Second pass, print non-primary keys. if (!keyOnly) { for (StorableProperty property : mAllProperties.values()) { // Don't print any derived or join properties since they may throw an exception. if (!property.isPrimaryKeyMember() && (!property.isDerived()) && (!property.isJoin())) { addPropertyAppendCall(b, property, commaCountVar); } } } b.loadConstant('}'); invokeAppend(b, TypeDesc.CHAR); // For key string, also show all the alternate keys. This makes the // FetchNoneException message more helpful. if (keyOnly) { int altKeyCount = mInfo.getAlternateKeyCount(); for (int i=0; i<altKeyCount; i++) { b.loadConstant(-1); b.storeLocal(commaCountVar); b.loadConstant(", {"); invokeAppend(b, TypeDesc.STRING); StorableKey<S> key = mInfo.getAlternateKey(i); for (OrderedProperty<S> op : key.getProperties()) { StorableProperty<S> property = op.getChainedProperty().getPrimeProperty(); addPropertyAppendCall(b, property, commaCountVar); } b.loadConstant('}'); invokeAppend(b, TypeDesc.CHAR); } } b.invokeVirtual(stringBuilder, TO_STRING_METHOD_NAME, TypeDesc.STRING, null); b.returnValue(TypeDesc.STRING); }
java
private void addToStringMethod(boolean keyOnly) { TypeDesc stringBuilder = TypeDesc.forClass(StringBuilder.class); Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true); MethodInfo mi = addMethodIfNotFinal(modifiers, keyOnly ? TO_STRING_KEY_ONLY_METHOD_NAME : TO_STRING_METHOD_NAME, TypeDesc.STRING, null); if (mi == null) { return; } CodeBuilder b = new CodeBuilder(mi); b.newObject(stringBuilder); b.dup(); b.invokeConstructor(stringBuilder, null); b.loadConstant(mStorableType.getName()); invokeAppend(b, TypeDesc.STRING); String detail; if (keyOnly) { detail = " (key only) {"; } else { detail = " {"; } b.loadConstant(detail); invokeAppend(b, TypeDesc.STRING); // First pass, just print primary keys. LocalVariable commaCountVar = b.createLocalVariable(null, TypeDesc.INT); b.loadConstant(-1); b.storeLocal(commaCountVar); for (StorableProperty property : mInfo.getPrimaryKeyProperties().values()) { addPropertyAppendCall(b, property, commaCountVar); } // Second pass, print non-primary keys. if (!keyOnly) { for (StorableProperty property : mAllProperties.values()) { // Don't print any derived or join properties since they may throw an exception. if (!property.isPrimaryKeyMember() && (!property.isDerived()) && (!property.isJoin())) { addPropertyAppendCall(b, property, commaCountVar); } } } b.loadConstant('}'); invokeAppend(b, TypeDesc.CHAR); // For key string, also show all the alternate keys. This makes the // FetchNoneException message more helpful. if (keyOnly) { int altKeyCount = mInfo.getAlternateKeyCount(); for (int i=0; i<altKeyCount; i++) { b.loadConstant(-1); b.storeLocal(commaCountVar); b.loadConstant(", {"); invokeAppend(b, TypeDesc.STRING); StorableKey<S> key = mInfo.getAlternateKey(i); for (OrderedProperty<S> op : key.getProperties()) { StorableProperty<S> property = op.getChainedProperty().getPrimeProperty(); addPropertyAppendCall(b, property, commaCountVar); } b.loadConstant('}'); invokeAppend(b, TypeDesc.CHAR); } } b.invokeVirtual(stringBuilder, TO_STRING_METHOD_NAME, TypeDesc.STRING, null); b.returnValue(TypeDesc.STRING); }
[ "private", "void", "addToStringMethod", "(", "boolean", "keyOnly", ")", "{", "TypeDesc", "stringBuilder", "=", "TypeDesc", ".", "forClass", "(", "StringBuilder", ".", "class", ")", ";", "Modifiers", "modifiers", "=", "Modifiers", ".", "PUBLIC", ".", "toSynchronized", "(", "true", ")", ";", "MethodInfo", "mi", "=", "addMethodIfNotFinal", "(", "modifiers", ",", "keyOnly", "?", "TO_STRING_KEY_ONLY_METHOD_NAME", ":", "TO_STRING_METHOD_NAME", ",", "TypeDesc", ".", "STRING", ",", "null", ")", ";", "if", "(", "mi", "==", "null", ")", "{", "return", ";", "}", "CodeBuilder", "b", "=", "new", "CodeBuilder", "(", "mi", ")", ";", "b", ".", "newObject", "(", "stringBuilder", ")", ";", "b", ".", "dup", "(", ")", ";", "b", ".", "invokeConstructor", "(", "stringBuilder", ",", "null", ")", ";", "b", ".", "loadConstant", "(", "mStorableType", ".", "getName", "(", ")", ")", ";", "invokeAppend", "(", "b", ",", "TypeDesc", ".", "STRING", ")", ";", "String", "detail", ";", "if", "(", "keyOnly", ")", "{", "detail", "=", "\" (key only) {\"", ";", "}", "else", "{", "detail", "=", "\" {\"", ";", "}", "b", ".", "loadConstant", "(", "detail", ")", ";", "invokeAppend", "(", "b", ",", "TypeDesc", ".", "STRING", ")", ";", "// First pass, just print primary keys.\r", "LocalVariable", "commaCountVar", "=", "b", ".", "createLocalVariable", "(", "null", ",", "TypeDesc", ".", "INT", ")", ";", "b", ".", "loadConstant", "(", "-", "1", ")", ";", "b", ".", "storeLocal", "(", "commaCountVar", ")", ";", "for", "(", "StorableProperty", "property", ":", "mInfo", ".", "getPrimaryKeyProperties", "(", ")", ".", "values", "(", ")", ")", "{", "addPropertyAppendCall", "(", "b", ",", "property", ",", "commaCountVar", ")", ";", "}", "// Second pass, print non-primary keys.\r", "if", "(", "!", "keyOnly", ")", "{", "for", "(", "StorableProperty", "property", ":", "mAllProperties", ".", "values", "(", ")", ")", "{", "// Don't print any derived or join properties since they may throw an exception.\r", "if", "(", "!", "property", ".", "isPrimaryKeyMember", "(", ")", "&&", "(", "!", "property", ".", "isDerived", "(", ")", ")", "&&", "(", "!", "property", ".", "isJoin", "(", ")", ")", ")", "{", "addPropertyAppendCall", "(", "b", ",", "property", ",", "commaCountVar", ")", ";", "}", "}", "}", "b", ".", "loadConstant", "(", "'", "'", ")", ";", "invokeAppend", "(", "b", ",", "TypeDesc", ".", "CHAR", ")", ";", "// For key string, also show all the alternate keys. This makes the\r", "// FetchNoneException message more helpful.\r", "if", "(", "keyOnly", ")", "{", "int", "altKeyCount", "=", "mInfo", ".", "getAlternateKeyCount", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "altKeyCount", ";", "i", "++", ")", "{", "b", ".", "loadConstant", "(", "-", "1", ")", ";", "b", ".", "storeLocal", "(", "commaCountVar", ")", ";", "b", ".", "loadConstant", "(", "\", {\"", ")", ";", "invokeAppend", "(", "b", ",", "TypeDesc", ".", "STRING", ")", ";", "StorableKey", "<", "S", ">", "key", "=", "mInfo", ".", "getAlternateKey", "(", "i", ")", ";", "for", "(", "OrderedProperty", "<", "S", ">", "op", ":", "key", ".", "getProperties", "(", ")", ")", "{", "StorableProperty", "<", "S", ">", "property", "=", "op", ".", "getChainedProperty", "(", ")", ".", "getPrimeProperty", "(", ")", ";", "addPropertyAppendCall", "(", "b", ",", "property", ",", "commaCountVar", ")", ";", "}", "b", ".", "loadConstant", "(", "'", "'", ")", ";", "invokeAppend", "(", "b", ",", "TypeDesc", ".", "CHAR", ")", ";", "}", "}", "b", ".", "invokeVirtual", "(", "stringBuilder", ",", "TO_STRING_METHOD_NAME", ",", "TypeDesc", ".", "STRING", ",", "null", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "STRING", ")", ";", "}" ]
Defines a toString method, which assumes that the ClassFile is targeting version 1.5 of Java. @param keyOnly when true, generate a toStringKeyOnly method instead
[ "Defines", "a", "toString", "method", "which", "assumes", "that", "the", "ClassFile", "is", "targeting", "version", "1", ".", "5", "of", "Java", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3136-L3218
8,178
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addGetTriggerAndEnterTxn
private Label addGetTriggerAndEnterTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { // trigger = support$.getXxxTrigger(); b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); Method m = lookupMethod(mSupportType.toClass(), "get" + opType + "Trigger"); b.invoke(m); b.storeLocal(triggerVar); // state = null; b.loadNull(); b.storeLocal(stateVar); // if (trigger == null) { // txn = null; // } else { // txn = support.getRootRepository().enterTransaction(); // tryStart: // if (forTry) { // state = trigger.beforeTryXxx(txn, this); // } else { // state = trigger.beforeXxx(txn, this); // } // } b.loadLocal(triggerVar); Label hasTrigger = b.createLabel(); b.ifNullBranch(hasTrigger, false); // txn = null b.loadNull(); b.storeLocal(txnVar); Label cont = b.createLabel(); b.branch(cont); hasTrigger.setLocation(); // txn = support.getRootRepository().enterTransaction(); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); TypeDesc transactionType = TypeDesc.forClass(Transaction.class); b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); b.invokeInterface(mSupportType, "getRootRepository", repositoryType, null); b.invokeInterface(repositoryType, ENTER_TRANSACTION_METHOD_NAME, transactionType, null); b.storeLocal(txnVar); Label tryStart = b.createLabel().setLocation(); // if (forTry) { // state = trigger.beforeTryXxx(txn, this); // } else { // state = trigger.beforeXxx(txn, this); // } b.loadLocal(triggerVar); b.loadLocal(txnVar); b.loadThis(); if (forTryVar == null) { if (forTry) { b.invokeVirtual(triggerVar.getType(), "beforeTry" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); } else { b.invokeVirtual(triggerVar.getType(), "before" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); } b.storeLocal(stateVar); } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.invokeVirtual(triggerVar.getType(), "before" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); b.storeLocal(stateVar); b.branch(cont); isForTry.setLocation(); b.invokeVirtual(triggerVar.getType(), "beforeTry" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); b.storeLocal(stateVar); } cont.setLocation(); return tryStart; }
java
private Label addGetTriggerAndEnterTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { // trigger = support$.getXxxTrigger(); b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); Method m = lookupMethod(mSupportType.toClass(), "get" + opType + "Trigger"); b.invoke(m); b.storeLocal(triggerVar); // state = null; b.loadNull(); b.storeLocal(stateVar); // if (trigger == null) { // txn = null; // } else { // txn = support.getRootRepository().enterTransaction(); // tryStart: // if (forTry) { // state = trigger.beforeTryXxx(txn, this); // } else { // state = trigger.beforeXxx(txn, this); // } // } b.loadLocal(triggerVar); Label hasTrigger = b.createLabel(); b.ifNullBranch(hasTrigger, false); // txn = null b.loadNull(); b.storeLocal(txnVar); Label cont = b.createLabel(); b.branch(cont); hasTrigger.setLocation(); // txn = support.getRootRepository().enterTransaction(); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); TypeDesc transactionType = TypeDesc.forClass(Transaction.class); b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); b.invokeInterface(mSupportType, "getRootRepository", repositoryType, null); b.invokeInterface(repositoryType, ENTER_TRANSACTION_METHOD_NAME, transactionType, null); b.storeLocal(txnVar); Label tryStart = b.createLabel().setLocation(); // if (forTry) { // state = trigger.beforeTryXxx(txn, this); // } else { // state = trigger.beforeXxx(txn, this); // } b.loadLocal(triggerVar); b.loadLocal(txnVar); b.loadThis(); if (forTryVar == null) { if (forTry) { b.invokeVirtual(triggerVar.getType(), "beforeTry" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); } else { b.invokeVirtual(triggerVar.getType(), "before" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); } b.storeLocal(stateVar); } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.invokeVirtual(triggerVar.getType(), "before" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); b.storeLocal(stateVar); b.branch(cont); isForTry.setLocation(); b.invokeVirtual(triggerVar.getType(), "beforeTry" + opType, TypeDesc.OBJECT, new TypeDesc[] {transactionType, TypeDesc.OBJECT}); b.storeLocal(stateVar); } cont.setLocation(); return tryStart; }
[ "private", "Label", "addGetTriggerAndEnterTxn", "(", "CodeBuilder", "b", ",", "String", "opType", ",", "LocalVariable", "forTryVar", ",", "boolean", "forTry", ",", "LocalVariable", "triggerVar", ",", "LocalVariable", "txnVar", ",", "LocalVariable", "stateVar", ")", "{", "// trigger = support$.getXxxTrigger();\r", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "SUPPORT_FIELD_NAME", ",", "mSupportType", ")", ";", "Method", "m", "=", "lookupMethod", "(", "mSupportType", ".", "toClass", "(", ")", ",", "\"get\"", "+", "opType", "+", "\"Trigger\"", ")", ";", "b", ".", "invoke", "(", "m", ")", ";", "b", ".", "storeLocal", "(", "triggerVar", ")", ";", "// state = null;\r", "b", ".", "loadNull", "(", ")", ";", "b", ".", "storeLocal", "(", "stateVar", ")", ";", "// if (trigger == null) {\r", "// txn = null;\r", "// } else {\r", "// txn = support.getRootRepository().enterTransaction();\r", "// tryStart:\r", "// if (forTry) {\r", "// state = trigger.beforeTryXxx(txn, this);\r", "// } else {\r", "// state = trigger.beforeXxx(txn, this);\r", "// }\r", "// }\r", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "Label", "hasTrigger", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifNullBranch", "(", "hasTrigger", ",", "false", ")", ";", "// txn = null\r", "b", ".", "loadNull", "(", ")", ";", "b", ".", "storeLocal", "(", "txnVar", ")", ";", "Label", "cont", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "branch", "(", "cont", ")", ";", "hasTrigger", ".", "setLocation", "(", ")", ";", "// txn = support.getRootRepository().enterTransaction();\r", "TypeDesc", "repositoryType", "=", "TypeDesc", ".", "forClass", "(", "Repository", ".", "class", ")", ";", "TypeDesc", "transactionType", "=", "TypeDesc", ".", "forClass", "(", "Transaction", ".", "class", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadField", "(", "SUPPORT_FIELD_NAME", ",", "mSupportType", ")", ";", "b", ".", "invokeInterface", "(", "mSupportType", ",", "\"getRootRepository\"", ",", "repositoryType", ",", "null", ")", ";", "b", ".", "invokeInterface", "(", "repositoryType", ",", "ENTER_TRANSACTION_METHOD_NAME", ",", "transactionType", ",", "null", ")", ";", "b", ".", "storeLocal", "(", "txnVar", ")", ";", "Label", "tryStart", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "// if (forTry) {\r", "// state = trigger.beforeTryXxx(txn, this);\r", "// } else {\r", "// state = trigger.beforeXxx(txn, this);\r", "// }\r", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "b", ".", "loadLocal", "(", "txnVar", ")", ";", "b", ".", "loadThis", "(", ")", ";", "if", "(", "forTryVar", "==", "null", ")", "{", "if", "(", "forTry", ")", "{", "b", ".", "invokeVirtual", "(", "triggerVar", ".", "getType", "(", ")", ",", "\"beforeTry\"", "+", "opType", ",", "TypeDesc", ".", "OBJECT", ",", "new", "TypeDesc", "[", "]", "{", "transactionType", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "}", "else", "{", "b", ".", "invokeVirtual", "(", "triggerVar", ".", "getType", "(", ")", ",", "\"before\"", "+", "opType", ",", "TypeDesc", ".", "OBJECT", ",", "new", "TypeDesc", "[", "]", "{", "transactionType", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "}", "b", ".", "storeLocal", "(", "stateVar", ")", ";", "}", "else", "{", "b", ".", "loadLocal", "(", "forTryVar", ")", ";", "Label", "isForTry", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "isForTry", ",", "\"!=\"", ")", ";", "b", ".", "invokeVirtual", "(", "triggerVar", ".", "getType", "(", ")", ",", "\"before\"", "+", "opType", ",", "TypeDesc", ".", "OBJECT", ",", "new", "TypeDesc", "[", "]", "{", "transactionType", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "b", ".", "storeLocal", "(", "stateVar", ")", ";", "b", ".", "branch", "(", "cont", ")", ";", "isForTry", ".", "setLocation", "(", ")", ";", "b", ".", "invokeVirtual", "(", "triggerVar", ".", "getType", "(", ")", ",", "\"beforeTry\"", "+", "opType", ",", "TypeDesc", ".", "OBJECT", ",", "new", "TypeDesc", "[", "]", "{", "transactionType", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "b", ".", "storeLocal", "(", "stateVar", ")", ";", "}", "cont", ".", "setLocation", "(", ")", ";", "return", "tryStart", ";", "}" ]
Generates code to get a trigger, forcing a transaction if trigger is not null. Also, if there is a trigger, the "before" method is called. @param opType type of operation, Insert, Update, or Delete @param forTryVar optional boolean variable for selecting whether to call "before" or "beforeTry" method @param forTry used if forTryVar is null @param triggerVar required variable of type Trigger for storing trigger @param txnVar required variable of type Transaction for storing transaction @param stateVar variable of type Object for storing state @return try start label for transaction
[ "Generates", "code", "to", "get", "a", "trigger", "forcing", "a", "transaction", "if", "trigger", "is", "not", "null", ".", "Also", "if", "there", "is", "a", "trigger", "the", "before", "method", "is", "called", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3300-L3391
8,179
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addTriggerAfterAndExitTxn
private void addTriggerAfterAndExitTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { // if (trigger != null) { b.loadLocal(triggerVar); Label cont = b.createLabel(); b.ifNullBranch(cont, true); // if (forTry) { // trigger.afterTryXxx(this, state); // } else { // trigger.afterXxx(this, state); // } b.loadLocal(triggerVar); b.loadThis(); b.loadLocal(stateVar); if (forTryVar == null) { if (forTry) { b.invokeVirtual(TypeDesc.forClass(Trigger.class), "afterTry" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); } else { b.invokeVirtual(TypeDesc.forClass(Trigger.class), "after" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); } } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "after" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); Label commitAndExit = b.createLabel(); b.branch(commitAndExit); isForTry.setLocation(); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "afterTry" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); commitAndExit.setLocation(); } // txn.commit(); // txn.exit(); TypeDesc transactionType = TypeDesc.forClass(Transaction.class); b.loadLocal(txnVar); b.invokeInterface(transactionType, COMMIT_METHOD_NAME, null, null); b.loadLocal(txnVar); b.invokeInterface(transactionType, EXIT_METHOD_NAME, null, null); cont.setLocation(); }
java
private void addTriggerAfterAndExitTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { // if (trigger != null) { b.loadLocal(triggerVar); Label cont = b.createLabel(); b.ifNullBranch(cont, true); // if (forTry) { // trigger.afterTryXxx(this, state); // } else { // trigger.afterXxx(this, state); // } b.loadLocal(triggerVar); b.loadThis(); b.loadLocal(stateVar); if (forTryVar == null) { if (forTry) { b.invokeVirtual(TypeDesc.forClass(Trigger.class), "afterTry" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); } else { b.invokeVirtual(TypeDesc.forClass(Trigger.class), "after" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); } } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "after" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); Label commitAndExit = b.createLabel(); b.branch(commitAndExit); isForTry.setLocation(); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "afterTry" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); commitAndExit.setLocation(); } // txn.commit(); // txn.exit(); TypeDesc transactionType = TypeDesc.forClass(Transaction.class); b.loadLocal(txnVar); b.invokeInterface(transactionType, COMMIT_METHOD_NAME, null, null); b.loadLocal(txnVar); b.invokeInterface(transactionType, EXIT_METHOD_NAME, null, null); cont.setLocation(); }
[ "private", "void", "addTriggerAfterAndExitTxn", "(", "CodeBuilder", "b", ",", "String", "opType", ",", "LocalVariable", "forTryVar", ",", "boolean", "forTry", ",", "LocalVariable", "triggerVar", ",", "LocalVariable", "txnVar", ",", "LocalVariable", "stateVar", ")", "{", "// if (trigger != null) {\r", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "Label", "cont", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifNullBranch", "(", "cont", ",", "true", ")", ";", "// if (forTry) {\r", "// trigger.afterTryXxx(this, state);\r", "// } else {\r", "// trigger.afterXxx(this, state);\r", "// }\r", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadLocal", "(", "stateVar", ")", ";", "if", "(", "forTryVar", "==", "null", ")", "{", "if", "(", "forTry", ")", "{", "b", ".", "invokeVirtual", "(", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "class", ")", ",", "\"afterTry\"", "+", "opType", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "OBJECT", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "}", "else", "{", "b", ".", "invokeVirtual", "(", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "class", ")", ",", "\"after\"", "+", "opType", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "OBJECT", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "}", "}", "else", "{", "b", ".", "loadLocal", "(", "forTryVar", ")", ";", "Label", "isForTry", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "isForTry", ",", "\"!=\"", ")", ";", "b", ".", "invokeVirtual", "(", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "class", ")", ",", "\"after\"", "+", "opType", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "OBJECT", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "Label", "commitAndExit", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "branch", "(", "commitAndExit", ")", ";", "isForTry", ".", "setLocation", "(", ")", ";", "b", ".", "invokeVirtual", "(", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "class", ")", ",", "\"afterTry\"", "+", "opType", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "OBJECT", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "commitAndExit", ".", "setLocation", "(", ")", ";", "}", "// txn.commit();\r", "// txn.exit();\r", "TypeDesc", "transactionType", "=", "TypeDesc", ".", "forClass", "(", "Transaction", ".", "class", ")", ";", "b", ".", "loadLocal", "(", "txnVar", ")", ";", "b", ".", "invokeInterface", "(", "transactionType", ",", "COMMIT_METHOD_NAME", ",", "null", ",", "null", ")", ";", "b", ".", "loadLocal", "(", "txnVar", ")", ";", "b", ".", "invokeInterface", "(", "transactionType", ",", "EXIT_METHOD_NAME", ",", "null", ",", "null", ")", ";", "cont", ".", "setLocation", "(", ")", ";", "}" ]
Generates code to call a trigger after the persistence operation has been invoked. @param opType type of operation, Insert, Update, or Delete @param forTryVar optional boolean variable for selecting whether to call "after" or "afterTry" method @param forTry used if forTryVar is null @param triggerVar required variable of type Trigger for retrieving trigger @param txnVar required variable of type Transaction for storing transaction @param stateVar required variable of type Object for retrieving state
[ "Generates", "code", "to", "call", "a", "trigger", "after", "the", "persistence", "operation", "has", "been", "invoked", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3405-L3460
8,180
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addTriggerFailedAndExitTxn
private void addTriggerFailedAndExitTxn(CodeBuilder b, String opType, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { TypeDesc transactionType = TypeDesc.forClass(Transaction.class); // if (trigger != null) { b.loadLocal(triggerVar); Label isNull = b.createLabel(); b.ifNullBranch(isNull, true); // try { // trigger.failedXxx(this, state); // } catch (Throwable e) { // uncaught(e); // } Label tryStart = b.createLabel().setLocation(); b.loadLocal(triggerVar); b.loadThis(); b.loadLocal(stateVar); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "failed" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); Label tryEnd = b.createLabel().setLocation(); Label cont = b.createLabel(); b.branch(cont); b.exceptionHandler(tryStart, tryEnd, Throwable.class.getName()); b.invokeStatic(UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}); cont.setLocation(); // txn.exit(); b.loadLocal(txnVar); b.invokeInterface(transactionType, EXIT_METHOD_NAME, null, null); isNull.setLocation(); }
java
private void addTriggerFailedAndExitTxn(CodeBuilder b, String opType, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar) { TypeDesc transactionType = TypeDesc.forClass(Transaction.class); // if (trigger != null) { b.loadLocal(triggerVar); Label isNull = b.createLabel(); b.ifNullBranch(isNull, true); // try { // trigger.failedXxx(this, state); // } catch (Throwable e) { // uncaught(e); // } Label tryStart = b.createLabel().setLocation(); b.loadLocal(triggerVar); b.loadThis(); b.loadLocal(stateVar); b.invokeVirtual(TypeDesc.forClass(Trigger.class), "failed" + opType, null, new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT}); Label tryEnd = b.createLabel().setLocation(); Label cont = b.createLabel(); b.branch(cont); b.exceptionHandler(tryStart, tryEnd, Throwable.class.getName()); b.invokeStatic(UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}); cont.setLocation(); // txn.exit(); b.loadLocal(txnVar); b.invokeInterface(transactionType, EXIT_METHOD_NAME, null, null); isNull.setLocation(); }
[ "private", "void", "addTriggerFailedAndExitTxn", "(", "CodeBuilder", "b", ",", "String", "opType", ",", "LocalVariable", "triggerVar", ",", "LocalVariable", "txnVar", ",", "LocalVariable", "stateVar", ")", "{", "TypeDesc", "transactionType", "=", "TypeDesc", ".", "forClass", "(", "Transaction", ".", "class", ")", ";", "// if (trigger != null) {\r", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "Label", "isNull", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifNullBranch", "(", "isNull", ",", "true", ")", ";", "// try {\r", "// trigger.failedXxx(this, state);\r", "// } catch (Throwable e) {\r", "// uncaught(e);\r", "// }\r", "Label", "tryStart", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "b", ".", "loadLocal", "(", "triggerVar", ")", ";", "b", ".", "loadThis", "(", ")", ";", "b", ".", "loadLocal", "(", "stateVar", ")", ";", "b", ".", "invokeVirtual", "(", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "class", ")", ",", "\"failed\"", "+", "opType", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "OBJECT", ",", "TypeDesc", ".", "OBJECT", "}", ")", ";", "Label", "tryEnd", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "Label", "cont", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "branch", "(", "cont", ")", ";", "b", ".", "exceptionHandler", "(", "tryStart", ",", "tryEnd", ",", "Throwable", ".", "class", ".", "getName", "(", ")", ")", ";", "b", ".", "invokeStatic", "(", "UNCAUGHT_METHOD_NAME", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "forClass", "(", "Throwable", ".", "class", ")", "}", ")", ";", "cont", ".", "setLocation", "(", ")", ";", "// txn.exit();\r", "b", ".", "loadLocal", "(", "txnVar", ")", ";", "b", ".", "invokeInterface", "(", "transactionType", ",", "EXIT_METHOD_NAME", ",", "null", ",", "null", ")", ";", "isNull", ".", "setLocation", "(", ")", ";", "}" ]
Generates code to call a trigger after the persistence operation has failed. @param opType type of operation, Insert, Update, or Delete @param triggerVar required variable of type Trigger for retrieving trigger @param txnVar required variable of type Transaction for storing transaction @param stateVar required variable of type Object for retrieving state
[ "Generates", "code", "to", "call", "a", "trigger", "after", "the", "persistence", "operation", "has", "failed", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3471-L3508
8,181
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.addTriggerFailedAndExitTxn
private void addTriggerFailedAndExitTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar, Label tryStart) { if (tryStart == null) { addTriggerFailedAndExitTxn(b, opType, triggerVar, txnVar, stateVar); return; } // } catch (... e) { // if (trigger != null) { // try { // trigger.failedXxx(this, state); // } catch (Throwable e) { // uncaught(e); // } // } // txn.exit(); // if (e instanceof Trigger.Abort) { // if (forTryVar) { // return false; // } else { // // Try to add some trace for context // throw ((Trigger.Abort) e).withStackTrace(); // } // } // if (e instanceof RepositoryException) { // throw ((RepositoryException) e).toPersistException(); // } // throw e; // } Label tryEnd = b.createLabel().setLocation(); b.exceptionHandler(tryStart, tryEnd, null); LocalVariable exceptionVar = b.createLocalVariable(null, TypeDesc.OBJECT); b.storeLocal(exceptionVar); addTriggerFailedAndExitTxn(b, opType, triggerVar, txnVar, stateVar); b.loadLocal(exceptionVar); TypeDesc abortException = TypeDesc.forClass(Trigger.Abort.class); b.instanceOf(abortException); Label nextCheck = b.createLabel(); b.ifZeroComparisonBranch(nextCheck, "=="); if (forTryVar == null) { if (forTry) { b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); } else { b.loadLocal(exceptionVar); b.checkCast(abortException); b.invokeVirtual(abortException, "withStackTrace", abortException, null); b.throwObject(); } } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.loadLocal(exceptionVar); b.checkCast(abortException); b.invokeVirtual(abortException, "withStackTrace", abortException, null); b.throwObject(); isForTry.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); } nextCheck.setLocation(); b.loadLocal(exceptionVar); TypeDesc repException = TypeDesc.forClass(RepositoryException.class); b.instanceOf(repException); Label throwAny = b.createLabel(); b.ifZeroComparisonBranch(throwAny, "=="); b.loadLocal(exceptionVar); b.checkCast(repException); b.invokeVirtual(repException, "toPersistException", TypeDesc.forClass(PersistException.class), null); b.throwObject(); throwAny.setLocation(); b.loadLocal(exceptionVar); b.throwObject(); }
java
private void addTriggerFailedAndExitTxn(CodeBuilder b, String opType, LocalVariable forTryVar, boolean forTry, LocalVariable triggerVar, LocalVariable txnVar, LocalVariable stateVar, Label tryStart) { if (tryStart == null) { addTriggerFailedAndExitTxn(b, opType, triggerVar, txnVar, stateVar); return; } // } catch (... e) { // if (trigger != null) { // try { // trigger.failedXxx(this, state); // } catch (Throwable e) { // uncaught(e); // } // } // txn.exit(); // if (e instanceof Trigger.Abort) { // if (forTryVar) { // return false; // } else { // // Try to add some trace for context // throw ((Trigger.Abort) e).withStackTrace(); // } // } // if (e instanceof RepositoryException) { // throw ((RepositoryException) e).toPersistException(); // } // throw e; // } Label tryEnd = b.createLabel().setLocation(); b.exceptionHandler(tryStart, tryEnd, null); LocalVariable exceptionVar = b.createLocalVariable(null, TypeDesc.OBJECT); b.storeLocal(exceptionVar); addTriggerFailedAndExitTxn(b, opType, triggerVar, txnVar, stateVar); b.loadLocal(exceptionVar); TypeDesc abortException = TypeDesc.forClass(Trigger.Abort.class); b.instanceOf(abortException); Label nextCheck = b.createLabel(); b.ifZeroComparisonBranch(nextCheck, "=="); if (forTryVar == null) { if (forTry) { b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); } else { b.loadLocal(exceptionVar); b.checkCast(abortException); b.invokeVirtual(abortException, "withStackTrace", abortException, null); b.throwObject(); } } else { b.loadLocal(forTryVar); Label isForTry = b.createLabel(); b.ifZeroComparisonBranch(isForTry, "!="); b.loadLocal(exceptionVar); b.checkCast(abortException); b.invokeVirtual(abortException, "withStackTrace", abortException, null); b.throwObject(); isForTry.setLocation(); b.loadConstant(false); b.returnValue(TypeDesc.BOOLEAN); } nextCheck.setLocation(); b.loadLocal(exceptionVar); TypeDesc repException = TypeDesc.forClass(RepositoryException.class); b.instanceOf(repException); Label throwAny = b.createLabel(); b.ifZeroComparisonBranch(throwAny, "=="); b.loadLocal(exceptionVar); b.checkCast(repException); b.invokeVirtual(repException, "toPersistException", TypeDesc.forClass(PersistException.class), null); b.throwObject(); throwAny.setLocation(); b.loadLocal(exceptionVar); b.throwObject(); }
[ "private", "void", "addTriggerFailedAndExitTxn", "(", "CodeBuilder", "b", ",", "String", "opType", ",", "LocalVariable", "forTryVar", ",", "boolean", "forTry", ",", "LocalVariable", "triggerVar", ",", "LocalVariable", "txnVar", ",", "LocalVariable", "stateVar", ",", "Label", "tryStart", ")", "{", "if", "(", "tryStart", "==", "null", ")", "{", "addTriggerFailedAndExitTxn", "(", "b", ",", "opType", ",", "triggerVar", ",", "txnVar", ",", "stateVar", ")", ";", "return", ";", "}", "// } catch (... e) {\r", "// if (trigger != null) {\r", "// try {\r", "// trigger.failedXxx(this, state);\r", "// } catch (Throwable e) {\r", "// uncaught(e);\r", "// }\r", "// }\r", "// txn.exit();\r", "// if (e instanceof Trigger.Abort) {\r", "// if (forTryVar) {\r", "// return false;\r", "// } else {\r", "// // Try to add some trace for context\r", "// throw ((Trigger.Abort) e).withStackTrace();\r", "// }\r", "// }\r", "// if (e instanceof RepositoryException) {\r", "// throw ((RepositoryException) e).toPersistException();\r", "// }\r", "// throw e;\r", "// }\r", "Label", "tryEnd", "=", "b", ".", "createLabel", "(", ")", ".", "setLocation", "(", ")", ";", "b", ".", "exceptionHandler", "(", "tryStart", ",", "tryEnd", ",", "null", ")", ";", "LocalVariable", "exceptionVar", "=", "b", ".", "createLocalVariable", "(", "null", ",", "TypeDesc", ".", "OBJECT", ")", ";", "b", ".", "storeLocal", "(", "exceptionVar", ")", ";", "addTriggerFailedAndExitTxn", "(", "b", ",", "opType", ",", "triggerVar", ",", "txnVar", ",", "stateVar", ")", ";", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "TypeDesc", "abortException", "=", "TypeDesc", ".", "forClass", "(", "Trigger", ".", "Abort", ".", "class", ")", ";", "b", ".", "instanceOf", "(", "abortException", ")", ";", "Label", "nextCheck", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "nextCheck", ",", "\"==\"", ")", ";", "if", "(", "forTryVar", "==", "null", ")", "{", "if", "(", "forTry", ")", "{", "b", ".", "loadConstant", "(", "false", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "}", "else", "{", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "b", ".", "checkCast", "(", "abortException", ")", ";", "b", ".", "invokeVirtual", "(", "abortException", ",", "\"withStackTrace\"", ",", "abortException", ",", "null", ")", ";", "b", ".", "throwObject", "(", ")", ";", "}", "}", "else", "{", "b", ".", "loadLocal", "(", "forTryVar", ")", ";", "Label", "isForTry", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "isForTry", ",", "\"!=\"", ")", ";", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "b", ".", "checkCast", "(", "abortException", ")", ";", "b", ".", "invokeVirtual", "(", "abortException", ",", "\"withStackTrace\"", ",", "abortException", ",", "null", ")", ";", "b", ".", "throwObject", "(", ")", ";", "isForTry", ".", "setLocation", "(", ")", ";", "b", ".", "loadConstant", "(", "false", ")", ";", "b", ".", "returnValue", "(", "TypeDesc", ".", "BOOLEAN", ")", ";", "}", "nextCheck", ".", "setLocation", "(", ")", ";", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "TypeDesc", "repException", "=", "TypeDesc", ".", "forClass", "(", "RepositoryException", ".", "class", ")", ";", "b", ".", "instanceOf", "(", "repException", ")", ";", "Label", "throwAny", "=", "b", ".", "createLabel", "(", ")", ";", "b", ".", "ifZeroComparisonBranch", "(", "throwAny", ",", "\"==\"", ")", ";", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "b", ".", "checkCast", "(", "repException", ")", ";", "b", ".", "invokeVirtual", "(", "repException", ",", "\"toPersistException\"", ",", "TypeDesc", ".", "forClass", "(", "PersistException", ".", "class", ")", ",", "null", ")", ";", "b", ".", "throwObject", "(", ")", ";", "throwAny", ".", "setLocation", "(", ")", ";", "b", ".", "loadLocal", "(", "exceptionVar", ")", ";", "b", ".", "throwObject", "(", ")", ";", "}" ]
Generates exception handler code to call a trigger after the persistence operation has failed. @param opType type of operation, Insert, Update, or Delete @param forTryVar optional boolean variable for selecting whether to throw or catch Trigger.Abort. @param forTry used if forTryVar is null @param triggerVar required variable of type Trigger for retrieving trigger @param txnVar required variable of type Transaction for storing transaction @param stateVar required variable of type Object for retrieving state @param tryStart start of exception handler around transaction
[ "Generates", "exception", "handler", "code", "to", "call", "a", "trigger", "after", "the", "persistence", "operation", "has", "failed", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3523-L3610
8,182
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
StorableGenerator.defineUncaughtExceptionHandler
private void defineUncaughtExceptionHandler() { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE.toStatic(true), UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}); CodeBuilder b = new CodeBuilder(mi); // Thread t = Thread.currentThread(); // t.getUncaughtExceptionHandler().uncaughtException(t, e); TypeDesc threadType = TypeDesc.forClass(Thread.class); b.invokeStatic(Thread.class.getName(), "currentThread", threadType, null); LocalVariable threadVar = b.createLocalVariable(null, threadType); b.storeLocal(threadVar); b.loadLocal(threadVar); TypeDesc handlerType = TypeDesc.forClass(Thread.UncaughtExceptionHandler.class); b.invokeVirtual(threadType, "getUncaughtExceptionHandler", handlerType, null); b.loadLocal(threadVar); b.loadLocal(b.getParameter(0)); b.invokeInterface(handlerType, "uncaughtException", null, new TypeDesc[] {threadType, TypeDesc.forClass(Throwable.class)}); b.returnVoid(); }
java
private void defineUncaughtExceptionHandler() { MethodInfo mi = mClassFile.addMethod (Modifiers.PRIVATE.toStatic(true), UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}); CodeBuilder b = new CodeBuilder(mi); // Thread t = Thread.currentThread(); // t.getUncaughtExceptionHandler().uncaughtException(t, e); TypeDesc threadType = TypeDesc.forClass(Thread.class); b.invokeStatic(Thread.class.getName(), "currentThread", threadType, null); LocalVariable threadVar = b.createLocalVariable(null, threadType); b.storeLocal(threadVar); b.loadLocal(threadVar); TypeDesc handlerType = TypeDesc.forClass(Thread.UncaughtExceptionHandler.class); b.invokeVirtual(threadType, "getUncaughtExceptionHandler", handlerType, null); b.loadLocal(threadVar); b.loadLocal(b.getParameter(0)); b.invokeInterface(handlerType, "uncaughtException", null, new TypeDesc[] {threadType, TypeDesc.forClass(Throwable.class)}); b.returnVoid(); }
[ "private", "void", "defineUncaughtExceptionHandler", "(", ")", "{", "MethodInfo", "mi", "=", "mClassFile", ".", "addMethod", "(", "Modifiers", ".", "PRIVATE", ".", "toStatic", "(", "true", ")", ",", "UNCAUGHT_METHOD_NAME", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "TypeDesc", ".", "forClass", "(", "Throwable", ".", "class", ")", "}", ")", ";", "CodeBuilder", "b", "=", "new", "CodeBuilder", "(", "mi", ")", ";", "// Thread t = Thread.currentThread();\r", "// t.getUncaughtExceptionHandler().uncaughtException(t, e);\r", "TypeDesc", "threadType", "=", "TypeDesc", ".", "forClass", "(", "Thread", ".", "class", ")", ";", "b", ".", "invokeStatic", "(", "Thread", ".", "class", ".", "getName", "(", ")", ",", "\"currentThread\"", ",", "threadType", ",", "null", ")", ";", "LocalVariable", "threadVar", "=", "b", ".", "createLocalVariable", "(", "null", ",", "threadType", ")", ";", "b", ".", "storeLocal", "(", "threadVar", ")", ";", "b", ".", "loadLocal", "(", "threadVar", ")", ";", "TypeDesc", "handlerType", "=", "TypeDesc", ".", "forClass", "(", "Thread", ".", "UncaughtExceptionHandler", ".", "class", ")", ";", "b", ".", "invokeVirtual", "(", "threadType", ",", "\"getUncaughtExceptionHandler\"", ",", "handlerType", ",", "null", ")", ";", "b", ".", "loadLocal", "(", "threadVar", ")", ";", "b", ".", "loadLocal", "(", "b", ".", "getParameter", "(", "0", ")", ")", ";", "b", ".", "invokeInterface", "(", "handlerType", ",", "\"uncaughtException\"", ",", "null", ",", "new", "TypeDesc", "[", "]", "{", "threadType", ",", "TypeDesc", ".", "forClass", "(", "Throwable", ".", "class", ")", "}", ")", ";", "b", ".", "returnVoid", "(", ")", ";", "}" ]
Generates method which passes exception to uncaught exception handler.
[ "Generates", "method", "which", "passes", "exception", "to", "uncaught", "exception", "handler", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java#L3615-L3635
8,183
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java
JDBCSupportStrategy.createStrategy
@SuppressWarnings("unchecked") static JDBCSupportStrategy createStrategy(JDBCRepository repo) { String databaseProductName = repo.getDatabaseProductName().trim(); if (databaseProductName != null && databaseProductName.length() > 0) { String strategyName = Character.toUpperCase(databaseProductName.charAt(0)) + databaseProductName.substring(1).toLowerCase(); if (strategyName.indexOf(' ') > 0) { strategyName = strategyName.substring(0, strategyName.indexOf(' ')); } strategyName = strategyName.replaceAll("[^A-Za-z0-9]", ""); String className = "com.amazon.carbonado.repo.jdbc." + strategyName + "SupportStrategy"; try { Class<JDBCSupportStrategy> clazz = (Class<JDBCSupportStrategy>) Class.forName(className); return clazz.getDeclaredConstructor(JDBCRepository.class).newInstance(repo); } catch (ClassNotFoundException e) { // just use default strategy } catch (Exception e) { ThrowUnchecked.fireFirstDeclaredCause(e); } } return new JDBCSupportStrategy(repo); }
java
@SuppressWarnings("unchecked") static JDBCSupportStrategy createStrategy(JDBCRepository repo) { String databaseProductName = repo.getDatabaseProductName().trim(); if (databaseProductName != null && databaseProductName.length() > 0) { String strategyName = Character.toUpperCase(databaseProductName.charAt(0)) + databaseProductName.substring(1).toLowerCase(); if (strategyName.indexOf(' ') > 0) { strategyName = strategyName.substring(0, strategyName.indexOf(' ')); } strategyName = strategyName.replaceAll("[^A-Za-z0-9]", ""); String className = "com.amazon.carbonado.repo.jdbc." + strategyName + "SupportStrategy"; try { Class<JDBCSupportStrategy> clazz = (Class<JDBCSupportStrategy>) Class.forName(className); return clazz.getDeclaredConstructor(JDBCRepository.class).newInstance(repo); } catch (ClassNotFoundException e) { // just use default strategy } catch (Exception e) { ThrowUnchecked.fireFirstDeclaredCause(e); } } return new JDBCSupportStrategy(repo); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "static", "JDBCSupportStrategy", "createStrategy", "(", "JDBCRepository", "repo", ")", "{", "String", "databaseProductName", "=", "repo", ".", "getDatabaseProductName", "(", ")", ".", "trim", "(", ")", ";", "if", "(", "databaseProductName", "!=", "null", "&&", "databaseProductName", ".", "length", "(", ")", ">", "0", ")", "{", "String", "strategyName", "=", "Character", ".", "toUpperCase", "(", "databaseProductName", ".", "charAt", "(", "0", ")", ")", "+", "databaseProductName", ".", "substring", "(", "1", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "strategyName", ".", "indexOf", "(", "'", "'", ")", ">", "0", ")", "{", "strategyName", "=", "strategyName", ".", "substring", "(", "0", ",", "strategyName", ".", "indexOf", "(", "'", "'", ")", ")", ";", "}", "strategyName", "=", "strategyName", ".", "replaceAll", "(", "\"[^A-Za-z0-9]\"", ",", "\"\"", ")", ";", "String", "className", "=", "\"com.amazon.carbonado.repo.jdbc.\"", "+", "strategyName", "+", "\"SupportStrategy\"", ";", "try", "{", "Class", "<", "JDBCSupportStrategy", ">", "clazz", "=", "(", "Class", "<", "JDBCSupportStrategy", ">", ")", "Class", ".", "forName", "(", "className", ")", ";", "return", "clazz", ".", "getDeclaredConstructor", "(", "JDBCRepository", ".", "class", ")", ".", "newInstance", "(", "repo", ")", ";", "}", "catch", "(", "ClassNotFoundException", "e", ")", "{", "// just use default strategy\r", "}", "catch", "(", "Exception", "e", ")", "{", "ThrowUnchecked", ".", "fireFirstDeclaredCause", "(", "e", ")", ";", "}", "}", "return", "new", "JDBCSupportStrategy", "(", "repo", ")", ";", "}" ]
Create a strategy based on the name of the database product. If one can't be found by product name the default will be used.
[ "Create", "a", "strategy", "based", "on", "the", "name", "of", "the", "database", "product", ".", "If", "one", "can", "t", "be", "found", "by", "product", "name", "the", "default", "will", "be", "used", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java#L56-L80
8,184
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngine.java
LobEngine.createNewBlob
public Blob createNewBlob(int blockSize) throws PersistException { StoredLob lob = mLobStorage.prepare(); lob.setLocator(mLocatorSequence.nextLongValue()); lob.setBlockSize(blockSize); lob.setLength(0); lob.insert(); return new BlobImpl(lob.getLocator()); }
java
public Blob createNewBlob(int blockSize) throws PersistException { StoredLob lob = mLobStorage.prepare(); lob.setLocator(mLocatorSequence.nextLongValue()); lob.setBlockSize(blockSize); lob.setLength(0); lob.insert(); return new BlobImpl(lob.getLocator()); }
[ "public", "Blob", "createNewBlob", "(", "int", "blockSize", ")", "throws", "PersistException", "{", "StoredLob", "lob", "=", "mLobStorage", ".", "prepare", "(", ")", ";", "lob", ".", "setLocator", "(", "mLocatorSequence", ".", "nextLongValue", "(", ")", ")", ";", "lob", ".", "setBlockSize", "(", "blockSize", ")", ";", "lob", ".", "setLength", "(", "0", ")", ";", "lob", ".", "insert", "(", ")", ";", "return", "new", "BlobImpl", "(", "lob", ".", "getLocator", "(", ")", ")", ";", "}" ]
Returns a new Blob whose length is zero. @param blockSize block size (in <i>bytes</i>) to use @return new empty Blob
[ "Returns", "a", "new", "Blob", "whose", "length", "is", "zero", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngine.java#L126-L133
8,185
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngine.java
LobEngine.createNewClob
public Clob createNewClob(int blockSize) throws PersistException { StoredLob lob = mLobStorage.prepare(); lob.setLocator(mLocatorSequence.nextLongValue()); lob.setBlockSize(blockSize); lob.setLength(0); lob.insert(); return new ClobImpl(lob.getLocator()); }
java
public Clob createNewClob(int blockSize) throws PersistException { StoredLob lob = mLobStorage.prepare(); lob.setLocator(mLocatorSequence.nextLongValue()); lob.setBlockSize(blockSize); lob.setLength(0); lob.insert(); return new ClobImpl(lob.getLocator()); }
[ "public", "Clob", "createNewClob", "(", "int", "blockSize", ")", "throws", "PersistException", "{", "StoredLob", "lob", "=", "mLobStorage", ".", "prepare", "(", ")", ";", "lob", ".", "setLocator", "(", "mLocatorSequence", ".", "nextLongValue", "(", ")", ")", ";", "lob", ".", "setBlockSize", "(", "blockSize", ")", ";", "lob", ".", "setLength", "(", "0", ")", ";", "lob", ".", "insert", "(", ")", ";", "return", "new", "ClobImpl", "(", "lob", ".", "getLocator", "(", ")", ")", ";", "}" ]
Returns a new Clob whose length is zero. @param blockSize block size (in <i>bytes</i>) to use @return new empty Clob
[ "Returns", "a", "new", "Clob", "whose", "length", "is", "zero", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngine.java#L141-L148
8,186
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngine.java
LobEngine.getLocator
public long getLocator(Lob lob) { if (lob == null) { return 0; } Long locator = (Long) lob.getLocator(); return locator == null ? 0 : locator; }
java
public long getLocator(Lob lob) { if (lob == null) { return 0; } Long locator = (Long) lob.getLocator(); return locator == null ? 0 : locator; }
[ "public", "long", "getLocator", "(", "Lob", "lob", ")", "{", "if", "(", "lob", "==", "null", ")", "{", "return", "0", ";", "}", "Long", "locator", "=", "(", "Long", ")", "lob", ".", "getLocator", "(", ")", ";", "return", "locator", "==", "null", "?", "0", ":", "locator", ";", "}" ]
Returns the locator for the given Lob, or zero if null. @throws ClassCastException if Lob is unrecognized
[ "Returns", "the", "locator", "for", "the", "given", "Lob", "or", "zero", "if", "null", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngine.java#L155-L161
8,187
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngine.java
LobEngine.deleteLob
public void deleteLob(long locator) throws PersistException { if (locator == 0) { return; } Transaction txn = mRepo.enterTransaction(IsolationLevel.READ_COMMITTED); try { StoredLob lob = mLobStorage.prepare(); lob.setLocator(locator); if (lob.tryDelete()) { try { mLobBlockStorage.query("locator = ?").with(lob.getLocator()).deleteAll(); } catch (FetchException e) { throw e.toPersistException(); } } txn.commit(); } finally { txn.exit(); } }
java
public void deleteLob(long locator) throws PersistException { if (locator == 0) { return; } Transaction txn = mRepo.enterTransaction(IsolationLevel.READ_COMMITTED); try { StoredLob lob = mLobStorage.prepare(); lob.setLocator(locator); if (lob.tryDelete()) { try { mLobBlockStorage.query("locator = ?").with(lob.getLocator()).deleteAll(); } catch (FetchException e) { throw e.toPersistException(); } } txn.commit(); } finally { txn.exit(); } }
[ "public", "void", "deleteLob", "(", "long", "locator", ")", "throws", "PersistException", "{", "if", "(", "locator", "==", "0", ")", "{", "return", ";", "}", "Transaction", "txn", "=", "mRepo", ".", "enterTransaction", "(", "IsolationLevel", ".", "READ_COMMITTED", ")", ";", "try", "{", "StoredLob", "lob", "=", "mLobStorage", ".", "prepare", "(", ")", ";", "lob", ".", "setLocator", "(", "locator", ")", ";", "if", "(", "lob", ".", "tryDelete", "(", ")", ")", "{", "try", "{", "mLobBlockStorage", ".", "query", "(", "\"locator = ?\"", ")", ".", "with", "(", "lob", ".", "getLocator", "(", ")", ")", ".", "deleteAll", "(", ")", ";", "}", "catch", "(", "FetchException", "e", ")", "{", "throw", "e", ".", "toPersistException", "(", ")", ";", "}", "}", "txn", ".", "commit", "(", ")", ";", "}", "finally", "{", "txn", ".", "exit", "(", ")", ";", "}", "}" ]
Deletes Lob data, freeing up all space consumed by it.
[ "Deletes", "Lob", "data", "freeing", "up", "all", "space", "consumed", "by", "it", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngine.java#L166-L186
8,188
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/spi/LobEngine.java
LobEngine.getSupportTrigger
public synchronized <S extends Storable> Trigger<S> getSupportTrigger(Class<S> type, int blockSize) { Object key = KeyFactory.createKey(new Object[] {type, blockSize}); Trigger<S> trigger = (mTriggers == null) ? null : (Trigger<S>) mTriggers.get(key); if (trigger == null) { StorableInfo<S> info = StorableIntrospector.examine(type); List<LobProperty<?>> lobProperties = null; for (StorableProperty<? extends S> prop : info.getAllProperties().values()) { if (Blob.class.isAssignableFrom(prop.getType())) { if (lobProperties == null) { lobProperties = new ArrayList<LobProperty<?>>(); } lobProperties.add(new BlobProperty(this, prop.getName())); } else if (Clob.class.isAssignableFrom(prop.getType())) { if (lobProperties == null) { lobProperties = new ArrayList<LobProperty<?>>(); } lobProperties.add(new ClobProperty(this, prop.getName())); } } if (lobProperties != null) { trigger = new LobEngineTrigger<S>(this, type, blockSize, lobProperties); } if (mTriggers == null) { mTriggers = SoftValuedCache.newCache(7); } mTriggers.put(key, trigger); } return trigger; }
java
public synchronized <S extends Storable> Trigger<S> getSupportTrigger(Class<S> type, int blockSize) { Object key = KeyFactory.createKey(new Object[] {type, blockSize}); Trigger<S> trigger = (mTriggers == null) ? null : (Trigger<S>) mTriggers.get(key); if (trigger == null) { StorableInfo<S> info = StorableIntrospector.examine(type); List<LobProperty<?>> lobProperties = null; for (StorableProperty<? extends S> prop : info.getAllProperties().values()) { if (Blob.class.isAssignableFrom(prop.getType())) { if (lobProperties == null) { lobProperties = new ArrayList<LobProperty<?>>(); } lobProperties.add(new BlobProperty(this, prop.getName())); } else if (Clob.class.isAssignableFrom(prop.getType())) { if (lobProperties == null) { lobProperties = new ArrayList<LobProperty<?>>(); } lobProperties.add(new ClobProperty(this, prop.getName())); } } if (lobProperties != null) { trigger = new LobEngineTrigger<S>(this, type, blockSize, lobProperties); } if (mTriggers == null) { mTriggers = SoftValuedCache.newCache(7); } mTriggers.put(key, trigger); } return trigger; }
[ "public", "synchronized", "<", "S", "extends", "Storable", ">", "Trigger", "<", "S", ">", "getSupportTrigger", "(", "Class", "<", "S", ">", "type", ",", "int", "blockSize", ")", "{", "Object", "key", "=", "KeyFactory", ".", "createKey", "(", "new", "Object", "[", "]", "{", "type", ",", "blockSize", "}", ")", ";", "Trigger", "<", "S", ">", "trigger", "=", "(", "mTriggers", "==", "null", ")", "?", "null", ":", "(", "Trigger", "<", "S", ">", ")", "mTriggers", ".", "get", "(", "key", ")", ";", "if", "(", "trigger", "==", "null", ")", "{", "StorableInfo", "<", "S", ">", "info", "=", "StorableIntrospector", ".", "examine", "(", "type", ")", ";", "List", "<", "LobProperty", "<", "?", ">", ">", "lobProperties", "=", "null", ";", "for", "(", "StorableProperty", "<", "?", "extends", "S", ">", "prop", ":", "info", ".", "getAllProperties", "(", ")", ".", "values", "(", ")", ")", "{", "if", "(", "Blob", ".", "class", ".", "isAssignableFrom", "(", "prop", ".", "getType", "(", ")", ")", ")", "{", "if", "(", "lobProperties", "==", "null", ")", "{", "lobProperties", "=", "new", "ArrayList", "<", "LobProperty", "<", "?", ">", ">", "(", ")", ";", "}", "lobProperties", ".", "add", "(", "new", "BlobProperty", "(", "this", ",", "prop", ".", "getName", "(", ")", ")", ")", ";", "}", "else", "if", "(", "Clob", ".", "class", ".", "isAssignableFrom", "(", "prop", ".", "getType", "(", ")", ")", ")", "{", "if", "(", "lobProperties", "==", "null", ")", "{", "lobProperties", "=", "new", "ArrayList", "<", "LobProperty", "<", "?", ">", ">", "(", ")", ";", "}", "lobProperties", ".", "add", "(", "new", "ClobProperty", "(", "this", ",", "prop", ".", "getName", "(", ")", ")", ")", ";", "}", "}", "if", "(", "lobProperties", "!=", "null", ")", "{", "trigger", "=", "new", "LobEngineTrigger", "<", "S", ">", "(", "this", ",", "type", ",", "blockSize", ",", "lobProperties", ")", ";", "}", "if", "(", "mTriggers", "==", "null", ")", "{", "mTriggers", "=", "SoftValuedCache", ".", "newCache", "(", "7", ")", ";", "}", "mTriggers", ".", "put", "(", "key", ",", "trigger", ")", ";", "}", "return", "trigger", ";", "}" ]
Returns a Trigger for binding to this LobEngine. Storage implementations which use LobEngine must install this Trigger. Trigger instances are cached, so subsequent calls for the same trigger return the same instance. @param type type of Storable to create trigger for @param blockSize block size to use @return support trigger or null if storable type has no lob properties
[ "Returns", "a", "Trigger", "for", "binding", "to", "this", "LobEngine", ".", "Storage", "implementations", "which", "use", "LobEngine", "must", "install", "this", "Trigger", ".", "Trigger", "instances", "are", "cached", "so", "subsequent", "calls", "for", "the", "same", "trigger", "return", "the", "same", "instance", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/spi/LobEngine.java#L433-L471
8,189
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java
JDBCExceptionTransformer.isConstraintError
public boolean isConstraintError(SQLException e) { if (e != null) { String sqlstate = e.getSQLState(); if (sqlstate != null) { return sqlstate.startsWith(SQLSTATE_CONSTRAINT_VIOLATION_CLASS_CODE); } } return false; }
java
public boolean isConstraintError(SQLException e) { if (e != null) { String sqlstate = e.getSQLState(); if (sqlstate != null) { return sqlstate.startsWith(SQLSTATE_CONSTRAINT_VIOLATION_CLASS_CODE); } } return false; }
[ "public", "boolean", "isConstraintError", "(", "SQLException", "e", ")", "{", "if", "(", "e", "!=", "null", ")", "{", "String", "sqlstate", "=", "e", ".", "getSQLState", "(", ")", ";", "if", "(", "sqlstate", "!=", "null", ")", "{", "return", "sqlstate", ".", "startsWith", "(", "SQLSTATE_CONSTRAINT_VIOLATION_CLASS_CODE", ")", ";", "}", "}", "return", "false", ";", "}" ]
Examines the SQLSTATE code of the given SQL exception and determines if it is a generic constaint violation.
[ "Examines", "the", "SQLSTATE", "code", "of", "the", "given", "SQL", "exception", "and", "determines", "if", "it", "is", "a", "generic", "constaint", "violation", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java#L70-L78
8,190
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java
JDBCExceptionTransformer.isUniqueConstraintError
public boolean isUniqueConstraintError(SQLException e) { if (isConstraintError(e)) { String sqlstate = e.getSQLState(); return SQLSTATE_UNIQUE_CONSTRAINT_VIOLATION.equals(sqlstate); } return false; }
java
public boolean isUniqueConstraintError(SQLException e) { if (isConstraintError(e)) { String sqlstate = e.getSQLState(); return SQLSTATE_UNIQUE_CONSTRAINT_VIOLATION.equals(sqlstate); } return false; }
[ "public", "boolean", "isUniqueConstraintError", "(", "SQLException", "e", ")", "{", "if", "(", "isConstraintError", "(", "e", ")", ")", "{", "String", "sqlstate", "=", "e", ".", "getSQLState", "(", ")", ";", "return", "SQLSTATE_UNIQUE_CONSTRAINT_VIOLATION", ".", "equals", "(", "sqlstate", ")", ";", "}", "return", "false", ";", "}" ]
Examines the SQLSTATE code of the given SQL exception and determines if it is a unique constaint violation.
[ "Examines", "the", "SQLSTATE", "code", "of", "the", "given", "SQL", "exception", "and", "determines", "if", "it", "is", "a", "unique", "constaint", "violation", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java#L84-L90
8,191
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/RepositoryException.java
RepositoryException.toPersistException
public final PersistException toPersistException(final String message) { Throwable cause; if (this instanceof PersistException) { cause = this; } else { cause = getCause(); } if (cause == null) { cause = this; } else if (cause instanceof PersistException && message == null) { return (PersistException) cause; } String causeMessage = cause.getMessage(); if (causeMessage == null) { causeMessage = message; } else if (message != null) { causeMessage = message + " : " + causeMessage; } return makePersistException(causeMessage, cause); }
java
public final PersistException toPersistException(final String message) { Throwable cause; if (this instanceof PersistException) { cause = this; } else { cause = getCause(); } if (cause == null) { cause = this; } else if (cause instanceof PersistException && message == null) { return (PersistException) cause; } String causeMessage = cause.getMessage(); if (causeMessage == null) { causeMessage = message; } else if (message != null) { causeMessage = message + " : " + causeMessage; } return makePersistException(causeMessage, cause); }
[ "public", "final", "PersistException", "toPersistException", "(", "final", "String", "message", ")", "{", "Throwable", "cause", ";", "if", "(", "this", "instanceof", "PersistException", ")", "{", "cause", "=", "this", ";", "}", "else", "{", "cause", "=", "getCause", "(", ")", ";", "}", "if", "(", "cause", "==", "null", ")", "{", "cause", "=", "this", ";", "}", "else", "if", "(", "cause", "instanceof", "PersistException", "&&", "message", "==", "null", ")", "{", "return", "(", "PersistException", ")", "cause", ";", "}", "String", "causeMessage", "=", "cause", ".", "getMessage", "(", ")", ";", "if", "(", "causeMessage", "==", "null", ")", "{", "causeMessage", "=", "message", ";", "}", "else", "if", "(", "message", "!=", "null", ")", "{", "causeMessage", "=", "message", "+", "\" : \"", "+", "causeMessage", ";", "}", "return", "makePersistException", "(", "causeMessage", ",", "cause", ")", ";", "}" ]
Converts RepositoryException into an appropriate PersistException, prepending the specified message. If message is null, original exception message is preserved. @param message message to prepend, which may be null
[ "Converts", "RepositoryException", "into", "an", "appropriate", "PersistException", "prepending", "the", "specified", "message", ".", "If", "message", "is", "null", "original", "exception", "message", "is", "preserved", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/RepositoryException.java#L139-L161
8,192
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/RepositoryException.java
RepositoryException.toFetchException
public final FetchException toFetchException(final String message) { Throwable cause; if (this instanceof FetchException) { cause = this; } else { cause = getCause(); } if (cause == null) { cause = this; } else if (cause instanceof FetchException && message == null) { return (FetchException) cause; } String causeMessage = cause.getMessage(); if (causeMessage == null) { causeMessage = message; } else if (message != null) { causeMessage = message + " : " + causeMessage; } return makeFetchException(causeMessage, cause); }
java
public final FetchException toFetchException(final String message) { Throwable cause; if (this instanceof FetchException) { cause = this; } else { cause = getCause(); } if (cause == null) { cause = this; } else if (cause instanceof FetchException && message == null) { return (FetchException) cause; } String causeMessage = cause.getMessage(); if (causeMessage == null) { causeMessage = message; } else if (message != null) { causeMessage = message + " : " + causeMessage; } return makeFetchException(causeMessage, cause); }
[ "public", "final", "FetchException", "toFetchException", "(", "final", "String", "message", ")", "{", "Throwable", "cause", ";", "if", "(", "this", "instanceof", "FetchException", ")", "{", "cause", "=", "this", ";", "}", "else", "{", "cause", "=", "getCause", "(", ")", ";", "}", "if", "(", "cause", "==", "null", ")", "{", "cause", "=", "this", ";", "}", "else", "if", "(", "cause", "instanceof", "FetchException", "&&", "message", "==", "null", ")", "{", "return", "(", "FetchException", ")", "cause", ";", "}", "String", "causeMessage", "=", "cause", ".", "getMessage", "(", ")", ";", "if", "(", "causeMessage", "==", "null", ")", "{", "causeMessage", "=", "message", ";", "}", "else", "if", "(", "message", "!=", "null", ")", "{", "causeMessage", "=", "message", "+", "\" : \"", "+", "causeMessage", ";", "}", "return", "makeFetchException", "(", "causeMessage", ",", "cause", ")", ";", "}" ]
Converts RepositoryException into an appropriate FetchException, prepending the specified message. If message is null, original exception message is preserved. @param message message to prepend, which may be null
[ "Converts", "RepositoryException", "into", "an", "appropriate", "FetchException", "prepending", "the", "specified", "message", ".", "If", "message", "is", "null", "original", "exception", "message", "is", "preserved", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/RepositoryException.java#L177-L199
8,193
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java
StorablePropertyAdapter.getAdapterInstance
public Object getAdapterInstance() { if (mAdapterInstance == null) { try { mAdapterInstance = mConstructor.newInstance (mEnclosingType, mPropertyName, mAnnotation.getAnnotation()); } catch (Exception e) { ThrowUnchecked.fireFirstDeclaredCause(e); } } return mAdapterInstance; }
java
public Object getAdapterInstance() { if (mAdapterInstance == null) { try { mAdapterInstance = mConstructor.newInstance (mEnclosingType, mPropertyName, mAnnotation.getAnnotation()); } catch (Exception e) { ThrowUnchecked.fireFirstDeclaredCause(e); } } return mAdapterInstance; }
[ "public", "Object", "getAdapterInstance", "(", ")", "{", "if", "(", "mAdapterInstance", "==", "null", ")", "{", "try", "{", "mAdapterInstance", "=", "mConstructor", ".", "newInstance", "(", "mEnclosingType", ",", "mPropertyName", ",", "mAnnotation", ".", "getAnnotation", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "ThrowUnchecked", ".", "fireFirstDeclaredCause", "(", "e", ")", ";", "}", "}", "return", "mAdapterInstance", ";", "}" ]
Returns an instance of the adapter, for which an adapt method is applied to.
[ "Returns", "an", "instance", "of", "the", "adapter", "for", "which", "an", "adapt", "method", "is", "applied", "to", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java#L236-L246
8,194
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java
StorablePropertyAdapter.findAdaptMethod
@SuppressWarnings("unchecked") public Method findAdaptMethod(Class from, Class to) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (to.isAssignableFrom(method.getReturnType()) && method.getParameterTypes()[0].isAssignableFrom(from)) { candidates.add(method); } } reduceCandidates(candidates, to); if (candidates.size() == 0) { return null; } return candidates.get(0); }
java
@SuppressWarnings("unchecked") public Method findAdaptMethod(Class from, Class to) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (to.isAssignableFrom(method.getReturnType()) && method.getParameterTypes()[0].isAssignableFrom(from)) { candidates.add(method); } } reduceCandidates(candidates, to); if (candidates.size() == 0) { return null; } return candidates.get(0); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "Method", "findAdaptMethod", "(", "Class", "from", ",", "Class", "to", ")", "{", "Method", "[", "]", "methods", "=", "mAdaptMethods", ";", "List", "<", "Method", ">", "candidates", "=", "new", "ArrayList", "<", "Method", ">", "(", "methods", ".", "length", ")", ";", "for", "(", "int", "i", "=", "methods", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "Method", "method", "=", "methods", "[", "i", "]", ";", "if", "(", "to", ".", "isAssignableFrom", "(", "method", ".", "getReturnType", "(", ")", ")", "&&", "method", ".", "getParameterTypes", "(", ")", "[", "0", "]", ".", "isAssignableFrom", "(", "from", ")", ")", "{", "candidates", ".", "add", "(", "method", ")", ";", "}", "}", "reduceCandidates", "(", "candidates", ",", "to", ")", ";", "if", "(", "candidates", ".", "size", "(", ")", "==", "0", ")", "{", "return", "null", ";", "}", "return", "candidates", ".", "get", "(", "0", ")", ";", "}" ]
Returns an adapt method that supports the given conversion, or null if none.
[ "Returns", "an", "adapt", "method", "that", "supports", "the", "given", "conversion", "or", "null", "if", "none", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java#L264-L280
8,195
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java
StorablePropertyAdapter.findAdaptMethodsFrom
public Method[] findAdaptMethodsFrom(Class from) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (method.getParameterTypes()[0].isAssignableFrom(from)) { candidates.add(method); } } return (Method[]) candidates.toArray(new Method[candidates.size()]); }
java
public Method[] findAdaptMethodsFrom(Class from) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (method.getParameterTypes()[0].isAssignableFrom(from)) { candidates.add(method); } } return (Method[]) candidates.toArray(new Method[candidates.size()]); }
[ "public", "Method", "[", "]", "findAdaptMethodsFrom", "(", "Class", "from", ")", "{", "Method", "[", "]", "methods", "=", "mAdaptMethods", ";", "List", "<", "Method", ">", "candidates", "=", "new", "ArrayList", "<", "Method", ">", "(", "methods", ".", "length", ")", ";", "for", "(", "int", "i", "=", "methods", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "Method", "method", "=", "methods", "[", "i", "]", ";", "if", "(", "method", ".", "getParameterTypes", "(", ")", "[", "0", "]", ".", "isAssignableFrom", "(", "from", ")", ")", "{", "candidates", ".", "add", "(", "method", ")", ";", "}", "}", "return", "(", "Method", "[", "]", ")", "candidates", ".", "toArray", "(", "new", "Method", "[", "candidates", ".", "size", "(", ")", "]", ")", ";", "}" ]
Returns all the adapt methods that convert from the given type.
[ "Returns", "all", "the", "adapt", "methods", "that", "convert", "from", "the", "given", "type", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java#L285-L295
8,196
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java
StorablePropertyAdapter.findAdaptMethodsTo
@SuppressWarnings("unchecked") public Method[] findAdaptMethodsTo(Class to) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (to.isAssignableFrom(method.getReturnType())) { candidates.add(method); } } reduceCandidates(candidates, to); return (Method[]) candidates.toArray(new Method[candidates.size()]); }
java
@SuppressWarnings("unchecked") public Method[] findAdaptMethodsTo(Class to) { Method[] methods = mAdaptMethods; List<Method> candidates = new ArrayList<Method>(methods.length); for (int i=methods.length; --i>=0; ) { Method method = methods[i]; if (to.isAssignableFrom(method.getReturnType())) { candidates.add(method); } } reduceCandidates(candidates, to); return (Method[]) candidates.toArray(new Method[candidates.size()]); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "Method", "[", "]", "findAdaptMethodsTo", "(", "Class", "to", ")", "{", "Method", "[", "]", "methods", "=", "mAdaptMethods", ";", "List", "<", "Method", ">", "candidates", "=", "new", "ArrayList", "<", "Method", ">", "(", "methods", ".", "length", ")", ";", "for", "(", "int", "i", "=", "methods", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "Method", "method", "=", "methods", "[", "i", "]", ";", "if", "(", "to", ".", "isAssignableFrom", "(", "method", ".", "getReturnType", "(", ")", ")", ")", "{", "candidates", ".", "add", "(", "method", ")", ";", "}", "}", "reduceCandidates", "(", "candidates", ",", "to", ")", ";", "return", "(", "Method", "[", "]", ")", "candidates", ".", "toArray", "(", "new", "Method", "[", "candidates", ".", "size", "(", ")", "]", ")", ";", "}" ]
Returns all the adapt methods that convert to the given type.
[ "Returns", "all", "the", "adapt", "methods", "that", "convert", "to", "the", "given", "type", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java#L300-L312
8,197
michael-rapp/AndroidMaterialValidation
library/src/main/java/de/mrapp/android/validation/constraints/ConjunctiveConstraint.java
ConjunctiveConstraint.create
public static <Type> ConjunctiveConstraint<Type> create( @NonNull final Constraint<Type>[] constraints) { return new ConjunctiveConstraint<>(constraints); }
java
public static <Type> ConjunctiveConstraint<Type> create( @NonNull final Constraint<Type>[] constraints) { return new ConjunctiveConstraint<>(constraints); }
[ "public", "static", "<", "Type", ">", "ConjunctiveConstraint", "<", "Type", ">", "create", "(", "@", "NonNull", "final", "Constraint", "<", "Type", ">", "[", "]", "constraints", ")", "{", "return", "new", "ConjunctiveConstraint", "<>", "(", "constraints", ")", ";", "}" ]
Creates and returns a constraint, which allows to combine multiple constraints in a conjunctive manner. @param <Type> The type of the values, which should be verified @param constraints The single constraints, the constraint should consist of, as an array of the type {@link Constraint}. The constraints may neither be null, nor empty @return The constraint, which has been created, as an instance of the class {@link ConjunctiveConstraint}
[ "Creates", "and", "returns", "a", "constraint", "which", "allows", "to", "combine", "multiple", "constraints", "in", "a", "conjunctive", "manner", "." ]
ac8693baeac7abddf2e38a47da4c1849d4661a8b
https://github.com/michael-rapp/AndroidMaterialValidation/blob/ac8693baeac7abddf2e38a47da4c1849d4661a8b/library/src/main/java/de/mrapp/android/validation/constraints/ConjunctiveConstraint.java#L60-L63
8,198
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/raw/GenericStorableCodecFactory.java
GenericStorableCodecFactory.createStrategy
protected <S extends Storable> GenericEncodingStrategy<S> createStrategy (Class<S> type, StorableIndex<S> pkIndex) throws SupportException { return new GenericEncodingStrategy<S>(type, pkIndex); }
java
protected <S extends Storable> GenericEncodingStrategy<S> createStrategy (Class<S> type, StorableIndex<S> pkIndex) throws SupportException { return new GenericEncodingStrategy<S>(type, pkIndex); }
[ "protected", "<", "S", "extends", "Storable", ">", "GenericEncodingStrategy", "<", "S", ">", "createStrategy", "(", "Class", "<", "S", ">", "type", ",", "StorableIndex", "<", "S", ">", "pkIndex", ")", "throws", "SupportException", "{", "return", "new", "GenericEncodingStrategy", "<", "S", ">", "(", "type", ",", "pkIndex", ")", ";", "}" ]
Override to return a different EncodingStrategy. @param type type of Storable to generate code for @param pkIndex specifies sequence and ordering of key properties (optional)
[ "Override", "to", "return", "a", "different", "EncodingStrategy", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/raw/GenericStorableCodecFactory.java#L103-L108
8,199
Carbonado/Carbonado
src/main/java/com/amazon/carbonado/util/Comparators.java
Comparators.arrayComparator
public static <T> Comparator<T> arrayComparator(Class<T> arrayType, boolean unsigned) { if (!arrayType.isArray()) { throw new IllegalArgumentException(); } Comparator c; TypeDesc componentType = TypeDesc.forClass(arrayType.getComponentType()); switch (componentType.getTypeCode()) { case TypeDesc.BYTE_CODE: c = unsigned ? UnsignedByteArray : SignedByteArray; break; case TypeDesc.SHORT_CODE: c = unsigned ? UnsignedShortArray : SignedShortArray; break; case TypeDesc.INT_CODE: c = unsigned ? UnsignedIntArray : SignedIntArray; break; case TypeDesc.LONG_CODE: c = unsigned ? UnsignedLongArray : SignedLongArray; break; case TypeDesc.BOOLEAN_CODE: c = BooleanArray; break; case TypeDesc.CHAR_CODE: c = CharArray; break; case TypeDesc.FLOAT_CODE: c = FloatArray; break; case TypeDesc.DOUBLE_CODE: c = DoubleArray; break; case TypeDesc.OBJECT_CODE: default: if (componentType.isArray()) { c = new ComparatorArray(arrayComparator(componentType.toClass(), unsigned)); } else if (Comparable.class.isAssignableFrom(componentType.toClass())) { c = ComparableArray; } else { c = null; } break; } return (Comparator<T>) c; }
java
public static <T> Comparator<T> arrayComparator(Class<T> arrayType, boolean unsigned) { if (!arrayType.isArray()) { throw new IllegalArgumentException(); } Comparator c; TypeDesc componentType = TypeDesc.forClass(arrayType.getComponentType()); switch (componentType.getTypeCode()) { case TypeDesc.BYTE_CODE: c = unsigned ? UnsignedByteArray : SignedByteArray; break; case TypeDesc.SHORT_CODE: c = unsigned ? UnsignedShortArray : SignedShortArray; break; case TypeDesc.INT_CODE: c = unsigned ? UnsignedIntArray : SignedIntArray; break; case TypeDesc.LONG_CODE: c = unsigned ? UnsignedLongArray : SignedLongArray; break; case TypeDesc.BOOLEAN_CODE: c = BooleanArray; break; case TypeDesc.CHAR_CODE: c = CharArray; break; case TypeDesc.FLOAT_CODE: c = FloatArray; break; case TypeDesc.DOUBLE_CODE: c = DoubleArray; break; case TypeDesc.OBJECT_CODE: default: if (componentType.isArray()) { c = new ComparatorArray(arrayComparator(componentType.toClass(), unsigned)); } else if (Comparable.class.isAssignableFrom(componentType.toClass())) { c = ComparableArray; } else { c = null; } break; } return (Comparator<T>) c; }
[ "public", "static", "<", "T", ">", "Comparator", "<", "T", ">", "arrayComparator", "(", "Class", "<", "T", ">", "arrayType", ",", "boolean", "unsigned", ")", "{", "if", "(", "!", "arrayType", ".", "isArray", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "Comparator", "c", ";", "TypeDesc", "componentType", "=", "TypeDesc", ".", "forClass", "(", "arrayType", ".", "getComponentType", "(", ")", ")", ";", "switch", "(", "componentType", ".", "getTypeCode", "(", ")", ")", "{", "case", "TypeDesc", ".", "BYTE_CODE", ":", "c", "=", "unsigned", "?", "UnsignedByteArray", ":", "SignedByteArray", ";", "break", ";", "case", "TypeDesc", ".", "SHORT_CODE", ":", "c", "=", "unsigned", "?", "UnsignedShortArray", ":", "SignedShortArray", ";", "break", ";", "case", "TypeDesc", ".", "INT_CODE", ":", "c", "=", "unsigned", "?", "UnsignedIntArray", ":", "SignedIntArray", ";", "break", ";", "case", "TypeDesc", ".", "LONG_CODE", ":", "c", "=", "unsigned", "?", "UnsignedLongArray", ":", "SignedLongArray", ";", "break", ";", "case", "TypeDesc", ".", "BOOLEAN_CODE", ":", "c", "=", "BooleanArray", ";", "break", ";", "case", "TypeDesc", ".", "CHAR_CODE", ":", "c", "=", "CharArray", ";", "break", ";", "case", "TypeDesc", ".", "FLOAT_CODE", ":", "c", "=", "FloatArray", ";", "break", ";", "case", "TypeDesc", ".", "DOUBLE_CODE", ":", "c", "=", "DoubleArray", ";", "break", ";", "case", "TypeDesc", ".", "OBJECT_CODE", ":", "default", ":", "if", "(", "componentType", ".", "isArray", "(", ")", ")", "{", "c", "=", "new", "ComparatorArray", "(", "arrayComparator", "(", "componentType", ".", "toClass", "(", ")", ",", "unsigned", ")", ")", ";", "}", "else", "if", "(", "Comparable", ".", "class", ".", "isAssignableFrom", "(", "componentType", ".", "toClass", "(", ")", ")", ")", "{", "c", "=", "ComparableArray", ";", "}", "else", "{", "c", "=", "null", ";", "}", "break", ";", "}", "return", "(", "Comparator", "<", "T", ">", ")", "c", ";", "}" ]
Returns a comparator which can sort single or multi-dimensional arrays of primitves or Comparables. @param unsigned applicable only to arrays of bytes, shorts, ints, or longs @return null if unsupported
[ "Returns", "a", "comparator", "which", "can", "sort", "single", "or", "multi", "-", "dimensional", "arrays", "of", "primitves", "or", "Comparables", "." ]
eee29b365a61c8f03e1a1dc6bed0692e6b04b1db
https://github.com/Carbonado/Carbonado/blob/eee29b365a61c8f03e1a1dc6bed0692e6b04b1db/src/main/java/com/amazon/carbonado/util/Comparators.java#L38-L83