repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getRelationshipField | public Field getRelationshipField(Class<?> clazz, String fieldName) {
return relationshipFieldMap.get(clazz).get(fieldName);
} | java | public Field getRelationshipField(Class<?> clazz, String fieldName) {
return relationshipFieldMap.get(clazz).get(fieldName);
} | [
"public",
"Field",
"getRelationshipField",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"fieldName",
")",
"{",
"return",
"relationshipFieldMap",
".",
"get",
"(",
"clazz",
")",
".",
"get",
"(",
"fieldName",
")",
";",
"}"
] | Returns relationship field.
@param clazz {@link Class} class holding relationship
@param fieldName {@link String} name of the field
@return {@link Field} field | [
"Returns",
"relationship",
"field",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L235-L237 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getRelationshipType | public Class<?> getRelationshipType(Class<?> clazz, String fieldName) {
return relationshipTypeMap.get(clazz).get(fieldName);
} | java | public Class<?> getRelationshipType(Class<?> clazz, String fieldName) {
return relationshipTypeMap.get(clazz).get(fieldName);
} | [
"public",
"Class",
"<",
"?",
">",
"getRelationshipType",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"fieldName",
")",
"{",
"return",
"relationshipTypeMap",
".",
"get",
"(",
"clazz",
")",
".",
"get",
"(",
"fieldName",
")",
";",
"}"
] | Returns a type of a relationship.
@param clazz {@link Class} owning the field with relationship annotation
@param fieldName {@link String} name of the field
@return {@link Class} field type | [
"Returns",
"a",
"type",
"of",
"a",
"relationship",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L245-L247 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getTypeName | public String getTypeName(Class<?> clazz) {
Type type = typeAnnotations.get(clazz);
if (type != null) {
return type.value();
}
return null;
} | java | public String getTypeName(Class<?> clazz) {
Type type = typeAnnotations.get(clazz);
if (type != null) {
return type.value();
}
return null;
} | [
"public",
"String",
"getTypeName",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"Type",
"type",
"=",
"typeAnnotations",
".",
"get",
"(",
"clazz",
")",
";",
"if",
"(",
"type",
"!=",
"null",
")",
"{",
"return",
"type",
".",
"value",
"(",
")",
";",... | Resolves and returns name of the type given to provided class.
@param clazz {@link Class} to resolve type name for
@return type name or <code>null</code> if type was not registered | [
"Resolves",
"and",
"returns",
"name",
"of",
"the",
"type",
"given",
"to",
"provided",
"class",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L285-L292 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getRelationshipMetaField | public Field getRelationshipMetaField(Class<?> clazz, String relationshipName) {
return relationshipMetaFieldMap.get(clazz).get(relationshipName);
} | java | public Field getRelationshipMetaField(Class<?> clazz, String relationshipName) {
return relationshipMetaFieldMap.get(clazz).get(relationshipName);
} | [
"public",
"Field",
"getRelationshipMetaField",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"relationshipName",
")",
"{",
"return",
"relationshipMetaFieldMap",
".",
"get",
"(",
"clazz",
")",
".",
"get",
"(",
"relationshipName",
")",
";",
"}"
] | Returns relationship meta field.
@param clazz {@link Class} class holding relationship
@param relationshipName {@link String} name of the relationship
@return {@link Field} field | [
"Returns",
"relationship",
"meta",
"field",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L334-L336 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getRelationshipMetaType | public Class<?> getRelationshipMetaType(Class<?> clazz, String relationshipName) {
return relationshipMetaTypeMap.get(clazz).get(relationshipName);
} | java | public Class<?> getRelationshipMetaType(Class<?> clazz, String relationshipName) {
return relationshipMetaTypeMap.get(clazz).get(relationshipName);
} | [
"public",
"Class",
"<",
"?",
">",
"getRelationshipMetaType",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"relationshipName",
")",
"{",
"return",
"relationshipMetaTypeMap",
".",
"get",
"(",
"clazz",
")",
".",
"get",
"(",
"relationshipName",
")",
";",... | Returns a type of a relationship meta field.
@param clazz {@link Class} owning the field with relationship meta annotation
@param relationshipName {@link String} name of the field
@return {@link Class} meta field type | [
"Returns",
"a",
"type",
"of",
"a",
"relationship",
"meta",
"field",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L344-L346 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java | ConverterConfiguration.getRelationshipLinksField | public Field getRelationshipLinksField(Class<?> clazz, String relationshipName) {
return relationshipLinksFieldMap.get(clazz).get(relationshipName);
} | java | public Field getRelationshipLinksField(Class<?> clazz, String relationshipName) {
return relationshipLinksFieldMap.get(clazz).get(relationshipName);
} | [
"public",
"Field",
"getRelationshipLinksField",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"String",
"relationshipName",
")",
"{",
"return",
"relationshipLinksFieldMap",
".",
"get",
"(",
"clazz",
")",
".",
"get",
"(",
"relationshipName",
")",
";",
"}"
] | Returns relationship links field.
@param clazz {@link Class} class holding relationship
@param relationshipName {@link String} name of the relationship
@return {@link Field} field | [
"Returns",
"relationship",
"links",
"field",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ConverterConfiguration.java#L354-L356 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.setTypeResolver | public void setTypeResolver(RelationshipResolver resolver, Class<?> type) {
if (resolver != null) {
String typeName = ReflectionUtils.getTypeName(type);
if (typeName != null) {
typedResolvers.put(type, resolver);
}
}
} | java | public void setTypeResolver(RelationshipResolver resolver, Class<?> type) {
if (resolver != null) {
String typeName = ReflectionUtils.getTypeName(type);
if (typeName != null) {
typedResolvers.put(type, resolver);
}
}
} | [
"public",
"void",
"setTypeResolver",
"(",
"RelationshipResolver",
"resolver",
",",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"if",
"(",
"resolver",
"!=",
"null",
")",
"{",
"String",
"typeName",
"=",
"ReflectionUtils",
".",
"getTypeName",
"(",
"type",
")",
... | Registers relationship resolver for given type. Resolver will be used if relationship resolution is enabled
trough relationship annotation.
@param resolver resolver instance
@param type type | [
"Registers",
"relationship",
"resolver",
"for",
"given",
"type",
".",
"Resolver",
"will",
"be",
"used",
"if",
"relationship",
"resolution",
"is",
"enabled",
"trough",
"relationship",
"annotation",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L131-L139 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.readObject | @Deprecated
public <T> T readObject(byte [] data, Class<T> clazz) {
return readDocument(data, clazz).get();
} | java | @Deprecated
public <T> T readObject(byte [] data, Class<T> clazz) {
return readDocument(data, clazz).get();
} | [
"@",
"Deprecated",
"public",
"<",
"T",
">",
"T",
"readObject",
"(",
"byte",
"[",
"]",
"data",
",",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"return",
"readDocument",
"(",
"data",
",",
"clazz",
")",
".",
"get",
"(",
")",
";",
"}"
] | Converts raw data input into requested target type.
@param data raw data
@param clazz target object
@param <T> type
@return converted object
@throws RuntimeException in case conversion fails | [
"Converts",
"raw",
"data",
"input",
"into",
"requested",
"target",
"type",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L148-L151 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.readObjectCollection | @Deprecated
public <T> List<T> readObjectCollection(byte [] data, Class<T> clazz) {
return readDocumentCollection(data, clazz).get();
} | java | @Deprecated
public <T> List<T> readObjectCollection(byte [] data, Class<T> clazz) {
return readDocumentCollection(data, clazz).get();
} | [
"@",
"Deprecated",
"public",
"<",
"T",
">",
"List",
"<",
"T",
">",
"readObjectCollection",
"(",
"byte",
"[",
"]",
"data",
",",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"return",
"readDocumentCollection",
"(",
"data",
",",
"clazz",
")",
".",
"get",
... | Converts rawdata input into a collection of requested output objects.
@param data raw data input
@param clazz target type
@param <T> type
@return collection of converted elements
@throws RuntimeException in case conversion fails | [
"Converts",
"rawdata",
"input",
"into",
"a",
"collection",
"of",
"requested",
"output",
"objects",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L161-L164 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.readObject | private <T> T readObject(JsonNode source, Class<T> clazz, boolean handleRelationships)
throws IOException, IllegalAccessException, InstantiationException {
String identifier = createIdentifier(source);
T result = (T) resourceCache.get(identifier);
if (result == null) {
Class<?> type = getActualType(source, clazz);
if (source.has(ATTRIBUTES)) {
result = (T) objectMapper.treeToValue(source.get(ATTRIBUTES), type);
} else {
if (type.isInterface()) {
result = null;
} else {
result = (T) objectMapper.treeToValue(objectMapper.createObjectNode(), type);
}
}
// Handle meta
if (source.has(META)) {
Field field = configuration.getMetaField(type);
if (field != null) {
Class<?> metaType = configuration.getMetaType(type);
Object metaObject = objectMapper.treeToValue(source.get(META), metaType);
field.set(result, metaObject);
}
}
// Handle links
if (source.has(LINKS)) {
Field linkField = configuration.getLinksField(type);
if (linkField != null) {
linkField.set(result, new Links(mapLinks(source.get(LINKS))));
}
}
if (result != null) {
// Add parsed object to cache
resourceCache.cache(identifier, result);
// Set object id
setIdValue(result, source.get(ID));
if (handleRelationships) {
// Handle relationships
handleRelationships(source, result);
}
}
}
return result;
} | java | private <T> T readObject(JsonNode source, Class<T> clazz, boolean handleRelationships)
throws IOException, IllegalAccessException, InstantiationException {
String identifier = createIdentifier(source);
T result = (T) resourceCache.get(identifier);
if (result == null) {
Class<?> type = getActualType(source, clazz);
if (source.has(ATTRIBUTES)) {
result = (T) objectMapper.treeToValue(source.get(ATTRIBUTES), type);
} else {
if (type.isInterface()) {
result = null;
} else {
result = (T) objectMapper.treeToValue(objectMapper.createObjectNode(), type);
}
}
// Handle meta
if (source.has(META)) {
Field field = configuration.getMetaField(type);
if (field != null) {
Class<?> metaType = configuration.getMetaType(type);
Object metaObject = objectMapper.treeToValue(source.get(META), metaType);
field.set(result, metaObject);
}
}
// Handle links
if (source.has(LINKS)) {
Field linkField = configuration.getLinksField(type);
if (linkField != null) {
linkField.set(result, new Links(mapLinks(source.get(LINKS))));
}
}
if (result != null) {
// Add parsed object to cache
resourceCache.cache(identifier, result);
// Set object id
setIdValue(result, source.get(ID));
if (handleRelationships) {
// Handle relationships
handleRelationships(source, result);
}
}
}
return result;
} | [
"private",
"<",
"T",
">",
"T",
"readObject",
"(",
"JsonNode",
"source",
",",
"Class",
"<",
"T",
">",
"clazz",
",",
"boolean",
"handleRelationships",
")",
"throws",
"IOException",
",",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"String",
"ident... | Converts provided input into a target object. After conversion completes any relationships defined are resolved.
@param source JSON source
@param clazz target type
@param <T> type
@return converted target object
@throws IOException
@throws IllegalAccessException | [
"Converts",
"provided",
"input",
"into",
"a",
"target",
"object",
".",
"After",
"conversion",
"completes",
"any",
"relationships",
"defined",
"are",
"resolved",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L324-L375 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.parseIncluded | private Map<String, Object> parseIncluded(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
// Get resources
Map<String, Object> includedResources = getIncludedResources(parent);
if (!includedResources.isEmpty()) {
// Add to result
for (String identifier : includedResources.keySet()) {
result.put(identifier, includedResources.get(identifier));
}
ArrayNode includedArray = (ArrayNode) parent.get(INCLUDED);
for (int i = 0; i < includedArray.size(); i++) {
// Handle relationships
JsonNode node = includedArray.get(i);
Object resourceObject = includedResources.get(createIdentifier(node));
if (resourceObject != null){
handleRelationships(node, resourceObject);
}
}
}
}
return result;
} | java | private Map<String, Object> parseIncluded(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
// Get resources
Map<String, Object> includedResources = getIncludedResources(parent);
if (!includedResources.isEmpty()) {
// Add to result
for (String identifier : includedResources.keySet()) {
result.put(identifier, includedResources.get(identifier));
}
ArrayNode includedArray = (ArrayNode) parent.get(INCLUDED);
for (int i = 0; i < includedArray.size(); i++) {
// Handle relationships
JsonNode node = includedArray.get(i);
Object resourceObject = includedResources.get(createIdentifier(node));
if (resourceObject != null){
handleRelationships(node, resourceObject);
}
}
}
}
return result;
} | [
"private",
"Map",
"<",
"String",
",",
"Object",
">",
"parseIncluded",
"(",
"JsonNode",
"parent",
")",
"throws",
"IOException",
",",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"result",
"=",
"new",
"H... | Converts included data and returns it as pairs of its unique identifiers and converted types.
@param parent data source
@return identifier/object pairs
@throws IOException
@throws IllegalAccessException | [
"Converts",
"included",
"data",
"and",
"returns",
"it",
"as",
"pairs",
"of",
"its",
"unique",
"identifiers",
"and",
"converted",
"types",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L385-L412 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.getIncludedResources | private Map<String, Object> getIncludedResources(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
for (JsonNode jsonNode : parent.get(INCLUDED)) {
String type = jsonNode.get(TYPE).asText();
Class<?> clazz = configuration.getTypeClass(type);
if (clazz != null) {
Object object = readObject(jsonNode, clazz, false);
if (object != null) {
result.put(createIdentifier(jsonNode), object);
}
} else if (!deserializationFeatures.contains(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS)) {
throw new IllegalArgumentException("Included section contains unknown resource type: " + type);
}
}
}
return result;
} | java | private Map<String, Object> getIncludedResources(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
for (JsonNode jsonNode : parent.get(INCLUDED)) {
String type = jsonNode.get(TYPE).asText();
Class<?> clazz = configuration.getTypeClass(type);
if (clazz != null) {
Object object = readObject(jsonNode, clazz, false);
if (object != null) {
result.put(createIdentifier(jsonNode), object);
}
} else if (!deserializationFeatures.contains(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS)) {
throw new IllegalArgumentException("Included section contains unknown resource type: " + type);
}
}
}
return result;
} | [
"private",
"Map",
"<",
"String",
",",
"Object",
">",
"getIncludedResources",
"(",
"JsonNode",
"parent",
")",
"throws",
"IOException",
",",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"result",
"=",
"new... | Parses out included resources excluding relationships.
@param parent root node
@return map of identifier/resource pairs
@throws IOException
@throws IllegalAccessException
@throws InstantiationException | [
"Parses",
"out",
"included",
"resources",
"excluding",
"relationships",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L422-L444 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.parseRelationship | private Object parseRelationship(JsonNode relationshipDataNode, Class<?> type)
throws IOException, IllegalAccessException, InstantiationException {
if (ValidationUtils.isRelationshipParsable(relationshipDataNode)) {
String identifier = createIdentifier(relationshipDataNode);
if (resourceCache.contains(identifier)) {
return resourceCache.get(identifier);
} else {
// Never cache relationship objects
resourceCache.lock();
try {
return readObject(relationshipDataNode, type, true);
} finally {
resourceCache.unlock();
}
}
}
return null;
} | java | private Object parseRelationship(JsonNode relationshipDataNode, Class<?> type)
throws IOException, IllegalAccessException, InstantiationException {
if (ValidationUtils.isRelationshipParsable(relationshipDataNode)) {
String identifier = createIdentifier(relationshipDataNode);
if (resourceCache.contains(identifier)) {
return resourceCache.get(identifier);
} else {
// Never cache relationship objects
resourceCache.lock();
try {
return readObject(relationshipDataNode, type, true);
} finally {
resourceCache.unlock();
}
}
}
return null;
} | [
"private",
"Object",
"parseRelationship",
"(",
"JsonNode",
"relationshipDataNode",
",",
"Class",
"<",
"?",
">",
"type",
")",
"throws",
"IOException",
",",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"if",
"(",
"ValidationUtils",
".",
"isRelationshipP... | Creates relationship object by consuming provided 'data' node.
@param relationshipDataNode relationship data node
@param type object type
@return created object or <code>null</code> in case data node is not valid
@throws IOException
@throws IllegalAccessException
@throws InstantiationException | [
"Creates",
"relationship",
"object",
"by",
"consuming",
"provided",
"data",
"node",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L576-L595 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.setIdValue | private void setIdValue(Object target, JsonNode idValue) throws IllegalAccessException {
Field idField = configuration.getIdField(target.getClass());
ResourceIdHandler idHandler = configuration.getIdHandler(target.getClass());
if (idValue != null) {
idField.set(target, idHandler.fromString(idValue.asText()));
}
} | java | private void setIdValue(Object target, JsonNode idValue) throws IllegalAccessException {
Field idField = configuration.getIdField(target.getClass());
ResourceIdHandler idHandler = configuration.getIdHandler(target.getClass());
if (idValue != null) {
idField.set(target, idHandler.fromString(idValue.asText()));
}
} | [
"private",
"void",
"setIdValue",
"(",
"Object",
"target",
",",
"JsonNode",
"idValue",
")",
"throws",
"IllegalAccessException",
"{",
"Field",
"idField",
"=",
"configuration",
".",
"getIdField",
"(",
"target",
".",
"getClass",
"(",
")",
")",
";",
"ResourceIdHandle... | Sets an id attribute value to a target object.
@param target target POJO
@param idValue id node
@throws IllegalAccessException thrown in case target field is not accessible | [
"Sets",
"an",
"id",
"attribute",
"value",
"to",
"a",
"target",
"object",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L622-L629 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.getResolver | private RelationshipResolver getResolver(Class<?> type) {
RelationshipResolver resolver = typedResolvers.get(type);
return resolver != null ? resolver : globalResolver;
} | java | private RelationshipResolver getResolver(Class<?> type) {
RelationshipResolver resolver = typedResolvers.get(type);
return resolver != null ? resolver : globalResolver;
} | [
"private",
"RelationshipResolver",
"getResolver",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"RelationshipResolver",
"resolver",
"=",
"typedResolvers",
".",
"get",
"(",
"type",
")",
";",
"return",
"resolver",
"!=",
"null",
"?",
"resolver",
":",
"globalReso... | Returns relationship resolver for given type. In case no specific type resolver is registered, global resolver
is returned.
@param type relationship object type
@return relationship resolver or <code>null</code> | [
"Returns",
"relationship",
"resolver",
"for",
"given",
"type",
".",
"In",
"case",
"no",
"specific",
"type",
"resolver",
"is",
"registered",
"global",
"resolver",
"is",
"returned",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L991-L994 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java | ResourceConverter.registerType | public boolean registerType(Class<?> type) {
if (!configuration.isRegisteredType(type) && ConverterConfiguration.isEligibleType(type)) {
return configuration.registerType(type);
}
return false;
} | java | public boolean registerType(Class<?> type) {
if (!configuration.isRegisteredType(type) && ConverterConfiguration.isEligibleType(type)) {
return configuration.registerType(type);
}
return false;
} | [
"public",
"boolean",
"registerType",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"if",
"(",
"!",
"configuration",
".",
"isRegisteredType",
"(",
"type",
")",
"&&",
"ConverterConfiguration",
".",
"isEligibleType",
"(",
"type",
")",
")",
"{",
"return",
"co... | Registers new type to be used with this converter instance.
@param type {@link Class} type to register
@return <code>true</code> if type was registed, else <code>false</code> (in case type was registered already or
type is not eligible for registering ie. missing required annotations) | [
"Registers",
"new",
"type",
"to",
"be",
"used",
"with",
"this",
"converter",
"instance",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceConverter.java#L1271-L1276 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ReflectionUtils.java | ReflectionUtils.getAnnotatedFields | public static List<Field> getAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotation,
boolean checkSuperclass) {
Field [] fields = clazz.getDeclaredFields();
List<Field> result = new ArrayList<>();
for (Field field : fields) {
if (field.isAnnotationPresent(annotation)) {
result.add(field);
}
}
if (checkSuperclass && clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object.class)) {
result.addAll(getAnnotatedFields(clazz.getSuperclass(), annotation, true));
}
return result;
} | java | public static List<Field> getAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotation,
boolean checkSuperclass) {
Field [] fields = clazz.getDeclaredFields();
List<Field> result = new ArrayList<>();
for (Field field : fields) {
if (field.isAnnotationPresent(annotation)) {
result.add(field);
}
}
if (checkSuperclass && clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object.class)) {
result.addAll(getAnnotatedFields(clazz.getSuperclass(), annotation, true));
}
return result;
} | [
"public",
"static",
"List",
"<",
"Field",
">",
"getAnnotatedFields",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"annotation",
",",
"boolean",
"checkSuperclass",
")",
"{",
"Field",
"[",
"]",
"fields",
"=",
... | Returns all field from a given class that are annotated with provided annotation type.
@param clazz source class
@param annotation target annotation
@param checkSuperclass if true, method will follow class hierarchy to look for fields with target annotation
@return list of fields or empty collection in case no fields were found | [
"Returns",
"all",
"field",
"from",
"a",
"given",
"class",
"that",
"are",
"annotated",
"with",
"provided",
"annotation",
"type",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ReflectionUtils.java#L30-L47 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ReflectionUtils.java | ReflectionUtils.getTypeName | public static String getTypeName(Class<?> clazz) {
Type typeAnnotation = clazz.getAnnotation(Type.class);
return typeAnnotation != null ? typeAnnotation.value() : null;
} | java | public static String getTypeName(Class<?> clazz) {
Type typeAnnotation = clazz.getAnnotation(Type.class);
return typeAnnotation != null ? typeAnnotation.value() : null;
} | [
"public",
"static",
"String",
"getTypeName",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"Type",
"typeAnnotation",
"=",
"clazz",
".",
"getAnnotation",
"(",
"Type",
".",
"class",
")",
";",
"return",
"typeAnnotation",
"!=",
"null",
"?",
"typeAnnotation",
... | Returns the type name defined using Type annotation on provided class.
@param clazz type class
@return name of the type or <code>null</code> in case Type annotation is not present | [
"Returns",
"the",
"type",
"name",
"defined",
"using",
"Type",
"annotation",
"on",
"provided",
"class",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ReflectionUtils.java#L54-L57 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceCache.java | ResourceCache.init | public void init() {
if (initDepth.get() == null) {
initDepth.set(1);
} else {
initDepth.set(initDepth.get() + 1);
}
if (resourceCache.get() == null) {
resourceCache.set(new HashMap<String, Object>());
}
if (cacheLocked.get() == null) {
cacheLocked.set(Boolean.FALSE);
}
} | java | public void init() {
if (initDepth.get() == null) {
initDepth.set(1);
} else {
initDepth.set(initDepth.get() + 1);
}
if (resourceCache.get() == null) {
resourceCache.set(new HashMap<String, Object>());
}
if (cacheLocked.get() == null) {
cacheLocked.set(Boolean.FALSE);
}
} | [
"public",
"void",
"init",
"(",
")",
"{",
"if",
"(",
"initDepth",
".",
"get",
"(",
")",
"==",
"null",
")",
"{",
"initDepth",
".",
"set",
"(",
"1",
")",
";",
"}",
"else",
"{",
"initDepth",
".",
"set",
"(",
"initDepth",
".",
"get",
"(",
")",
"+",
... | Initialises cache for current thread-scope. | [
"Initialises",
"cache",
"for",
"current",
"thread",
"-",
"scope",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceCache.java#L42-L56 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceCache.java | ResourceCache.clear | public void clear() {
verifyState();
initDepth.set(initDepth.get() - 1);
if (initDepth.get() == 0) {
resourceCache.set(null);
cacheLocked.set(null);
initDepth.set(null);
}
} | java | public void clear() {
verifyState();
initDepth.set(initDepth.get() - 1);
if (initDepth.get() == 0) {
resourceCache.set(null);
cacheLocked.set(null);
initDepth.set(null);
}
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"verifyState",
"(",
")",
";",
"initDepth",
".",
"set",
"(",
"initDepth",
".",
"get",
"(",
")",
"-",
"1",
")",
";",
"if",
"(",
"initDepth",
".",
"get",
"(",
")",
"==",
"0",
")",
"{",
"resourceCache",
".",
... | Clears current thread scope state.
@throws IllegalStateException in case <code>init()</code> was not called | [
"Clears",
"current",
"thread",
"scope",
"state",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceCache.java#L62-L71 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceCache.java | ResourceCache.cache | public void cache(Map<String, Object> resources) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().putAll(resources);
}
} | java | public void cache(Map<String, Object> resources) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().putAll(resources);
}
} | [
"public",
"void",
"cache",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"resources",
")",
"{",
"verifyState",
"(",
")",
";",
"if",
"(",
"!",
"cacheLocked",
".",
"get",
"(",
")",
")",
"{",
"resourceCache",
".",
"get",
"(",
")",
".",
"putAll",
"(",... | Adds multiple resources to cache.
@param resources items to add
@throws IllegalStateException in case <code>init()</code> was not called | [
"Adds",
"multiple",
"resources",
"to",
"cache",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceCache.java#L79-L85 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ResourceCache.java | ResourceCache.cache | public void cache(String identifier, Object resource) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().put(identifier, resource);
}
} | java | public void cache(String identifier, Object resource) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().put(identifier, resource);
}
} | [
"public",
"void",
"cache",
"(",
"String",
"identifier",
",",
"Object",
"resource",
")",
"{",
"verifyState",
"(",
")",
";",
"if",
"(",
"!",
"cacheLocked",
".",
"get",
"(",
")",
")",
"{",
"resourceCache",
".",
"get",
"(",
")",
".",
"put",
"(",
"identif... | Adds resource to cache.
@param identifier resource identifier
@param resource resource
@throws IllegalStateException in case <code>init()</code> was not called | [
"Adds",
"resource",
"to",
"cache",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ResourceCache.java#L93-L99 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ErrorUtils.java | ErrorUtils.parseErrorResponse | public static <T extends Errors> T parseErrorResponse(ObjectMapper mapper, ResponseBody errorResponse, Class<T> cls) throws IOException {
return mapper.readValue(errorResponse.bytes(), cls);
} | java | public static <T extends Errors> T parseErrorResponse(ObjectMapper mapper, ResponseBody errorResponse, Class<T> cls) throws IOException {
return mapper.readValue(errorResponse.bytes(), cls);
} | [
"public",
"static",
"<",
"T",
"extends",
"Errors",
">",
"T",
"parseErrorResponse",
"(",
"ObjectMapper",
"mapper",
",",
"ResponseBody",
"errorResponse",
",",
"Class",
"<",
"T",
">",
"cls",
")",
"throws",
"IOException",
"{",
"return",
"mapper",
".",
"readValue",... | Parses provided ResponseBody and returns it as T.
@param mapper Jackson Object mapper instance
@param errorResponse error response body
@return T collection
@throws IOException | [
"Parses",
"provided",
"ResponseBody",
"and",
"returns",
"it",
"as",
"T",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ErrorUtils.java#L32-L34 | train |
jasminb/jsonapi-converter | src/main/java/com/github/jasminb/jsonapi/ErrorUtils.java | ErrorUtils.parseError | public static <T extends Errors> T parseError(ObjectMapper mapper, JsonNode errorResponse, Class<T> cls) throws JsonProcessingException {
return mapper.treeToValue(errorResponse, cls);
} | java | public static <T extends Errors> T parseError(ObjectMapper mapper, JsonNode errorResponse, Class<T> cls) throws JsonProcessingException {
return mapper.treeToValue(errorResponse, cls);
} | [
"public",
"static",
"<",
"T",
"extends",
"Errors",
">",
"T",
"parseError",
"(",
"ObjectMapper",
"mapper",
",",
"JsonNode",
"errorResponse",
",",
"Class",
"<",
"T",
">",
"cls",
")",
"throws",
"JsonProcessingException",
"{",
"return",
"mapper",
".",
"treeToValue... | Parses provided JsonNode and returns it as T.
@param mapper Jackson Object mapper instance
@param errorResponse error response body
@return T collection
@throws JsonProcessingException thrown in case JsonNode cannot be parsed | [
"Parses",
"provided",
"JsonNode",
"and",
"returns",
"it",
"as",
"T",
"."
] | 73b41c3b9274e70e62b3425071ca8afdc7bddaf6 | https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ErrorUtils.java#L44-L46 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/Either.java | Either.left | public static <L, R> Either<L, R> left(L l) {
return new Left<>(l);
} | java | public static <L, R> Either<L, R> left(L l) {
return new Left<>(l);
} | [
"public",
"static",
"<",
"L",
",",
"R",
">",
"Either",
"<",
"L",
",",
"R",
">",
"left",
"(",
"L",
"l",
")",
"{",
"return",
"new",
"Left",
"<>",
"(",
"l",
")",
";",
"}"
] | Static factory method for creating a left value.
@param l the wrapped value
@param <L> the left parameter type
@param <R> the right parameter type
@return a left value of l | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"left",
"value",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/Either.java#L385-L387 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/Either.java | Either.right | public static <L, R> Either<L, R> right(R r) {
return new Right<>(r);
} | java | public static <L, R> Either<L, R> right(R r) {
return new Right<>(r);
} | [
"public",
"static",
"<",
"L",
",",
"R",
">",
"Either",
"<",
"L",
",",
"R",
">",
"right",
"(",
"R",
"r",
")",
"{",
"return",
"new",
"Right",
"<>",
"(",
"r",
")",
";",
"}"
] | Static factory method for creating a right value.
@param r the wrapped value
@param <L> the left parameter type
@param <R> the right parameter type
@return a right value of r | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"right",
"value",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/Either.java#L397-L399 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/optics/lenses/ListLens.java | ListLens.asCopy | public static <X> Lens.Simple<List<X>, List<X>> asCopy() {
return simpleLens(ArrayList::new, (xs, ys) -> ys);
} | java | public static <X> Lens.Simple<List<X>, List<X>> asCopy() {
return simpleLens(ArrayList::new, (xs, ys) -> ys);
} | [
"public",
"static",
"<",
"X",
">",
"Lens",
".",
"Simple",
"<",
"List",
"<",
"X",
">",
",",
"List",
"<",
"X",
">",
">",
"asCopy",
"(",
")",
"{",
"return",
"simpleLens",
"(",
"ArrayList",
"::",
"new",
",",
"(",
"xs",
",",
"ys",
")",
"->",
"ys",
... | Convenience static factory method for creating a lens over a copy of a list. Useful for composition to avoid
mutating a list reference.
@param <X> the list element type
@return a lens that focuses on copies of lists | [
"Convenience",
"static",
"factory",
"method",
"for",
"creating",
"a",
"lens",
"over",
"a",
"copy",
"of",
"a",
"list",
".",
"Useful",
"for",
"composition",
"to",
"avoid",
"mutating",
"a",
"list",
"reference",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/optics/lenses/ListLens.java#L32-L34 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/Try.java | Try.success | public static <T extends Throwable, A> Try<T, A> success(A a) {
return new Success<>(a);
} | java | public static <T extends Throwable, A> Try<T, A> success(A a) {
return new Success<>(a);
} | [
"public",
"static",
"<",
"T",
"extends",
"Throwable",
",",
"A",
">",
"Try",
"<",
"T",
",",
"A",
">",
"success",
"(",
"A",
"a",
")",
"{",
"return",
"new",
"Success",
"<>",
"(",
"a",
")",
";",
"}"
] | Static factory method for creating a success value.
@param a the wrapped value
@param <T> the failure parameter type
@param <A> the success parameter type
@return a success value of a | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"success",
"value",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/Try.java#L245-L247 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/Try.java | Try.failure | public static <T extends Throwable, A> Try<T, A> failure(T t) {
return new Failure<>(t);
} | java | public static <T extends Throwable, A> Try<T, A> failure(T t) {
return new Failure<>(t);
} | [
"public",
"static",
"<",
"T",
"extends",
"Throwable",
",",
"A",
">",
"Try",
"<",
"T",
",",
"A",
">",
"failure",
"(",
"T",
"t",
")",
"{",
"return",
"new",
"Failure",
"<>",
"(",
"t",
")",
";",
"}"
] | Static factory method for creating a failure value.
@param t the wrapped {@link Throwable}
@param <T> the failure parameter type
@param <A> the success parameter type
@return a failure value of t | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"failure",
"value",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/Try.java#L257-L259 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/functor/builtin/State.java | State.mapState | public <B> State<S, B> mapState(Fn1<? super Tuple2<A, S>, ? extends Product2<B, S>> fn) {
return state(s -> fn.apply(run(s)));
} | java | public <B> State<S, B> mapState(Fn1<? super Tuple2<A, S>, ? extends Product2<B, S>> fn) {
return state(s -> fn.apply(run(s)));
} | [
"public",
"<",
"B",
">",
"State",
"<",
"S",
",",
"B",
">",
"mapState",
"(",
"Fn1",
"<",
"?",
"super",
"Tuple2",
"<",
"A",
",",
"S",
">",
",",
"?",
"extends",
"Product2",
"<",
"B",
",",
"S",
">",
">",
"fn",
")",
"{",
"return",
"state",
"(",
... | Map both the result and the final state to a new result and final state.
@param fn the mapping function
@param <B> the potentially new final state type
@return the mapped {@link State} | [
"Map",
"both",
"the",
"result",
"and",
"the",
"final",
"state",
"to",
"a",
"new",
"result",
"and",
"final",
"state",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/functor/builtin/State.java#L74-L76 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/functor/builtin/State.java | State.withState | public State<S, A> withState(Fn1<? super S, ? extends S> fn) {
return state(s -> run(fn.apply(s)));
} | java | public State<S, A> withState(Fn1<? super S, ? extends S> fn) {
return state(s -> run(fn.apply(s)));
} | [
"public",
"State",
"<",
"S",
",",
"A",
">",
"withState",
"(",
"Fn1",
"<",
"?",
"super",
"S",
",",
"?",
"extends",
"S",
">",
"fn",
")",
"{",
"return",
"state",
"(",
"s",
"->",
"run",
"(",
"fn",
".",
"apply",
"(",
"s",
")",
")",
")",
";",
"}"... | Map the final state to a new final state using the provided function.
@param fn the state-mapping function
@return the mapped {@link State} | [
"Map",
"the",
"final",
"state",
"to",
"a",
"new",
"final",
"state",
"using",
"the",
"provided",
"function",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/functor/builtin/State.java#L84-L86 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.cons | public static <Head, Tail extends HList> HCons<Head, Tail> cons(Head head, Tail tail) {
return new HCons<>(head, tail);
} | java | public static <Head, Tail extends HList> HCons<Head, Tail> cons(Head head, Tail tail) {
return new HCons<>(head, tail);
} | [
"public",
"static",
"<",
"Head",
",",
"Tail",
"extends",
"HList",
">",
"HCons",
"<",
"Head",
",",
"Tail",
">",
"cons",
"(",
"Head",
"head",
",",
"Tail",
"tail",
")",
"{",
"return",
"new",
"HCons",
"<>",
"(",
"head",
",",
"tail",
")",
";",
"}"
] | Static factory method for creating an HList from the given head and tail.
@param head the head element
@param tail the tail HList
@param <Head> the head type
@param <Tail> the tail type
@return the newly created HList | [
"Static",
"factory",
"method",
"for",
"creating",
"an",
"HList",
"from",
"the",
"given",
"head",
"and",
"tail",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L65-L67 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2> Tuple2<_1, _2> tuple(_1 _1, _2 _2) {
return singletonHList(_2).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2> Tuple2<_1, _2> tuple(_1 _1, _2 _2) {
return singletonHList(_2).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
">",
"Tuple2",
"<",
"_1",
",",
"_2",
">",
"tuple",
"(",
"_1",
"_1",
",",
"_2",
"_2",
")",
"{",
"return",
"singletonHList",
"(",
"_2",
")",
".",
"cons",
"(",... | Static factory method for creating a 2-element HList.
@param _1 the head element
@param _2 the second element
@param <_1> the head element type
@param <_2> the second element type
@return the 2-element HList
@see Tuple2 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"2",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L90-L93 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3> Tuple3<_1, _2, _3> tuple(_1 _1, _2 _2, _3 _3) {
return tuple(_2, _3).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3> Tuple3<_1, _2, _3> tuple(_1 _1, _2 _2, _3 _3) {
return tuple(_2, _3).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
">",
"Tuple3",
"<",
"_1",
",",
"_2",
",",
"_3",
">",
"tuple",
"(",
"_1",
"_1",
",",
"_2",
"_2",
",",
"_3",
"_3",
")",
"{",
"return",
"tuple",
... | Static factory method for creating a 3-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@return the 3-element HList
@see Tuple3 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"3",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L107-L110 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4> Tuple4<_1, _2, _3, _4> tuple(_1 _1, _2 _2, _3 _3, _4 _4) {
return tuple(_2, _3, _4).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4> Tuple4<_1, _2, _3, _4> tuple(_1 _1, _2 _2, _3 _3, _4 _4) {
return tuple(_2, _3, _4).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
">",
"Tuple4",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
">",
"tuple",
"(",
"_1",
"_1",
",",
"_2",
"_2",
",",
"_3",
"_3",
",",
... | Static factory method for creating a 4-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param _4 the fourth element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@param <_4> the fourth element type
@return the 4-element HList
@see Tuple4 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"4",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L126-L129 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5> Tuple5<_1, _2, _3, _4, _5> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5) {
return tuple(_2, _3, _4, _5).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5> Tuple5<_1, _2, _3, _4, _5> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5) {
return tuple(_2, _3, _4, _5).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
">",
"Tuple5",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
">",
"tuple",
"(",
"_1",
"_1",
",",
"_2",
"_2",
... | Static factory method for creating a 5-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param _4 the fourth element
@param _5 the fifth element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@param <_4> the fourth element type
@param <_5> the fifth element type
@return the 5-element HList
@see Tuple5 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"5",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L147-L150 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6> Tuple6<_1, _2, _3, _4, _5, _6> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5,
_6 _6) {
return tuple(_2, _3, _4, _5, _6).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6> Tuple6<_1, _2, _3, _4, _5, _6> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5,
_6 _6) {
return tuple(_2, _3, _4, _5, _6).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
">",
"Tuple6",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
">",
"tuple",
"(",
"_1",
... | Static factory method for creating a 6-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param _4 the fourth element
@param _5 the fifth element
@param _6 the sixth element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@param <_4> the fourth element type
@param <_5> the fifth element type
@param <_6> the sixth element type
@return the 6-element HList
@see Tuple6 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"6",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L170-L174 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7> Tuple7<_1, _2, _3, _4, _5, _6, _7> tuple(_1 _1, _2 _2, _3 _3, _4 _4,
_5 _5, _6 _6, _7 _7) {
return tuple(_2, _3, _4, _5, _6, _7).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7> Tuple7<_1, _2, _3, _4, _5, _6, _7> tuple(_1 _1, _2 _2, _3 _3, _4 _4,
_5 _5, _6 _6, _7 _7) {
return tuple(_2, _3, _4, _5, _6, _7).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
",",
"_7",
">",
"Tuple7",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
",",
"_7",
">"... | Static factory method for creating a 7-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param _4 the fourth element
@param _5 the fifth element
@param _6 the sixth element
@param _7 the seventh element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@param <_4> the fourth element type
@param <_5> the fifth element type
@param <_6> the sixth element type
@param <_7> the seventh element type
@return the 7-element HList
@see Tuple7 | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"7",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L196-L200 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java | HList.tuple | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7, _8> Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> tuple(_1 _1, _2 _2, _3 _3,
_4 _4, _5 _5, _6 _6,
_7 _7, _8 _8) {
return tuple(_2, _3, _4, _5, _6, _7, _8).cons(_1);
} | java | @SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7, _8> Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> tuple(_1 _1, _2 _2, _3 _3,
_4 _4, _5 _5, _6 _6,
_7 _7, _8 _8) {
return tuple(_2, _3, _4, _5, _6, _7, _8).cons(_1);
} | [
"@",
"SuppressWarnings",
"(",
"\"JavaDoc\"",
")",
"public",
"static",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
",",
"_7",
",",
"_8",
">",
"Tuple8",
"<",
"_1",
",",
"_2",
",",
"_3",
",",
"_4",
",",
"_5",
",",
"_6",
","... | Static factory method for creating an 8-element HList.
@param _1 the head element
@param _2 the second element
@param _3 the third element
@param _4 the fourth element
@param _5 the fifth element
@param _6 the sixth element
@param _7 the seventh element
@param _8 the eighth element
@param <_1> the head element type
@param <_2> the second element type
@param <_3> the third element type
@param <_4> the fourth element type
@param <_5> the fifth element type
@param <_6> the sixth element type
@param <_7> the seventh element type
@param <_8> the eighth element type
@return the 8-element HList
@see Tuple8 | [
"Static",
"factory",
"method",
"for",
"creating",
"an",
"8",
"-",
"element",
"HList",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java#L224-L229 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java | Lazy.lazy | public static <A> Lazy<A> lazy(Supplier<A> supplier) {
return new Later<>(fn0(supplier));
} | java | public static <A> Lazy<A> lazy(Supplier<A> supplier) {
return new Later<>(fn0(supplier));
} | [
"public",
"static",
"<",
"A",
">",
"Lazy",
"<",
"A",
">",
"lazy",
"(",
"Supplier",
"<",
"A",
">",
"supplier",
")",
"{",
"return",
"new",
"Later",
"<>",
"(",
"fn0",
"(",
"supplier",
")",
")",
";",
"}"
] | Wrap a computation in a lazy computation.
@param supplier the computation
@param <A> the value type
@return the new {@link Lazy} | [
"Wrap",
"a",
"computation",
"in",
"a",
"lazy",
"computation",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java#L105-L107 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/optics/lenses/MapLens.java | MapLens.asCopy | public static <K, V> Lens.Simple<Map<K, V>, Map<K, V>> asCopy() {
return adapt(asCopy(HashMap::new));
} | java | public static <K, V> Lens.Simple<Map<K, V>, Map<K, V>> asCopy() {
return adapt(asCopy(HashMap::new));
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"Lens",
".",
"Simple",
"<",
"Map",
"<",
"K",
",",
"V",
">",
",",
"Map",
"<",
"K",
",",
"V",
">",
">",
"asCopy",
"(",
")",
"{",
"return",
"adapt",
"(",
"asCopy",
"(",
"HashMap",
"::",
"new",
")",
... | A lens that focuses on a copy of a Map. Useful for composition to avoid mutating a map reference.
@param <K> the key type
@param <V> the value type
@return a lens that focuses on copies of maps | [
"A",
"lens",
"that",
"focuses",
"on",
"a",
"copy",
"of",
"a",
"Map",
".",
"Useful",
"for",
"composition",
"to",
"avoid",
"mutating",
"a",
"map",
"reference",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/optics/lenses/MapLens.java#L61-L63 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/optics/lenses/MapLens.java | MapLens.keys | public static <K, V> Lens.Simple<Map<K, V>, Set<K>> keys() {
return simpleLens(m -> new HashSet<>(m.keySet()), (m, ks) -> {
HashSet<K> ksCopy = new HashSet<>(ks);
Map<K, V> updated = new HashMap<>(m);
Set<K> keys = updated.keySet();
keys.retainAll(ksCopy);
ksCopy.removeAll(keys);
ksCopy.forEach(k -> updated.put(k, null));
return updated;
});
} | java | public static <K, V> Lens.Simple<Map<K, V>, Set<K>> keys() {
return simpleLens(m -> new HashSet<>(m.keySet()), (m, ks) -> {
HashSet<K> ksCopy = new HashSet<>(ks);
Map<K, V> updated = new HashMap<>(m);
Set<K> keys = updated.keySet();
keys.retainAll(ksCopy);
ksCopy.removeAll(keys);
ksCopy.forEach(k -> updated.put(k, null));
return updated;
});
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"Lens",
".",
"Simple",
"<",
"Map",
"<",
"K",
",",
"V",
">",
",",
"Set",
"<",
"K",
">",
">",
"keys",
"(",
")",
"{",
"return",
"simpleLens",
"(",
"m",
"->",
"new",
"HashSet",
"<>",
"(",
"m",
".",
"... | A lens that focuses on the keys of a map.
@param <K> the key type
@param <V> the value type
@return a lens that focuses on the keys of a map | [
"A",
"lens",
"that",
"focuses",
"on",
"the",
"keys",
"of",
"a",
"map",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/optics/lenses/MapLens.java#L120-L130 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java | HMap.get | @SuppressWarnings("unchecked")
public <A, B> Maybe<B> get(TypeSafeKey<A, B> key) {
return maybe((A) table.get(key)).fmap(view(key));
} | java | @SuppressWarnings("unchecked")
public <A, B> Maybe<B> get(TypeSafeKey<A, B> key) {
return maybe((A) table.get(key)).fmap(view(key));
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"A",
",",
"B",
">",
"Maybe",
"<",
"B",
">",
"get",
"(",
"TypeSafeKey",
"<",
"A",
",",
"B",
">",
"key",
")",
"{",
"return",
"maybe",
"(",
"(",
"A",
")",
"table",
".",
"get",
"(",
... | Retrieve the value at this key.
@param key the key
@param <A> the value type
@param <B> the value type
@return Maybe the value at this key | [
"Retrieve",
"the",
"value",
"at",
"this",
"key",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java#L48-L51 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java | HMap.put | public <V> HMap put(TypeSafeKey<?, V> key, V value) {
return alter(t -> t.put(key, view(key.mirror(), value)));
} | java | public <V> HMap put(TypeSafeKey<?, V> key, V value) {
return alter(t -> t.put(key, view(key.mirror(), value)));
} | [
"public",
"<",
"V",
">",
"HMap",
"put",
"(",
"TypeSafeKey",
"<",
"?",
",",
"V",
">",
"key",
",",
"V",
"value",
")",
"{",
"return",
"alter",
"(",
"t",
"->",
"t",
".",
"put",
"(",
"key",
",",
"view",
"(",
"key",
".",
"mirror",
"(",
")",
",",
... | Store a value for the given key.
@param key the key
@param value the value
@param <V> the value type
@return the updated HMap | [
"Store",
"a",
"value",
"for",
"the",
"given",
"key",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java#L73-L75 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java | HMap.singletonHMap | public static <V> HMap singletonHMap(TypeSafeKey<?, V> key, V value) {
return emptyHMap().put(key, value);
} | java | public static <V> HMap singletonHMap(TypeSafeKey<?, V> key, V value) {
return emptyHMap().put(key, value);
} | [
"public",
"static",
"<",
"V",
">",
"HMap",
"singletonHMap",
"(",
"TypeSafeKey",
"<",
"?",
",",
"V",
">",
"key",
",",
"V",
"value",
")",
"{",
"return",
"emptyHMap",
"(",
")",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"}"
] | Static factory method for creating a singleton HMap.
@param key the only mapped key
@param value the only mapped value
@param <V> the only mapped value type
@return a singleton HMap | [
"Static",
"factory",
"method",
"for",
"creating",
"a",
"singleton",
"HMap",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java#L197-L199 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java | HMap.hMap | public static <V1, V2> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2) {
return singletonHMap(key1, value1).put(key2, value2);
} | java | public static <V1, V2> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2) {
return singletonHMap(key1, value1).put(key2, value2);
} | [
"public",
"static",
"<",
"V1",
",",
"V2",
">",
"HMap",
"hMap",
"(",
"TypeSafeKey",
"<",
"?",
",",
"V1",
">",
"key1",
",",
"V1",
"value1",
",",
"TypeSafeKey",
"<",
"?",
",",
"V2",
">",
"key2",
",",
"V2",
"value2",
")",
"{",
"return",
"singletonHMap"... | Static factory method for creating an HMap from two given associations.
@param key1 the first mapped key
@param value1 the value mapped at key1
@param key2 the second mapped key
@param value2 the value mapped at key2
@param <V1> value1's type
@param <V2> value2's type
@return an HMap with the given associations | [
"Static",
"factory",
"method",
"for",
"creating",
"an",
"HMap",
"from",
"two",
"given",
"associations",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java#L212-L215 | train |
palatable/lambda | src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java | HMap.hMap | public static <V1, V2, V3> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2,
TypeSafeKey<?, V3> key3, V3 value3) {
return hMap(key1, value1,
key2, value2)
.put(key3, value3);
} | java | public static <V1, V2, V3> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2,
TypeSafeKey<?, V3> key3, V3 value3) {
return hMap(key1, value1,
key2, value2)
.put(key3, value3);
} | [
"public",
"static",
"<",
"V1",
",",
"V2",
",",
"V3",
">",
"HMap",
"hMap",
"(",
"TypeSafeKey",
"<",
"?",
",",
"V1",
">",
"key1",
",",
"V1",
"value1",
",",
"TypeSafeKey",
"<",
"?",
",",
"V2",
">",
"key2",
",",
"V2",
"value2",
",",
"TypeSafeKey",
"<... | Static factory method for creating an HMap from three given associations.
@param key1 the first mapped key
@param value1 the value mapped at key1
@param key2 the second mapped key
@param value2 the value mapped at key2
@param key3 the third mapped key
@param value3 the value mapped at key3
@param <V1> value1's type
@param <V2> value2's type
@param <V3> value3's type
@return an HMap with the given associations | [
"Static",
"factory",
"method",
"for",
"creating",
"an",
"HMap",
"from",
"three",
"given",
"associations",
"."
] | b643ba836c5916d1d8193822e5efb4e7b40c489a | https://github.com/palatable/lambda/blob/b643ba836c5916d1d8193822e5efb4e7b40c489a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java#L231-L237 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/command/TextCommandFactory.java | TextCommandFactory.createVerbosityCommand | public final Command createVerbosityCommand(CountDownLatch latch, int level, boolean noreply) {
return new TextVerbosityCommand(latch, level, noreply);
} | java | public final Command createVerbosityCommand(CountDownLatch latch, int level, boolean noreply) {
return new TextVerbosityCommand(latch, level, noreply);
} | [
"public",
"final",
"Command",
"createVerbosityCommand",
"(",
"CountDownLatch",
"latch",
",",
"int",
"level",
",",
"boolean",
"noreply",
")",
"{",
"return",
"new",
"TextVerbosityCommand",
"(",
"latch",
",",
"level",
",",
"noreply",
")",
";",
"}"
] | Create verbosity command
@param latch
@param level
@param noreply
@return | [
"Create",
"verbosity",
"command"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/command/TextCommandFactory.java#L79-L81 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioTCPSession.java | NioTCPSession.blockingRead | protected final int blockingRead() throws ClosedChannelException, IOException {
int n = 0;
int readCount = 0;
Selector readSelector = SelectorFactory.getSelector();
SelectionKey tmpKey = null;
try {
if (this.selectableChannel.isOpen()) {
tmpKey = this.selectableChannel.register(readSelector, 0);
tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
int code = readSelector.select(500);
tmpKey.interestOps(tmpKey.interestOps() & ~SelectionKey.OP_READ);
if (code > 0) {
do {
n = ((ReadableByteChannel) this.selectableChannel).read(this.readBuffer.buf());
readCount += n;
if (log.isDebugEnabled()) {
log.debug("use temp selector read " + n + " bytes");
}
} while (n > 0 && this.readBuffer.hasRemaining());
if (readCount > 0) {
decodeAndDispatch();
}
}
}
} finally {
if (tmpKey != null) {
tmpKey.cancel();
tmpKey = null;
}
if (readSelector != null) {
// Cancel the key.
readSelector.selectNow();
SelectorFactory.returnSelector(readSelector);
}
}
return readCount;
} | java | protected final int blockingRead() throws ClosedChannelException, IOException {
int n = 0;
int readCount = 0;
Selector readSelector = SelectorFactory.getSelector();
SelectionKey tmpKey = null;
try {
if (this.selectableChannel.isOpen()) {
tmpKey = this.selectableChannel.register(readSelector, 0);
tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
int code = readSelector.select(500);
tmpKey.interestOps(tmpKey.interestOps() & ~SelectionKey.OP_READ);
if (code > 0) {
do {
n = ((ReadableByteChannel) this.selectableChannel).read(this.readBuffer.buf());
readCount += n;
if (log.isDebugEnabled()) {
log.debug("use temp selector read " + n + " bytes");
}
} while (n > 0 && this.readBuffer.hasRemaining());
if (readCount > 0) {
decodeAndDispatch();
}
}
}
} finally {
if (tmpKey != null) {
tmpKey.cancel();
tmpKey = null;
}
if (readSelector != null) {
// Cancel the key.
readSelector.selectNow();
SelectorFactory.returnSelector(readSelector);
}
}
return readCount;
} | [
"protected",
"final",
"int",
"blockingRead",
"(",
")",
"throws",
"ClosedChannelException",
",",
"IOException",
"{",
"int",
"n",
"=",
"0",
";",
"int",
"readCount",
"=",
"0",
";",
"Selector",
"readSelector",
"=",
"SelectorFactory",
".",
"getSelector",
"(",
")",
... | Blocking read using temp selector
@return
@throws ClosedChannelException
@throws IOException | [
"Blocking",
"read",
"using",
"temp",
"selector"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioTCPSession.java#L234-L270 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/transcoders/BaseSerializingTranscoder.java | BaseSerializingTranscoder.encodeString | protected byte[] encodeString(String in) {
byte[] rv = null;
try {
rv = in.getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return rv;
} | java | protected byte[] encodeString(String in) {
byte[] rv = null;
try {
rv = in.getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return rv;
} | [
"protected",
"byte",
"[",
"]",
"encodeString",
"(",
"String",
"in",
")",
"{",
"byte",
"[",
"]",
"rv",
"=",
"null",
";",
"try",
"{",
"rv",
"=",
"in",
".",
"getBytes",
"(",
"this",
".",
"charset",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingExcept... | Encode a string into the current character set. | [
"Encode",
"a",
"string",
"into",
"the",
"current",
"character",
"set",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/transcoders/BaseSerializingTranscoder.java#L318-L326 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/impl/Optimizer.java | Optimizer.optimiezeMergeBuffer | @SuppressWarnings("unchecked")
public final Command optimiezeMergeBuffer(Command optimiezeCommand, final Queue writeQueue,
final Queue<Command> executingCmds, int sendBufferSize) {
if (log.isDebugEnabled()) {
log.debug("Optimieze merge buffer:" + optimiezeCommand.toString());
}
if (this.optimiezeMergeBuffer
&& optimiezeCommand.getIoBuffer().remaining() < sendBufferSize - 24) {
optimiezeCommand =
this.mergeBuffer(optimiezeCommand, writeQueue, executingCmds, sendBufferSize);
}
return optimiezeCommand;
} | java | @SuppressWarnings("unchecked")
public final Command optimiezeMergeBuffer(Command optimiezeCommand, final Queue writeQueue,
final Queue<Command> executingCmds, int sendBufferSize) {
if (log.isDebugEnabled()) {
log.debug("Optimieze merge buffer:" + optimiezeCommand.toString());
}
if (this.optimiezeMergeBuffer
&& optimiezeCommand.getIoBuffer().remaining() < sendBufferSize - 24) {
optimiezeCommand =
this.mergeBuffer(optimiezeCommand, writeQueue, executingCmds, sendBufferSize);
}
return optimiezeCommand;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"final",
"Command",
"optimiezeMergeBuffer",
"(",
"Command",
"optimiezeCommand",
",",
"final",
"Queue",
"writeQueue",
",",
"final",
"Queue",
"<",
"Command",
">",
"executingCmds",
",",
"int",
"sendBufferSiz... | merge buffers to fit socket's send buffer size
@param currentCommand
@return
@throws InterruptedException | [
"merge",
"buffers",
"to",
"fit",
"socket",
"s",
"send",
"buffer",
"size"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/impl/Optimizer.java#L126-L138 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/impl/Optimizer.java | Optimizer.optimiezeGet | @SuppressWarnings("unchecked")
public final Command optimiezeGet(final Queue writeQueue, final Queue<Command> executingCmds,
Command optimiezeCommand) {
if (optimiezeCommand.getCommandType() == CommandType.GET_ONE
|| optimiezeCommand.getCommandType() == CommandType.GETS_ONE) {
if (this.optimiezeGet) {
optimiezeCommand = this.mergeGetCommands(optimiezeCommand, writeQueue, executingCmds,
optimiezeCommand.getCommandType());
}
}
return optimiezeCommand;
} | java | @SuppressWarnings("unchecked")
public final Command optimiezeGet(final Queue writeQueue, final Queue<Command> executingCmds,
Command optimiezeCommand) {
if (optimiezeCommand.getCommandType() == CommandType.GET_ONE
|| optimiezeCommand.getCommandType() == CommandType.GETS_ONE) {
if (this.optimiezeGet) {
optimiezeCommand = this.mergeGetCommands(optimiezeCommand, writeQueue, executingCmds,
optimiezeCommand.getCommandType());
}
}
return optimiezeCommand;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"final",
"Command",
"optimiezeGet",
"(",
"final",
"Queue",
"writeQueue",
",",
"final",
"Queue",
"<",
"Command",
">",
"executingCmds",
",",
"Command",
"optimiezeCommand",
")",
"{",
"if",
"(",
"optimiez... | Merge get operation to multi-get operation
@param currentCmd
@param mergeCommands
@return
@throws InterruptedException | [
"Merge",
"get",
"operation",
"to",
"multi",
"-",
"get",
"operation"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/impl/Optimizer.java#L148-L159 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/auth/AuthInfo.java | AuthInfo.plain | public static AuthInfo plain(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"PLAIN"});
} | java | public static AuthInfo plain(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"PLAIN"});
} | [
"public",
"static",
"AuthInfo",
"plain",
"(",
"String",
"username",
",",
"String",
"password",
")",
"{",
"return",
"new",
"AuthInfo",
"(",
"new",
"PlainCallbackHandler",
"(",
"username",
",",
"password",
")",
",",
"new",
"String",
"[",
"]",
"{",
"\"PLAIN\"",... | Get a typical auth descriptor for PLAIN auth with the given username and password.
@param u the username
@param p the password
@return an AuthInfo | [
"Get",
"a",
"typical",
"auth",
"descriptor",
"for",
"PLAIN",
"auth",
"with",
"the",
"given",
"username",
"and",
"password",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/auth/AuthInfo.java#L48-L50 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/auth/AuthInfo.java | AuthInfo.cramMD5 | public static AuthInfo cramMD5(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"CRAM-MD5"});
} | java | public static AuthInfo cramMD5(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"CRAM-MD5"});
} | [
"public",
"static",
"AuthInfo",
"cramMD5",
"(",
"String",
"username",
",",
"String",
"password",
")",
"{",
"return",
"new",
"AuthInfo",
"(",
"new",
"PlainCallbackHandler",
"(",
"username",
",",
"password",
")",
",",
"new",
"String",
"[",
"]",
"{",
"\"CRAM-MD... | Get a typical auth descriptor for CRAM-MD5 auth with the given username and password.
@param u the username
@param p the password
@return an AuthInfo | [
"Get",
"a",
"typical",
"auth",
"descriptor",
"for",
"CRAM",
"-",
"MD5",
"auth",
"with",
"the",
"given",
"username",
"and",
"password",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/auth/AuthInfo.java#L60-L62 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/aws/AWSElasticCacheClientBuilder.java | AWSElasticCacheClientBuilder.build | @Override
public AWSElasticCacheClient build() throws IOException {
AWSElasticCacheClient memcachedClient =
new AWSElasticCacheClient(this.sessionLocator, this.sessionComparator, this.bufferAllocator,
this.configuration, this.socketOptions, this.commandFactory, this.transcoder,
this.stateListeners, this.authInfoMap, this.connectionPoolSize, this.connectTimeout,
this.name, this.failureMode, configAddrs, this.pollConfigIntervalMs);
this.configureClient(memcachedClient);
return memcachedClient;
} | java | @Override
public AWSElasticCacheClient build() throws IOException {
AWSElasticCacheClient memcachedClient =
new AWSElasticCacheClient(this.sessionLocator, this.sessionComparator, this.bufferAllocator,
this.configuration, this.socketOptions, this.commandFactory, this.transcoder,
this.stateListeners, this.authInfoMap, this.connectionPoolSize, this.connectTimeout,
this.name, this.failureMode, configAddrs, this.pollConfigIntervalMs);
this.configureClient(memcachedClient);
return memcachedClient;
} | [
"@",
"Override",
"public",
"AWSElasticCacheClient",
"build",
"(",
")",
"throws",
"IOException",
"{",
"AWSElasticCacheClient",
"memcachedClient",
"=",
"new",
"AWSElasticCacheClient",
"(",
"this",
".",
"sessionLocator",
",",
"this",
".",
"sessionComparator",
",",
"this"... | Returns a new instanceof AWSElasticCacheClient. | [
"Returns",
"a",
"new",
"instanceof",
"AWSElasticCacheClient",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/aws/AWSElasticCacheClientBuilder.java#L96-L107 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/ResourcesUtils.java | ResourcesUtils.getResourceURL | public static URL getResourceURL(String resource) throws IOException {
URL url = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
url = loader.getResource(resource);
}
if (url == null) {
url = ClassLoader.getSystemResource(resource);
}
if (url == null) {
throw new IOException("Could not find resource " + resource);
}
return url;
} | java | public static URL getResourceURL(String resource) throws IOException {
URL url = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
url = loader.getResource(resource);
}
if (url == null) {
url = ClassLoader.getSystemResource(resource);
}
if (url == null) {
throw new IOException("Could not find resource " + resource);
}
return url;
} | [
"public",
"static",
"URL",
"getResourceURL",
"(",
"String",
"resource",
")",
"throws",
"IOException",
"{",
"URL",
"url",
"=",
"null",
";",
"ClassLoader",
"loader",
"=",
"ResourcesUtils",
".",
"class",
".",
"getClassLoader",
"(",
")",
";",
"if",
"(",
"loader"... | Returns the URL of the resource on the classpath
@param resource The resource to find
@throws IOException If the resource cannot be found or read
@return The resource | [
"Returns",
"the",
"URL",
"of",
"the",
"resource",
"on",
"the",
"classpath"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/ResourcesUtils.java#L35-L48 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/ResourcesUtils.java | ResourcesUtils.getResourceAsStream | public static InputStream getResourceAsStream(String resource) throws IOException {
InputStream in = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
in = loader.getResourceAsStream(resource);
}
if (in == null) {
in = ClassLoader.getSystemResourceAsStream(resource);
}
if (in == null) {
throw new IOException("Could not find resource " + resource);
}
return in;
} | java | public static InputStream getResourceAsStream(String resource) throws IOException {
InputStream in = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
in = loader.getResourceAsStream(resource);
}
if (in == null) {
in = ClassLoader.getSystemResourceAsStream(resource);
}
if (in == null) {
throw new IOException("Could not find resource " + resource);
}
return in;
} | [
"public",
"static",
"InputStream",
"getResourceAsStream",
"(",
"String",
"resource",
")",
"throws",
"IOException",
"{",
"InputStream",
"in",
"=",
"null",
";",
"ClassLoader",
"loader",
"=",
"ResourcesUtils",
".",
"class",
".",
"getClassLoader",
"(",
")",
";",
"if... | Returns a resource on the classpath as a Stream object
@param resource The resource to find
@throws IOException If the resource cannot be found or read
@return The resource | [
"Returns",
"a",
"resource",
"on",
"the",
"classpath",
"as",
"a",
"Stream",
"object"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/ResourcesUtils.java#L81-L94 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioController.java | NioController.initialSelectorManager | protected void initialSelectorManager() throws IOException {
if (this.selectorManager == null) {
this.selectorManager = new SelectorManager(this.selectorPoolSize, this, this.configuration);
this.selectorManager.start();
}
} | java | protected void initialSelectorManager() throws IOException {
if (this.selectorManager == null) {
this.selectorManager = new SelectorManager(this.selectorPoolSize, this, this.configuration);
this.selectorManager.start();
}
} | [
"protected",
"void",
"initialSelectorManager",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"this",
".",
"selectorManager",
"==",
"null",
")",
"{",
"this",
".",
"selectorManager",
"=",
"new",
"SelectorManager",
"(",
"this",
".",
"selectorPoolSize",
",",
... | Start selector manager
@throws IOException | [
"Start",
"selector",
"manager"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioController.java#L131-L136 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioController.java | NioController.onRead | public void onRead(SelectionKey key) {
if (this.readEventDispatcher == null) {
dispatchReadEvent(key);
} else {
this.readEventDispatcher.dispatch(new ReadTask(key));
}
} | java | public void onRead(SelectionKey key) {
if (this.readEventDispatcher == null) {
dispatchReadEvent(key);
} else {
this.readEventDispatcher.dispatch(new ReadTask(key));
}
} | [
"public",
"void",
"onRead",
"(",
"SelectionKey",
"key",
")",
"{",
"if",
"(",
"this",
".",
"readEventDispatcher",
"==",
"null",
")",
"{",
"dispatchReadEvent",
"(",
"key",
")",
";",
"}",
"else",
"{",
"this",
".",
"readEventDispatcher",
".",
"dispatch",
"(",
... | Read event occured | [
"Read",
"event",
"occured"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioController.java#L148-L154 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioController.java | NioController.onWrite | public void onWrite(final SelectionKey key) {
if (this.writeEventDispatcher == null) {
dispatchWriteEvent(key);
} else {
this.writeEventDispatcher.dispatch(new WriteTask(key));
}
} | java | public void onWrite(final SelectionKey key) {
if (this.writeEventDispatcher == null) {
dispatchWriteEvent(key);
} else {
this.writeEventDispatcher.dispatch(new WriteTask(key));
}
} | [
"public",
"void",
"onWrite",
"(",
"final",
"SelectionKey",
"key",
")",
"{",
"if",
"(",
"this",
".",
"writeEventDispatcher",
"==",
"null",
")",
"{",
"dispatchWriteEvent",
"(",
"key",
")",
";",
"}",
"else",
"{",
"this",
".",
"writeEventDispatcher",
".",
"dis... | Writable event occured | [
"Writable",
"event",
"occured"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioController.java#L159-L165 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioController.java | NioController.closeSelectionKey | public void closeSelectionKey(SelectionKey key) {
if (key.attachment() instanceof Session) {
Session session = (Session) key.attachment();
if (session != null) {
session.close();
}
}
} | java | public void closeSelectionKey(SelectionKey key) {
if (key.attachment() instanceof Session) {
Session session = (Session) key.attachment();
if (session != null) {
session.close();
}
}
} | [
"public",
"void",
"closeSelectionKey",
"(",
"SelectionKey",
"key",
")",
"{",
"if",
"(",
"key",
".",
"attachment",
"(",
")",
"instanceof",
"Session",
")",
"{",
"Session",
"session",
"=",
"(",
"Session",
")",
"key",
".",
"attachment",
"(",
")",
";",
"if",
... | Cancel selection key | [
"Cancel",
"selection",
"key"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioController.java#L170-L177 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/NioController.java | NioController.buildSessionConfig | protected final NioSessionConfig buildSessionConfig(SelectableChannel sc,
Queue<WriteMessage> queue) {
final NioSessionConfig sessionConfig =
new NioSessionConfig(sc, getHandler(), this.selectorManager, getCodecFactory(),
getStatistics(), queue, this.dispatchMessageDispatcher, isHandleReadWriteConcurrently(),
this.sessionTimeout, this.configuration.getSessionIdleTimeout());
return sessionConfig;
} | java | protected final NioSessionConfig buildSessionConfig(SelectableChannel sc,
Queue<WriteMessage> queue) {
final NioSessionConfig sessionConfig =
new NioSessionConfig(sc, getHandler(), this.selectorManager, getCodecFactory(),
getStatistics(), queue, this.dispatchMessageDispatcher, isHandleReadWriteConcurrently(),
this.sessionTimeout, this.configuration.getSessionIdleTimeout());
return sessionConfig;
} | [
"protected",
"final",
"NioSessionConfig",
"buildSessionConfig",
"(",
"SelectableChannel",
"sc",
",",
"Queue",
"<",
"WriteMessage",
">",
"queue",
")",
"{",
"final",
"NioSessionConfig",
"sessionConfig",
"=",
"new",
"NioSessionConfig",
"(",
"sc",
",",
"getHandler",
"("... | Build nio session config
@param sc
@param queue
@return | [
"Build",
"nio",
"session",
"config"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/NioController.java#L217-L224 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/command/binary/BinaryGetMultiCommand.java | BinaryGetMultiCommand.readHeader | protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus != ResponseStatus.NO_ERROR) {
if (ByteUtils.stepBuffer(buffer, this.responseTotalBodyLength)) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
}
} | java | protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus != ResponseStatus.NO_ERROR) {
if (ByteUtils.stepBuffer(buffer, this.responseTotalBodyLength)) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
}
} | [
"protected",
"void",
"readHeader",
"(",
"ByteBuffer",
"buffer",
")",
"{",
"super",
".",
"readHeader",
"(",
"buffer",
")",
";",
"if",
"(",
"this",
".",
"responseStatus",
"!=",
"ResponseStatus",
".",
"NO_ERROR",
")",
"{",
"if",
"(",
"ByteUtils",
".",
"stepBu... | optimistic,if response status is greater than zero,then skip buffer to next response,set result
as null | [
"optimistic",
"if",
"response",
"status",
"is",
"greater",
"than",
"zero",
"then",
"skip",
"buffer",
"to",
"next",
"response",
"set",
"result",
"as",
"null"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/command/binary/BinaryGetMultiCommand.java#L69-L76 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/aws/AWSElasticCacheClient.java | AWSElasticCacheClient.getConfig | public ClusterConfigration getConfig(String key)
throws MemcachedException, InterruptedException, TimeoutException {
Command cmd = this.commandFactory.createAWSElasticCacheConfigCommand("get", key);
final Session session = this.sendCommand(cmd);
this.latchWait(cmd, opTimeout, session);
cmd.getIoBuffer().free();
this.checkException(cmd);
String result = (String) cmd.getResult();
if (result == null) {
throw new MemcachedException("Operation fail,may be caused by networking or timeout");
}
return AWSUtils.parseConfiguration(result);
} | java | public ClusterConfigration getConfig(String key)
throws MemcachedException, InterruptedException, TimeoutException {
Command cmd = this.commandFactory.createAWSElasticCacheConfigCommand("get", key);
final Session session = this.sendCommand(cmd);
this.latchWait(cmd, opTimeout, session);
cmd.getIoBuffer().free();
this.checkException(cmd);
String result = (String) cmd.getResult();
if (result == null) {
throw new MemcachedException("Operation fail,may be caused by networking or timeout");
}
return AWSUtils.parseConfiguration(result);
} | [
"public",
"ClusterConfigration",
"getConfig",
"(",
"String",
"key",
")",
"throws",
"MemcachedException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"Command",
"cmd",
"=",
"this",
".",
"commandFactory",
".",
"createAWSElasticCacheConfigCommand",
"(",
"\"g... | Get config by key from cache node by network command.
@since 2.3.0
@return clusetr config. | [
"Get",
"config",
"by",
"key",
"from",
"cache",
"node",
"by",
"network",
"command",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/aws/AWSElasticCacheClient.java#L253-L265 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/utils/ByteUtils.java | ByteUtils.nextLine | public static final String nextLine(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
int index = MemcachedDecoder.SPLIT_MATCHER
.matchFirst(com.google.code.yanf4j.buffer.IoBuffer.wrap(buffer));
if (index >= 0) {
int limit = buffer.limit();
buffer.limit(index);
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
buffer.limit(limit);
buffer.position(index + ByteUtils.SPLIT.remaining());
return getString(bytes);
}
return null;
} | java | public static final String nextLine(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
int index = MemcachedDecoder.SPLIT_MATCHER
.matchFirst(com.google.code.yanf4j.buffer.IoBuffer.wrap(buffer));
if (index >= 0) {
int limit = buffer.limit();
buffer.limit(index);
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
buffer.limit(limit);
buffer.position(index + ByteUtils.SPLIT.remaining());
return getString(bytes);
}
return null;
} | [
"public",
"static",
"final",
"String",
"nextLine",
"(",
"ByteBuffer",
"buffer",
")",
"{",
"if",
"(",
"buffer",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"int",
"index",
"=",
"MemcachedDecoder",
".",
"SPLIT_MATCHER",
".",
"matchFirst",
"(",
"com",... | Read next line from ByteBuffer
@param buffer
@return | [
"Read",
"next",
"line",
"from",
"ByteBuffer"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/utils/ByteUtils.java#L257-L275 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/SocketChannelController.java | SocketChannelController.configureSocketChannel | protected final void configureSocketChannel(SocketChannel sc) throws IOException {
sc.socket().setSoTimeout(this.soTimeout);
sc.configureBlocking(false);
if (this.socketOptions.get(StandardSocketOption.SO_REUSEADDR) != null) {
sc.socket().setReuseAddress(StandardSocketOption.SO_REUSEADDR.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_REUSEADDR)));
}
if (this.socketOptions.get(StandardSocketOption.SO_SNDBUF) != null) {
sc.socket().setSendBufferSize(StandardSocketOption.SO_SNDBUF.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_SNDBUF)));
}
if (this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE) != null) {
sc.socket().setKeepAlive(StandardSocketOption.SO_KEEPALIVE.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE)));
}
if (this.socketOptions.get(StandardSocketOption.SO_LINGER) != null) {
sc.socket().setSoLinger(this.soLingerOn, StandardSocketOption.SO_LINGER.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_LINGER)));
}
if (this.socketOptions.get(StandardSocketOption.SO_RCVBUF) != null) {
sc.socket().setReceiveBufferSize(StandardSocketOption.SO_RCVBUF.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_RCVBUF)));
}
if (this.socketOptions.get(StandardSocketOption.TCP_NODELAY) != null) {
sc.socket().setTcpNoDelay(StandardSocketOption.TCP_NODELAY.type()
.cast(this.socketOptions.get(StandardSocketOption.TCP_NODELAY)));
}
} | java | protected final void configureSocketChannel(SocketChannel sc) throws IOException {
sc.socket().setSoTimeout(this.soTimeout);
sc.configureBlocking(false);
if (this.socketOptions.get(StandardSocketOption.SO_REUSEADDR) != null) {
sc.socket().setReuseAddress(StandardSocketOption.SO_REUSEADDR.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_REUSEADDR)));
}
if (this.socketOptions.get(StandardSocketOption.SO_SNDBUF) != null) {
sc.socket().setSendBufferSize(StandardSocketOption.SO_SNDBUF.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_SNDBUF)));
}
if (this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE) != null) {
sc.socket().setKeepAlive(StandardSocketOption.SO_KEEPALIVE.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE)));
}
if (this.socketOptions.get(StandardSocketOption.SO_LINGER) != null) {
sc.socket().setSoLinger(this.soLingerOn, StandardSocketOption.SO_LINGER.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_LINGER)));
}
if (this.socketOptions.get(StandardSocketOption.SO_RCVBUF) != null) {
sc.socket().setReceiveBufferSize(StandardSocketOption.SO_RCVBUF.type()
.cast(this.socketOptions.get(StandardSocketOption.SO_RCVBUF)));
}
if (this.socketOptions.get(StandardSocketOption.TCP_NODELAY) != null) {
sc.socket().setTcpNoDelay(StandardSocketOption.TCP_NODELAY.type()
.cast(this.socketOptions.get(StandardSocketOption.TCP_NODELAY)));
}
} | [
"protected",
"final",
"void",
"configureSocketChannel",
"(",
"SocketChannel",
"sc",
")",
"throws",
"IOException",
"{",
"sc",
".",
"socket",
"(",
")",
".",
"setSoTimeout",
"(",
"this",
".",
"soTimeout",
")",
";",
"sc",
".",
"configureBlocking",
"(",
"false",
... | Confiure socket channel
@param sc
@throws IOException | [
"Confiure",
"socket",
"channel"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/SocketChannelController.java#L85-L113 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/command/binary/BinaryStoreCommand.java | BinaryStoreCommand.readHeader | protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus == ResponseStatus.NO_ERROR) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
} | java | protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus == ResponseStatus.NO_ERROR) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
} | [
"protected",
"void",
"readHeader",
"(",
"ByteBuffer",
"buffer",
")",
"{",
"super",
".",
"readHeader",
"(",
"buffer",
")",
";",
"if",
"(",
"this",
".",
"responseStatus",
"==",
"ResponseStatus",
".",
"NO_ERROR",
")",
"{",
"this",
".",
"decodeStatus",
"=",
"B... | optimistic,if no error,goto done | [
"optimistic",
"if",
"no",
"error",
"goto",
"done"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/command/binary/BinaryStoreCommand.java#L60-L65 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/core/impl/AbstractController.java | AbstractController.bind | public void bind(InetSocketAddress inetSocketAddress) throws IOException {
if (inetSocketAddress == null) {
throw new IllegalArgumentException("Null inetSocketAddress");
}
setLocalSocketAddress(inetSocketAddress);
start();
} | java | public void bind(InetSocketAddress inetSocketAddress) throws IOException {
if (inetSocketAddress == null) {
throw new IllegalArgumentException("Null inetSocketAddress");
}
setLocalSocketAddress(inetSocketAddress);
start();
} | [
"public",
"void",
"bind",
"(",
"InetSocketAddress",
"inetSocketAddress",
")",
"throws",
"IOException",
"{",
"if",
"(",
"inetSocketAddress",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Null inetSocketAddress\"",
")",
";",
"}",
"setLoca... | Bind localhost address
@param inetSocketAddress
@throws IOException | [
"Bind",
"localhost",
"address"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/core/impl/AbstractController.java#L534-L540 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java | MemcachedHandler.onMessageReceived | @Override
public final void onMessageReceived(final Session session, final Object msg) {
Command command = (Command) msg;
if (this.statisticsHandler.isStatistics()) {
if (command.getCopiedMergeCount() > 0 && command instanceof MapReturnValueAware) {
Map<String, CachedData> returnValues = ((MapReturnValueAware) command).getReturnValues();
int size = returnValues.size();
this.statisticsHandler.statistics(CommandType.GET_HIT, size);
this.statisticsHandler.statistics(CommandType.GET_MISS,
command.getCopiedMergeCount() - size);
} else if (command instanceof TextGetOneCommand || command instanceof BinaryGetCommand) {
if (command.getResult() != null) {
this.statisticsHandler.statistics(CommandType.GET_HIT);
} else {
this.statisticsHandler.statistics(CommandType.GET_MISS);
}
} else {
if (command.getCopiedMergeCount() > 0) {
this.statisticsHandler.statistics(command.getCommandType(),
command.getCopiedMergeCount());
} else
this.statisticsHandler.statistics(command.getCommandType());
}
}
} | java | @Override
public final void onMessageReceived(final Session session, final Object msg) {
Command command = (Command) msg;
if (this.statisticsHandler.isStatistics()) {
if (command.getCopiedMergeCount() > 0 && command instanceof MapReturnValueAware) {
Map<String, CachedData> returnValues = ((MapReturnValueAware) command).getReturnValues();
int size = returnValues.size();
this.statisticsHandler.statistics(CommandType.GET_HIT, size);
this.statisticsHandler.statistics(CommandType.GET_MISS,
command.getCopiedMergeCount() - size);
} else if (command instanceof TextGetOneCommand || command instanceof BinaryGetCommand) {
if (command.getResult() != null) {
this.statisticsHandler.statistics(CommandType.GET_HIT);
} else {
this.statisticsHandler.statistics(CommandType.GET_MISS);
}
} else {
if (command.getCopiedMergeCount() > 0) {
this.statisticsHandler.statistics(command.getCommandType(),
command.getCopiedMergeCount());
} else
this.statisticsHandler.statistics(command.getCommandType());
}
}
} | [
"@",
"Override",
"public",
"final",
"void",
"onMessageReceived",
"(",
"final",
"Session",
"session",
",",
"final",
"Object",
"msg",
")",
"{",
"Command",
"command",
"=",
"(",
"Command",
")",
"msg",
";",
"if",
"(",
"this",
".",
"statisticsHandler",
".",
"isS... | On receive message from memcached server | [
"On",
"receive",
"message",
"from",
"memcached",
"server"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java#L69-L93 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java | MemcachedHandler.onSessionStarted | @Override
public void onSessionStarted(Session session) {
session.setUseBlockingRead(true);
session.setAttribute(HEART_BEAT_FAIL_COUNT_ATTR, new AtomicInteger(0));
for (MemcachedClientStateListener listener : this.client.getStateListeners()) {
listener.onConnected(this.client, session.getRemoteSocketAddress());
}
this.listener.onConnect((MemcachedTCPSession) session, this.client);
} | java | @Override
public void onSessionStarted(Session session) {
session.setUseBlockingRead(true);
session.setAttribute(HEART_BEAT_FAIL_COUNT_ATTR, new AtomicInteger(0));
for (MemcachedClientStateListener listener : this.client.getStateListeners()) {
listener.onConnected(this.client, session.getRemoteSocketAddress());
}
this.listener.onConnect((MemcachedTCPSession) session, this.client);
} | [
"@",
"Override",
"public",
"void",
"onSessionStarted",
"(",
"Session",
"session",
")",
"{",
"session",
".",
"setUseBlockingRead",
"(",
"true",
")",
";",
"session",
".",
"setAttribute",
"(",
"HEART_BEAT_FAIL_COUNT_ATTR",
",",
"new",
"AtomicInteger",
"(",
"0",
")"... | On session started | [
"On",
"session",
"started"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java#L134-L142 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java | MemcachedHandler.reconnect | protected void reconnect(MemcachedTCPSession session) {
if (!this.client.isShutdown()) {
// Prevent reconnecting repeatedly
synchronized (session) {
if (!session.isAllowReconnect()) {
return;
}
session.setAllowReconnect(false);
}
MemcachedSession memcachedTCPSession = session;
InetSocketAddressWrapper inetSocketAddressWrapper =
memcachedTCPSession.getInetSocketAddressWrapper();
this.client.getConnector().addToWatingQueue(
new ReconnectRequest(inetSocketAddressWrapper, 0, this.client.getHealSessionInterval()));
}
} | java | protected void reconnect(MemcachedTCPSession session) {
if (!this.client.isShutdown()) {
// Prevent reconnecting repeatedly
synchronized (session) {
if (!session.isAllowReconnect()) {
return;
}
session.setAllowReconnect(false);
}
MemcachedSession memcachedTCPSession = session;
InetSocketAddressWrapper inetSocketAddressWrapper =
memcachedTCPSession.getInetSocketAddressWrapper();
this.client.getConnector().addToWatingQueue(
new ReconnectRequest(inetSocketAddressWrapper, 0, this.client.getHealSessionInterval()));
}
} | [
"protected",
"void",
"reconnect",
"(",
"MemcachedTCPSession",
"session",
")",
"{",
"if",
"(",
"!",
"this",
".",
"client",
".",
"isShutdown",
"(",
")",
")",
"{",
"// Prevent reconnecting repeatedly",
"synchronized",
"(",
"session",
")",
"{",
"if",
"(",
"!",
"... | Auto reconect to memcached server
@param session | [
"Auto",
"reconect",
"to",
"memcached",
"server"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/impl/MemcachedHandler.java#L243-L258 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java | IoBuffer.setAllocator | public static void setAllocator(IoBufferAllocator newAllocator) {
if (newAllocator == null) {
throw new NullPointerException("allocator");
}
IoBufferAllocator oldAllocator = allocator;
allocator = newAllocator;
if (null != oldAllocator) {
oldAllocator.dispose();
}
} | java | public static void setAllocator(IoBufferAllocator newAllocator) {
if (newAllocator == null) {
throw new NullPointerException("allocator");
}
IoBufferAllocator oldAllocator = allocator;
allocator = newAllocator;
if (null != oldAllocator) {
oldAllocator.dispose();
}
} | [
"public",
"static",
"void",
"setAllocator",
"(",
"IoBufferAllocator",
"newAllocator",
")",
"{",
"if",
"(",
"newAllocator",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"allocator\"",
")",
";",
"}",
"IoBufferAllocator",
"oldAllocator",
"="... | Sets the allocator used by existing and new buffers | [
"Sets",
"the",
"allocator",
"used",
"by",
"existing",
"and",
"new",
"buffers"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java#L154-L166 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java | IoBuffer.allocate | public static IoBuffer allocate(int capacity, boolean direct) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity: " + capacity);
}
return allocator.allocate(capacity, direct);
} | java | public static IoBuffer allocate(int capacity, boolean direct) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity: " + capacity);
}
return allocator.allocate(capacity, direct);
} | [
"public",
"static",
"IoBuffer",
"allocate",
"(",
"int",
"capacity",
",",
"boolean",
"direct",
")",
"{",
"if",
"(",
"capacity",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"capacity: \"",
"+",
"capacity",
")",
";",
"}",
"return",
... | Returns the buffer which is capable of the specified size.
@param capacity the capacity of the buffer
@param direct <tt>true</tt> to get a direct buffer, <tt>false</tt> to get a heap buffer. | [
"Returns",
"the",
"buffer",
"which",
"is",
"capable",
"of",
"the",
"specified",
"size",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java#L201-L207 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java | IoBuffer.wrap | public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
return wrap(ByteBuffer.wrap(byteArray, offset, length));
} | java | public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
return wrap(ByteBuffer.wrap(byteArray, offset, length));
} | [
"public",
"static",
"IoBuffer",
"wrap",
"(",
"byte",
"[",
"]",
"byteArray",
",",
"int",
"offset",
",",
"int",
"length",
")",
"{",
"return",
"wrap",
"(",
"ByteBuffer",
".",
"wrap",
"(",
"byteArray",
",",
"offset",
",",
"length",
")",
")",
";",
"}"
] | Wraps the specified byte array into MINA heap buffer. | [
"Wraps",
"the",
"specified",
"byte",
"array",
"into",
"MINA",
"heap",
"buffer",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/buffer/IoBuffer.java#L226-L228 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/Reactor.java | Reactor.lookJVMBug | private boolean lookJVMBug(long before, int selected, long wait) throws IOException {
boolean seeing = false;
long now = System.currentTimeMillis();
if (JVMBUG_THRESHHOLD > 0 && selected == 0 && wait > JVMBUG_THRESHHOLD
&& now - before < wait / 4 && !wakenUp.get() /* waken up */
&& !Thread.currentThread().isInterrupted()/* Interrupted */) {
jvmBug.incrementAndGet();
if (jvmBug.get() >= JVMBUG_THRESHHOLD2) {
gate.lock();
try {
lastJVMBug = now;
log.warn("JVM bug occured at " + new Date(lastJVMBug)
+ ",http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6403933,reactIndex="
+ reactorIndex);
if (jvmBug1) {
log.debug("seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex);
} else {
jvmBug1 = true;
log.info("seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex);
}
seeing = true;
final Selector new_selector = SystemUtils.openSelector();
for (SelectionKey k : selector.keys()) {
if (!k.isValid() || k.interestOps() == 0) {
continue;
}
final SelectableChannel channel = k.channel();
final Object attachment = k.attachment();
channel.register(new_selector, k.interestOps(), attachment);
}
selector.close();
selector = new_selector;
} finally {
gate.unlock();
}
jvmBug.set(0);
} else if (jvmBug.get() == JVMBUG_THRESHHOLD || jvmBug.get() == JVMBUG_THRESHHOLD1) {
if (jvmBug0) {
log.debug("seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex);
} else {
jvmBug0 = true;
log.info("seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex);
}
gate.lock();
seeing = true;
try {
for (SelectionKey k : selector.keys()) {
if (k.isValid() && k.interestOps() == 0) {
k.cancel();
}
}
} finally {
gate.unlock();
}
}
} else {
jvmBug.set(0);
}
return seeing;
} | java | private boolean lookJVMBug(long before, int selected, long wait) throws IOException {
boolean seeing = false;
long now = System.currentTimeMillis();
if (JVMBUG_THRESHHOLD > 0 && selected == 0 && wait > JVMBUG_THRESHHOLD
&& now - before < wait / 4 && !wakenUp.get() /* waken up */
&& !Thread.currentThread().isInterrupted()/* Interrupted */) {
jvmBug.incrementAndGet();
if (jvmBug.get() >= JVMBUG_THRESHHOLD2) {
gate.lock();
try {
lastJVMBug = now;
log.warn("JVM bug occured at " + new Date(lastJVMBug)
+ ",http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6403933,reactIndex="
+ reactorIndex);
if (jvmBug1) {
log.debug("seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex);
} else {
jvmBug1 = true;
log.info("seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex);
}
seeing = true;
final Selector new_selector = SystemUtils.openSelector();
for (SelectionKey k : selector.keys()) {
if (!k.isValid() || k.interestOps() == 0) {
continue;
}
final SelectableChannel channel = k.channel();
final Object attachment = k.attachment();
channel.register(new_selector, k.interestOps(), attachment);
}
selector.close();
selector = new_selector;
} finally {
gate.unlock();
}
jvmBug.set(0);
} else if (jvmBug.get() == JVMBUG_THRESHHOLD || jvmBug.get() == JVMBUG_THRESHHOLD1) {
if (jvmBug0) {
log.debug("seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex);
} else {
jvmBug0 = true;
log.info("seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex);
}
gate.lock();
seeing = true;
try {
for (SelectionKey k : selector.keys()) {
if (k.isValid() && k.interestOps() == 0) {
k.cancel();
}
}
} finally {
gate.unlock();
}
}
} else {
jvmBug.set(0);
}
return seeing;
} | [
"private",
"boolean",
"lookJVMBug",
"(",
"long",
"before",
",",
"int",
"selected",
",",
"long",
"wait",
")",
"throws",
"IOException",
"{",
"boolean",
"seeing",
"=",
"false",
";",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"if",
... | Look jvm bug
@param before
@param selected
@param wait
@return
@throws IOException | [
"Look",
"jvm",
"bug"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/Reactor.java#L205-L271 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/nio/impl/Reactor.java | Reactor.dispatchEvent | public final void dispatchEvent(Set<SelectionKey> selectedKeySet) {
Iterator<SelectionKey> it = selectedKeySet.iterator();
boolean skipOpRead = false;
while (it.hasNext()) {
SelectionKey key = it.next();
it.remove();
if (!key.isValid()) {
if (key.attachment() != null) {
controller.closeSelectionKey(key);
} else {
key.cancel();
}
continue;
}
try {
if (key.isValid() && key.isAcceptable()) {
controller.onAccept(key);
continue;
}
if (key.isValid() && (key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
// Remove write interest
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
controller.onWrite(key);
if (!controller.isHandleReadWriteConcurrently()) {
skipOpRead = true;
}
}
if (!skipOpRead && key.isValid()
&& (key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
if (!controller.getStatistics().isReceiveOverFlow()) {
// Remove read interest
controller.onRead(key);
} else {
key.interestOps(key.interestOps() | SelectionKey.OP_READ);
}
}
if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT) {
controller.onConnect(key);
}
} catch (CancelledKeyException e) {
// ignore
} catch (RejectedExecutionException e) {
if (key.attachment() instanceof AbstractNioSession) {
((AbstractNioSession) key.attachment()).onException(e);
}
controller.notifyException(e);
if (selector.isOpen()) {
continue;
} else {
break;
}
} catch (Exception e) {
if (key.attachment() instanceof AbstractNioSession) {
((AbstractNioSession) key.attachment()).onException(e);
}
controller.closeSelectionKey(key);
controller.notifyException(e);
log.error("Reactor dispatch events error", e);
if (selector.isOpen()) {
continue;
} else {
break;
}
}
}
} | java | public final void dispatchEvent(Set<SelectionKey> selectedKeySet) {
Iterator<SelectionKey> it = selectedKeySet.iterator();
boolean skipOpRead = false;
while (it.hasNext()) {
SelectionKey key = it.next();
it.remove();
if (!key.isValid()) {
if (key.attachment() != null) {
controller.closeSelectionKey(key);
} else {
key.cancel();
}
continue;
}
try {
if (key.isValid() && key.isAcceptable()) {
controller.onAccept(key);
continue;
}
if (key.isValid() && (key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
// Remove write interest
key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
controller.onWrite(key);
if (!controller.isHandleReadWriteConcurrently()) {
skipOpRead = true;
}
}
if (!skipOpRead && key.isValid()
&& (key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
if (!controller.getStatistics().isReceiveOverFlow()) {
// Remove read interest
controller.onRead(key);
} else {
key.interestOps(key.interestOps() | SelectionKey.OP_READ);
}
}
if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT) {
controller.onConnect(key);
}
} catch (CancelledKeyException e) {
// ignore
} catch (RejectedExecutionException e) {
if (key.attachment() instanceof AbstractNioSession) {
((AbstractNioSession) key.attachment()).onException(e);
}
controller.notifyException(e);
if (selector.isOpen()) {
continue;
} else {
break;
}
} catch (Exception e) {
if (key.attachment() instanceof AbstractNioSession) {
((AbstractNioSession) key.attachment()).onException(e);
}
controller.closeSelectionKey(key);
controller.notifyException(e);
log.error("Reactor dispatch events error", e);
if (selector.isOpen()) {
continue;
} else {
break;
}
}
}
} | [
"public",
"final",
"void",
"dispatchEvent",
"(",
"Set",
"<",
"SelectionKey",
">",
"selectedKeySet",
")",
"{",
"Iterator",
"<",
"SelectionKey",
">",
"it",
"=",
"selectedKeySet",
".",
"iterator",
"(",
")",
";",
"boolean",
"skipOpRead",
"=",
"false",
";",
"whil... | Dispatch selected event
@param selectedKeySet | [
"Dispatch",
"selected",
"event"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/nio/impl/Reactor.java#L278-L347 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java | XMemcachedClient.addServer | public final void addServer(final String server, final int port, int weight) throws IOException {
if (weight <= 0) {
throw new IllegalArgumentException("weight<=0");
}
this.checkServerPort(server, port);
this.connect(new InetSocketAddressWrapper(this.newSocketAddress(server, port),
this.serverOrderCount.incrementAndGet(), weight, null));
} | java | public final void addServer(final String server, final int port, int weight) throws IOException {
if (weight <= 0) {
throw new IllegalArgumentException("weight<=0");
}
this.checkServerPort(server, port);
this.connect(new InetSocketAddressWrapper(this.newSocketAddress(server, port),
this.serverOrderCount.incrementAndGet(), weight, null));
} | [
"public",
"final",
"void",
"addServer",
"(",
"final",
"String",
"server",
",",
"final",
"int",
"port",
",",
"int",
"weight",
")",
"throws",
"IOException",
"{",
"if",
"(",
"weight",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"we... | add a memcached server to MemcachedClient
@param server
@param port
@param weight
@throws IOException | [
"add",
"a",
"memcached",
"server",
"to",
"MemcachedClient"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java#L391-L398 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java | XMemcachedClient.catalogKeys | private final Collection<List<String>> catalogKeys(final Collection<String> keyCollections) {
final Map<Session, List<String>> catalogMap = new HashMap<Session, List<String>>();
for (String key : keyCollections) {
Session index = this.sessionLocator.getSessionByKey(key);
List<String> tmpKeys = catalogMap.get(index);
if (tmpKeys == null) {
tmpKeys = new ArrayList<String>(10);
catalogMap.put(index, tmpKeys);
}
tmpKeys.add(key);
}
Collection<List<String>> catalogKeys = catalogMap.values();
return catalogKeys;
} | java | private final Collection<List<String>> catalogKeys(final Collection<String> keyCollections) {
final Map<Session, List<String>> catalogMap = new HashMap<Session, List<String>>();
for (String key : keyCollections) {
Session index = this.sessionLocator.getSessionByKey(key);
List<String> tmpKeys = catalogMap.get(index);
if (tmpKeys == null) {
tmpKeys = new ArrayList<String>(10);
catalogMap.put(index, tmpKeys);
}
tmpKeys.add(key);
}
Collection<List<String>> catalogKeys = catalogMap.values();
return catalogKeys;
} | [
"private",
"final",
"Collection",
"<",
"List",
"<",
"String",
">",
">",
"catalogKeys",
"(",
"final",
"Collection",
"<",
"String",
">",
"keyCollections",
")",
"{",
"final",
"Map",
"<",
"Session",
",",
"List",
"<",
"String",
">",
">",
"catalogMap",
"=",
"n... | Hash key to servers
@param keyCollections
@return | [
"Hash",
"key",
"to",
"servers"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java#L1234-L1249 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java | XMemcachedClient.deleteWithNoReply | public final void deleteWithNoReply(final String key, final int time)
throws InterruptedException, MemcachedException {
try {
this.delete0(key, time, 0, true, this.opTimeout);
} catch (TimeoutException e) {
throw new MemcachedException(e);
}
} | java | public final void deleteWithNoReply(final String key, final int time)
throws InterruptedException, MemcachedException {
try {
this.delete0(key, time, 0, true, this.opTimeout);
} catch (TimeoutException e) {
throw new MemcachedException(e);
}
} | [
"public",
"final",
"void",
"deleteWithNoReply",
"(",
"final",
"String",
"key",
",",
"final",
"int",
"time",
")",
"throws",
"InterruptedException",
",",
"MemcachedException",
"{",
"try",
"{",
"this",
".",
"delete0",
"(",
"key",
",",
"time",
",",
"0",
",",
"... | Delete key's data item from memcached.This method doesn't wait for reply
@param key
@param time
@throws InterruptedException
@throws MemcachedException | [
"Delete",
"key",
"s",
"data",
"item",
"from",
"memcached",
".",
"This",
"method",
"doesn",
"t",
"wait",
"for",
"reply"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java#L1782-L1789 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java | XMemcachedClient.getNamespace | public String getNamespace(String ns)
throws TimeoutException, InterruptedException, MemcachedException {
String key = this.keyProvider.process(this.getNSKey(ns));
byte[] keyBytes = ByteUtils.getBytes(key);
ByteUtils.checkKey(keyBytes);
Object item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder);
while (item == null) {
item = String.valueOf(System.nanoTime());
boolean added = this.add0(key, 0, item, this.transcoder, this.opTimeout);
if (!added) {
item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder);
}
}
String namespace = item.toString();
if (!ByteUtils.isNumber(namespace)) {
throw new IllegalStateException(
"Namespace key already has value.The key is:" + key + ",and the value is:" + namespace);
}
return namespace;
} | java | public String getNamespace(String ns)
throws TimeoutException, InterruptedException, MemcachedException {
String key = this.keyProvider.process(this.getNSKey(ns));
byte[] keyBytes = ByteUtils.getBytes(key);
ByteUtils.checkKey(keyBytes);
Object item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder);
while (item == null) {
item = String.valueOf(System.nanoTime());
boolean added = this.add0(key, 0, item, this.transcoder, this.opTimeout);
if (!added) {
item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder);
}
}
String namespace = item.toString();
if (!ByteUtils.isNumber(namespace)) {
throw new IllegalStateException(
"Namespace key already has value.The key is:" + key + ",and the value is:" + namespace);
}
return namespace;
} | [
"public",
"String",
"getNamespace",
"(",
"String",
"ns",
")",
"throws",
"TimeoutException",
",",
"InterruptedException",
",",
"MemcachedException",
"{",
"String",
"key",
"=",
"this",
".",
"keyProvider",
".",
"process",
"(",
"this",
".",
"getNSKey",
"(",
"ns",
... | Returns the real namespace of ns.
@param ns
@return
@throws TimeoutException
@throws InterruptedException
@throws MemcachedException | [
"Returns",
"the",
"real",
"namespace",
"of",
"ns",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java#L2545-L2564 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/SelectorFactory.java | SelectorFactory.setMaxSelectors | public final static void setMaxSelectors(int size) throws IOException {
synchronized (selectors) {
if (size < maxSelectors) {
reduce(size);
} else if (size > maxSelectors) {
grow(size);
}
maxSelectors = size;
}
} | java | public final static void setMaxSelectors(int size) throws IOException {
synchronized (selectors) {
if (size < maxSelectors) {
reduce(size);
} else if (size > maxSelectors) {
grow(size);
}
maxSelectors = size;
}
} | [
"public",
"final",
"static",
"void",
"setMaxSelectors",
"(",
"int",
"size",
")",
"throws",
"IOException",
"{",
"synchronized",
"(",
"selectors",
")",
"{",
"if",
"(",
"size",
"<",
"maxSelectors",
")",
"{",
"reduce",
"(",
"size",
")",
";",
"}",
"else",
"if... | Set max selector pool size.
@param size max pool size | [
"Set",
"max",
"selector",
"pool",
"size",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/SelectorFactory.java#L66-L76 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java | LinkedTransferQueue.advanceHead | private boolean advanceHead(QNode h, QNode nh) {
if (h == this.head.get() && this.head.compareAndSet(h, nh)) {
h.next = h; // forget old next
return true;
}
return false;
} | java | private boolean advanceHead(QNode h, QNode nh) {
if (h == this.head.get() && this.head.compareAndSet(h, nh)) {
h.next = h; // forget old next
return true;
}
return false;
} | [
"private",
"boolean",
"advanceHead",
"(",
"QNode",
"h",
",",
"QNode",
"nh",
")",
"{",
"if",
"(",
"h",
"==",
"this",
".",
"head",
".",
"get",
"(",
")",
"&&",
"this",
".",
"head",
".",
"compareAndSet",
"(",
"h",
",",
"nh",
")",
")",
"{",
"h",
"."... | Tries to cas nh as new head; if successful, unlink old head's next node to avoid garbage
retention. | [
"Tries",
"to",
"cas",
"nh",
"as",
"new",
"head",
";",
"if",
"successful",
"unlink",
"old",
"head",
"s",
"next",
"node",
"to",
"avoid",
"garbage",
"retention",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java#L203-L209 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java | LinkedTransferQueue.getValidatedTail | private QNode getValidatedTail() {
for (;;) {
QNode h = this.head.get();
QNode first = h.next;
if (first != null && first.next == first) { // help advance
advanceHead(h, first);
continue;
}
QNode t = this.tail.get();
QNode last = t.next;
if (t == this.tail.get()) {
if (last != null) {
this.tail.compareAndSet(t, last); // help advance
} else {
return t;
}
}
}
} | java | private QNode getValidatedTail() {
for (;;) {
QNode h = this.head.get();
QNode first = h.next;
if (first != null && first.next == first) { // help advance
advanceHead(h, first);
continue;
}
QNode t = this.tail.get();
QNode last = t.next;
if (t == this.tail.get()) {
if (last != null) {
this.tail.compareAndSet(t, last); // help advance
} else {
return t;
}
}
}
} | [
"private",
"QNode",
"getValidatedTail",
"(",
")",
"{",
"for",
"(",
";",
";",
")",
"{",
"QNode",
"h",
"=",
"this",
".",
"head",
".",
"get",
"(",
")",
";",
"QNode",
"first",
"=",
"h",
".",
"next",
";",
"if",
"(",
"first",
"!=",
"null",
"&&",
"fir... | Returns validated tail for use in cleaning methods | [
"Returns",
"validated",
"tail",
"for",
"use",
"in",
"cleaning",
"methods"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java#L362-L380 | train |
killme2008/xmemcached | src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java | LinkedTransferQueue.traversalHead | QNode traversalHead() {
for (;;) {
QNode t = this.tail.get();
QNode h = this.head.get();
if (h != null && t != null) {
QNode last = t.next;
QNode first = h.next;
if (t == this.tail.get()) {
if (last != null) {
this.tail.compareAndSet(t, last);
} else if (first != null) {
Object x = first.get();
if (x == first) {
advanceHead(h, first);
} else {
return h;
}
} else {
return h;
}
}
}
}
} | java | QNode traversalHead() {
for (;;) {
QNode t = this.tail.get();
QNode h = this.head.get();
if (h != null && t != null) {
QNode last = t.next;
QNode first = h.next;
if (t == this.tail.get()) {
if (last != null) {
this.tail.compareAndSet(t, last);
} else if (first != null) {
Object x = first.get();
if (x == first) {
advanceHead(h, first);
} else {
return h;
}
} else {
return h;
}
}
}
}
} | [
"QNode",
"traversalHead",
"(",
")",
"{",
"for",
"(",
";",
";",
")",
"{",
"QNode",
"t",
"=",
"this",
".",
"tail",
".",
"get",
"(",
")",
";",
"QNode",
"h",
"=",
"this",
".",
"head",
".",
"get",
"(",
")",
";",
"if",
"(",
"h",
"!=",
"null",
"&&... | Return head after performing any outstanding helping steps | [
"Return",
"head",
"after",
"performing",
"any",
"outstanding",
"helping",
"steps"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/com/google/code/yanf4j/util/LinkedTransferQueue.java#L592-L615 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/aws/AWSUtils.java | AWSUtils.parseConfiguration | public static ClusterConfigration parseConfiguration(String line) {
String[] lines = line.trim().split("(?:\\r?\\n)");
if (lines.length < 2) {
throw new IllegalArgumentException("Incorrect config response:" + line);
}
String configversion = lines[0];
String nodeListStr = lines[1];
if (!ByteUtils.isNumber(configversion)) {
throw new IllegalArgumentException(
"Invalid configversion: " + configversion + ", it should be a number.");
}
String[] nodeStrs = nodeListStr.split("(?:\\s)+");
int version = Integer.parseInt(configversion);
List<CacheNode> nodeList = new ArrayList<CacheNode>(nodeStrs.length);
for (String nodeStr : nodeStrs) {
if (nodeStr.equals("")) {
continue;
}
int firstDelimiter = nodeStr.indexOf(DELIMITER);
int secondDelimiter = nodeStr.lastIndexOf(DELIMITER);
if (firstDelimiter < 1 || firstDelimiter == secondDelimiter) {
throw new IllegalArgumentException(
"Invalid server ''" + nodeStr + "'' in response: " + line);
}
String hostName = nodeStr.substring(0, firstDelimiter).trim();
String ipAddress = nodeStr.substring(firstDelimiter + 1, secondDelimiter).trim();
String portNum = nodeStr.substring(secondDelimiter + 1).trim();
int port = Integer.parseInt(portNum);
nodeList.add(new CacheNode(hostName, ipAddress, port));
}
return new ClusterConfigration(version, nodeList);
} | java | public static ClusterConfigration parseConfiguration(String line) {
String[] lines = line.trim().split("(?:\\r?\\n)");
if (lines.length < 2) {
throw new IllegalArgumentException("Incorrect config response:" + line);
}
String configversion = lines[0];
String nodeListStr = lines[1];
if (!ByteUtils.isNumber(configversion)) {
throw new IllegalArgumentException(
"Invalid configversion: " + configversion + ", it should be a number.");
}
String[] nodeStrs = nodeListStr.split("(?:\\s)+");
int version = Integer.parseInt(configversion);
List<CacheNode> nodeList = new ArrayList<CacheNode>(nodeStrs.length);
for (String nodeStr : nodeStrs) {
if (nodeStr.equals("")) {
continue;
}
int firstDelimiter = nodeStr.indexOf(DELIMITER);
int secondDelimiter = nodeStr.lastIndexOf(DELIMITER);
if (firstDelimiter < 1 || firstDelimiter == secondDelimiter) {
throw new IllegalArgumentException(
"Invalid server ''" + nodeStr + "'' in response: " + line);
}
String hostName = nodeStr.substring(0, firstDelimiter).trim();
String ipAddress = nodeStr.substring(firstDelimiter + 1, secondDelimiter).trim();
String portNum = nodeStr.substring(secondDelimiter + 1).trim();
int port = Integer.parseInt(portNum);
nodeList.add(new CacheNode(hostName, ipAddress, port));
}
return new ClusterConfigration(version, nodeList);
} | [
"public",
"static",
"ClusterConfigration",
"parseConfiguration",
"(",
"String",
"line",
")",
"{",
"String",
"[",
"]",
"lines",
"=",
"line",
".",
"trim",
"(",
")",
".",
"split",
"(",
"\"(?:\\\\r?\\\\n)\"",
")",
";",
"if",
"(",
"lines",
".",
"length",
"<",
... | Parse response string to ClusterConfiguration instance.
@param line
@return | [
"Parse",
"response",
"string",
"to",
"ClusterConfiguration",
"instance",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/aws/AWSUtils.java#L23-L57 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/Counter.java | Counter.get | public long get() throws MemcachedException, InterruptedException, TimeoutException {
Object result = this.memcachedClient.get(this.key);
if (result == null) {
throw new MemcachedClientException("key is not existed.");
} else {
if (result instanceof Long)
return (Long) result;
else
return Long.valueOf(((String) result).trim());
}
} | java | public long get() throws MemcachedException, InterruptedException, TimeoutException {
Object result = this.memcachedClient.get(this.key);
if (result == null) {
throw new MemcachedClientException("key is not existed.");
} else {
if (result instanceof Long)
return (Long) result;
else
return Long.valueOf(((String) result).trim());
}
} | [
"public",
"long",
"get",
"(",
")",
"throws",
"MemcachedException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"Object",
"result",
"=",
"this",
".",
"memcachedClient",
".",
"get",
"(",
"this",
".",
"key",
")",
";",
"if",
"(",
"result",
"==",
... | Get current value
@return
@throws MemcachedException
@throws InterruptedException
@throws TimeoutException | [
"Get",
"current",
"value"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/Counter.java#L69-L79 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/Counter.java | Counter.set | public void set(long value) throws MemcachedException, InterruptedException, TimeoutException {
this.memcachedClient.set(this.key, 0, String.valueOf(value));
} | java | public void set(long value) throws MemcachedException, InterruptedException, TimeoutException {
this.memcachedClient.set(this.key, 0, String.valueOf(value));
} | [
"public",
"void",
"set",
"(",
"long",
"value",
")",
"throws",
"MemcachedException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"this",
".",
"memcachedClient",
".",
"set",
"(",
"this",
".",
"key",
",",
"0",
",",
"String",
".",
"valueOf",
"(",
... | Set counter's value to expected.
@param value
@throws MemcachedException
@throws InterruptedException
@throws TimeoutException | [
"Set",
"counter",
"s",
"value",
"to",
"expected",
"."
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/Counter.java#L89-L91 | train |
killme2008/xmemcached | src/main/java/net/rubyeye/xmemcached/Counter.java | Counter.addAndGet | public long addAndGet(long delta)
throws MemcachedException, InterruptedException, TimeoutException {
if (delta >= 0) {
return this.memcachedClient.incr(this.key, delta, this.initialValue);
} else {
return this.memcachedClient.decr(this.key, -delta, this.initialValue);
}
} | java | public long addAndGet(long delta)
throws MemcachedException, InterruptedException, TimeoutException {
if (delta >= 0) {
return this.memcachedClient.incr(this.key, delta, this.initialValue);
} else {
return this.memcachedClient.decr(this.key, -delta, this.initialValue);
}
} | [
"public",
"long",
"addAndGet",
"(",
"long",
"delta",
")",
"throws",
"MemcachedException",
",",
"InterruptedException",
",",
"TimeoutException",
"{",
"if",
"(",
"delta",
">=",
"0",
")",
"{",
"return",
"this",
".",
"memcachedClient",
".",
"incr",
"(",
"this",
... | Add value and get the result
@param delta
@return
@throws MemcachedException
@throws InterruptedException
@throws TimeoutException | [
"Add",
"value",
"and",
"get",
"the",
"result"
] | 66150915938813b3e3413de1d7b43b6ff9b1478d | https://github.com/killme2008/xmemcached/blob/66150915938813b3e3413de1d7b43b6ff9b1478d/src/main/java/net/rubyeye/xmemcached/Counter.java#L140-L147 | train |
fasseg/exp4j | src/main/java/net/objecthunter/exp4j/function/Function.java | Function.getAllowedFunctionCharacters | public static char[] getAllowedFunctionCharacters() {
char[] chars = new char[53];
int count = 0;
for (int i = 65; i < 91; i++) {
chars[count++] = (char) i;
}
for (int i = 97; i < 123; i++) {
chars[count++] = (char) i;
}
chars[count] = '_';
return chars;
} | java | public static char[] getAllowedFunctionCharacters() {
char[] chars = new char[53];
int count = 0;
for (int i = 65; i < 91; i++) {
chars[count++] = (char) i;
}
for (int i = 97; i < 123; i++) {
chars[count++] = (char) i;
}
chars[count] = '_';
return chars;
} | [
"public",
"static",
"char",
"[",
"]",
"getAllowedFunctionCharacters",
"(",
")",
"{",
"char",
"[",
"]",
"chars",
"=",
"new",
"char",
"[",
"53",
"]",
";",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"65",
";",
"i",
"<",
"91",
";",
... | Get the set of characters which are allowed for use in Function names.
@return the set of characters allowed
@deprecated since 0.4.5 All unicode letters are allowed to be used in function names since 0.4.3. This API
Function can be safely ignored. Checks for function name validity can be done using Character.isLetter() et al. | [
"Get",
"the",
"set",
"of",
"characters",
"which",
"are",
"allowed",
"for",
"use",
"in",
"Function",
"names",
"."
] | 3efb9944a9fe99e3f379b6426e0d20d061358793 | https://github.com/fasseg/exp4j/blob/3efb9944a9fe99e3f379b6426e0d20d061358793/src/main/java/net/objecthunter/exp4j/function/Function.java#L89-L100 | train |
fasseg/exp4j | src/main/java/net/objecthunter/exp4j/function/Functions.java | Functions.getBuiltinFunction | public static Function getBuiltinFunction(final String name) {
if (name.equals("sin")) {
return builtinFunctions[INDEX_SIN];
} else if (name.equals("cos")) {
return builtinFunctions[INDEX_COS];
} else if (name.equals("tan")) {
return builtinFunctions[INDEX_TAN];
} else if (name.equals("cot")) {
return builtinFunctions[INDEX_COT];
} else if (name.equals("asin")) {
return builtinFunctions[INDEX_ASIN];
} else if (name.equals("acos")) {
return builtinFunctions[INDEX_ACOS];
} else if (name.equals("atan")) {
return builtinFunctions[INDEX_ATAN];
} else if (name.equals("sinh")) {
return builtinFunctions[INDEX_SINH];
} else if (name.equals("cosh")) {
return builtinFunctions[INDEX_COSH];
} else if (name.equals("tanh")) {
return builtinFunctions[INDEX_TANH];
} else if (name.equals("abs")) {
return builtinFunctions[INDEX_ABS];
} else if (name.equals("log")) {
return builtinFunctions[INDEX_LOG];
} else if (name.equals("log10")) {
return builtinFunctions[INDEX_LOG10];
} else if (name.equals("log2")) {
return builtinFunctions[INDEX_LOG2];
} else if (name.equals("log1p")) {
return builtinFunctions[INDEX_LOG1P];
} else if (name.equals("ceil")) {
return builtinFunctions[INDEX_CEIL];
} else if (name.equals("floor")) {
return builtinFunctions[INDEX_FLOOR];
} else if (name.equals("sqrt")) {
return builtinFunctions[INDEX_SQRT];
} else if (name.equals("cbrt")) {
return builtinFunctions[INDEX_CBRT];
} else if (name.equals("pow")) {
return builtinFunctions[INDEX_POW];
} else if (name.equals("exp")) {
return builtinFunctions[INDEX_EXP];
} else if (name.equals("expm1")) {
return builtinFunctions[INDEX_EXPM1];
} else if (name.equals("signum")) {
return builtinFunctions[INDEX_SGN];
} else {
return null;
}
} | java | public static Function getBuiltinFunction(final String name) {
if (name.equals("sin")) {
return builtinFunctions[INDEX_SIN];
} else if (name.equals("cos")) {
return builtinFunctions[INDEX_COS];
} else if (name.equals("tan")) {
return builtinFunctions[INDEX_TAN];
} else if (name.equals("cot")) {
return builtinFunctions[INDEX_COT];
} else if (name.equals("asin")) {
return builtinFunctions[INDEX_ASIN];
} else if (name.equals("acos")) {
return builtinFunctions[INDEX_ACOS];
} else if (name.equals("atan")) {
return builtinFunctions[INDEX_ATAN];
} else if (name.equals("sinh")) {
return builtinFunctions[INDEX_SINH];
} else if (name.equals("cosh")) {
return builtinFunctions[INDEX_COSH];
} else if (name.equals("tanh")) {
return builtinFunctions[INDEX_TANH];
} else if (name.equals("abs")) {
return builtinFunctions[INDEX_ABS];
} else if (name.equals("log")) {
return builtinFunctions[INDEX_LOG];
} else if (name.equals("log10")) {
return builtinFunctions[INDEX_LOG10];
} else if (name.equals("log2")) {
return builtinFunctions[INDEX_LOG2];
} else if (name.equals("log1p")) {
return builtinFunctions[INDEX_LOG1P];
} else if (name.equals("ceil")) {
return builtinFunctions[INDEX_CEIL];
} else if (name.equals("floor")) {
return builtinFunctions[INDEX_FLOOR];
} else if (name.equals("sqrt")) {
return builtinFunctions[INDEX_SQRT];
} else if (name.equals("cbrt")) {
return builtinFunctions[INDEX_CBRT];
} else if (name.equals("pow")) {
return builtinFunctions[INDEX_POW];
} else if (name.equals("exp")) {
return builtinFunctions[INDEX_EXP];
} else if (name.equals("expm1")) {
return builtinFunctions[INDEX_EXPM1];
} else if (name.equals("signum")) {
return builtinFunctions[INDEX_SGN];
} else {
return null;
}
} | [
"public",
"static",
"Function",
"getBuiltinFunction",
"(",
"final",
"String",
"name",
")",
"{",
"if",
"(",
"name",
".",
"equals",
"(",
"\"sin\"",
")",
")",
"{",
"return",
"builtinFunctions",
"[",
"INDEX_SIN",
"]",
";",
"}",
"else",
"if",
"(",
"name",
"."... | Get the builtin function for a given name
@param name te name of the function
@return a Function instance | [
"Get",
"the",
"builtin",
"function",
"for",
"a",
"given",
"name"
] | 3efb9944a9fe99e3f379b6426e0d20d061358793 | https://github.com/fasseg/exp4j/blob/3efb9944a9fe99e3f379b6426e0d20d061358793/src/main/java/net/objecthunter/exp4j/function/Functions.java#L204-L255 | train |
EdwardRaff/JSAT | JSAT/src/jsat/utils/BooleanList.java | BooleanList.unmodifiableView | public static List<Boolean> unmodifiableView(boolean[] array, int length)
{
return Collections.unmodifiableList(view(array, length));
} | java | public static List<Boolean> unmodifiableView(boolean[] array, int length)
{
return Collections.unmodifiableList(view(array, length));
} | [
"public",
"static",
"List",
"<",
"Boolean",
">",
"unmodifiableView",
"(",
"boolean",
"[",
"]",
"array",
",",
"int",
"length",
")",
"{",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"view",
"(",
"array",
",",
"length",
")",
")",
";",
"}"
] | Creates an returns an unmodifiable view of the given boolean array that requires
only a small object allocation.
@param array the array to wrap into an unmodifiable list
@param length the number of values of the array to use, starting from zero
@return an unmodifiable list view of the array | [
"Creates",
"an",
"returns",
"an",
"unmodifiable",
"view",
"of",
"the",
"given",
"boolean",
"array",
"that",
"requires",
"only",
"a",
"small",
"object",
"allocation",
"."
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/BooleanList.java#L269-L272 | train |
EdwardRaff/JSAT | JSAT/src/jsat/utils/BooleanList.java | BooleanList.view | public static BooleanList view(boolean[] array, int length)
{
if(length > array.length || length < 0)
throw new IllegalArgumentException("length must be non-negative and no more than the size of the array("+array.length+"), not " + length);
return new BooleanList(array, length);
} | java | public static BooleanList view(boolean[] array, int length)
{
if(length > array.length || length < 0)
throw new IllegalArgumentException("length must be non-negative and no more than the size of the array("+array.length+"), not " + length);
return new BooleanList(array, length);
} | [
"public",
"static",
"BooleanList",
"view",
"(",
"boolean",
"[",
"]",
"array",
",",
"int",
"length",
")",
"{",
"if",
"(",
"length",
">",
"array",
".",
"length",
"||",
"length",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"length must b... | Creates and returns a view of the given boolean array that requires only
a small object allocation. Changes to the list will be reflected in the
array up to a point. If the modification would require increasing the
capacity of the array, a new array will be allocated - at which point
operations will no longer be reflected in the original array.
@param array the array to wrap by a BooleanList object
@param length the initial length of the list
@return a BoolaenList backed by the given array, unless modified to the
point of requiring the allocation of a new array | [
"Creates",
"and",
"returns",
"a",
"view",
"of",
"the",
"given",
"boolean",
"array",
"that",
"requires",
"only",
"a",
"small",
"object",
"allocation",
".",
"Changes",
"to",
"the",
"list",
"will",
"be",
"reflected",
"in",
"the",
"array",
"up",
"to",
"a",
"... | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/utils/BooleanList.java#L286-L291 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.setMomentum | public void setMomentum(double momentum)
{
if(momentum < 0 || Double.isNaN(momentum) || Double.isInfinite(momentum))
throw new ArithmeticException("Momentum must be non negative, not " + momentum);
this.momentum = momentum;
} | java | public void setMomentum(double momentum)
{
if(momentum < 0 || Double.isNaN(momentum) || Double.isInfinite(momentum))
throw new ArithmeticException("Momentum must be non negative, not " + momentum);
this.momentum = momentum;
} | [
"public",
"void",
"setMomentum",
"(",
"double",
"momentum",
")",
"{",
"if",
"(",
"momentum",
"<",
"0",
"||",
"Double",
".",
"isNaN",
"(",
"momentum",
")",
"||",
"Double",
".",
"isInfinite",
"(",
"momentum",
")",
")",
"throw",
"new",
"ArithmeticException",
... | Sets the non negative momentum used in training.
@param momentum the momentum to apply to training | [
"Sets",
"the",
"non",
"negative",
"momentum",
"used",
"in",
"training",
"."
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L315-L320 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.setWeightDecay | public void setWeightDecay(double weightDecay)
{
if(weightDecay < 0 || weightDecay >= 1 || Double.isNaN(weightDecay))
throw new ArithmeticException("Weight decay must be in [0,1), not " + weightDecay);
this.weightDecay = weightDecay;
} | java | public void setWeightDecay(double weightDecay)
{
if(weightDecay < 0 || weightDecay >= 1 || Double.isNaN(weightDecay))
throw new ArithmeticException("Weight decay must be in [0,1), not " + weightDecay);
this.weightDecay = weightDecay;
} | [
"public",
"void",
"setWeightDecay",
"(",
"double",
"weightDecay",
")",
"{",
"if",
"(",
"weightDecay",
"<",
"0",
"||",
"weightDecay",
">=",
"1",
"||",
"Double",
".",
"isNaN",
"(",
"weightDecay",
")",
")",
"throw",
"new",
"ArithmeticException",
"(",
"\"Weight ... | Sets the weight decay used for each update. The weight decay must be in
the range [0, 1). Weight decay values must often be very small, often
1e-8 or less.
@param weightDecay the weight decay to apply when training | [
"Sets",
"the",
"weight",
"decay",
"used",
"for",
"each",
"update",
".",
"The",
"weight",
"decay",
"must",
"be",
"in",
"the",
"range",
"[",
"0",
"1",
")",
".",
"Weight",
"decay",
"values",
"must",
"often",
"be",
"very",
"small",
"often",
"1e",
"-",
"8... | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L397-L402 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.setUp | private void setUp(Random rand)
{
Ws = new ArrayList<>(npl.length);
bs = new ArrayList<>(npl.length);
//First Hiden layer takes input raw
DenseMatrix W = new DenseMatrix(npl[0], inputSize);
Vec b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
//Other Hiden Layers Layers
for(int i = 1; i < npl.length; i++)
{
W = new DenseMatrix(npl[i], npl[i-1]);
b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
}
//Output layer
W = new DenseMatrix(outputSize, npl[npl.length-1]);
b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
} | java | private void setUp(Random rand)
{
Ws = new ArrayList<>(npl.length);
bs = new ArrayList<>(npl.length);
//First Hiden layer takes input raw
DenseMatrix W = new DenseMatrix(npl[0], inputSize);
Vec b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
//Other Hiden Layers Layers
for(int i = 1; i < npl.length; i++)
{
W = new DenseMatrix(npl[i], npl[i-1]);
b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
}
//Output layer
W = new DenseMatrix(outputSize, npl[npl.length-1]);
b = new DenseVector(W.rows());
initializeWeights(W, rand);
initializeWeights(b, W.cols(), rand);
Ws.add(W);
bs.add(b);
} | [
"private",
"void",
"setUp",
"(",
"Random",
"rand",
")",
"{",
"Ws",
"=",
"new",
"ArrayList",
"<>",
"(",
"npl",
".",
"length",
")",
";",
"bs",
"=",
"new",
"ArrayList",
"<>",
"(",
"npl",
".",
"length",
")",
";",
"//First Hiden layer takes input raw",
"Dense... | Creates the weights for the hidden layers and output layer
@param rand source of randomness | [
"Creates",
"the",
"weights",
"for",
"the",
"hidden",
"layers",
"and",
"output",
"layer"
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L737-L769 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.computeOutputDelta | private double computeOutputDelta(DataSet dataSet, final int idx, Vec delta_out, Vec a_i, Vec d_i)
{
double error = 0;
if (dataSet instanceof ClassificationDataSet)
{
ClassificationDataSet cds = (ClassificationDataSet) dataSet;
final int ct = cds.getDataPointCategory(idx);
for (int i = 0; i < outputSize; i++)
if (i == ct)
delta_out.set(i, f.max() - targetBump);
else
delta_out.set(i, f.min() + targetBump);
for (int j = 0; j < delta_out.length(); j++)
{
double val = delta_out.get(j);
error += pow((val - a_i.get(j)), 2);
val = -(val - a_i.get(j)) * d_i.get(j);
delta_out.set(j, val);
}
}
else if(dataSet instanceof RegressionDataSet)
{
RegressionDataSet rds = (RegressionDataSet) dataSet;
double val = rds.getTargetValue(idx);
val = f.min()+targetBump + targetMultiplier*(val-targetMin);
error += pow((val - a_i.get(0)), 2);
delta_out.set(0, -(val - a_i.get(0)) * d_i.get(0));
}
else
{
throw new RuntimeException("BUG: please report");
}
return error;
} | java | private double computeOutputDelta(DataSet dataSet, final int idx, Vec delta_out, Vec a_i, Vec d_i)
{
double error = 0;
if (dataSet instanceof ClassificationDataSet)
{
ClassificationDataSet cds = (ClassificationDataSet) dataSet;
final int ct = cds.getDataPointCategory(idx);
for (int i = 0; i < outputSize; i++)
if (i == ct)
delta_out.set(i, f.max() - targetBump);
else
delta_out.set(i, f.min() + targetBump);
for (int j = 0; j < delta_out.length(); j++)
{
double val = delta_out.get(j);
error += pow((val - a_i.get(j)), 2);
val = -(val - a_i.get(j)) * d_i.get(j);
delta_out.set(j, val);
}
}
else if(dataSet instanceof RegressionDataSet)
{
RegressionDataSet rds = (RegressionDataSet) dataSet;
double val = rds.getTargetValue(idx);
val = f.min()+targetBump + targetMultiplier*(val-targetMin);
error += pow((val - a_i.get(0)), 2);
delta_out.set(0, -(val - a_i.get(0)) * d_i.get(0));
}
else
{
throw new RuntimeException("BUG: please report");
}
return error;
} | [
"private",
"double",
"computeOutputDelta",
"(",
"DataSet",
"dataSet",
",",
"final",
"int",
"idx",
",",
"Vec",
"delta_out",
",",
"Vec",
"a_i",
",",
"Vec",
"d_i",
")",
"{",
"double",
"error",
"=",
"0",
";",
"if",
"(",
"dataSet",
"instanceof",
"Classification... | Computes the delta between the networks output for a same and its true value
@param dataSet the data set we are learning from
@param idx the index into the data set for the current data point
@param delta_out the place to store the delta, may already be initialized with random noise
@param a_i the activation of the final output layer for the data point
@param d_i the derivative of the activation of the final output layer
@return the error that occurred in predicting this data point | [
"Computes",
"the",
"delta",
"between",
"the",
"networks",
"output",
"for",
"a",
"same",
"and",
"its",
"true",
"value"
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L780-L816 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.feedForward | private void feedForward(Vec input, List<Vec> activations, List<Vec> derivatives)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = activations.get(i);
a_i.zeroOut();
W_i.multiply(x, 1, a_i);
a_i.mutableAdd(b_i);
a_i.applyFunction(f);
Vec d_i = derivatives.get(i);
a_i.copyTo(d_i);
d_i.applyFunction(f.getD());
x = a_i;
}
} | java | private void feedForward(Vec input, List<Vec> activations, List<Vec> derivatives)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = activations.get(i);
a_i.zeroOut();
W_i.multiply(x, 1, a_i);
a_i.mutableAdd(b_i);
a_i.applyFunction(f);
Vec d_i = derivatives.get(i);
a_i.copyTo(d_i);
d_i.applyFunction(f.getD());
x = a_i;
}
} | [
"private",
"void",
"feedForward",
"(",
"Vec",
"input",
",",
"List",
"<",
"Vec",
">",
"activations",
",",
"List",
"<",
"Vec",
">",
"derivatives",
")",
"{",
"Vec",
"x",
"=",
"input",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Ws",
".",
... | Feeds a vector through the network to get an output
@param input the input to feed forward though the network
@param activations the list of allocated vectors to store the activation
outputs for each layer
@param derivatives the list of allocated vectors to store the derivatives
of the activations | [
"Feeds",
"a",
"vector",
"through",
"the",
"network",
"to",
"get",
"an",
"output"
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L826-L847 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java | BackPropagationNet.feedForward | private Vec feedForward(Vec input)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = W_i.multiply(x);
a_i.mutableAdd(b_i);
a_i.applyFunction(f);
x = a_i;
}
return x;
} | java | private Vec feedForward(Vec input)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = W_i.multiply(x);
a_i.mutableAdd(b_i);
a_i.applyFunction(f);
x = a_i;
}
return x;
} | [
"private",
"Vec",
"feedForward",
"(",
"Vec",
"input",
")",
"{",
"Vec",
"x",
"=",
"input",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"Ws",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"Matrix",
"W_i",
"=",
"Ws",
".",
"get",
"... | Feeds an input through the network
@param inputthe input vector to feed in
@return the output vector for the given input at the final layer | [
"Feeds",
"an",
"input",
"through",
"the",
"network"
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/neuralnetwork/BackPropagationNet.java#L854-L871 | train |
EdwardRaff/JSAT | JSAT/src/jsat/classifiers/svm/PegasosK.java | PegasosK.setRegularization | public void setRegularization(double regularization)
{
if(Double.isNaN(regularization) || Double.isInfinite(regularization) || regularization <= 0)
throw new ArithmeticException("Regularization must be a positive constant, not " + regularization);
this.regularization = regularization;
} | java | public void setRegularization(double regularization)
{
if(Double.isNaN(regularization) || Double.isInfinite(regularization) || regularization <= 0)
throw new ArithmeticException("Regularization must be a positive constant, not " + regularization);
this.regularization = regularization;
} | [
"public",
"void",
"setRegularization",
"(",
"double",
"regularization",
")",
"{",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"regularization",
")",
"||",
"Double",
".",
"isInfinite",
"(",
"regularization",
")",
"||",
"regularization",
"<=",
"0",
")",
"throw",
"... | Sets the amount of regularization to apply. The regularization must be a
positive value
@param regularization the amount of regularization to apply | [
"Sets",
"the",
"amount",
"of",
"regularization",
"to",
"apply",
".",
"The",
"regularization",
"must",
"be",
"a",
"positive",
"value"
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/svm/PegasosK.java#L107-L112 | train |
EdwardRaff/JSAT | JSAT/src/jsat/linear/EigenValueDecomposition.java | EigenValueDecomposition.sortByEigenValue | public void sortByEigenValue(Comparator<Double> cmp)
{
if(isComplex())
throw new ArithmeticException("Eigen values can not be sorted due to complex results");
IndexTable it = new IndexTable(DoubleList.unmodifiableView(d, d.length), cmp);
for(int i = 0; i < d.length; i++)
{
RowColumnOps.swapCol(V, i, it.index(i));
double tmp = d[i];
d[i] = d[it.index(i)];
d[it.index(i)] = tmp;
it.swap(i, it.index(i));
}
} | java | public void sortByEigenValue(Comparator<Double> cmp)
{
if(isComplex())
throw new ArithmeticException("Eigen values can not be sorted due to complex results");
IndexTable it = new IndexTable(DoubleList.unmodifiableView(d, d.length), cmp);
for(int i = 0; i < d.length; i++)
{
RowColumnOps.swapCol(V, i, it.index(i));
double tmp = d[i];
d[i] = d[it.index(i)];
d[it.index(i)] = tmp;
it.swap(i, it.index(i));
}
} | [
"public",
"void",
"sortByEigenValue",
"(",
"Comparator",
"<",
"Double",
">",
"cmp",
")",
"{",
"if",
"(",
"isComplex",
"(",
")",
")",
"throw",
"new",
"ArithmeticException",
"(",
"\"Eigen values can not be sorted due to complex results\"",
")",
";",
"IndexTable",
"it"... | Sorts the eigen values and the corresponding eigenvector columns by the
associated eigen value. Sorting can not occur if complex values are
present.
@param cmp the comparator to use to sort the eigen values | [
"Sorts",
"the",
"eigen",
"values",
"and",
"the",
"corresponding",
"eigenvector",
"columns",
"by",
"the",
"associated",
"eigen",
"value",
".",
"Sorting",
"can",
"not",
"occur",
"if",
"complex",
"values",
"are",
"present",
"."
] | 0ff53b7b39684b2379cc1da522f5b3a954b15cfb | https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/linear/EigenValueDecomposition.java#L692-L708 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.