id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
10,400
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java
PartnerAccountService.create
public Optional<PartnerAccount> create(long partnerId, PartnerAccount account) { return HTTP.POST(String.format("/v2/partners/%d/accounts", partnerId), account, PARTNER_ACCOUNT); }
java
public Optional<PartnerAccount> create(long partnerId, PartnerAccount account) { return HTTP.POST(String.format("/v2/partners/%d/accounts", partnerId), account, PARTNER_ACCOUNT); }
[ "public", "Optional", "<", "PartnerAccount", ">", "create", "(", "long", "partnerId", ",", "PartnerAccount", "account", ")", "{", "return", "HTTP", ".", "POST", "(", "String", ".", "format", "(", "\"/v2/partners/%d/accounts\"", ",", "partnerId", ")", ",", "account", ",", "PARTNER_ACCOUNT", ")", ";", "}" ]
Creates the given account. @param partnerId The id of the partner the account belongs to @param account The account to create @return The account that was created
[ "Creates", "the", "given", "account", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java#L68-L71
10,401
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java
PartnerAccountService.update
public Optional<PartnerAccount> update(long partnerId, PartnerAccount account) { return HTTP.PUT(String.format("/v2/partners/%d/accounts/%d", partnerId, account.getId()), account, PARTNER_ACCOUNT); }
java
public Optional<PartnerAccount> update(long partnerId, PartnerAccount account) { return HTTP.PUT(String.format("/v2/partners/%d/accounts/%d", partnerId, account.getId()), account, PARTNER_ACCOUNT); }
[ "public", "Optional", "<", "PartnerAccount", ">", "update", "(", "long", "partnerId", ",", "PartnerAccount", "account", ")", "{", "return", "HTTP", ".", "PUT", "(", "String", ".", "format", "(", "\"/v2/partners/%d/accounts/%d\"", ",", "partnerId", ",", "account", ".", "getId", "(", ")", ")", ",", "account", ",", "PARTNER_ACCOUNT", ")", ";", "}" ]
Updates the given account. @param partnerId The id of the partner the account belongs to @param account The account to update @return The account that was updated
[ "Updates", "the", "given", "account", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java#L79-L82
10,402
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java
PartnerAccountService.delete
public PartnerAccountService delete(long partnerId, long accountId) { HTTP.DELETE(String.format("/v2/partners/%d/accounts/%d", partnerId, accountId)); return this; }
java
public PartnerAccountService delete(long partnerId, long accountId) { HTTP.DELETE(String.format("/v2/partners/%d/accounts/%d", partnerId, accountId)); return this; }
[ "public", "PartnerAccountService", "delete", "(", "long", "partnerId", ",", "long", "accountId", ")", "{", "HTTP", ".", "DELETE", "(", "String", ".", "format", "(", "\"/v2/partners/%d/accounts/%d\"", ",", "partnerId", ",", "accountId", ")", ")", ";", "return", "this", ";", "}" ]
Deletes the account with the given id. @param partnerId The id of the partner the account belongs to @param accountId The id of the account to delete @return This object
[ "Deletes", "the", "account", "with", "the", "given", "id", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/PartnerAccountService.java#L90-L94
10,403
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java
GsonMessageBodyHandler.writeTo
@Override public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { OutputStreamWriter outputStreamWriter = null; try { outputStreamWriter = new OutputStreamWriter(entityStream, CHARSET); Type jsonType = getAppropriateType(type, genericType); String json = getGson().toJson(object, jsonType); if(logger.isLoggable(Level.FINE)) logger.fine("Outgoing JSON Entity: "+json); getGson().toJson(object, jsonType, outputStreamWriter); } finally { if(outputStreamWriter != null) outputStreamWriter.close(); } }
java
@Override public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { OutputStreamWriter outputStreamWriter = null; try { outputStreamWriter = new OutputStreamWriter(entityStream, CHARSET); Type jsonType = getAppropriateType(type, genericType); String json = getGson().toJson(object, jsonType); if(logger.isLoggable(Level.FINE)) logger.fine("Outgoing JSON Entity: "+json); getGson().toJson(object, jsonType, outputStreamWriter); } finally { if(outputStreamWriter != null) outputStreamWriter.close(); } }
[ "@", "Override", "public", "void", "writeTo", "(", "Object", "object", ",", "Class", "<", "?", ">", "type", ",", "Type", "genericType", ",", "Annotation", "[", "]", "annotations", ",", "MediaType", "mediaType", ",", "MultivaluedMap", "<", "String", ",", "Object", ">", "httpHeaders", ",", "OutputStream", "entityStream", ")", "throws", "IOException", ",", "WebApplicationException", "{", "OutputStreamWriter", "outputStreamWriter", "=", "null", ";", "try", "{", "outputStreamWriter", "=", "new", "OutputStreamWriter", "(", "entityStream", ",", "CHARSET", ")", ";", "Type", "jsonType", "=", "getAppropriateType", "(", "type", ",", "genericType", ")", ";", "String", "json", "=", "getGson", "(", ")", ".", "toJson", "(", "object", ",", "jsonType", ")", ";", "if", "(", "logger", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "logger", ".", "fine", "(", "\"Outgoing JSON Entity: \"", "+", "json", ")", ";", "getGson", "(", ")", ".", "toJson", "(", "object", ",", "jsonType", ",", "outputStreamWriter", ")", ";", "}", "finally", "{", "if", "(", "outputStreamWriter", "!=", "null", ")", "outputStreamWriter", ".", "close", "(", ")", ";", "}", "}" ]
Write a type to a HTTP message. @param object The instance to write @param type The class of instance that is to be written @param genericType The type of instance to be written @param annotations An array of the annotations attached to the message entity instance @param mediaType The media type of the HTTP entity @param httpHeaders A mutable map of the HTTP message headers @param entityStream the OutputStream for the HTTP entity
[ "Write", "a", "type", "to", "a", "HTTP", "message", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java#L325-L346
10,404
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java
GsonMessageBodyHandler.readFrom
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException, WebApplicationException { String json = null; Object result = null; InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(inputStream, CHARSET); Type jsonType = getAppropriateType(type, genericType); json = getStringFromInputStream(inputStream); if(logger.isLoggable(Level.FINE)) logger.fine("Incoming JSON Entity: "+json); result = getGson().fromJson(json, jsonType); } catch(JsonSyntaxException e) { logger.severe("Error in Incoming JSON Entity: "+json); } finally { if(inputStreamReader != null) inputStreamReader.close(); } return result; }
java
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream inputStream) throws IOException, WebApplicationException { String json = null; Object result = null; InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(inputStream, CHARSET); Type jsonType = getAppropriateType(type, genericType); json = getStringFromInputStream(inputStream); if(logger.isLoggable(Level.FINE)) logger.fine("Incoming JSON Entity: "+json); result = getGson().fromJson(json, jsonType); } catch(JsonSyntaxException e) { logger.severe("Error in Incoming JSON Entity: "+json); } finally { if(inputStreamReader != null) inputStreamReader.close(); } return result; }
[ "@", "Override", "public", "Object", "readFrom", "(", "Class", "<", "Object", ">", "type", ",", "Type", "genericType", ",", "Annotation", "[", "]", "annotations", ",", "MediaType", "mediaType", ",", "MultivaluedMap", "<", "String", ",", "String", ">", "httpHeaders", ",", "InputStream", "inputStream", ")", "throws", "IOException", ",", "WebApplicationException", "{", "String", "json", "=", "null", ";", "Object", "result", "=", "null", ";", "InputStreamReader", "inputStreamReader", "=", "null", ";", "try", "{", "inputStreamReader", "=", "new", "InputStreamReader", "(", "inputStream", ",", "CHARSET", ")", ";", "Type", "jsonType", "=", "getAppropriateType", "(", "type", ",", "genericType", ")", ";", "json", "=", "getStringFromInputStream", "(", "inputStream", ")", ";", "if", "(", "logger", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "logger", ".", "fine", "(", "\"Incoming JSON Entity: \"", "+", "json", ")", ";", "result", "=", "getGson", "(", ")", ".", "fromJson", "(", "json", ",", "jsonType", ")", ";", "}", "catch", "(", "JsonSyntaxException", "e", ")", "{", "logger", ".", "severe", "(", "\"Error in Incoming JSON Entity: \"", "+", "json", ")", ";", "}", "finally", "{", "if", "(", "inputStreamReader", "!=", "null", ")", "inputStreamReader", ".", "close", "(", ")", ";", "}", "return", "result", ";", "}" ]
Read a type from the InputStream. @param type The type that is to be read from the entity stream @param genericType The type of instance to be produced @param annotations An array of the annotations on the declaration of the artifact that will be initialized with the produced instance @param mediaType The media type of the HTTP entity, if one is not specified in the request then application/octet-stream is used @param httpHeaders The read-only HTTP headers associated with HTTP entity @param inputStream The InputStream of the HTTP entity @return The type that was read from the stream
[ "Read", "a", "type", "from", "the", "InputStream", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java#L358-L387
10,405
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java
GsonMessageBodyHandler.getAppropriateType
private Type getAppropriateType(Class<?> type, Type genericType) { return type.equals(genericType) ? type : genericType; }
java
private Type getAppropriateType(Class<?> type, Type genericType) { return type.equals(genericType) ? type : genericType; }
[ "private", "Type", "getAppropriateType", "(", "Class", "<", "?", ">", "type", ",", "Type", "genericType", ")", "{", "return", "type", ".", "equals", "(", "genericType", ")", "?", "type", ":", "genericType", ";", "}" ]
Returns the type of the given class. @param type The class to get the type for @param genericType The type to use if the input class is a generic type @return The type of the given class
[ "Returns", "the", "type", "of", "the", "given", "class", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java#L395-L398
10,406
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java
GsonMessageBodyHandler.getStringFromInputStream
private static String getStringFromInputStream(InputStream is) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(is)); while((line = br.readLine()) != null) { sb.append(line); } } catch(IOException e) { logger.severe("Unable to get string from stream: "+e.getClass().getName()+": "+e.getMessage()); } finally { try { if(br != null) br.close(); } catch(IOException e) { } } return sb.toString(); }
java
private static String getStringFromInputStream(InputStream is) { BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line; try { br = new BufferedReader(new InputStreamReader(is)); while((line = br.readLine()) != null) { sb.append(line); } } catch(IOException e) { logger.severe("Unable to get string from stream: "+e.getClass().getName()+": "+e.getMessage()); } finally { try { if(br != null) br.close(); } catch(IOException e) { } } return sb.toString(); }
[ "private", "static", "String", "getStringFromInputStream", "(", "InputStream", "is", ")", "{", "BufferedReader", "br", "=", "null", ";", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "String", "line", ";", "try", "{", "br", "=", "new", "BufferedReader", "(", "new", "InputStreamReader", "(", "is", ")", ")", ";", "while", "(", "(", "line", "=", "br", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "sb", ".", "append", "(", "line", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "logger", ".", "severe", "(", "\"Unable to get string from stream: \"", "+", "e", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "}", "finally", "{", "try", "{", "if", "(", "br", "!=", "null", ")", "br", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "}", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Extracts the string from the given input stream. @param is The input stream @return The string extracted
[ "Extracts", "the", "string", "from", "the", "given", "input", "stream", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/httpclient/GsonMessageBodyHandler.java#L405-L437
10,407
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/httpclient/filters/LicenseKeyFilter.java
LicenseKeyFilter.filter
public void filter(ClientRequestContext request) throws IOException { if(!request.getHeaders().containsKey("X-License-Key")) request.getHeaders().add("X-License-Key", this.licensekey); }
java
public void filter(ClientRequestContext request) throws IOException { if(!request.getHeaders().containsKey("X-License-Key")) request.getHeaders().add("X-License-Key", this.licensekey); }
[ "public", "void", "filter", "(", "ClientRequestContext", "request", ")", "throws", "IOException", "{", "if", "(", "!", "request", ".", "getHeaders", "(", ")", ".", "containsKey", "(", "\"X-License-Key\"", ")", ")", "request", ".", "getHeaders", "(", ")", ".", "add", "(", "\"X-License-Key\"", ",", "this", ".", "licensekey", ")", ";", "}" ]
Adds the License key to the client request. @param request The client request
[ "Adds", "the", "License", "key", "to", "the", "client", "request", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/httpclient/filters/LicenseKeyFilter.java#L45-L49
10,408
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/model/alerts/conditions/MetricCondition.java
MetricCondition.getEntitiesArray
public long[] getEntitiesArray() { long[] ret = new long[entities.size()]; for(int i = 0; i < entities.size(); i++) ret[i] = entities.get(i); return ret; }
java
public long[] getEntitiesArray() { long[] ret = new long[entities.size()]; for(int i = 0; i < entities.size(); i++) ret[i] = entities.get(i); return ret; }
[ "public", "long", "[", "]", "getEntitiesArray", "(", ")", "{", "long", "[", "]", "ret", "=", "new", "long", "[", "entities", ".", "size", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "entities", ".", "size", "(", ")", ";", "i", "++", ")", "ret", "[", "i", "]", "=", "entities", ".", "get", "(", "i", ")", ";", "return", "ret", ";", "}" ]
Returns the array of entities for the condition. @return The array of entities
[ "Returns", "the", "array", "of", "entities", "for", "the", "condition", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/model/alerts/conditions/MetricCondition.java#L101-L107
10,409
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/model/insights/Filter.java
Filter.addEventType
public void addEventType(String eventType) { if(this.eventTypes == null) this.eventTypes = new ArrayList<String>(); this.eventTypes.add(eventType); }
java
public void addEventType(String eventType) { if(this.eventTypes == null) this.eventTypes = new ArrayList<String>(); this.eventTypes.add(eventType); }
[ "public", "void", "addEventType", "(", "String", "eventType", ")", "{", "if", "(", "this", ".", "eventTypes", "==", "null", ")", "this", ".", "eventTypes", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "this", ".", "eventTypes", ".", "add", "(", "eventType", ")", ";", "}" ]
Adds an event type to the dashboard filter. @param eventType The event type to add to the dashboard filter
[ "Adds", "an", "event", "type", "to", "the", "dashboard", "filter", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/model/insights/Filter.java#L68-L73
10,410
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/model/insights/Filter.java
Filter.addAttribute
public void addAttribute(String attribute) { if(this.attributes == null) this.attributes = new ArrayList<String>(); this.attributes.add(attribute); }
java
public void addAttribute(String attribute) { if(this.attributes == null) this.attributes = new ArrayList<String>(); this.attributes.add(attribute); }
[ "public", "void", "addAttribute", "(", "String", "attribute", ")", "{", "if", "(", "this", ".", "attributes", "==", "null", ")", "this", ".", "attributes", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "this", ".", "attributes", ".", "add", "(", "attribute", ")", ";", "}" ]
Adds an attribute to the dashboard filter. @param attribute The attribute to add to the dashboard filter
[ "Adds", "an", "attribute", "to", "the", "dashboard", "filter", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/model/insights/Filter.java#L97-L102
10,411
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getAttributeBoolean
public boolean getAttributeBoolean(ScoreAttribute sa) { if (!(sa.getDefaultValue() instanceof Boolean)) throw new RuntimeException(sa.toString() + " is not a boolean attribute"); return (Boolean) getAttributeObject(sa); }
java
public boolean getAttributeBoolean(ScoreAttribute sa) { if (!(sa.getDefaultValue() instanceof Boolean)) throw new RuntimeException(sa.toString() + " is not a boolean attribute"); return (Boolean) getAttributeObject(sa); }
[ "public", "boolean", "getAttributeBoolean", "(", "ScoreAttribute", "sa", ")", "{", "if", "(", "!", "(", "sa", ".", "getDefaultValue", "(", ")", "instanceof", "Boolean", ")", ")", "throw", "new", "RuntimeException", "(", "sa", ".", "toString", "(", ")", "+", "\" is not a boolean attribute\"", ")", ";", "return", "(", "Boolean", ")", "getAttributeObject", "(", "sa", ")", ";", "}" ]
Returns the boolean value associated to an attribute @throws RuntimeException if sa doesn't accept boolean value
[ "Returns", "the", "boolean", "value", "associated", "to", "an", "attribute" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L244-L249
10,412
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getAttributeNumber
public double getAttributeNumber(ScoreAttribute sa) { if (!(sa.getDefaultValue() instanceof Number)) throw new RuntimeException(sa.toString() + " is not a number attribute"); return ((Number) getAttributeObject(sa)).doubleValue(); }
java
public double getAttributeNumber(ScoreAttribute sa) { if (!(sa.getDefaultValue() instanceof Number)) throw new RuntimeException(sa.toString() + " is not a number attribute"); return ((Number) getAttributeObject(sa)).doubleValue(); }
[ "public", "double", "getAttributeNumber", "(", "ScoreAttribute", "sa", ")", "{", "if", "(", "!", "(", "sa", ".", "getDefaultValue", "(", ")", "instanceof", "Number", ")", ")", "throw", "new", "RuntimeException", "(", "sa", ".", "toString", "(", ")", "+", "\" is not a number attribute\"", ")", ";", "return", "(", "(", "Number", ")", "getAttributeObject", "(", "sa", ")", ")", ".", "doubleValue", "(", ")", ";", "}" ]
Returns the number value associated to an attribute, as a double. @throws RuntimeException if sa doesn't accept boolean value
[ "Returns", "the", "number", "value", "associated", "to", "an", "attribute", "as", "a", "double", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L257-L262
10,413
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getAttributeObject
public Object getAttributeObject(ScoreAttribute sa) { Object ret = m_attributes.get(sa.getName()); if (ret == null) ret = sa.getDefaultValue(); return ret; }
java
public Object getAttributeObject(ScoreAttribute sa) { Object ret = m_attributes.get(sa.getName()); if (ret == null) ret = sa.getDefaultValue(); return ret; }
[ "public", "Object", "getAttributeObject", "(", "ScoreAttribute", "sa", ")", "{", "Object", "ret", "=", "m_attributes", ".", "get", "(", "sa", ".", "getName", "(", ")", ")", ";", "if", "(", "ret", "==", "null", ")", "ret", "=", "sa", ".", "getDefaultValue", "(", ")", ";", "return", "ret", ";", "}" ]
Returns the object associated to an attribute @return an object or <TT>null</TT> if attribute has not been defined. @see #getAttributeSize(ScoreAttribute)
[ "Returns", "the", "object", "associated", "to", "an", "attribute" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L270-L275
10,414
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getAttributeSize
public float getAttributeSize(ScoreAttribute sa) throws AttributeNotDefinedException, RuntimeException { if (!(sa.getDefaultValue() instanceof ScoreAttribute.Size)) throw new RuntimeException(sa.toString() + " is not a size attribute"); ScoreAttribute.Size s = (ScoreAttribute.Size) getAttributeObject(sa); if (s == null) throw new AttributeNotDefinedException(sa); SizeUnit u = s.getUnit(); float size = s.getSize(); if ((u.equals(SizeUnit.PX)) || (u.equals(SizeUnit.PT))) { return size; } else if (u.equals(SizeUnit.NOTE_HEIGHT)) { return (float) (size * getMetrics().getNoteHeight()); } else if (u.equals(SizeUnit.NOTE_WIDTH)) { return (float) (size * getMetrics().getNoteWidth()); } else if (u.equals(SizeUnit.GRACENOTE_HEIGHT)) { return (float) (size * getMetrics().getGraceNoteHeight()); } else if (u.equals(SizeUnit.GRACENOTE_WIDTH)) { return (float) (size * getMetrics().getGraceNoteWidth()); } else if (u.equals(SizeUnit.STAFF_HEIGHT)) { return (float) (size * getMetrics().getStaffCharBounds() .getHeight()); } else if (u.equals(SizeUnit.STAFF_WIDTH)) { return (float) (size * getMetrics().getStaffCharBounds() .getWidth()); } else if (u.equals(SizeUnit.PERCENT)) { return size/100 * getAttributeSize(ScoreAttribute.NOTATION_SIZE); } else throw new RuntimeException("unknown size unit for attribute: " + sa.toString()); }
java
public float getAttributeSize(ScoreAttribute sa) throws AttributeNotDefinedException, RuntimeException { if (!(sa.getDefaultValue() instanceof ScoreAttribute.Size)) throw new RuntimeException(sa.toString() + " is not a size attribute"); ScoreAttribute.Size s = (ScoreAttribute.Size) getAttributeObject(sa); if (s == null) throw new AttributeNotDefinedException(sa); SizeUnit u = s.getUnit(); float size = s.getSize(); if ((u.equals(SizeUnit.PX)) || (u.equals(SizeUnit.PT))) { return size; } else if (u.equals(SizeUnit.NOTE_HEIGHT)) { return (float) (size * getMetrics().getNoteHeight()); } else if (u.equals(SizeUnit.NOTE_WIDTH)) { return (float) (size * getMetrics().getNoteWidth()); } else if (u.equals(SizeUnit.GRACENOTE_HEIGHT)) { return (float) (size * getMetrics().getGraceNoteHeight()); } else if (u.equals(SizeUnit.GRACENOTE_WIDTH)) { return (float) (size * getMetrics().getGraceNoteWidth()); } else if (u.equals(SizeUnit.STAFF_HEIGHT)) { return (float) (size * getMetrics().getStaffCharBounds() .getHeight()); } else if (u.equals(SizeUnit.STAFF_WIDTH)) { return (float) (size * getMetrics().getStaffCharBounds() .getWidth()); } else if (u.equals(SizeUnit.PERCENT)) { return size/100 * getAttributeSize(ScoreAttribute.NOTATION_SIZE); } else throw new RuntimeException("unknown size unit for attribute: " + sa.toString()); }
[ "public", "float", "getAttributeSize", "(", "ScoreAttribute", "sa", ")", "throws", "AttributeNotDefinedException", ",", "RuntimeException", "{", "if", "(", "!", "(", "sa", ".", "getDefaultValue", "(", ")", "instanceof", "ScoreAttribute", ".", "Size", ")", ")", "throw", "new", "RuntimeException", "(", "sa", ".", "toString", "(", ")", "+", "\" is not a size attribute\"", ")", ";", "ScoreAttribute", ".", "Size", "s", "=", "(", "ScoreAttribute", ".", "Size", ")", "getAttributeObject", "(", "sa", ")", ";", "if", "(", "s", "==", "null", ")", "throw", "new", "AttributeNotDefinedException", "(", "sa", ")", ";", "SizeUnit", "u", "=", "s", ".", "getUnit", "(", ")", ";", "float", "size", "=", "s", ".", "getSize", "(", ")", ";", "if", "(", "(", "u", ".", "equals", "(", "SizeUnit", ".", "PX", ")", ")", "||", "(", "u", ".", "equals", "(", "SizeUnit", ".", "PT", ")", ")", ")", "{", "return", "size", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "NOTE_HEIGHT", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getNoteHeight", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "NOTE_WIDTH", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getNoteWidth", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "GRACENOTE_HEIGHT", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getGraceNoteHeight", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "GRACENOTE_WIDTH", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getGraceNoteWidth", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "STAFF_HEIGHT", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getStaffCharBounds", "(", ")", ".", "getHeight", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "STAFF_WIDTH", ")", ")", "{", "return", "(", "float", ")", "(", "size", "*", "getMetrics", "(", ")", ".", "getStaffCharBounds", "(", ")", ".", "getWidth", "(", ")", ")", ";", "}", "else", "if", "(", "u", ".", "equals", "(", "SizeUnit", ".", "PERCENT", ")", ")", "{", "return", "size", "/", "100", "*", "getAttributeSize", "(", "ScoreAttribute", ".", "NOTATION_SIZE", ")", ";", "}", "else", "throw", "new", "RuntimeException", "(", "\"unknown size unit for attribute: \"", "+", "sa", ".", "toString", "(", ")", ")", ";", "}" ]
Gets the size of an attribute, calculated from score metrics if needed. @return a float value @throws AttributeNotDefinedException if attribute has not been defined in the template @throws RuntimeException if size unit is unknown or attribute doesn't accept size value
[ "Gets", "the", "size", "of", "an", "attribute", "calculated", "from", "score", "metrics", "if", "needed", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L319-L350
10,415
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getDefaultTextSize
public float getDefaultTextSize() { ScoreAttribute.Size s = (ScoreAttribute.Size) getAttributeObject(ScoreAttribute.TEXT_DEFAULT_SIZE); if (s.getUnit().equals(SizeUnit.PT)) return s.getSize(); else { //% of notation size return (s.getSize()/100f) * getAttributeSize(ScoreAttribute.NOTATION_SIZE); } }
java
public float getDefaultTextSize() { ScoreAttribute.Size s = (ScoreAttribute.Size) getAttributeObject(ScoreAttribute.TEXT_DEFAULT_SIZE); if (s.getUnit().equals(SizeUnit.PT)) return s.getSize(); else { //% of notation size return (s.getSize()/100f) * getAttributeSize(ScoreAttribute.NOTATION_SIZE); } }
[ "public", "float", "getDefaultTextSize", "(", ")", "{", "ScoreAttribute", ".", "Size", "s", "=", "(", "ScoreAttribute", ".", "Size", ")", "getAttributeObject", "(", "ScoreAttribute", ".", "TEXT_DEFAULT_SIZE", ")", ";", "if", "(", "s", ".", "getUnit", "(", ")", ".", "equals", "(", "SizeUnit", ".", "PT", ")", ")", "return", "s", ".", "getSize", "(", ")", ";", "else", "{", "//% of notation size\r", "return", "(", "s", ".", "getSize", "(", ")", "/", "100f", ")", "*", "getAttributeSize", "(", "ScoreAttribute", ".", "NOTATION_SIZE", ")", ";", "}", "}" ]
Returns the default text size in pt. if text size is expressed in percent, all font sizes will be calculated from default font size.
[ "Returns", "the", "default", "text", "size", "in", "pt", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L370-L380
10,416
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getElementColor
public Color getElementColor(byte scoreElement) { Object ret = m_attributes.get("COLOR_"+Byte.toString(scoreElement)); if (ret == null) { ret = m_attributes.get("COLOR_"+Byte.toString(ScoreElements._DEFAULT)); if (ret == null) return null; //No default color set } return (Color) ret; }
java
public Color getElementColor(byte scoreElement) { Object ret = m_attributes.get("COLOR_"+Byte.toString(scoreElement)); if (ret == null) { ret = m_attributes.get("COLOR_"+Byte.toString(ScoreElements._DEFAULT)); if (ret == null) return null; //No default color set } return (Color) ret; }
[ "public", "Color", "getElementColor", "(", "byte", "scoreElement", ")", "{", "Object", "ret", "=", "m_attributes", ".", "get", "(", "\"COLOR_\"", "+", "Byte", ".", "toString", "(", "scoreElement", ")", ")", ";", "if", "(", "ret", "==", "null", ")", "{", "ret", "=", "m_attributes", ".", "get", "(", "\"COLOR_\"", "+", "Byte", ".", "toString", "(", "ScoreElements", ".", "_DEFAULT", ")", ")", ";", "if", "(", "ret", "==", "null", ")", "return", "null", ";", "//No default color set\r", "}", "return", "(", "Color", ")", "ret", ";", "}" ]
Returns the color of the given element @param scoreElement One of the {@link ScoreElements} constant @return a Color object, or <TT>null</TT> if no default color has been set.
[ "Returns", "the", "color", "of", "the", "given", "element" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L388-L396
10,417
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getFieldsAtPosition
public byte[] getFieldsAtPosition(byte vert, byte horiz) { Position p = new Position(vert, horiz); if (m_fieldsPosition.get(p) != null) { Vector v = (Vector) m_fieldsPosition.get(p); Vector ret = new Vector(v.size()); for (Object aV : v) { byte field = (Byte) aV; if (isVisible(field)) ret.add(field); } byte[] ret2 = new byte[ret.size()]; for (int i = 0; i < ret2.length; i++) { ret2[i] = (Byte) ret.get(i); } return ret2; } return new byte[0]; }
java
public byte[] getFieldsAtPosition(byte vert, byte horiz) { Position p = new Position(vert, horiz); if (m_fieldsPosition.get(p) != null) { Vector v = (Vector) m_fieldsPosition.get(p); Vector ret = new Vector(v.size()); for (Object aV : v) { byte field = (Byte) aV; if (isVisible(field)) ret.add(field); } byte[] ret2 = new byte[ret.size()]; for (int i = 0; i < ret2.length; i++) { ret2[i] = (Byte) ret.get(i); } return ret2; } return new byte[0]; }
[ "public", "byte", "[", "]", "getFieldsAtPosition", "(", "byte", "vert", ",", "byte", "horiz", ")", "{", "Position", "p", "=", "new", "Position", "(", "vert", ",", "horiz", ")", ";", "if", "(", "m_fieldsPosition", ".", "get", "(", "p", ")", "!=", "null", ")", "{", "Vector", "v", "=", "(", "Vector", ")", "m_fieldsPosition", ".", "get", "(", "p", ")", ";", "Vector", "ret", "=", "new", "Vector", "(", "v", ".", "size", "(", ")", ")", ";", "for", "(", "Object", "aV", ":", "v", ")", "{", "byte", "field", "=", "(", "Byte", ")", "aV", ";", "if", "(", "isVisible", "(", "field", ")", ")", "ret", ".", "add", "(", "field", ")", ";", "}", "byte", "[", "]", "ret2", "=", "new", "byte", "[", "ret", ".", "size", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ret2", ".", "length", ";", "i", "++", ")", "{", "ret2", "[", "i", "]", "=", "(", "Byte", ")", "ret", ".", "get", "(", "i", ")", ";", "}", "return", "ret2", ";", "}", "return", "new", "byte", "[", "0", "]", ";", "}" ]
Returns the list of visible fields at the given position @param vert one of {@link VerticalPosition} constants @param horiz one of {@link HorizontalPosition} constants @return array of {@link ScoreElements} constants
[ "Returns", "the", "list", "of", "visible", "fields", "at", "the", "given", "position" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L425-L442
10,418
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getPosition
public byte[] getPosition(byte field) { Iterator it = m_fieldsPosition.keySet().iterator(); Byte B = field; while (it.hasNext()) { Position p = (Position) it.next(); if (((Vector) m_fieldsPosition.get(p)).contains(B)) { return new byte[] { p.m_vertical, p.m_horizontal }; } } if (field != ScoreElements._DEFAULT) { return getPosition(ScoreElements._DEFAULT); } return null; }
java
public byte[] getPosition(byte field) { Iterator it = m_fieldsPosition.keySet().iterator(); Byte B = field; while (it.hasNext()) { Position p = (Position) it.next(); if (((Vector) m_fieldsPosition.get(p)).contains(B)) { return new byte[] { p.m_vertical, p.m_horizontal }; } } if (field != ScoreElements._DEFAULT) { return getPosition(ScoreElements._DEFAULT); } return null; }
[ "public", "byte", "[", "]", "getPosition", "(", "byte", "field", ")", "{", "Iterator", "it", "=", "m_fieldsPosition", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "Byte", "B", "=", "field", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "Position", "p", "=", "(", "Position", ")", "it", ".", "next", "(", ")", ";", "if", "(", "(", "(", "Vector", ")", "m_fieldsPosition", ".", "get", "(", "p", ")", ")", ".", "contains", "(", "B", ")", ")", "{", "return", "new", "byte", "[", "]", "{", "p", ".", "m_vertical", ",", "p", ".", "m_horizontal", "}", ";", "}", "}", "if", "(", "field", "!=", "ScoreElements", ".", "_DEFAULT", ")", "{", "return", "getPosition", "(", "ScoreElements", ".", "_DEFAULT", ")", ";", "}", "return", "null", ";", "}" ]
Returns position of a field @param field one of {@link ScoreElements} constants @return an array of 2 bytes : [VerticalPosition.xxx, HorizontalAlign.xxx] <TT>null</TT> if position has not been defined
[ "Returns", "position", "of", "a", "field" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L507-L520
10,419
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getTextFont
public Font getTextFont(byte field) { FieldInfos fi = getFieldInfos(field); Vector v = new Vector(m_defaultTextFontFamilyNames.length+fi.m_fontFamilyNames.length); Collections.addAll(v, fi.m_fontFamilyNames); Collections.addAll(v, m_defaultTextFontFamilyNames); Iterator it = v.iterator(); Font font = null; String s = ""; int style = getTextStyle(field); int size = (int) getTextSize(field); while (it.hasNext()) { String fontName = (String) it.next(); if (s.length() > 0) s += ", "; s += fontName; if (isFontAvailable(fontName)) { font = new Font(fontName, style, size); break; } } if (font == null) { System.err.println("None of these fonts are available: " + s); font = new Font("Dialog", style, size); } if (fi.m_textAttributes != null) { font = font.deriveFont(fi.m_textAttributes); } return font; }
java
public Font getTextFont(byte field) { FieldInfos fi = getFieldInfos(field); Vector v = new Vector(m_defaultTextFontFamilyNames.length+fi.m_fontFamilyNames.length); Collections.addAll(v, fi.m_fontFamilyNames); Collections.addAll(v, m_defaultTextFontFamilyNames); Iterator it = v.iterator(); Font font = null; String s = ""; int style = getTextStyle(field); int size = (int) getTextSize(field); while (it.hasNext()) { String fontName = (String) it.next(); if (s.length() > 0) s += ", "; s += fontName; if (isFontAvailable(fontName)) { font = new Font(fontName, style, size); break; } } if (font == null) { System.err.println("None of these fonts are available: " + s); font = new Font("Dialog", style, size); } if (fi.m_textAttributes != null) { font = font.deriveFont(fi.m_textAttributes); } return font; }
[ "public", "Font", "getTextFont", "(", "byte", "field", ")", "{", "FieldInfos", "fi", "=", "getFieldInfos", "(", "field", ")", ";", "Vector", "v", "=", "new", "Vector", "(", "m_defaultTextFontFamilyNames", ".", "length", "+", "fi", ".", "m_fontFamilyNames", ".", "length", ")", ";", "Collections", ".", "addAll", "(", "v", ",", "fi", ".", "m_fontFamilyNames", ")", ";", "Collections", ".", "addAll", "(", "v", ",", "m_defaultTextFontFamilyNames", ")", ";", "Iterator", "it", "=", "v", ".", "iterator", "(", ")", ";", "Font", "font", "=", "null", ";", "String", "s", "=", "\"\"", ";", "int", "style", "=", "getTextStyle", "(", "field", ")", ";", "int", "size", "=", "(", "int", ")", "getTextSize", "(", "field", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "String", "fontName", "=", "(", "String", ")", "it", ".", "next", "(", ")", ";", "if", "(", "s", ".", "length", "(", ")", ">", "0", ")", "s", "+=", "\", \"", ";", "s", "+=", "fontName", ";", "if", "(", "isFontAvailable", "(", "fontName", ")", ")", "{", "font", "=", "new", "Font", "(", "fontName", ",", "style", ",", "size", ")", ";", "break", ";", "}", "}", "if", "(", "font", "==", "null", ")", "{", "System", ".", "err", ".", "println", "(", "\"None of these fonts are available: \"", "+", "s", ")", ";", "font", "=", "new", "Font", "(", "\"Dialog\"", ",", "style", ",", "size", ")", ";", "}", "if", "(", "fi", ".", "m_textAttributes", "!=", "null", ")", "{", "font", "=", "font", ".", "deriveFont", "(", "fi", ".", "m_textAttributes", ")", ";", "}", "return", "font", ";", "}" ]
Returns the styled and sized font for a field. @param field one of {@link ScoreElements} constants
[ "Returns", "the", "styled", "and", "sized", "font", "for", "a", "field", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L574-L602
10,420
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.getTextSize
public float getTextSize(byte field) { FieldInfos fi = getFieldInfos(field); if (fi.m_fontSizeUnit.equals(SizeUnit.PT)) return fi.m_fontSize; else return getDefaultTextSize() * (fi.m_fontSize/100f); }
java
public float getTextSize(byte field) { FieldInfos fi = getFieldInfos(field); if (fi.m_fontSizeUnit.equals(SizeUnit.PT)) return fi.m_fontSize; else return getDefaultTextSize() * (fi.m_fontSize/100f); }
[ "public", "float", "getTextSize", "(", "byte", "field", ")", "{", "FieldInfos", "fi", "=", "getFieldInfos", "(", "field", ")", ";", "if", "(", "fi", ".", "m_fontSizeUnit", ".", "equals", "(", "SizeUnit", ".", "PT", ")", ")", "return", "fi", ".", "m_fontSize", ";", "else", "return", "getDefaultTextSize", "(", ")", "*", "(", "fi", ".", "m_fontSize", "/", "100f", ")", ";", "}" ]
Returns the font size of a field, in pt @param field one of {@link ScoreElements} constants
[ "Returns", "the", "font", "size", "of", "a", "field", "in", "pt" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L634-L640
10,421
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setAttribute
public void setAttribute(ScoreAttribute sa, Object value) { if (value == null) m_attributes.remove(sa.getName()); else m_attributes.put(sa.getName(), value); notifyListeners(); }
java
public void setAttribute(ScoreAttribute sa, Object value) { if (value == null) m_attributes.remove(sa.getName()); else m_attributes.put(sa.getName(), value); notifyListeners(); }
[ "public", "void", "setAttribute", "(", "ScoreAttribute", "sa", ",", "Object", "value", ")", "{", "if", "(", "value", "==", "null", ")", "m_attributes", ".", "remove", "(", "sa", ".", "getName", "(", ")", ")", ";", "else", "m_attributes", ".", "put", "(", "sa", ".", "getName", "(", ")", ",", "value", ")", ";", "notifyListeners", "(", ")", ";", "}" ]
Sets the object associated to an attribute @param value <TT>null</TT> to remove this attribute
[ "Sets", "the", "object", "associated", "to", "an", "attribute" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L716-L722
10,422
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setAttributeSize
public void setAttributeSize(ScoreAttribute sa, float size) { m_attributes.put(sa.getName(), new ScoreAttribute.Size(size, ((ScoreAttribute.Size) sa.getDefaultValue()).getUnit())); notifyListeners(); }
java
public void setAttributeSize(ScoreAttribute sa, float size) { m_attributes.put(sa.getName(), new ScoreAttribute.Size(size, ((ScoreAttribute.Size) sa.getDefaultValue()).getUnit())); notifyListeners(); }
[ "public", "void", "setAttributeSize", "(", "ScoreAttribute", "sa", ",", "float", "size", ")", "{", "m_attributes", ".", "put", "(", "sa", ".", "getName", "(", ")", ",", "new", "ScoreAttribute", ".", "Size", "(", "size", ",", "(", "(", "ScoreAttribute", ".", "Size", ")", "sa", ".", "getDefaultValue", "(", ")", ")", ".", "getUnit", "(", ")", ")", ")", ";", "notifyListeners", "(", ")", ";", "}" ]
Sets the size associated to an attribute, using the attribute's default unit
[ "Sets", "the", "size", "associated", "to", "an", "attribute", "using", "the", "attribute", "s", "default", "unit" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L728-L732
10,423
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setAttributeSize
public void setAttributeSize(ScoreAttribute sa, float size, SizeUnit unit) { if (!(sa.getDefaultValue() instanceof ScoreAttribute.Size)) throw new RuntimeException(sa.toString() + " is not a size attribute"); m_attributes.put(sa.getName(), new ScoreAttribute.Size(size, unit)); notifyListeners(); }
java
public void setAttributeSize(ScoreAttribute sa, float size, SizeUnit unit) { if (!(sa.getDefaultValue() instanceof ScoreAttribute.Size)) throw new RuntimeException(sa.toString() + " is not a size attribute"); m_attributes.put(sa.getName(), new ScoreAttribute.Size(size, unit)); notifyListeners(); }
[ "public", "void", "setAttributeSize", "(", "ScoreAttribute", "sa", ",", "float", "size", ",", "SizeUnit", "unit", ")", "{", "if", "(", "!", "(", "sa", ".", "getDefaultValue", "(", ")", "instanceof", "ScoreAttribute", ".", "Size", ")", ")", "throw", "new", "RuntimeException", "(", "sa", ".", "toString", "(", ")", "+", "\" is not a size attribute\"", ")", ";", "m_attributes", ".", "put", "(", "sa", ".", "getName", "(", ")", ",", "new", "ScoreAttribute", ".", "Size", "(", "size", ",", "unit", ")", ")", ";", "notifyListeners", "(", ")", ";", "}" ]
Sets the size associated to an attribute @param unit {@link SizeUnit#PX}, {@link SizeUnit#STAFF_HEIGHT}... @throws RuntimeException if attribute doesn't accept size value
[ "Sets", "the", "size", "associated", "to", "an", "attribute" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L740-L746
10,424
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setDefaultTextFontFamilyName
public void setDefaultTextFontFamilyName(String[] faces) { if ((faces != null) && (faces.length > 0)) m_defaultTextFontFamilyNames = faces; else m_defaultTextFontFamilyNames = new String[] { "Dialog" }; notifyListeners(); }
java
public void setDefaultTextFontFamilyName(String[] faces) { if ((faces != null) && (faces.length > 0)) m_defaultTextFontFamilyNames = faces; else m_defaultTextFontFamilyNames = new String[] { "Dialog" }; notifyListeners(); }
[ "public", "void", "setDefaultTextFontFamilyName", "(", "String", "[", "]", "faces", ")", "{", "if", "(", "(", "faces", "!=", "null", ")", "&&", "(", "faces", ".", "length", ">", "0", ")", ")", "m_defaultTextFontFamilyNames", "=", "faces", ";", "else", "m_defaultTextFontFamilyNames", "=", "new", "String", "[", "]", "{", "\"Dialog\"", "}", ";", "notifyListeners", "(", ")", ";", "}" ]
Set the default font faces, in order of preference. If font face is not set for a field, it will use the first default font face available @param faces e.g. new String[] { "Dialog", "Arial" }
[ "Set", "the", "default", "font", "faces", "in", "order", "of", "preference", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L757-L763
10,425
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setElementColor
public void setElementColor(byte scoreElement, Color color) { String name = "COLOR_"+Byte.toString(scoreElement); if (color == null) m_attributes.remove(name); else m_attributes.put(name, color); notifyListeners(); }
java
public void setElementColor(byte scoreElement, Color color) { String name = "COLOR_"+Byte.toString(scoreElement); if (color == null) m_attributes.remove(name); else m_attributes.put(name, color); notifyListeners(); }
[ "public", "void", "setElementColor", "(", "byte", "scoreElement", ",", "Color", "color", ")", "{", "String", "name", "=", "\"COLOR_\"", "+", "Byte", ".", "toString", "(", "scoreElement", ")", ";", "if", "(", "color", "==", "null", ")", "m_attributes", ".", "remove", "(", "name", ")", ";", "else", "m_attributes", ".", "put", "(", "name", ",", "color", ")", ";", "notifyListeners", "(", ")", ";", "}" ]
Sets the color of the given element type @param scoreElement One of the {@link ScoreElements} constant @param color <TT>null</TT> to remove this attribute
[ "Sets", "the", "color", "of", "the", "given", "element", "type" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L782-L789
10,426
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setPosition
public void setPosition(byte[] fields, byte vert, byte horiz) { for (byte field : fields) { setVisible(field, true); Position p = new Position(vert, horiz); byte[] p1f = getPosition(field); Position p1 = p1f == null ? null : new Position(p1f[0], p1f[1]); // fix HHR if (!p.equals(p1)) { Iterator it = m_fieldsPosition.values().iterator(); Byte B = field; while (it.hasNext()) { Vector v = (Vector) it.next(); if (v.contains(B)) v.remove(B); } //don't know why get(p) doesn't work, p.toString() is ok if (m_fieldsPosition.get(p) == null) m_fieldsPosition.put(p, new Vector()); Vector v = (Vector) m_fieldsPosition.get(p); v.add(B); } } notifyListeners(); }
java
public void setPosition(byte[] fields, byte vert, byte horiz) { for (byte field : fields) { setVisible(field, true); Position p = new Position(vert, horiz); byte[] p1f = getPosition(field); Position p1 = p1f == null ? null : new Position(p1f[0], p1f[1]); // fix HHR if (!p.equals(p1)) { Iterator it = m_fieldsPosition.values().iterator(); Byte B = field; while (it.hasNext()) { Vector v = (Vector) it.next(); if (v.contains(B)) v.remove(B); } //don't know why get(p) doesn't work, p.toString() is ok if (m_fieldsPosition.get(p) == null) m_fieldsPosition.put(p, new Vector()); Vector v = (Vector) m_fieldsPosition.get(p); v.add(B); } } notifyListeners(); }
[ "public", "void", "setPosition", "(", "byte", "[", "]", "fields", ",", "byte", "vert", ",", "byte", "horiz", ")", "{", "for", "(", "byte", "field", ":", "fields", ")", "{", "setVisible", "(", "field", ",", "true", ")", ";", "Position", "p", "=", "new", "Position", "(", "vert", ",", "horiz", ")", ";", "byte", "[", "]", "p1f", "=", "getPosition", "(", "field", ")", ";", "Position", "p1", "=", "p1f", "==", "null", "?", "null", ":", "new", "Position", "(", "p1f", "[", "0", "]", ",", "p1f", "[", "1", "]", ")", ";", "// fix HHR\r", "if", "(", "!", "p", ".", "equals", "(", "p1", ")", ")", "{", "Iterator", "it", "=", "m_fieldsPosition", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "Byte", "B", "=", "field", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "Vector", "v", "=", "(", "Vector", ")", "it", ".", "next", "(", ")", ";", "if", "(", "v", ".", "contains", "(", "B", ")", ")", "v", ".", "remove", "(", "B", ")", ";", "}", "//don't know why get(p) doesn't work, p.toString() is ok\r", "if", "(", "m_fieldsPosition", ".", "get", "(", "p", ")", "==", "null", ")", "m_fieldsPosition", ".", "put", "(", "p", ",", "new", "Vector", "(", ")", ")", ";", "Vector", "v", "=", "(", "Vector", ")", "m_fieldsPosition", ".", "get", "(", "p", ")", ";", "v", ".", "add", "(", "B", ")", ";", "}", "}", "notifyListeners", "(", ")", ";", "}" ]
Sets the position of several fields @param fields array of {@link ScoreElements} constants @param vert one of {@link VerticalPosition} constants @param horiz one of {@link HorizontalPosition} constants
[ "Sets", "the", "position", "of", "several", "fields" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L834-L856
10,427
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setTextAttributes
public void setTextAttributes(byte[] fields, Hashtable attrib) { for (byte field : fields) { getFieldInfos(field).m_textAttributes = attrib; } notifyListeners(); }
java
public void setTextAttributes(byte[] fields, Hashtable attrib) { for (byte field : fields) { getFieldInfos(field).m_textAttributes = attrib; } notifyListeners(); }
[ "public", "void", "setTextAttributes", "(", "byte", "[", "]", "fields", ",", "Hashtable", "attrib", ")", "{", "for", "(", "byte", "field", ":", "fields", ")", "{", "getFieldInfos", "(", "field", ")", ".", "m_textAttributes", "=", "attrib", ";", "}", "notifyListeners", "(", ")", ";", "}" ]
Sets the text attributes of several fields @param fields one of {@link ScoreElements} constants @param attrib Map of attributes @see java.awt.font.TextAttribute
[ "Sets", "the", "text", "attributes", "of", "several", "fields" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L881-L886
10,428
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setTextFontFamilyName
public void setTextFontFamilyName(byte[] fields, String[] fontFamilies) { if (fontFamilies == null) fontFamilies = new String[0]; for (byte field : fields) { getFieldInfos(field).m_fontFamilyNames = fontFamilies; } notifyListeners(); }
java
public void setTextFontFamilyName(byte[] fields, String[] fontFamilies) { if (fontFamilies == null) fontFamilies = new String[0]; for (byte field : fields) { getFieldInfos(field).m_fontFamilyNames = fontFamilies; } notifyListeners(); }
[ "public", "void", "setTextFontFamilyName", "(", "byte", "[", "]", "fields", ",", "String", "[", "]", "fontFamilies", ")", "{", "if", "(", "fontFamilies", "==", "null", ")", "fontFamilies", "=", "new", "String", "[", "0", "]", ";", "for", "(", "byte", "field", ":", "fields", ")", "{", "getFieldInfos", "(", "field", ")", ".", "m_fontFamilyNames", "=", "fontFamilies", ";", "}", "notifyListeners", "(", ")", ";", "}" ]
Sets the font family of several fields @param fields one of {@link ScoreElements} constants @param fontFamilies array of font names, e.g. {"Georgia", "Verdana"}
[ "Sets", "the", "font", "family", "of", "several", "fields" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L911-L918
10,429
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setTextSize
public void setTextSize(byte field, float size, SizeUnit unit) { FieldInfos fi = getFieldInfos(field); fi.m_fontSize = size; fi.m_fontSizeUnit = unit; notifyListeners(); }
java
public void setTextSize(byte field, float size, SizeUnit unit) { FieldInfos fi = getFieldInfos(field); fi.m_fontSize = size; fi.m_fontSizeUnit = unit; notifyListeners(); }
[ "public", "void", "setTextSize", "(", "byte", "field", ",", "float", "size", ",", "SizeUnit", "unit", ")", "{", "FieldInfos", "fi", "=", "getFieldInfos", "(", "field", ")", ";", "fi", ".", "m_fontSize", "=", "size", ";", "fi", ".", "m_fontSizeUnit", "=", "unit", ";", "notifyListeners", "(", ")", ";", "}" ]
Sets the font size of a field @param field one of {@link ScoreElements} constants @param size text size in percent of {@link #getDefaultTextSize()} if {@link #getTextSize(byte)} is {@link SizeUnit#PERCENT}, else in pt @param unit {@link SizeUnit#PERCENT} or {@link SizeUnit#PT}
[ "Sets", "the", "font", "size", "of", "a", "field" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L932-L937
10,430
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setTextStyle
public void setTextStyle(byte[] fields, int style) { for (byte field : fields) { getFieldInfos(field).m_fontStyle = style; } notifyListeners(); }
java
public void setTextStyle(byte[] fields, int style) { for (byte field : fields) { getFieldInfos(field).m_fontStyle = style; } notifyListeners(); }
[ "public", "void", "setTextStyle", "(", "byte", "[", "]", "fields", ",", "int", "style", ")", "{", "for", "(", "byte", "field", ":", "fields", ")", "{", "getFieldInfos", "(", "field", ")", ".", "m_fontStyle", "=", "style", ";", "}", "notifyListeners", "(", ")", ";", "}" ]
Sets the font style of several fields @param fields array of {@link ScoreElements} constants @param style style from Font class : {@link Font#PLAIN}, {@link Font#BOLD}, {@link Font#ITALIC} or Font.BOLD+Font.ITALIC
[ "Sets", "the", "font", "style", "of", "several", "fields" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L1013-L1018
10,431
Sciss/abc4j
abc/src/main/java/abc/ui/swing/ScoreTemplate.java
ScoreTemplate.setVisible
public void setVisible(byte[] fields, boolean visible) { for (byte field : fields) { getFieldInfos(field).m_visible = visible; } notifyListeners(); }
java
public void setVisible(byte[] fields, boolean visible) { for (byte field : fields) { getFieldInfos(field).m_visible = visible; } notifyListeners(); }
[ "public", "void", "setVisible", "(", "byte", "[", "]", "fields", ",", "boolean", "visible", ")", "{", "for", "(", "byte", "field", ":", "fields", ")", "{", "getFieldInfos", "(", "field", ")", ".", "m_visible", "=", "visible", ";", "}", "notifyListeners", "(", ")", ";", "}" ]
Sets the visibility of several fields @param fields array of {@link ScoreElements} constants
[ "Sets", "the", "visibility", "of", "several", "fields" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/ui/swing/ScoreTemplate.java#L1037-L1042
10,432
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/AlertEventService.java
AlertEventService.list
public Collection<AlertEvent> list(List<String> queryParams) { return HTTP.GET("/v2/alerts_events.json", null, queryParams, ALERT_EVENTS).get(); }
java
public Collection<AlertEvent> list(List<String> queryParams) { return HTTP.GET("/v2/alerts_events.json", null, queryParams, ALERT_EVENTS).get(); }
[ "public", "Collection", "<", "AlertEvent", ">", "list", "(", "List", "<", "String", ">", "queryParams", ")", "{", "return", "HTTP", ".", "GET", "(", "\"/v2/alerts_events.json\"", ",", "null", ",", "queryParams", ",", "ALERT_EVENTS", ")", ".", "get", "(", ")", ";", "}" ]
Returns the set of alert events with the given query parameters. @param queryParams The query parameters @return The set of alert events
[ "Returns", "the", "set", "of", "alert", "events", "with", "the", "given", "query", "parameters", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/AlertEventService.java#L49-L52
10,433
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.list
public Collection<Monitor> list(Label label) { return HTTP.GET(String.format("/v1/monitors/labels/%s", label.getKey()), MONITORS).get(); }
java
public Collection<Monitor> list(Label label) { return HTTP.GET(String.format("/v1/monitors/labels/%s", label.getKey()), MONITORS).get(); }
[ "public", "Collection", "<", "Monitor", ">", "list", "(", "Label", "label", ")", "{", "return", "HTTP", ".", "GET", "(", "String", ".", "format", "(", "\"/v1/monitors/labels/%s\"", ",", "label", ".", "getKey", "(", ")", ")", ",", "MONITORS", ")", ".", "get", "(", ")", ";", "}" ]
Returns the set of monitors for the given label. @param label The label to use to select the monitors to return @return The set of monitors for the given label
[ "Returns", "the", "set", "of", "monitors", "for", "the", "given", "label", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L118-L121
10,434
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.show
public Optional<Monitor> show(String monitorId) { return HTTP.GET(String.format("/v3/monitors/%s", monitorId), MONITOR); }
java
public Optional<Monitor> show(String monitorId) { return HTTP.GET(String.format("/v3/monitors/%s", monitorId), MONITOR); }
[ "public", "Optional", "<", "Monitor", ">", "show", "(", "String", "monitorId", ")", "{", "return", "HTTP", ".", "GET", "(", "String", ".", "format", "(", "\"/v3/monitors/%s\"", ",", "monitorId", ")", ",", "MONITOR", ")", ";", "}" ]
Returns the monitor for the given monitor id. @param monitorId The id for the monitor to return @return The monitor
[ "Returns", "the", "monitor", "for", "the", "given", "monitor", "id", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L128-L131
10,435
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.showScript
public Optional<Script> showScript(String monitorId) { return HTTP.GET(String.format("/v3/monitors/%s/script", monitorId), SCRIPT); }
java
public Optional<Script> showScript(String monitorId) { return HTTP.GET(String.format("/v3/monitors/%s/script", monitorId), SCRIPT); }
[ "public", "Optional", "<", "Script", ">", "showScript", "(", "String", "monitorId", ")", "{", "return", "HTTP", ".", "GET", "(", "String", ".", "format", "(", "\"/v3/monitors/%s/script\"", ",", "monitorId", ")", ",", "SCRIPT", ")", ";", "}" ]
Returns the script for the given monitor id. @param monitorId The id for the monitor to return @return The script
[ "Returns", "the", "script", "for", "the", "given", "monitor", "id", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L138-L141
10,436
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.create
public Optional<Monitor> create(Monitor monitor) { Response obj = HTTP.POST("/v3/monitors", monitor).get(); String location = obj.getStringHeaders().getFirst("location"); if(location != null) monitor.setId(location.substring(location.lastIndexOf("/")+1)); return Optional.of(monitor); }
java
public Optional<Monitor> create(Monitor monitor) { Response obj = HTTP.POST("/v3/monitors", monitor).get(); String location = obj.getStringHeaders().getFirst("location"); if(location != null) monitor.setId(location.substring(location.lastIndexOf("/")+1)); return Optional.of(monitor); }
[ "public", "Optional", "<", "Monitor", ">", "create", "(", "Monitor", "monitor", ")", "{", "Response", "obj", "=", "HTTP", ".", "POST", "(", "\"/v3/monitors\"", ",", "monitor", ")", ".", "get", "(", ")", ";", "String", "location", "=", "obj", ".", "getStringHeaders", "(", ")", ".", "getFirst", "(", "\"location\"", ")", ";", "if", "(", "location", "!=", "null", ")", "monitor", ".", "setId", "(", "location", ".", "substring", "(", "location", ".", "lastIndexOf", "(", "\"/\"", ")", "+", "1", ")", ")", ";", "return", "Optional", ".", "of", "(", "monitor", ")", ";", "}" ]
Creates the given monitor. @param monitor The monitor to create @return This object
[ "Creates", "the", "given", "monitor", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L148-L155
10,437
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.update
public Optional<Monitor> update(Monitor monitor) { HTTP.PUT(String.format("/v3/monitors/%s", monitor.getId()), monitor); return Optional.of(monitor); }
java
public Optional<Monitor> update(Monitor monitor) { HTTP.PUT(String.format("/v3/monitors/%s", monitor.getId()), monitor); return Optional.of(monitor); }
[ "public", "Optional", "<", "Monitor", ">", "update", "(", "Monitor", "monitor", ")", "{", "HTTP", ".", "PUT", "(", "String", ".", "format", "(", "\"/v3/monitors/%s\"", ",", "monitor", ".", "getId", "(", ")", ")", ",", "monitor", ")", ";", "return", "Optional", ".", "of", "(", "monitor", ")", ";", "}" ]
Updates the given monitor. @param monitor The monitor to update @return The monitor that was updated
[ "Updates", "the", "given", "monitor", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L162-L166
10,438
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.updateScript
public Optional<Script> updateScript(String monitorId, Script script) { HTTP.PUT(String.format("/v3/monitors/%s/script", monitorId), script); return Optional.of(script); }
java
public Optional<Script> updateScript(String monitorId, Script script) { HTTP.PUT(String.format("/v3/monitors/%s/script", monitorId), script); return Optional.of(script); }
[ "public", "Optional", "<", "Script", ">", "updateScript", "(", "String", "monitorId", ",", "Script", "script", ")", "{", "HTTP", ".", "PUT", "(", "String", ".", "format", "(", "\"/v3/monitors/%s/script\"", ",", "monitorId", ")", ",", "script", ")", ";", "return", "Optional", ".", "of", "(", "script", ")", ";", "}" ]
Updates the given monitor to add a script. @param monitorId The id of the monitor to update @param script The script to add @return The monitor that was updated
[ "Updates", "the", "given", "monitor", "to", "add", "a", "script", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L174-L178
10,439
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.patch
public Optional<Monitor> patch(Monitor monitor) { HTTP.PATCH(String.format("/v3/monitors/%s", monitor.getId()), monitor); return Optional.of(monitor); }
java
public Optional<Monitor> patch(Monitor monitor) { HTTP.PATCH(String.format("/v3/monitors/%s", monitor.getId()), monitor); return Optional.of(monitor); }
[ "public", "Optional", "<", "Monitor", ">", "patch", "(", "Monitor", "monitor", ")", "{", "HTTP", ".", "PATCH", "(", "String", ".", "format", "(", "\"/v3/monitors/%s\"", ",", "monitor", ".", "getId", "(", ")", ")", ",", "monitor", ")", ";", "return", "Optional", ".", "of", "(", "monitor", ")", ";", "}" ]
Patches the given monitor. @param monitor The monitor to patch @return The monitor that was patched
[ "Patches", "the", "given", "monitor", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L185-L189
10,440
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.createLabel
public Optional<Label> createLabel(String monitorId, Label label) { HTTP.POST(String.format("/v1/monitors/%s/labels", monitorId), label.getKey()); return Optional.of(label); }
java
public Optional<Label> createLabel(String monitorId, Label label) { HTTP.POST(String.format("/v1/monitors/%s/labels", monitorId), label.getKey()); return Optional.of(label); }
[ "public", "Optional", "<", "Label", ">", "createLabel", "(", "String", "monitorId", ",", "Label", "label", ")", "{", "HTTP", ".", "POST", "(", "String", ".", "format", "(", "\"/v1/monitors/%s/labels\"", ",", "monitorId", ")", ",", "label", ".", "getKey", "(", ")", ")", ";", "return", "Optional", ".", "of", "(", "label", ")", ";", "}" ]
Adds the given label to the monitor with the given id. @param monitorId The id of the monitor to update @param label The label to add @return The label that was added
[ "Adds", "the", "given", "label", "to", "the", "monitor", "with", "the", "given", "id", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L197-L201
10,441
opsmatters/newrelic-api
src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java
MonitorService.deleteLabel
public MonitorService deleteLabel(String monitorId, Label label) { HTTP.DELETE(String.format("/v1/monitors/%s/labels/%s", monitorId, label.getKey())); return this; }
java
public MonitorService deleteLabel(String monitorId, Label label) { HTTP.DELETE(String.format("/v1/monitors/%s/labels/%s", monitorId, label.getKey())); return this; }
[ "public", "MonitorService", "deleteLabel", "(", "String", "monitorId", ",", "Label", "label", ")", "{", "HTTP", ".", "DELETE", "(", "String", ".", "format", "(", "\"/v1/monitors/%s/labels/%s\"", ",", "monitorId", ",", "label", ".", "getKey", "(", ")", ")", ")", ";", "return", "this", ";", "}" ]
Deletes the given label from the monitor with the given id. @param monitorId The id of the monitor with the label @param label The label to delete @return This object
[ "Deletes", "the", "given", "label", "from", "the", "monitor", "with", "the", "given", "id", "." ]
5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e
https://github.com/opsmatters/newrelic-api/blob/5bc2ea62ec368db891e4fd5fe3dcdf529d086b5e/src/main/java/com/opsmatters/newrelic/api/services/MonitorService.java#L220-L224
10,442
Sciss/abc4j
abc/src/main/java/abc/notation/Music.java
Music.append
public void append(Music music) { //if appending a music from a part //add a PartLabel to all voices if (!music.m_partLabel.equals(" ")) { for (Object m_voice : m_voices) { ((Voice) m_voice).addElement(new PartLabel(music.m_partLabel)); } } for (Object o : music.getVoices()) { Voice v = (Voice) o; if (!voiceExists(v.getVoiceName())) { //create new voice (in getVoice) //and copy v informations Voice vCopy = getVoice(v.getVoiceName()); vCopy.setTablature(v.getTablature()); vCopy.setVolume(v.getVolume()); vCopy.setInstrument(v.getInstrument()); //? vCopy.setFirstBarNumber(v.getFirstBar().getBarNumber()); } getVoice(v.getVoiceName()).addAll(v); } }
java
public void append(Music music) { //if appending a music from a part //add a PartLabel to all voices if (!music.m_partLabel.equals(" ")) { for (Object m_voice : m_voices) { ((Voice) m_voice).addElement(new PartLabel(music.m_partLabel)); } } for (Object o : music.getVoices()) { Voice v = (Voice) o; if (!voiceExists(v.getVoiceName())) { //create new voice (in getVoice) //and copy v informations Voice vCopy = getVoice(v.getVoiceName()); vCopy.setTablature(v.getTablature()); vCopy.setVolume(v.getVolume()); vCopy.setInstrument(v.getInstrument()); //? vCopy.setFirstBarNumber(v.getFirstBar().getBarNumber()); } getVoice(v.getVoiceName()).addAll(v); } }
[ "public", "void", "append", "(", "Music", "music", ")", "{", "//if appending a music from a part\r", "//add a PartLabel to all voices\r", "if", "(", "!", "music", ".", "m_partLabel", ".", "equals", "(", "\" \"", ")", ")", "{", "for", "(", "Object", "m_voice", ":", "m_voices", ")", "{", "(", "(", "Voice", ")", "m_voice", ")", ".", "addElement", "(", "new", "PartLabel", "(", "music", ".", "m_partLabel", ")", ")", ";", "}", "}", "for", "(", "Object", "o", ":", "music", ".", "getVoices", "(", ")", ")", "{", "Voice", "v", "=", "(", "Voice", ")", "o", ";", "if", "(", "!", "voiceExists", "(", "v", ".", "getVoiceName", "(", ")", ")", ")", "{", "//create new voice (in getVoice)\r", "//and copy v informations\r", "Voice", "vCopy", "=", "getVoice", "(", "v", ".", "getVoiceName", "(", ")", ")", ";", "vCopy", ".", "setTablature", "(", "v", ".", "getTablature", "(", ")", ")", ";", "vCopy", ".", "setVolume", "(", "v", ".", "getVolume", "(", ")", ")", ";", "vCopy", ".", "setInstrument", "(", "v", ".", "getInstrument", "(", ")", ")", ";", "//? vCopy.setFirstBarNumber(v.getFirstBar().getBarNumber());\r", "}", "getVoice", "(", "v", ".", "getVoiceName", "(", ")", ")", ".", "addAll", "(", "v", ")", ";", "}", "}" ]
Concatene the given music object to current one
[ "Concatene", "the", "given", "music", "object", "to", "current", "one" ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/notation/Music.java#L90-L111
10,443
Sciss/abc4j
abc/src/main/java/abc/notation/Music.java
Music.getVoice
public Voice getVoice(String voiceName) { for (Object m_voice : m_voices) { Voice v = (Voice) m_voice; if (v.getVoiceName().equals(voiceName)) return v; } Voice v = new Voice(voiceName, m_firstBarNumber); v.setPartLabel(m_partLabel); m_voices.add(v); return v; }
java
public Voice getVoice(String voiceName) { for (Object m_voice : m_voices) { Voice v = (Voice) m_voice; if (v.getVoiceName().equals(voiceName)) return v; } Voice v = new Voice(voiceName, m_firstBarNumber); v.setPartLabel(m_partLabel); m_voices.add(v); return v; }
[ "public", "Voice", "getVoice", "(", "String", "voiceName", ")", "{", "for", "(", "Object", "m_voice", ":", "m_voices", ")", "{", "Voice", "v", "=", "(", "Voice", ")", "m_voice", ";", "if", "(", "v", ".", "getVoiceName", "(", ")", ".", "equals", "(", "voiceName", ")", ")", "return", "v", ";", "}", "Voice", "v", "=", "new", "Voice", "(", "voiceName", ",", "m_firstBarNumber", ")", ";", "v", ".", "setPartLabel", "(", "m_partLabel", ")", ";", "m_voices", ".", "add", "(", "v", ")", ";", "return", "v", ";", "}" ]
Returns the asked voice, create it if needed.
[ "Returns", "the", "asked", "voice", "create", "it", "if", "needed", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/notation/Music.java#L124-L134
10,444
Sciss/abc4j
abc/src/main/java/abc/notation/Music.java
Music.addToAllVoices
public void addToAllVoices(MusicElement element) { for (Object m_voice : m_voices) { Voice v = (Voice) m_voice; v.addElement(element); } }
java
public void addToAllVoices(MusicElement element) { for (Object m_voice : m_voices) { Voice v = (Voice) m_voice; v.addElement(element); } }
[ "public", "void", "addToAllVoices", "(", "MusicElement", "element", ")", "{", "for", "(", "Object", "m_voice", ":", "m_voices", ")", "{", "Voice", "v", "=", "(", "Voice", ")", "m_voice", ";", "v", ".", "addElement", "(", "element", ")", ";", "}", "}" ]
Maybe could be used...? add an element to all voices be sure to add it first in the voice, are last when all elements have been added...
[ "Maybe", "could", "be", "used", "...", "?", "add", "an", "element", "to", "all", "voices", "be", "sure", "to", "add", "it", "first", "in", "the", "voice", "are", "last", "when", "all", "elements", "have", "been", "added", "..." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/notation/Music.java#L163-L168
10,445
Sciss/abc4j
abc/src/main/java/abc/notation/Music.java
Music.getElementAtStreamPosition
public MusicElement getElementAtStreamPosition(int offset) { Iterator it = m_voices.iterator(); CharStreamPosition pos; while (it.hasNext()) { Voice v = (Voice) it.next(); int size = v.size(); MusicElement current = null; for (int i = 0; i < size; i++) { current = (MusicElement) v.elementAt(i); if (current != null) { pos = current.getCharStreamPosition(); if (pos != null) { if ((pos.getStartIndex() <= offset) && (pos.getEndIndex() > offset)) return current; } } } } return null; }
java
public MusicElement getElementAtStreamPosition(int offset) { Iterator it = m_voices.iterator(); CharStreamPosition pos; while (it.hasNext()) { Voice v = (Voice) it.next(); int size = v.size(); MusicElement current = null; for (int i = 0; i < size; i++) { current = (MusicElement) v.elementAt(i); if (current != null) { pos = current.getCharStreamPosition(); if (pos != null) { if ((pos.getStartIndex() <= offset) && (pos.getEndIndex() > offset)) return current; } } } } return null; }
[ "public", "MusicElement", "getElementAtStreamPosition", "(", "int", "offset", ")", "{", "Iterator", "it", "=", "m_voices", ".", "iterator", "(", ")", ";", "CharStreamPosition", "pos", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "Voice", "v", "=", "(", "Voice", ")", "it", ".", "next", "(", ")", ";", "int", "size", "=", "v", ".", "size", "(", ")", ";", "MusicElement", "current", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "size", ";", "i", "++", ")", "{", "current", "=", "(", "MusicElement", ")", "v", ".", "elementAt", "(", "i", ")", ";", "if", "(", "current", "!=", "null", ")", "{", "pos", "=", "current", ".", "getCharStreamPosition", "(", ")", ";", "if", "(", "pos", "!=", "null", ")", "{", "if", "(", "(", "pos", ".", "getStartIndex", "(", ")", "<=", "offset", ")", "&&", "(", "pos", ".", "getEndIndex", "(", ")", ">", "offset", ")", ")", "return", "current", ";", "}", "}", "}", "}", "return", "null", ";", "}" ]
Returns the score element location at the specified offset. @param offset An offset in a char stream. @return The score element location at the specified offset. FIXME this is specific to ABC format... should be elsewhere than in Music object
[ "Returns", "the", "score", "element", "location", "at", "the", "specified", "offset", "." ]
117b405642c84a7bfca4e3e13668838258b90ca7
https://github.com/Sciss/abc4j/blob/117b405642c84a7bfca4e3e13668838258b90ca7/abc/src/main/java/abc/notation/Music.java#L213-L233
10,446
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeEncodingProvider.java
FlakeEncodingProvider.encodeAsBytes
@Override public byte[] encodeAsBytes(long time, int sequence) { byte[] buffer = new byte[16]; buffer[0] = (byte) (time >>> 56); buffer[1] = (byte) (time >>> 48); buffer[2] = (byte) (time >>> 40); buffer[3] = (byte) (time >>> 32); buffer[4] = (byte) (time >>> 24); buffer[5] = (byte) (time >>> 16); buffer[6] = (byte) (time >>> 8); buffer[7] = (byte) (time); long rest = shiftedMachineId | (0x0000FFFF & sequence); buffer[8] = (byte) (rest >>> 56); buffer[9] = (byte) (rest >>> 48); buffer[10] = (byte) (rest >>> 40); buffer[11] = (byte) (rest >>> 32); buffer[12] = (byte) (rest >>> 24); buffer[13] = (byte) (rest >>> 16); buffer[14] = (byte) (rest >>> 8); buffer[15] = (byte) (rest); return buffer; }
java
@Override public byte[] encodeAsBytes(long time, int sequence) { byte[] buffer = new byte[16]; buffer[0] = (byte) (time >>> 56); buffer[1] = (byte) (time >>> 48); buffer[2] = (byte) (time >>> 40); buffer[3] = (byte) (time >>> 32); buffer[4] = (byte) (time >>> 24); buffer[5] = (byte) (time >>> 16); buffer[6] = (byte) (time >>> 8); buffer[7] = (byte) (time); long rest = shiftedMachineId | (0x0000FFFF & sequence); buffer[8] = (byte) (rest >>> 56); buffer[9] = (byte) (rest >>> 48); buffer[10] = (byte) (rest >>> 40); buffer[11] = (byte) (rest >>> 32); buffer[12] = (byte) (rest >>> 24); buffer[13] = (byte) (rest >>> 16); buffer[14] = (byte) (rest >>> 8); buffer[15] = (byte) (rest); return buffer; }
[ "@", "Override", "public", "byte", "[", "]", "encodeAsBytes", "(", "long", "time", ",", "int", "sequence", ")", "{", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "16", "]", ";", "buffer", "[", "0", "]", "=", "(", "byte", ")", "(", "time", ">>>", "56", ")", ";", "buffer", "[", "1", "]", "=", "(", "byte", ")", "(", "time", ">>>", "48", ")", ";", "buffer", "[", "2", "]", "=", "(", "byte", ")", "(", "time", ">>>", "40", ")", ";", "buffer", "[", "3", "]", "=", "(", "byte", ")", "(", "time", ">>>", "32", ")", ";", "buffer", "[", "4", "]", "=", "(", "byte", ")", "(", "time", ">>>", "24", ")", ";", "buffer", "[", "5", "]", "=", "(", "byte", ")", "(", "time", ">>>", "16", ")", ";", "buffer", "[", "6", "]", "=", "(", "byte", ")", "(", "time", ">>>", "8", ")", ";", "buffer", "[", "7", "]", "=", "(", "byte", ")", "(", "time", ")", ";", "long", "rest", "=", "shiftedMachineId", "|", "(", "0x0000FFFF", "&", "sequence", ")", ";", "buffer", "[", "8", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "56", ")", ";", "buffer", "[", "9", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "48", ")", ";", "buffer", "[", "10", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "40", ")", ";", "buffer", "[", "11", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "32", ")", ";", "buffer", "[", "12", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "24", ")", ";", "buffer", "[", "13", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "16", ")", ";", "buffer", "[", "14", "]", "=", "(", "byte", ")", "(", "rest", ">>>", "8", ")", ";", "buffer", "[", "15", "]", "=", "(", "byte", ")", "(", "rest", ")", ";", "return", "buffer", ";", "}" ]
Return a 128-bit version of the given time and sequence numbers according to the Flake specification. @param time a time value to encode @param sequence a sequence value to encode @return the Flake id as bytes
[ "Return", "a", "128", "-", "bit", "version", "of", "the", "given", "time", "and", "sequence", "numbers", "according", "to", "the", "Flake", "specification", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeEncodingProvider.java#L53-L76
10,447
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeEncodingProvider.java
FlakeEncodingProvider.encodeAsString
@Override public String encodeAsString(long time, int sequence) { StringBuilder s = new StringBuilder(32); ByteBuffer bb = ByteBuffer.wrap(encodeAsBytes(time, sequence)); s.append(leftPad(toHexString(bb.getLong()), 16, '0')); s.append(leftPad(toHexString(bb.getLong()), 16, '0')); return s.toString(); }
java
@Override public String encodeAsString(long time, int sequence) { StringBuilder s = new StringBuilder(32); ByteBuffer bb = ByteBuffer.wrap(encodeAsBytes(time, sequence)); s.append(leftPad(toHexString(bb.getLong()), 16, '0')); s.append(leftPad(toHexString(bb.getLong()), 16, '0')); return s.toString(); }
[ "@", "Override", "public", "String", "encodeAsString", "(", "long", "time", ",", "int", "sequence", ")", "{", "StringBuilder", "s", "=", "new", "StringBuilder", "(", "32", ")", ";", "ByteBuffer", "bb", "=", "ByteBuffer", ".", "wrap", "(", "encodeAsBytes", "(", "time", ",", "sequence", ")", ")", ";", "s", ".", "append", "(", "leftPad", "(", "toHexString", "(", "bb", ".", "getLong", "(", ")", ")", ",", "16", ",", "'", "'", ")", ")", ";", "s", ".", "append", "(", "leftPad", "(", "toHexString", "(", "bb", ".", "getLong", "(", ")", ")", ",", "16", ",", "'", "'", ")", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}" ]
Return the 32 character left padded hex version of the given id. These can be lexicographically sorted. @param time a time value to encode @param sequence a sequence value to encode @return 32 character left padded hex version of the given id
[ "Return", "the", "32", "character", "left", "padded", "hex", "version", "of", "the", "given", "id", ".", "These", "can", "be", "lexicographically", "sorted", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeEncodingProvider.java#L99-L107
10,448
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java
FlakeDecodingUtils.decodeDate
public static Date decodeDate(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); return new Date(buffer.getLong()); }
java
public static Date decodeDate(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); return new Date(buffer.getLong()); }
[ "public", "static", "Date", "decodeDate", "(", "byte", "[", "]", "flakeBytes", ")", "{", "ByteBuffer", "buffer", "=", "ByteBuffer", ".", "allocate", "(", "16", ")", ";", "buffer", ".", "put", "(", "flakeBytes", ")", ";", "buffer", ".", "flip", "(", ")", ";", "return", "new", "Date", "(", "buffer", ".", "getLong", "(", ")", ")", ";", "}" ]
Return the Date from the given encoded Flake id. @param flakeBytes the id to decode from
[ "Return", "the", "Date", "from", "the", "given", "encoded", "Flake", "id", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java#L33-L38
10,449
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java
FlakeDecodingUtils.decodeMachineId
public static long decodeMachineId(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); buffer.getLong(); return buffer.getLong() >>> 16; }
java
public static long decodeMachineId(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); buffer.getLong(); return buffer.getLong() >>> 16; }
[ "public", "static", "long", "decodeMachineId", "(", "byte", "[", "]", "flakeBytes", ")", "{", "ByteBuffer", "buffer", "=", "ByteBuffer", ".", "allocate", "(", "16", ")", ";", "buffer", ".", "put", "(", "flakeBytes", ")", ";", "buffer", ".", "flip", "(", ")", ";", "buffer", ".", "getLong", "(", ")", ";", "return", "buffer", ".", "getLong", "(", ")", ">>>", "16", ";", "}" ]
Return the machine id from the given encoded Snowflake id. @param flakeBytes the id to decode from
[ "Return", "the", "machine", "id", "from", "the", "given", "encoded", "Snowflake", "id", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java#L45-L51
10,450
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java
FlakeDecodingUtils.decodeSequence
public static int decodeSequence(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); buffer.getLong(); return (int)(buffer.getLong() & 0x000000000000FFFF); }
java
public static int decodeSequence(byte[] flakeBytes) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.put(flakeBytes); buffer.flip(); buffer.getLong(); return (int)(buffer.getLong() & 0x000000000000FFFF); }
[ "public", "static", "int", "decodeSequence", "(", "byte", "[", "]", "flakeBytes", ")", "{", "ByteBuffer", "buffer", "=", "ByteBuffer", ".", "allocate", "(", "16", ")", ";", "buffer", ".", "put", "(", "flakeBytes", ")", ";", "buffer", ".", "flip", "(", ")", ";", "buffer", ".", "getLong", "(", ")", ";", "return", "(", "int", ")", "(", "buffer", ".", "getLong", "(", ")", "&", "0x000000000000FFFF", ")", ";", "}" ]
Return the sequence number from the given encoded Snowflake id. @param flakeBytes the id to decode from
[ "Return", "the", "sequence", "number", "from", "the", "given", "encoded", "Snowflake", "id", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/boundary/FlakeDecodingUtils.java#L58-L64
10,451
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/twitter/SnowflakeEncodingProvider.java
SnowflakeEncodingProvider.encodeAsString
@Override public String encodeAsString(long time, int sequence) { return leftPad(toHexString(encodeAsLong(time, sequence)), 16, '0'); }
java
@Override public String encodeAsString(long time, int sequence) { return leftPad(toHexString(encodeAsLong(time, sequence)), 16, '0'); }
[ "@", "Override", "public", "String", "encodeAsString", "(", "long", "time", ",", "int", "sequence", ")", "{", "return", "leftPad", "(", "toHexString", "(", "encodeAsLong", "(", "time", ",", "sequence", ")", ")", ",", "16", ",", "'", "'", ")", ";", "}" ]
Return the 16 character left padded hex version of the given id. These can be lexicographically sorted.
[ "Return", "the", "16", "character", "left", "padded", "hex", "version", "of", "the", "given", "id", ".", "These", "can", "be", "lexicographically", "sorted", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/provider/twitter/SnowflakeEncodingProvider.java#L97-L100
10,452
rholder/fauxflake
fauxflake-core/src/main/java/com/github/rholder/fauxflake/util/MacUtils.java
MacUtils.getOverride
public static byte[] getOverride() { String overrideMac = System.getProperty(OVERRIDE_MAC_PROP); byte[] macBytes = null; if (overrideMac != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); String[] rawBytes = overrideMac.split(":"); if (rawBytes.length == 6) { try { for (String b : rawBytes) { out.write(Integer.parseInt(b, 16)); } macBytes = out.toByteArray(); } catch (NumberFormatException e) { // do nothing } } } return macBytes; }
java
public static byte[] getOverride() { String overrideMac = System.getProperty(OVERRIDE_MAC_PROP); byte[] macBytes = null; if (overrideMac != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); String[] rawBytes = overrideMac.split(":"); if (rawBytes.length == 6) { try { for (String b : rawBytes) { out.write(Integer.parseInt(b, 16)); } macBytes = out.toByteArray(); } catch (NumberFormatException e) { // do nothing } } } return macBytes; }
[ "public", "static", "byte", "[", "]", "getOverride", "(", ")", "{", "String", "overrideMac", "=", "System", ".", "getProperty", "(", "OVERRIDE_MAC_PROP", ")", ";", "byte", "[", "]", "macBytes", "=", "null", ";", "if", "(", "overrideMac", "!=", "null", ")", "{", "ByteArrayOutputStream", "out", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "String", "[", "]", "rawBytes", "=", "overrideMac", ".", "split", "(", "\":\"", ")", ";", "if", "(", "rawBytes", ".", "length", "==", "6", ")", "{", "try", "{", "for", "(", "String", "b", ":", "rawBytes", ")", "{", "out", ".", "write", "(", "Integer", ".", "parseInt", "(", "b", ",", "16", ")", ")", ";", "}", "macBytes", "=", "out", ".", "toByteArray", "(", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "// do nothing", "}", "}", "}", "return", "macBytes", ";", "}" ]
Return the overridden MAC address, if the system property OVERRIDE_MAC_PROP has been set. If the value of the property isn't a valid MAC address or it was not set, then null is returned.
[ "Return", "the", "overridden", "MAC", "address", "if", "the", "system", "property", "OVERRIDE_MAC_PROP", "has", "been", "set", ".", "If", "the", "value", "of", "the", "property", "isn", "t", "a", "valid", "MAC", "address", "or", "it", "was", "not", "set", "then", "null", "is", "returned", "." ]
54631faefdaf6b0b4d27b365f18c085771575cb3
https://github.com/rholder/fauxflake/blob/54631faefdaf6b0b4d27b365f18c085771575cb3/fauxflake-core/src/main/java/com/github/rholder/fauxflake/util/MacUtils.java#L41-L59
10,453
highsource/annox
core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java
XAnnotationInvocationHandler.cloneArray
private Object cloneArray(Object array) { Class<?> type = array.getClass(); if (type == byte[].class) { byte[] byteArray = (byte[]) array; return byteArray.clone(); } if (type == char[].class) { char[] charArray = (char[]) array; return charArray.clone(); } if (type == double[].class) { double[] doubleArray = (double[]) array; return doubleArray.clone(); } if (type == float[].class) { float[] floatArray = (float[]) array; return floatArray.clone(); } if (type == int[].class) { int[] intArray = (int[]) array; return intArray.clone(); } if (type == long[].class) { long[] longArray = (long[]) array; return longArray.clone(); } if (type == short[].class) { short[] shortArray = (short[]) array; return shortArray.clone(); } if (type == boolean[].class) { boolean[] booleanArray = (boolean[]) array; return booleanArray.clone(); } Object[] objectArray = (Object[]) array; return objectArray.clone(); }
java
private Object cloneArray(Object array) { Class<?> type = array.getClass(); if (type == byte[].class) { byte[] byteArray = (byte[]) array; return byteArray.clone(); } if (type == char[].class) { char[] charArray = (char[]) array; return charArray.clone(); } if (type == double[].class) { double[] doubleArray = (double[]) array; return doubleArray.clone(); } if (type == float[].class) { float[] floatArray = (float[]) array; return floatArray.clone(); } if (type == int[].class) { int[] intArray = (int[]) array; return intArray.clone(); } if (type == long[].class) { long[] longArray = (long[]) array; return longArray.clone(); } if (type == short[].class) { short[] shortArray = (short[]) array; return shortArray.clone(); } if (type == boolean[].class) { boolean[] booleanArray = (boolean[]) array; return booleanArray.clone(); } Object[] objectArray = (Object[]) array; return objectArray.clone(); }
[ "private", "Object", "cloneArray", "(", "Object", "array", ")", "{", "Class", "<", "?", ">", "type", "=", "array", ".", "getClass", "(", ")", ";", "if", "(", "type", "==", "byte", "[", "]", ".", "class", ")", "{", "byte", "[", "]", "byteArray", "=", "(", "byte", "[", "]", ")", "array", ";", "return", "byteArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "char", "[", "]", ".", "class", ")", "{", "char", "[", "]", "charArray", "=", "(", "char", "[", "]", ")", "array", ";", "return", "charArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "double", "[", "]", ".", "class", ")", "{", "double", "[", "]", "doubleArray", "=", "(", "double", "[", "]", ")", "array", ";", "return", "doubleArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "float", "[", "]", ".", "class", ")", "{", "float", "[", "]", "floatArray", "=", "(", "float", "[", "]", ")", "array", ";", "return", "floatArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "int", "[", "]", ".", "class", ")", "{", "int", "[", "]", "intArray", "=", "(", "int", "[", "]", ")", "array", ";", "return", "intArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "long", "[", "]", ".", "class", ")", "{", "long", "[", "]", "longArray", "=", "(", "long", "[", "]", ")", "array", ";", "return", "longArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "short", "[", "]", ".", "class", ")", "{", "short", "[", "]", "shortArray", "=", "(", "short", "[", "]", ")", "array", ";", "return", "shortArray", ".", "clone", "(", ")", ";", "}", "if", "(", "type", "==", "boolean", "[", "]", ".", "class", ")", "{", "boolean", "[", "]", "booleanArray", "=", "(", "boolean", "[", "]", ")", "array", ";", "return", "booleanArray", ".", "clone", "(", ")", ";", "}", "Object", "[", "]", "objectArray", "=", "(", "Object", "[", "]", ")", "array", ";", "return", "objectArray", ".", "clone", "(", ")", ";", "}" ]
This method, which clones its array argument, would not be necessary if Cloneable had a public clone method.
[ "This", "method", "which", "clones", "its", "array", "argument", "would", "not", "be", "necessary", "if", "Cloneable", "had", "a", "public", "clone", "method", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java#L76-L114
10,454
highsource/annox
core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java
XAnnotationInvocationHandler.asOneOfUs
private XAnnotationInvocationHandler asOneOfUs(Object o) { if (Proxy.isProxyClass(o.getClass())) { InvocationHandler handler = Proxy.getInvocationHandler(o); if (handler instanceof XAnnotationInvocationHandler) return (XAnnotationInvocationHandler) handler; } return null; }
java
private XAnnotationInvocationHandler asOneOfUs(Object o) { if (Proxy.isProxyClass(o.getClass())) { InvocationHandler handler = Proxy.getInvocationHandler(o); if (handler instanceof XAnnotationInvocationHandler) return (XAnnotationInvocationHandler) handler; } return null; }
[ "private", "XAnnotationInvocationHandler", "asOneOfUs", "(", "Object", "o", ")", "{", "if", "(", "Proxy", ".", "isProxyClass", "(", "o", ".", "getClass", "(", ")", ")", ")", "{", "InvocationHandler", "handler", "=", "Proxy", ".", "getInvocationHandler", "(", "o", ")", ";", "if", "(", "handler", "instanceof", "XAnnotationInvocationHandler", ")", "return", "(", "XAnnotationInvocationHandler", ")", "handler", ";", "}", "return", "null", ";", "}" ]
Returns an object's invocation handler if that object is a dynamic proxy with a handler of type AnnotationInvocationHandler. Returns null otherwise.
[ "Returns", "an", "object", "s", "invocation", "handler", "if", "that", "object", "is", "a", "dynamic", "proxy", "with", "a", "handler", "of", "type", "AnnotationInvocationHandler", ".", "Returns", "null", "otherwise", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java#L200-L207
10,455
highsource/annox
core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java
XAnnotationInvocationHandler.memberValueEquals
private static boolean memberValueEquals(Object v1, Object v2) { Class<?> type = v1.getClass(); // Check for primitive, string, class, enum const, annotation, // or ExceptionProxy if (!type.isArray()) return v1.equals(v2); // Check for array of string, class, enum const, annotation, // or ExceptionProxy if (v1 instanceof Object[] && v2 instanceof Object[]) return Arrays.equals((Object[]) v1, (Object[]) v2); // Check for ill formed annotation(s) if (v2.getClass() != type) return false; // Deal with array of primitives if (type == byte[].class) return Arrays.equals((byte[]) v1, (byte[]) v2); if (type == char[].class) return Arrays.equals((char[]) v1, (char[]) v2); if (type == double[].class) return Arrays.equals((double[]) v1, (double[]) v2); if (type == float[].class) return Arrays.equals((float[]) v1, (float[]) v2); if (type == int[].class) return Arrays.equals((int[]) v1, (int[]) v2); if (type == long[].class) return Arrays.equals((long[]) v1, (long[]) v2); if (type == short[].class) return Arrays.equals((short[]) v1, (short[]) v2); assert type == boolean[].class; return Arrays.equals((boolean[]) v1, (boolean[]) v2); }
java
private static boolean memberValueEquals(Object v1, Object v2) { Class<?> type = v1.getClass(); // Check for primitive, string, class, enum const, annotation, // or ExceptionProxy if (!type.isArray()) return v1.equals(v2); // Check for array of string, class, enum const, annotation, // or ExceptionProxy if (v1 instanceof Object[] && v2 instanceof Object[]) return Arrays.equals((Object[]) v1, (Object[]) v2); // Check for ill formed annotation(s) if (v2.getClass() != type) return false; // Deal with array of primitives if (type == byte[].class) return Arrays.equals((byte[]) v1, (byte[]) v2); if (type == char[].class) return Arrays.equals((char[]) v1, (char[]) v2); if (type == double[].class) return Arrays.equals((double[]) v1, (double[]) v2); if (type == float[].class) return Arrays.equals((float[]) v1, (float[]) v2); if (type == int[].class) return Arrays.equals((int[]) v1, (int[]) v2); if (type == long[].class) return Arrays.equals((long[]) v1, (long[]) v2); if (type == short[].class) return Arrays.equals((short[]) v1, (short[]) v2); assert type == boolean[].class; return Arrays.equals((boolean[]) v1, (boolean[]) v2); }
[ "private", "static", "boolean", "memberValueEquals", "(", "Object", "v1", ",", "Object", "v2", ")", "{", "Class", "<", "?", ">", "type", "=", "v1", ".", "getClass", "(", ")", ";", "// Check for primitive, string, class, enum const, annotation,", "// or ExceptionProxy", "if", "(", "!", "type", ".", "isArray", "(", ")", ")", "return", "v1", ".", "equals", "(", "v2", ")", ";", "// Check for array of string, class, enum const, annotation,", "// or ExceptionProxy", "if", "(", "v1", "instanceof", "Object", "[", "]", "&&", "v2", "instanceof", "Object", "[", "]", ")", "return", "Arrays", ".", "equals", "(", "(", "Object", "[", "]", ")", "v1", ",", "(", "Object", "[", "]", ")", "v2", ")", ";", "// Check for ill formed annotation(s)", "if", "(", "v2", ".", "getClass", "(", ")", "!=", "type", ")", "return", "false", ";", "// Deal with array of primitives", "if", "(", "type", "==", "byte", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "byte", "[", "]", ")", "v1", ",", "(", "byte", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "char", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "char", "[", "]", ")", "v1", ",", "(", "char", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "double", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "double", "[", "]", ")", "v1", ",", "(", "double", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "float", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "float", "[", "]", ")", "v1", ",", "(", "float", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "int", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "int", "[", "]", ")", "v1", ",", "(", "int", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "long", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "long", "[", "]", ")", "v1", ",", "(", "long", "[", "]", ")", "v2", ")", ";", "if", "(", "type", "==", "short", "[", "]", ".", "class", ")", "return", "Arrays", ".", "equals", "(", "(", "short", "[", "]", ")", "v1", ",", "(", "short", "[", "]", ")", "v2", ")", ";", "assert", "type", "==", "boolean", "[", "]", ".", "class", ";", "return", "Arrays", ".", "equals", "(", "(", "boolean", "[", "]", ")", "v1", ",", "(", "boolean", "[", "]", ")", "v2", ")", ";", "}" ]
Returns true iff the two member values in "dynamic proxy return form" are equal using the appropriate equality function depending on the member type. The two values will be of the same type unless one of the containing annotations is ill-formed. If one of the containing annotations is ill-formed, this method will return false unless the two members are identical object references.
[ "Returns", "true", "iff", "the", "two", "member", "values", "in", "dynamic", "proxy", "return", "form", "are", "equal", "using", "the", "appropriate", "equality", "function", "depending", "on", "the", "member", "type", ".", "The", "two", "values", "will", "be", "of", "the", "same", "type", "unless", "one", "of", "the", "containing", "annotations", "is", "ill", "-", "formed", ".", "If", "one", "of", "the", "containing", "annotations", "is", "ill", "-", "formed", "this", "method", "will", "return", "false", "unless", "the", "two", "members", "are", "identical", "object", "references", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XAnnotationInvocationHandler.java#L217-L251
10,456
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ProtoFileParser.java
ProtoFileParser.verifyCustomOptionNameUnique
private void verifyCustomOptionNameUnique(final CustomOptionContext ctx) { if (ctx.customOptionName().customOptionNamePart().size() == 1) { final CustomOptionNamePartContext namePart = ctx.customOptionName().customOptionNamePart(0); verifyOptionNameUnique(namePart.getText(), namePart.getStart()); } }
java
private void verifyCustomOptionNameUnique(final CustomOptionContext ctx) { if (ctx.customOptionName().customOptionNamePart().size() == 1) { final CustomOptionNamePartContext namePart = ctx.customOptionName().customOptionNamePart(0); verifyOptionNameUnique(namePart.getText(), namePart.getStart()); } }
[ "private", "void", "verifyCustomOptionNameUnique", "(", "final", "CustomOptionContext", "ctx", ")", "{", "if", "(", "ctx", ".", "customOptionName", "(", ")", ".", "customOptionNamePart", "(", ")", ".", "size", "(", ")", "==", "1", ")", "{", "final", "CustomOptionNamePartContext", "namePart", "=", "ctx", ".", "customOptionName", "(", ")", ".", "customOptionNamePart", "(", "0", ")", ";", "verifyOptionNameUnique", "(", "namePart", ".", "getText", "(", ")", ",", "namePart", ".", "getStart", "(", ")", ")", ";", "}", "}" ]
Verifies uniqueness for custom options with a single NamePart. The multipart custom options should be validated during UninterpetedOption resolution in OptionsBuilder, not here!
[ "Verifies", "uniqueness", "for", "custom", "options", "with", "a", "single", "NamePart", ".", "The", "multipart", "custom", "options", "should", "be", "validated", "during", "UninterpetedOption", "resolution", "in", "OptionsBuilder", "not", "here!" ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ProtoFileParser.java#L453-L458
10,457
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/util/Tokenizer.java
Tokenizer.tokenize
public static String[] tokenize(String input, boolean lowercase) { String[] tokens = input.split("\\W"); // lower case for (int i = 0; i < tokens.length && lowercase; i++) { tokens[i] = tokens[i].toLowerCase(); } return tokens; }
java
public static String[] tokenize(String input, boolean lowercase) { String[] tokens = input.split("\\W"); // lower case for (int i = 0; i < tokens.length && lowercase; i++) { tokens[i] = tokens[i].toLowerCase(); } return tokens; }
[ "public", "static", "String", "[", "]", "tokenize", "(", "String", "input", ",", "boolean", "lowercase", ")", "{", "String", "[", "]", "tokens", "=", "input", ".", "split", "(", "\"\\\\W\"", ")", ";", "// lower case", "for", "(", "int", "i", "=", "0", ";", "i", "<", "tokens", ".", "length", "&&", "lowercase", ";", "i", "++", ")", "{", "tokens", "[", "i", "]", "=", "tokens", "[", "i", "]", ".", "toLowerCase", "(", ")", ";", "}", "return", "tokens", ";", "}" ]
tokenize based on simple regular expression
[ "tokenize", "based", "on", "simple", "regular", "expression" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/util/Tokenizer.java#L23-L31
10,458
forge/furnace
container/src/main/java/org/jboss/forge/furnace/impl/util/Files.java
Files.canonicalize
public static String canonicalize(String target) { if (target.startsWith(Files.HOME_ALIAS)) { String homePath = OperatingSystemUtils.getUserHomePath(); target = homePath + target.substring(1, target.length()); } return target; }
java
public static String canonicalize(String target) { if (target.startsWith(Files.HOME_ALIAS)) { String homePath = OperatingSystemUtils.getUserHomePath(); target = homePath + target.substring(1, target.length()); } return target; }
[ "public", "static", "String", "canonicalize", "(", "String", "target", ")", "{", "if", "(", "target", ".", "startsWith", "(", "Files", ".", "HOME_ALIAS", ")", ")", "{", "String", "homePath", "=", "OperatingSystemUtils", ".", "getUserHomePath", "(", ")", ";", "target", "=", "homePath", "+", "target", ".", "substring", "(", "1", ",", "target", ".", "length", "(", ")", ")", ";", "}", "return", "target", ";", "}" ]
Replace instances of internal tokens with actual file equivalents.
[ "Replace", "instances", "of", "internal", "tokens", "with", "actual", "file", "equivalents", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container/src/main/java/org/jboss/forge/furnace/impl/util/Files.java#L128-L137
10,459
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/MultiFieldDocument.java
MultiFieldDocument.getStringSerialization
public String getStringSerialization(int[] fieldToKeep) { if (fieldToKeep == null || fieldToKeep.length == 0) return getStringSerialization(); StringBuffer buffer = new StringBuffer(); buffer.append(this.getClass().getSimpleName()).append("\t"); buffer.append(this.label); buffer.append("\t").append(tokensPerField.length); for (int fieldNum = 0; fieldNum < tokensPerField.length; fieldNum++) { double tokperf = tokensPerField[fieldNum]; if (java.util.Arrays.binarySearch(fieldToKeep, fieldNum) != -1) buffer.append("\t").append(tokperf); else buffer.append("\t").append("0.0"); } for (int i = 0; i < indices.length; i++) { int fieldNum = this.indexToField[i]; if (java.util.Arrays.binarySearch(fieldToKeep, fieldNum) != -1) buffer.append("\t").append(indices[i]).append(":").append( freqs[i]).append(":").append(this.indexToField[i]); } buffer.append("\n"); return buffer.toString(); }
java
public String getStringSerialization(int[] fieldToKeep) { if (fieldToKeep == null || fieldToKeep.length == 0) return getStringSerialization(); StringBuffer buffer = new StringBuffer(); buffer.append(this.getClass().getSimpleName()).append("\t"); buffer.append(this.label); buffer.append("\t").append(tokensPerField.length); for (int fieldNum = 0; fieldNum < tokensPerField.length; fieldNum++) { double tokperf = tokensPerField[fieldNum]; if (java.util.Arrays.binarySearch(fieldToKeep, fieldNum) != -1) buffer.append("\t").append(tokperf); else buffer.append("\t").append("0.0"); } for (int i = 0; i < indices.length; i++) { int fieldNum = this.indexToField[i]; if (java.util.Arrays.binarySearch(fieldToKeep, fieldNum) != -1) buffer.append("\t").append(indices[i]).append(":").append( freqs[i]).append(":").append(this.indexToField[i]); } buffer.append("\n"); return buffer.toString(); }
[ "public", "String", "getStringSerialization", "(", "int", "[", "]", "fieldToKeep", ")", "{", "if", "(", "fieldToKeep", "==", "null", "||", "fieldToKeep", ".", "length", "==", "0", ")", "return", "getStringSerialization", "(", ")", ";", "StringBuffer", "buffer", "=", "new", "StringBuffer", "(", ")", ";", "buffer", ".", "append", "(", "this", ".", "getClass", "(", ")", ".", "getSimpleName", "(", ")", ")", ".", "append", "(", "\"\\t\"", ")", ";", "buffer", ".", "append", "(", "this", ".", "label", ")", ";", "buffer", ".", "append", "(", "\"\\t\"", ")", ".", "append", "(", "tokensPerField", ".", "length", ")", ";", "for", "(", "int", "fieldNum", "=", "0", ";", "fieldNum", "<", "tokensPerField", ".", "length", ";", "fieldNum", "++", ")", "{", "double", "tokperf", "=", "tokensPerField", "[", "fieldNum", "]", ";", "if", "(", "java", ".", "util", ".", "Arrays", ".", "binarySearch", "(", "fieldToKeep", ",", "fieldNum", ")", "!=", "-", "1", ")", "buffer", ".", "append", "(", "\"\\t\"", ")", ".", "append", "(", "tokperf", ")", ";", "else", "buffer", ".", "append", "(", "\"\\t\"", ")", ".", "append", "(", "\"0.0\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "indices", ".", "length", ";", "i", "++", ")", "{", "int", "fieldNum", "=", "this", ".", "indexToField", "[", "i", "]", ";", "if", "(", "java", ".", "util", ".", "Arrays", ".", "binarySearch", "(", "fieldToKeep", ",", "fieldNum", ")", "!=", "-", "1", ")", "buffer", ".", "append", "(", "\"\\t\"", ")", ".", "append", "(", "indices", "[", "i", "]", ")", ".", "append", "(", "\":\"", ")", ".", "append", "(", "freqs", "[", "i", "]", ")", ".", "append", "(", "\":\"", ")", ".", "append", "(", "this", ".", "indexToField", "[", "i", "]", ")", ";", "}", "buffer", ".", "append", "(", "\"\\n\"", ")", ";", "return", "buffer", ".", "toString", "(", ")", ";", "}" ]
but limiting it to a subset of its fields
[ "but", "limiting", "it", "to", "a", "subset", "of", "its", "fields" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/MultiFieldDocument.java#L160-L182
10,460
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/MultiFieldDocument.java
MultiFieldDocument.getFeatureVector
public Vector getFeatureVector(Lexicon lexicon) { Parameters.WeightingMethod method = lexicon.getMethod(); return getFeatureVector(lexicon, method, null); }
java
public Vector getFeatureVector(Lexicon lexicon) { Parameters.WeightingMethod method = lexicon.getMethod(); return getFeatureVector(lexicon, method, null); }
[ "public", "Vector", "getFeatureVector", "(", "Lexicon", "lexicon", ")", "{", "Parameters", ".", "WeightingMethod", "method", "=", "lexicon", ".", "getMethod", "(", ")", ";", "return", "getFeatureVector", "(", "lexicon", ",", "method", ",", "null", ")", ";", "}" ]
Returns a Vector representation of the document. This Vector object is weighted and used by the instances of Learner or TextClassifier
[ "Returns", "a", "Vector", "representation", "of", "the", "document", ".", "This", "Vector", "object", "is", "weighted", "and", "used", "by", "the", "instances", "of", "Learner", "or", "TextClassifier" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/MultiFieldDocument.java#L228-L231
10,461
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/MultiFieldDocument.java
MultiFieldDocument.getScore
private double getScore(int pos, Lexicon lexicon, double numdocs) { double score = 0; int indexTerm = this.indices[pos]; double occurences = (double) this.freqs[pos]; int fieldNum = this.indexToField[pos]; double frequency = occurences / tokensPerField[fieldNum]; // is there a custom weight for this field? String fieldName = lexicon.getFields()[fieldNum]; WeightingMethod method = lexicon.getMethod(fieldName); if (method.equals(Parameters.WeightingMethod.BOOLEAN)) { score = 1; } else if (method.equals(Parameters.WeightingMethod.OCCURRENCES)) { score = occurences; } else if (method.equals(Parameters.WeightingMethod.FREQUENCY)) { score = frequency; } else if (method.equals(Parameters.WeightingMethod.TFIDF)) { int df = lexicon.getDocFreq(indexTerm); double idf = numdocs / (double) df; score = frequency * Math.log(idf); if (idf == 1) score = frequency; } return score; }
java
private double getScore(int pos, Lexicon lexicon, double numdocs) { double score = 0; int indexTerm = this.indices[pos]; double occurences = (double) this.freqs[pos]; int fieldNum = this.indexToField[pos]; double frequency = occurences / tokensPerField[fieldNum]; // is there a custom weight for this field? String fieldName = lexicon.getFields()[fieldNum]; WeightingMethod method = lexicon.getMethod(fieldName); if (method.equals(Parameters.WeightingMethod.BOOLEAN)) { score = 1; } else if (method.equals(Parameters.WeightingMethod.OCCURRENCES)) { score = occurences; } else if (method.equals(Parameters.WeightingMethod.FREQUENCY)) { score = frequency; } else if (method.equals(Parameters.WeightingMethod.TFIDF)) { int df = lexicon.getDocFreq(indexTerm); double idf = numdocs / (double) df; score = frequency * Math.log(idf); if (idf == 1) score = frequency; } return score; }
[ "private", "double", "getScore", "(", "int", "pos", ",", "Lexicon", "lexicon", ",", "double", "numdocs", ")", "{", "double", "score", "=", "0", ";", "int", "indexTerm", "=", "this", ".", "indices", "[", "pos", "]", ";", "double", "occurences", "=", "(", "double", ")", "this", ".", "freqs", "[", "pos", "]", ";", "int", "fieldNum", "=", "this", ".", "indexToField", "[", "pos", "]", ";", "double", "frequency", "=", "occurences", "/", "tokensPerField", "[", "fieldNum", "]", ";", "// is there a custom weight for this field?", "String", "fieldName", "=", "lexicon", ".", "getFields", "(", ")", "[", "fieldNum", "]", ";", "WeightingMethod", "method", "=", "lexicon", ".", "getMethod", "(", "fieldName", ")", ";", "if", "(", "method", ".", "equals", "(", "Parameters", ".", "WeightingMethod", ".", "BOOLEAN", ")", ")", "{", "score", "=", "1", ";", "}", "else", "if", "(", "method", ".", "equals", "(", "Parameters", ".", "WeightingMethod", ".", "OCCURRENCES", ")", ")", "{", "score", "=", "occurences", ";", "}", "else", "if", "(", "method", ".", "equals", "(", "Parameters", ".", "WeightingMethod", ".", "FREQUENCY", ")", ")", "{", "score", "=", "frequency", ";", "}", "else", "if", "(", "method", ".", "equals", "(", "Parameters", ".", "WeightingMethod", ".", "TFIDF", ")", ")", "{", "int", "df", "=", "lexicon", ".", "getDocFreq", "(", "indexTerm", ")", ";", "double", "idf", "=", "numdocs", "/", "(", "double", ")", "df", ";", "score", "=", "frequency", "*", "Math", ".", "log", "(", "idf", ")", ";", "if", "(", "idf", "==", "1", ")", "score", "=", "frequency", ";", "}", "return", "score", ";", "}" ]
Returns the score of an attribute given the weighting scheme specified in the lexicon or for a specific field
[ "Returns", "the", "score", "of", "an", "attribute", "given", "the", "weighting", "scheme", "specified", "in", "the", "lexicon", "or", "for", "a", "specific", "field" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/MultiFieldDocument.java#L301-L327
10,462
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/MultiFieldDocument.java
MultiFieldDocument.normalizeL2
private void normalizeL2(double[] scores) { double square_sum = 0.0; for (int i = 0; i < scores.length; i++) { square_sum += (scores[i] * scores[i]); } double norm = Math.sqrt(square_sum); if (norm != 0) for (int i = 0; i < scores.length; i++) { scores[i] = scores[i] / norm; } }
java
private void normalizeL2(double[] scores) { double square_sum = 0.0; for (int i = 0; i < scores.length; i++) { square_sum += (scores[i] * scores[i]); } double norm = Math.sqrt(square_sum); if (norm != 0) for (int i = 0; i < scores.length; i++) { scores[i] = scores[i] / norm; } }
[ "private", "void", "normalizeL2", "(", "double", "[", "]", "scores", ")", "{", "double", "square_sum", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "scores", ".", "length", ";", "i", "++", ")", "{", "square_sum", "+=", "(", "scores", "[", "i", "]", "*", "scores", "[", "i", "]", ")", ";", "}", "double", "norm", "=", "Math", ".", "sqrt", "(", "square_sum", ")", ";", "if", "(", "norm", "!=", "0", ")", "for", "(", "int", "i", "=", "0", ";", "i", "<", "scores", ".", "length", ";", "i", "++", ")", "{", "scores", "[", "i", "]", "=", "scores", "[", "i", "]", "/", "norm", ";", "}", "}" ]
Returns the L2 norm factor of this vector's values.
[ "Returns", "the", "L2", "norm", "factor", "of", "this", "vector", "s", "values", "." ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/MultiFieldDocument.java#L332-L342
10,463
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java
ExtensionRegistries.findExtensionByName
public static ExtensionInfo findExtensionByName(final ExtensionRegistry registry, final Descriptor containingType, final String name) { final int index = name.lastIndexOf("."); final String nameLastPart = index == -1 ? name : name.substring(index + 1); return registry.findImmutableExtensionByName(containingType.getFullName() + "." + nameLastPart); }
java
public static ExtensionInfo findExtensionByName(final ExtensionRegistry registry, final Descriptor containingType, final String name) { final int index = name.lastIndexOf("."); final String nameLastPart = index == -1 ? name : name.substring(index + 1); return registry.findImmutableExtensionByName(containingType.getFullName() + "." + nameLastPart); }
[ "public", "static", "ExtensionInfo", "findExtensionByName", "(", "final", "ExtensionRegistry", "registry", ",", "final", "Descriptor", "containingType", ",", "final", "String", "name", ")", "{", "final", "int", "index", "=", "name", ".", "lastIndexOf", "(", "\".\"", ")", ";", "final", "String", "nameLastPart", "=", "index", "==", "-", "1", "?", "name", ":", "name", ".", "substring", "(", "index", "+", "1", ")", ";", "return", "registry", ".", "findImmutableExtensionByName", "(", "containingType", ".", "getFullName", "(", ")", "+", "\".\"", "+", "nameLastPart", ")", ";", "}" ]
Finds extension by its containing type and the dot separated multi-part name.
[ "Finds", "extension", "by", "its", "containing", "type", "and", "the", "dot", "separated", "multi", "-", "part", "name", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java#L25-L30
10,464
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java
ExtensionRegistries.addWithDependeciesToRegistry
public static ExtensionRegistry addWithDependeciesToRegistry(final FileDescriptor file, final ExtensionRegistry registry) { for (final FileDescriptor dependency : getFileWithAllDependencies(file)) { addToRegistry(dependency, registry); } return registry; }
java
public static ExtensionRegistry addWithDependeciesToRegistry(final FileDescriptor file, final ExtensionRegistry registry) { for (final FileDescriptor dependency : getFileWithAllDependencies(file)) { addToRegistry(dependency, registry); } return registry; }
[ "public", "static", "ExtensionRegistry", "addWithDependeciesToRegistry", "(", "final", "FileDescriptor", "file", ",", "final", "ExtensionRegistry", "registry", ")", "{", "for", "(", "final", "FileDescriptor", "dependency", ":", "getFileWithAllDependencies", "(", "file", ")", ")", "{", "addToRegistry", "(", "dependency", ",", "registry", ")", ";", "}", "return", "registry", ";", "}" ]
Adds all extensions, including dependencies, for the given FileDescriptor to the registry.
[ "Adds", "all", "extensions", "including", "dependencies", "for", "the", "given", "FileDescriptor", "to", "the", "registry", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java#L42-L49
10,465
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java
ExtensionRegistries.addToRegistry
public static ExtensionRegistry addToRegistry(final FileDescriptor file, final ExtensionRegistry registry) { for (final FieldDescriptor extension : file.getExtensions()) { addToRegistry(extension, registry); } for (final Descriptor descriptor : file.getMessageTypes()) { addToRegistry(descriptor, registry); } return registry; }
java
public static ExtensionRegistry addToRegistry(final FileDescriptor file, final ExtensionRegistry registry) { for (final FieldDescriptor extension : file.getExtensions()) { addToRegistry(extension, registry); } for (final Descriptor descriptor : file.getMessageTypes()) { addToRegistry(descriptor, registry); } return registry; }
[ "public", "static", "ExtensionRegistry", "addToRegistry", "(", "final", "FileDescriptor", "file", ",", "final", "ExtensionRegistry", "registry", ")", "{", "for", "(", "final", "FieldDescriptor", "extension", ":", "file", ".", "getExtensions", "(", ")", ")", "{", "addToRegistry", "(", "extension", ",", "registry", ")", ";", "}", "for", "(", "final", "Descriptor", "descriptor", ":", "file", ".", "getMessageTypes", "(", ")", ")", "{", "addToRegistry", "(", "descriptor", ",", "registry", ")", ";", "}", "return", "registry", ";", "}" ]
Adds all extensions, without dependencies, for the given FileDescriptor to the registry.
[ "Adds", "all", "extensions", "without", "dependencies", "for", "the", "given", "FileDescriptor", "to", "the", "registry", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java#L77-L88
10,466
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java
ExtensionRegistries.addToRegistry
public static ExtensionRegistry addToRegistry(final Descriptor descriptor, final ExtensionRegistry registry) { for (final FieldDescriptor extension : descriptor.getExtensions()) { addToRegistry(extension, registry); } for (final Descriptor child : descriptor.getNestedTypes()) { addToRegistry(child, registry); } return registry; }
java
public static ExtensionRegistry addToRegistry(final Descriptor descriptor, final ExtensionRegistry registry) { for (final FieldDescriptor extension : descriptor.getExtensions()) { addToRegistry(extension, registry); } for (final Descriptor child : descriptor.getNestedTypes()) { addToRegistry(child, registry); } return registry; }
[ "public", "static", "ExtensionRegistry", "addToRegistry", "(", "final", "Descriptor", "descriptor", ",", "final", "ExtensionRegistry", "registry", ")", "{", "for", "(", "final", "FieldDescriptor", "extension", ":", "descriptor", ".", "getExtensions", "(", ")", ")", "{", "addToRegistry", "(", "extension", ",", "registry", ")", ";", "}", "for", "(", "final", "Descriptor", "child", ":", "descriptor", ".", "getNestedTypes", "(", ")", ")", "{", "addToRegistry", "(", "child", ",", "registry", ")", ";", "}", "return", "registry", ";", "}" ]
Adds all extensions for the given Descriptor to the registry.
[ "Adds", "all", "extensions", "for", "the", "given", "Descriptor", "to", "the", "registry", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java#L93-L104
10,467
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java
ExtensionRegistries.addToRegistry
public static ExtensionRegistry addToRegistry(final FieldDescriptor extension, final ExtensionRegistry registry) { if (extension.getJavaType() == JavaType.MESSAGE) { registry.add(extension, DynamicMessage.getDefaultInstance(extension.getMessageType())); } else { registry.add(extension); } return registry; }
java
public static ExtensionRegistry addToRegistry(final FieldDescriptor extension, final ExtensionRegistry registry) { if (extension.getJavaType() == JavaType.MESSAGE) { registry.add(extension, DynamicMessage.getDefaultInstance(extension.getMessageType())); } else { registry.add(extension); } return registry; }
[ "public", "static", "ExtensionRegistry", "addToRegistry", "(", "final", "FieldDescriptor", "extension", ",", "final", "ExtensionRegistry", "registry", ")", "{", "if", "(", "extension", ".", "getJavaType", "(", ")", "==", "JavaType", ".", "MESSAGE", ")", "{", "registry", ".", "add", "(", "extension", ",", "DynamicMessage", ".", "getDefaultInstance", "(", "extension", ".", "getMessageType", "(", ")", ")", ")", ";", "}", "else", "{", "registry", ".", "add", "(", "extension", ")", ";", "}", "return", "registry", ";", "}" ]
Adds extension to the registry, making a default DynamicMessage if its type is a Message.
[ "Adds", "extension", "to", "the", "registry", "making", "a", "default", "DynamicMessage", "if", "its", "type", "is", "a", "Message", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ExtensionRegistries.java#L109-L118
10,468
protobufel/protobuf-el
protobufel/src/main/java/com/github/protobufel/SingleFieldBuilder.java
SingleFieldBuilder.onChanged
private void onChanged() { // If builder is null, this is the case where onChanged is being called // from setMessage or clear. if (builder != null) { message = null; } if (isClean && parent != null) { parent.markDirty(); // Don't keep dispatching invalidations until build is called again. isClean = false; } }
java
private void onChanged() { // If builder is null, this is the case where onChanged is being called // from setMessage or clear. if (builder != null) { message = null; } if (isClean && parent != null) { parent.markDirty(); // Don't keep dispatching invalidations until build is called again. isClean = false; } }
[ "private", "void", "onChanged", "(", ")", "{", "// If builder is null, this is the case where onChanged is being called\r", "// from setMessage or clear.\r", "if", "(", "builder", "!=", "null", ")", "{", "message", "=", "null", ";", "}", "if", "(", "isClean", "&&", "parent", "!=", "null", ")", "{", "parent", ".", "markDirty", "(", ")", ";", "// Don't keep dispatching invalidations until build is called again.\r", "isClean", "=", "false", ";", "}", "}" ]
Called when a the builder or one of its nested children has changed and any parent should be notified of its invalidation.
[ "Called", "when", "a", "the", "builder", "or", "one", "of", "its", "nested", "children", "has", "changed", "and", "any", "parent", "should", "be", "notified", "of", "its", "invalidation", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel/src/main/java/com/github/protobufel/SingleFieldBuilder.java#L230-L242
10,469
protobufel/protobuf-el
protobufel-el/src/main/java/com/github/protobufel/el/BeanELResolverEx.java
BeanELResolverEx.invoke
@Override public Object invoke(final ELContext context, final Object base, final Object method, Class<?>[] paramTypes, final Object[] params) { if ((base == null) || (method == null)) { return null; } final MethodDescriptor[] methodDescriptors = getMethodDescriptors(context, base); if (methodDescriptors != null) { final Method m = findMethodOrThrow(method.toString(), paramTypes, params, false, methodDescriptors); paramTypes = m.getParameterTypes(); } return super.invoke(context, base, method, paramTypes, params); }
java
@Override public Object invoke(final ELContext context, final Object base, final Object method, Class<?>[] paramTypes, final Object[] params) { if ((base == null) || (method == null)) { return null; } final MethodDescriptor[] methodDescriptors = getMethodDescriptors(context, base); if (methodDescriptors != null) { final Method m = findMethodOrThrow(method.toString(), paramTypes, params, false, methodDescriptors); paramTypes = m.getParameterTypes(); } return super.invoke(context, base, method, paramTypes, params); }
[ "@", "Override", "public", "Object", "invoke", "(", "final", "ELContext", "context", ",", "final", "Object", "base", ",", "final", "Object", "method", ",", "Class", "<", "?", ">", "[", "]", "paramTypes", ",", "final", "Object", "[", "]", "params", ")", "{", "if", "(", "(", "base", "==", "null", ")", "||", "(", "method", "==", "null", ")", ")", "{", "return", "null", ";", "}", "final", "MethodDescriptor", "[", "]", "methodDescriptors", "=", "getMethodDescriptors", "(", "context", ",", "base", ")", ";", "if", "(", "methodDescriptors", "!=", "null", ")", "{", "final", "Method", "m", "=", "findMethodOrThrow", "(", "method", ".", "toString", "(", ")", ",", "paramTypes", ",", "params", ",", "false", ",", "methodDescriptors", ")", ";", "paramTypes", "=", "m", ".", "getParameterTypes", "(", ")", ";", "}", "return", "super", ".", "invoke", "(", "context", ",", "base", ",", "method", ",", "paramTypes", ",", "params", ")", ";", "}" ]
Invokes the method considering the base's BeanInfo class' MethodDescriptors. Resolves method overloads by looking at the MethodDescriptors first and only then the base's class itself, choosing the most specific candidate.
[ "Invokes", "the", "method", "considering", "the", "base", "s", "BeanInfo", "class", "MethodDescriptors", ".", "Resolves", "method", "overloads", "by", "looking", "at", "the", "MethodDescriptors", "first", "and", "only", "then", "the", "base", "s", "class", "itself", "choosing", "the", "most", "specific", "candidate", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-el/src/main/java/com/github/protobufel/el/BeanELResolverEx.java#L72-L88
10,470
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/util/UnZip.java
UnZip.unzip
public static File unzip(File inputZip) { File rootDir = null; try { BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(inputZip); File test = File.createTempFile("aaa", "aaa"); String tempDir = test.getParent(); test.delete(); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; File target = new File(tempDir, entry.getName()); if (entry.getName().endsWith("/")) { target.mkdir(); if (rootDir == null) rootDir = target; continue; } FileOutputStream fos = new FileOutputStream(target); dest = new BufferedOutputStream(fos, BUFFER); while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); } } catch (Exception e) { e.printStackTrace(); } return rootDir; }
java
public static File unzip(File inputZip) { File rootDir = null; try { BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(inputZip); File test = File.createTempFile("aaa", "aaa"); String tempDir = test.getParent(); test.delete(); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; File target = new File(tempDir, entry.getName()); if (entry.getName().endsWith("/")) { target.mkdir(); if (rootDir == null) rootDir = target; continue; } FileOutputStream fos = new FileOutputStream(target); dest = new BufferedOutputStream(fos, BUFFER); while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); } } catch (Exception e) { e.printStackTrace(); } return rootDir; }
[ "public", "static", "File", "unzip", "(", "File", "inputZip", ")", "{", "File", "rootDir", "=", "null", ";", "try", "{", "BufferedOutputStream", "dest", "=", "null", ";", "BufferedInputStream", "is", "=", "null", ";", "ZipEntry", "entry", ";", "ZipFile", "zipfile", "=", "new", "ZipFile", "(", "inputZip", ")", ";", "File", "test", "=", "File", ".", "createTempFile", "(", "\"aaa\"", ",", "\"aaa\"", ")", ";", "String", "tempDir", "=", "test", ".", "getParent", "(", ")", ";", "test", ".", "delete", "(", ")", ";", "Enumeration", "e", "=", "zipfile", ".", "entries", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements", "(", ")", ")", "{", "entry", "=", "(", "ZipEntry", ")", "e", ".", "nextElement", "(", ")", ";", "is", "=", "new", "BufferedInputStream", "(", "zipfile", ".", "getInputStream", "(", "entry", ")", ")", ";", "int", "count", ";", "byte", "data", "[", "]", "=", "new", "byte", "[", "BUFFER", "]", ";", "File", "target", "=", "new", "File", "(", "tempDir", ",", "entry", ".", "getName", "(", ")", ")", ";", "if", "(", "entry", ".", "getName", "(", ")", ".", "endsWith", "(", "\"/\"", ")", ")", "{", "target", ".", "mkdir", "(", ")", ";", "if", "(", "rootDir", "==", "null", ")", "rootDir", "=", "target", ";", "continue", ";", "}", "FileOutputStream", "fos", "=", "new", "FileOutputStream", "(", "target", ")", ";", "dest", "=", "new", "BufferedOutputStream", "(", "fos", ",", "BUFFER", ")", ";", "while", "(", "(", "count", "=", "is", ".", "read", "(", "data", ",", "0", ",", "BUFFER", ")", ")", "!=", "-", "1", ")", "{", "dest", ".", "write", "(", "data", ",", "0", ",", "count", ")", ";", "}", "dest", ".", "flush", "(", ")", ";", "dest", ".", "close", "(", ")", ";", "is", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "return", "rootDir", ";", "}" ]
Unzips the argument into the temp directory and returns the unzipped location. The zip must have a root dir element and not just a flat list of files
[ "Unzips", "the", "argument", "into", "the", "temp", "directory", "and", "returns", "the", "unzipped", "location", ".", "The", "zip", "must", "have", "a", "root", "dir", "element", "and", "not", "just", "a", "flat", "list", "of", "files" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/util/UnZip.java#L18-L54
10,471
highsource/annox
core/src/main/java/org/jvnet/annox/model/XClass.java
XClass.checkMembers
private void checkMembers(XMember<?>[] members) { for (int index = 0; index < members.length; index++) { final XMember<?> member = members[index]; if (!member.getMember().getDeclaringClass() .isAssignableFrom(getTargetClass())) { throw new IllegalArgumentException("Member [" + member + "] does not belong to the target class [" + targetClass + "]."); } } }
java
private void checkMembers(XMember<?>[] members) { for (int index = 0; index < members.length; index++) { final XMember<?> member = members[index]; if (!member.getMember().getDeclaringClass() .isAssignableFrom(getTargetClass())) { throw new IllegalArgumentException("Member [" + member + "] does not belong to the target class [" + targetClass + "]."); } } }
[ "private", "void", "checkMembers", "(", "XMember", "<", "?", ">", "[", "]", "members", ")", "{", "for", "(", "int", "index", "=", "0", ";", "index", "<", "members", ".", "length", ";", "index", "++", ")", "{", "final", "XMember", "<", "?", ">", "member", "=", "members", "[", "index", "]", ";", "if", "(", "!", "member", ".", "getMember", "(", ")", ".", "getDeclaringClass", "(", ")", ".", "isAssignableFrom", "(", "getTargetClass", "(", ")", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Member [\"", "+", "member", "+", "\"] does not belong to the target class [\"", "+", "targetClass", "+", "\"].\"", ")", ";", "}", "}", "}" ]
Checks if all the passed members belong to the given target class.
[ "Checks", "if", "all", "the", "passed", "members", "belong", "to", "the", "given", "target", "class", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XClass.java#L139-L149
10,472
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/OperatingSystemUtils.java
OperatingSystemUtils.getSafeFilename
public static String getSafeFilename(String filename) { String result = filename; if (result != null) { result = result.replaceAll("[^a-zA-Z0-9]+", "-").replaceAll("^-+", ""); } return result; }
java
public static String getSafeFilename(String filename) { String result = filename; if (result != null) { result = result.replaceAll("[^a-zA-Z0-9]+", "-").replaceAll("^-+", ""); } return result; }
[ "public", "static", "String", "getSafeFilename", "(", "String", "filename", ")", "{", "String", "result", "=", "filename", ";", "if", "(", "result", "!=", "null", ")", "{", "result", "=", "result", ".", "replaceAll", "(", "\"[^a-zA-Z0-9]+\"", ",", "\"-\"", ")", ".", "replaceAll", "(", "\"^-+\"", ",", "\"\"", ")", ";", "}", "return", "result", ";", "}" ]
Generate a string that is usable as a single file name or directory path segment on any operating system. Replaces unsafe characters with the underscore '_' character
[ "Generate", "a", "string", "that", "is", "usable", "as", "a", "single", "file", "name", "or", "directory", "path", "segment", "on", "any", "operating", "system", ".", "Replaces", "unsafe", "characters", "with", "the", "underscore", "_", "character" ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/OperatingSystemUtils.java#L121-L129
10,473
protobufel/protobuf-el
protobufel-grammar/src/main/java/com/github/protobufel/grammar/ParserUtils.java
ParserUtils.getLineCount
public static int getLineCount(final String text) { final Matcher matcher = LINE_FINDER.matcher(text); int i = 0; while (matcher.find()) { i++; } return i; }
java
public static int getLineCount(final String text) { final Matcher matcher = LINE_FINDER.matcher(text); int i = 0; while (matcher.find()) { i++; } return i; }
[ "public", "static", "int", "getLineCount", "(", "final", "String", "text", ")", "{", "final", "Matcher", "matcher", "=", "LINE_FINDER", ".", "matcher", "(", "text", ")", ";", "int", "i", "=", "0", ";", "while", "(", "matcher", ".", "find", "(", ")", ")", "{", "i", "++", ";", "}", "return", "i", ";", "}" ]
Gets a zero-based line count of text. @param text a string in which to count lines @return a number of {@code \n} new lines in the text
[ "Gets", "a", "zero", "-", "based", "line", "count", "of", "text", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel-grammar/src/main/java/com/github/protobufel/grammar/ParserUtils.java#L69-L78
10,474
protobufel/protobuf-el
protobufel/src/main/java/com/github/protobufel/MessageAdapter.java
MessageAdapter.getChildFieldDescriptors
protected static List<FieldDescriptor> getChildFieldDescriptors(final Descriptor type) { final List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(); for (final FieldDescriptor field : type.getFields()) { if (field.getJavaType() == JavaType.MESSAGE) { fields.add(field); } } for (final FieldDescriptor field : type.getExtensions()) { if (field.getJavaType() == JavaType.MESSAGE) { fields.add(field); } } return Collections.unmodifiableList(fields); }
java
protected static List<FieldDescriptor> getChildFieldDescriptors(final Descriptor type) { final List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(); for (final FieldDescriptor field : type.getFields()) { if (field.getJavaType() == JavaType.MESSAGE) { fields.add(field); } } for (final FieldDescriptor field : type.getExtensions()) { if (field.getJavaType() == JavaType.MESSAGE) { fields.add(field); } } return Collections.unmodifiableList(fields); }
[ "protected", "static", "List", "<", "FieldDescriptor", ">", "getChildFieldDescriptors", "(", "final", "Descriptor", "type", ")", "{", "final", "List", "<", "FieldDescriptor", ">", "fields", "=", "new", "ArrayList", "<", "FieldDescriptor", ">", "(", ")", ";", "for", "(", "final", "FieldDescriptor", "field", ":", "type", ".", "getFields", "(", ")", ")", "{", "if", "(", "field", ".", "getJavaType", "(", ")", "==", "JavaType", ".", "MESSAGE", ")", "{", "fields", ".", "add", "(", "field", ")", ";", "}", "}", "for", "(", "final", "FieldDescriptor", "field", ":", "type", ".", "getExtensions", "(", ")", ")", "{", "if", "(", "field", ".", "getJavaType", "(", ")", "==", "JavaType", ".", "MESSAGE", ")", "{", "fields", ".", "add", "(", "field", ")", ";", "}", "}", "return", "Collections", ".", "unmodifiableList", "(", "fields", ")", ";", "}" ]
Gets all child MessageOrBuilder descriptors for the type. @author protobufel@gmail.com David Tesler
[ "Gets", "all", "child", "MessageOrBuilder", "descriptors", "for", "the", "type", "." ]
3a600e2f7a8e74b637f44eee0331ef6e57e7441c
https://github.com/protobufel/protobuf-el/blob/3a600e2f7a8e74b637f44eee0331ef6e57e7441c/protobufel/src/main/java/com/github/protobufel/MessageAdapter.java#L546-L562
10,475
highsource/annox
core/src/main/java/org/jvnet/annox/model/XAnnotated.java
XAnnotated.getAnnotations
public Annotation[] getAnnotations() { final XAnnotation<?>[] xannotations = getXAnnotations(); final Annotation[] annotations = new Annotation[xannotations.length]; for (int index = 0; index < xannotations.length; index++) { annotations[index] = xannotations[index].getResult(); } return annotations; }
java
public Annotation[] getAnnotations() { final XAnnotation<?>[] xannotations = getXAnnotations(); final Annotation[] annotations = new Annotation[xannotations.length]; for (int index = 0; index < xannotations.length; index++) { annotations[index] = xannotations[index].getResult(); } return annotations; }
[ "public", "Annotation", "[", "]", "getAnnotations", "(", ")", "{", "final", "XAnnotation", "<", "?", ">", "[", "]", "xannotations", "=", "getXAnnotations", "(", ")", ";", "final", "Annotation", "[", "]", "annotations", "=", "new", "Annotation", "[", "xannotations", ".", "length", "]", ";", "for", "(", "int", "index", "=", "0", ";", "index", "<", "xannotations", ".", "length", ";", "index", "++", ")", "{", "annotations", "[", "index", "]", "=", "xannotations", "[", "index", "]", ".", "getResult", "(", ")", ";", "}", "return", "annotations", ";", "}" ]
Returns annotations for this annotated item. @return Array of annotations.
[ "Returns", "annotations", "for", "this", "annotated", "item", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XAnnotated.java#L42-L49
10,476
forge/furnace
maven-plugin/src/main/java/org/jboss/forge/furnace/maven/plugin/GenerateDOTMojo.java
GenerateDOTMojo.generateDOTFile
private File generateDOTFile(AddonDependencyResolver addonResolver, AddonId id, String fileName) { File parent = new File(outputDirectory); parent.mkdirs(); File file = new File(parent, fileName); getLog().info("Generating " + file); AddonInfo addonInfo = addonResolver.resolveAddonDependencyHierarchy(id); toDOT(file, toGraph(addonResolver, addonInfo)); return file; }
java
private File generateDOTFile(AddonDependencyResolver addonResolver, AddonId id, String fileName) { File parent = new File(outputDirectory); parent.mkdirs(); File file = new File(parent, fileName); getLog().info("Generating " + file); AddonInfo addonInfo = addonResolver.resolveAddonDependencyHierarchy(id); toDOT(file, toGraph(addonResolver, addonInfo)); return file; }
[ "private", "File", "generateDOTFile", "(", "AddonDependencyResolver", "addonResolver", ",", "AddonId", "id", ",", "String", "fileName", ")", "{", "File", "parent", "=", "new", "File", "(", "outputDirectory", ")", ";", "parent", ".", "mkdirs", "(", ")", ";", "File", "file", "=", "new", "File", "(", "parent", ",", "fileName", ")", ";", "getLog", "(", ")", ".", "info", "(", "\"Generating \"", "+", "file", ")", ";", "AddonInfo", "addonInfo", "=", "addonResolver", ".", "resolveAddonDependencyHierarchy", "(", "id", ")", ";", "toDOT", "(", "file", ",", "toGraph", "(", "addonResolver", ",", "addonInfo", ")", ")", ";", "return", "file", ";", "}" ]
Generates the DOT file for a given addonId @param addonResolver @param id @return generated file
[ "Generates", "the", "DOT", "file", "for", "a", "given", "addonId" ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/maven-plugin/src/main/java/org/jboss/forge/furnace/maven/plugin/GenerateDOTMojo.java#L167-L176
10,477
forge/furnace
container/src/main/java/org/jboss/forge/furnace/impl/modules/AddonModuleLoader.java
AddonModuleLoader.loadAddonModule
public final Module loadAddonModule(Addon addon) throws ModuleLoadException { try { this.currentAddon.set(addon); ModuleIdentifier moduleId = moduleCache.getModuleId(addon); Module result = loadModule(moduleId); return result; } catch (ModuleLoadException e) { throw e; } finally { this.currentAddon.remove(); } }
java
public final Module loadAddonModule(Addon addon) throws ModuleLoadException { try { this.currentAddon.set(addon); ModuleIdentifier moduleId = moduleCache.getModuleId(addon); Module result = loadModule(moduleId); return result; } catch (ModuleLoadException e) { throw e; } finally { this.currentAddon.remove(); } }
[ "public", "final", "Module", "loadAddonModule", "(", "Addon", "addon", ")", "throws", "ModuleLoadException", "{", "try", "{", "this", ".", "currentAddon", ".", "set", "(", "addon", ")", ";", "ModuleIdentifier", "moduleId", "=", "moduleCache", ".", "getModuleId", "(", "addon", ")", ";", "Module", "result", "=", "loadModule", "(", "moduleId", ")", ";", "return", "result", ";", "}", "catch", "(", "ModuleLoadException", "e", ")", "{", "throw", "e", ";", "}", "finally", "{", "this", ".", "currentAddon", ".", "remove", "(", ")", ";", "}", "}" ]
Loads a module for the given Addon.
[ "Loads", "a", "module", "for", "the", "given", "Addon", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container/src/main/java/org/jboss/forge/furnace/impl/modules/AddonModuleLoader.java#L85-L102
10,478
forge/furnace
container/src/main/java/org/jboss/forge/furnace/impl/modules/AddonModuleLoader.java
AddonModuleLoader.installModuleMBeanServer
private void installModuleMBeanServer() { try { Method method = ModuleLoader.class.getDeclaredMethod("installMBeanServer"); method.setAccessible(true); method.invoke(null); } catch (Exception e) { throw new ContainerException("Could not install Modules MBean server", e); } }
java
private void installModuleMBeanServer() { try { Method method = ModuleLoader.class.getDeclaredMethod("installMBeanServer"); method.setAccessible(true); method.invoke(null); } catch (Exception e) { throw new ContainerException("Could not install Modules MBean server", e); } }
[ "private", "void", "installModuleMBeanServer", "(", ")", "{", "try", "{", "Method", "method", "=", "ModuleLoader", ".", "class", ".", "getDeclaredMethod", "(", "\"installMBeanServer\"", ")", ";", "method", ".", "setAccessible", "(", "true", ")", ";", "method", ".", "invoke", "(", "null", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ContainerException", "(", "\"Could not install Modules MBean server\"", ",", "e", ")", ";", "}", "}" ]
Installs the MBeanServer.
[ "Installs", "the", "MBeanServer", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container/src/main/java/org/jboss/forge/furnace/impl/modules/AddonModuleLoader.java#L326-L338
10,479
highsource/annox
core/src/main/java/org/jvnet/annox/model/XAnnotation.java
XAnnotation.getResult
public A getResult() { final InvocationHandler handler = new XAnnotationInvocationHandler(this); @SuppressWarnings("unchecked") final A annotation = (A) Proxy.newProxyInstance( annotationClass.getClassLoader(), new Class[] { annotationClass }, handler); return annotation; }
java
public A getResult() { final InvocationHandler handler = new XAnnotationInvocationHandler(this); @SuppressWarnings("unchecked") final A annotation = (A) Proxy.newProxyInstance( annotationClass.getClassLoader(), new Class[] { annotationClass }, handler); return annotation; }
[ "public", "A", "getResult", "(", ")", "{", "final", "InvocationHandler", "handler", "=", "new", "XAnnotationInvocationHandler", "(", "this", ")", ";", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "final", "A", "annotation", "=", "(", "A", ")", "Proxy", ".", "newProxyInstance", "(", "annotationClass", ".", "getClassLoader", "(", ")", ",", "new", "Class", "[", "]", "{", "annotationClass", "}", ",", "handler", ")", ";", "return", "annotation", ";", "}" ]
Returns the instance of the annotation for this xannotation. @return Instance of the annotation for this xannotation.
[ "Returns", "the", "instance", "of", "the", "annotation", "for", "this", "xannotation", "." ]
6588904a08e41cd382d8380bd7482832f7580eb3
https://github.com/highsource/annox/blob/6588904a08e41cd382d8380bd7482832f7580eb3/core/src/main/java/org/jvnet/annox/model/XAnnotation.java#L258-L267
10,480
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/util/CorpusUtils.java
CorpusUtils.filterFields
public static void filterFields(File trainingCorpus, File newRawFile, int[] fieldsToKeep) throws IOException { FileTrainingCorpus ftc = new FileTrainingCorpus(trainingCorpus); Writer writer = new BufferedWriter(new FileWriter(newRawFile)); Iterator<Document> iterator = ftc.iterator(); while (iterator.hasNext()) { MultiFieldDocument doc = (MultiFieldDocument) iterator.next(); String representation = doc.getStringSerialization(fieldsToKeep); writer.write(representation); } writer.close(); }
java
public static void filterFields(File trainingCorpus, File newRawFile, int[] fieldsToKeep) throws IOException { FileTrainingCorpus ftc = new FileTrainingCorpus(trainingCorpus); Writer writer = new BufferedWriter(new FileWriter(newRawFile)); Iterator<Document> iterator = ftc.iterator(); while (iterator.hasNext()) { MultiFieldDocument doc = (MultiFieldDocument) iterator.next(); String representation = doc.getStringSerialization(fieldsToKeep); writer.write(representation); } writer.close(); }
[ "public", "static", "void", "filterFields", "(", "File", "trainingCorpus", ",", "File", "newRawFile", ",", "int", "[", "]", "fieldsToKeep", ")", "throws", "IOException", "{", "FileTrainingCorpus", "ftc", "=", "new", "FileTrainingCorpus", "(", "trainingCorpus", ")", ";", "Writer", "writer", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "newRawFile", ")", ")", ";", "Iterator", "<", "Document", ">", "iterator", "=", "ftc", ".", "iterator", "(", ")", ";", "while", "(", "iterator", ".", "hasNext", "(", ")", ")", "{", "MultiFieldDocument", "doc", "=", "(", "MultiFieldDocument", ")", "iterator", ".", "next", "(", ")", ";", "String", "representation", "=", "doc", ".", "getStringSerialization", "(", "fieldsToKeep", ")", ";", "writer", ".", "write", "(", "representation", ")", ";", "}", "writer", ".", "close", "(", ")", ";", "}" ]
rewrite a raw file so that only a subset of the fields are kept
[ "rewrite", "a", "raw", "file", "so", "that", "only", "a", "subset", "of", "the", "fields", "are", "kept" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/util/CorpusUtils.java#L47-L58
10,481
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/util/CorpusUtils.java
CorpusUtils.randomSelection
public static void randomSelection(File input, int expected_number, boolean noTest) throws IOException { BitSet biset = new BitSet(); Random random = new java.util.Random(); // find the number of lines in the original file int maxNumLines = 0; BufferedReader reader = new BufferedReader(new FileReader(input)); while ((reader.readLine()) != null) { maxNumLines++; } System.out.println("Original file : " + maxNumLines + " lines"); boolean dumpAll = maxNumLines <= expected_number; int added = 0; while (added <= expected_number) { int randomInt = random.nextInt(maxNumLines + 1); if (biset.get(randomInt) == false) { biset.set(randomInt, true); added++; } } // read the original raw file and generate a subset File output = new File(input.getParentFile(), input.getName() + "_" + expected_number); // put the rest in a file which we can use for eval File eval = new File(input.getParentFile(), input.getName() + "_" + expected_number + ".test"); reader.close(); reader = new BufferedReader(new FileReader(input)); BufferedWriter writer = new BufferedWriter(new FileWriter(output)); BufferedWriter writer2 = null; if (noTest == false) writer2 = new BufferedWriter(new FileWriter(eval)); int count = 0; int kept = 0; String line = null; while ((line = reader.readLine()) != null) { if (biset.get(count) || dumpAll) { writer.append(line + "\n"); kept++; } else if (noTest == false) { writer2.append(line + "\n"); } count++; } System.out.println("New file : " + kept + " lines"); if (noTest == false) writer2.close(); writer.close(); reader.close(); }
java
public static void randomSelection(File input, int expected_number, boolean noTest) throws IOException { BitSet biset = new BitSet(); Random random = new java.util.Random(); // find the number of lines in the original file int maxNumLines = 0; BufferedReader reader = new BufferedReader(new FileReader(input)); while ((reader.readLine()) != null) { maxNumLines++; } System.out.println("Original file : " + maxNumLines + " lines"); boolean dumpAll = maxNumLines <= expected_number; int added = 0; while (added <= expected_number) { int randomInt = random.nextInt(maxNumLines + 1); if (biset.get(randomInt) == false) { biset.set(randomInt, true); added++; } } // read the original raw file and generate a subset File output = new File(input.getParentFile(), input.getName() + "_" + expected_number); // put the rest in a file which we can use for eval File eval = new File(input.getParentFile(), input.getName() + "_" + expected_number + ".test"); reader.close(); reader = new BufferedReader(new FileReader(input)); BufferedWriter writer = new BufferedWriter(new FileWriter(output)); BufferedWriter writer2 = null; if (noTest == false) writer2 = new BufferedWriter(new FileWriter(eval)); int count = 0; int kept = 0; String line = null; while ((line = reader.readLine()) != null) { if (biset.get(count) || dumpAll) { writer.append(line + "\n"); kept++; } else if (noTest == false) { writer2.append(line + "\n"); } count++; } System.out.println("New file : " + kept + " lines"); if (noTest == false) writer2.close(); writer.close(); reader.close(); }
[ "public", "static", "void", "randomSelection", "(", "File", "input", ",", "int", "expected_number", ",", "boolean", "noTest", ")", "throws", "IOException", "{", "BitSet", "biset", "=", "new", "BitSet", "(", ")", ";", "Random", "random", "=", "new", "java", ".", "util", ".", "Random", "(", ")", ";", "// find the number of lines in the original file", "int", "maxNumLines", "=", "0", ";", "BufferedReader", "reader", "=", "new", "BufferedReader", "(", "new", "FileReader", "(", "input", ")", ")", ";", "while", "(", "(", "reader", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "maxNumLines", "++", ";", "}", "System", ".", "out", ".", "println", "(", "\"Original file : \"", "+", "maxNumLines", "+", "\" lines\"", ")", ";", "boolean", "dumpAll", "=", "maxNumLines", "<=", "expected_number", ";", "int", "added", "=", "0", ";", "while", "(", "added", "<=", "expected_number", ")", "{", "int", "randomInt", "=", "random", ".", "nextInt", "(", "maxNumLines", "+", "1", ")", ";", "if", "(", "biset", ".", "get", "(", "randomInt", ")", "==", "false", ")", "{", "biset", ".", "set", "(", "randomInt", ",", "true", ")", ";", "added", "++", ";", "}", "}", "// read the original raw file and generate a subset", "File", "output", "=", "new", "File", "(", "input", ".", "getParentFile", "(", ")", ",", "input", ".", "getName", "(", ")", "+", "\"_\"", "+", "expected_number", ")", ";", "// put the rest in a file which we can use for eval", "File", "eval", "=", "new", "File", "(", "input", ".", "getParentFile", "(", ")", ",", "input", ".", "getName", "(", ")", "+", "\"_\"", "+", "expected_number", "+", "\".test\"", ")", ";", "reader", ".", "close", "(", ")", ";", "reader", "=", "new", "BufferedReader", "(", "new", "FileReader", "(", "input", ")", ")", ";", "BufferedWriter", "writer", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "output", ")", ")", ";", "BufferedWriter", "writer2", "=", "null", ";", "if", "(", "noTest", "==", "false", ")", "writer2", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "eval", ")", ")", ";", "int", "count", "=", "0", ";", "int", "kept", "=", "0", ";", "String", "line", "=", "null", ";", "while", "(", "(", "line", "=", "reader", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "biset", ".", "get", "(", "count", ")", "||", "dumpAll", ")", "{", "writer", ".", "append", "(", "line", "+", "\"\\n\"", ")", ";", "kept", "++", ";", "}", "else", "if", "(", "noTest", "==", "false", ")", "{", "writer2", ".", "append", "(", "line", "+", "\"\\n\"", ")", ";", "}", "count", "++", ";", "}", "System", ".", "out", ".", "println", "(", "\"New file : \"", "+", "kept", "+", "\" lines\"", ")", ";", "if", "(", "noTest", "==", "false", ")", "writer2", ".", "close", "(", ")", ";", "writer", ".", "close", "(", ")", ";", "reader", ".", "close", "(", ")", ";", "}" ]
Generates a random sample of lines from an input file and stores the selection in a file named like the original but with the suffix "_"+number of lines. @param input = input file @param expected_number = number of lines to generate @param noTest = indicates whether the lines which haven't been selected must be kept in a separate file e.g. for testing
[ "Generates", "a", "random", "sample", "of", "lines", "from", "an", "input", "file", "and", "stores", "the", "selection", "in", "a", "file", "named", "like", "the", "original", "but", "with", "the", "suffix", "_", "+", "number", "of", "lines", "." ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/util/CorpusUtils.java#L153-L211
10,482
forge/furnace
proxy/src/main/java/org/jboss/forge/furnace/proxy/Proxies.java
Proxies.unwrapProxyClassName
public static String unwrapProxyClassName(Class<?> type) { String typeName = null; if (type != null) { if (type.getName().contains("$$EnhancerByCGLIB$$")) { typeName = CGLIB_CLASSNAME_REGEXP.matcher(type.getName()).replaceAll("$1"); } else if (type.getName().contains("_jvst")) { typeName = JAVASSIST_CLASSNAME_REGEXP.matcher(type.getName()).replaceAll("$1"); } else { typeName = type.getName(); } } return typeName; }
java
public static String unwrapProxyClassName(Class<?> type) { String typeName = null; if (type != null) { if (type.getName().contains("$$EnhancerByCGLIB$$")) { typeName = CGLIB_CLASSNAME_REGEXP.matcher(type.getName()).replaceAll("$1"); } else if (type.getName().contains("_jvst")) { typeName = JAVASSIST_CLASSNAME_REGEXP.matcher(type.getName()).replaceAll("$1"); } else { typeName = type.getName(); } } return typeName; }
[ "public", "static", "String", "unwrapProxyClassName", "(", "Class", "<", "?", ">", "type", ")", "{", "String", "typeName", "=", "null", ";", "if", "(", "type", "!=", "null", ")", "{", "if", "(", "type", ".", "getName", "(", ")", ".", "contains", "(", "\"$$EnhancerByCGLIB$$\"", ")", ")", "{", "typeName", "=", "CGLIB_CLASSNAME_REGEXP", ".", "matcher", "(", "type", ".", "getName", "(", ")", ")", ".", "replaceAll", "(", "\"$1\"", ")", ";", "}", "else", "if", "(", "type", ".", "getName", "(", ")", ".", "contains", "(", "\"_jvst\"", ")", ")", "{", "typeName", "=", "JAVASSIST_CLASSNAME_REGEXP", ".", "matcher", "(", "type", ".", "getName", "(", ")", ")", ".", "replaceAll", "(", "\"$1\"", ")", ";", "}", "else", "{", "typeName", "=", "type", ".", "getName", "(", ")", ";", "}", "}", "return", "typeName", ";", "}" ]
Unwraps the proxy type if javassist or CGLib is used @param type the class type @return the unproxied class name
[ "Unwraps", "the", "proxy", "type", "if", "javassist", "or", "CGLib", "is", "used" ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/proxy/src/main/java/org/jboss/forge/furnace/proxy/Proxies.java#L372-L391
10,483
forge/furnace
proxy/src/main/java/org/jboss/forge/furnace/proxy/Proxies.java
Proxies.areEquivalent
public static boolean areEquivalent(Object proxiedObj, Object anotherProxiedObj) { if (proxiedObj == null && anotherProxiedObj == null) { return true; } else if (proxiedObj == null || anotherProxiedObj == null) { return false; } else { Object unproxiedObj = unwrap(proxiedObj); Object anotherUnproxiedObj = unwrap(anotherProxiedObj); boolean sameClassName = unwrapProxyClassName(unproxiedObj.getClass()).equals( unwrapProxyClassName(anotherUnproxiedObj.getClass())); if (sameClassName) { if (unproxiedObj.getClass().isEnum()) { // Enum hashCode is different if loaded from different classloaders and cannot be overriden. Enum<?> enumLeft = Enum.class.cast(unproxiedObj); Enum<?> enumRight = Enum.class.cast(anotherUnproxiedObj); return (enumLeft.name().equals(enumRight.name())) && (enumLeft.ordinal() == enumRight.ordinal()); } else { return (unproxiedObj.hashCode() == anotherUnproxiedObj.hashCode()); } } else { return false; } } }
java
public static boolean areEquivalent(Object proxiedObj, Object anotherProxiedObj) { if (proxiedObj == null && anotherProxiedObj == null) { return true; } else if (proxiedObj == null || anotherProxiedObj == null) { return false; } else { Object unproxiedObj = unwrap(proxiedObj); Object anotherUnproxiedObj = unwrap(anotherProxiedObj); boolean sameClassName = unwrapProxyClassName(unproxiedObj.getClass()).equals( unwrapProxyClassName(anotherUnproxiedObj.getClass())); if (sameClassName) { if (unproxiedObj.getClass().isEnum()) { // Enum hashCode is different if loaded from different classloaders and cannot be overriden. Enum<?> enumLeft = Enum.class.cast(unproxiedObj); Enum<?> enumRight = Enum.class.cast(anotherUnproxiedObj); return (enumLeft.name().equals(enumRight.name())) && (enumLeft.ordinal() == enumRight.ordinal()); } else { return (unproxiedObj.hashCode() == anotherUnproxiedObj.hashCode()); } } else { return false; } } }
[ "public", "static", "boolean", "areEquivalent", "(", "Object", "proxiedObj", ",", "Object", "anotherProxiedObj", ")", "{", "if", "(", "proxiedObj", "==", "null", "&&", "anotherProxiedObj", "==", "null", ")", "{", "return", "true", ";", "}", "else", "if", "(", "proxiedObj", "==", "null", "||", "anotherProxiedObj", "==", "null", ")", "{", "return", "false", ";", "}", "else", "{", "Object", "unproxiedObj", "=", "unwrap", "(", "proxiedObj", ")", ";", "Object", "anotherUnproxiedObj", "=", "unwrap", "(", "anotherProxiedObj", ")", ";", "boolean", "sameClassName", "=", "unwrapProxyClassName", "(", "unproxiedObj", ".", "getClass", "(", ")", ")", ".", "equals", "(", "unwrapProxyClassName", "(", "anotherUnproxiedObj", ".", "getClass", "(", ")", ")", ")", ";", "if", "(", "sameClassName", ")", "{", "if", "(", "unproxiedObj", ".", "getClass", "(", ")", ".", "isEnum", "(", ")", ")", "{", "// Enum hashCode is different if loaded from different classloaders and cannot be overriden.", "Enum", "<", "?", ">", "enumLeft", "=", "Enum", ".", "class", ".", "cast", "(", "unproxiedObj", ")", ";", "Enum", "<", "?", ">", "enumRight", "=", "Enum", ".", "class", ".", "cast", "(", "anotherUnproxiedObj", ")", ";", "return", "(", "enumLeft", ".", "name", "(", ")", ".", "equals", "(", "enumRight", ".", "name", "(", ")", ")", ")", "&&", "(", "enumLeft", ".", "ordinal", "(", ")", "==", "enumRight", ".", "ordinal", "(", ")", ")", ";", "}", "else", "{", "return", "(", "unproxiedObj", ".", "hashCode", "(", ")", "==", "anotherUnproxiedObj", ".", "hashCode", "(", ")", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "}" ]
This method tests if two proxied objects are equivalent. It does so by comparing the class names and the hashCode, since they may be loaded from different classloaders.
[ "This", "method", "tests", "if", "two", "proxied", "objects", "are", "equivalent", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/proxy/src/main/java/org/jboss/forge/furnace/proxy/Proxies.java#L398-L434
10,484
craftercms/search
crafter-search-api/src/main/java/org/craftercms/search/utils/SearchResultUtils.java
SearchResultUtils.getDocuments
@SuppressWarnings("unchecked") public static final List<Map<String, Object>> getDocuments(Map<String, Object> result) { if (MapUtils.isNotEmpty(result) && result.containsKey(RESPONSE_KEY)) { Map<String, Object> response = (Map<String, Object>)result.get(RESPONSE_KEY); if (MapUtils.isNotEmpty(response) && response.containsKey(DOCUMENTS_KEY)) { return (List<Map<String, Object>>)response.get(DOCUMENTS_KEY); } } return null; }
java
@SuppressWarnings("unchecked") public static final List<Map<String, Object>> getDocuments(Map<String, Object> result) { if (MapUtils.isNotEmpty(result) && result.containsKey(RESPONSE_KEY)) { Map<String, Object> response = (Map<String, Object>)result.get(RESPONSE_KEY); if (MapUtils.isNotEmpty(response) && response.containsKey(DOCUMENTS_KEY)) { return (List<Map<String, Object>>)response.get(DOCUMENTS_KEY); } } return null; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "final", "List", "<", "Map", "<", "String", ",", "Object", ">", ">", "getDocuments", "(", "Map", "<", "String", ",", "Object", ">", "result", ")", "{", "if", "(", "MapUtils", ".", "isNotEmpty", "(", "result", ")", "&&", "result", ".", "containsKey", "(", "RESPONSE_KEY", ")", ")", "{", "Map", "<", "String", ",", "Object", ">", "response", "=", "(", "Map", "<", "String", ",", "Object", ">", ")", "result", ".", "get", "(", "RESPONSE_KEY", ")", ";", "if", "(", "MapUtils", ".", "isNotEmpty", "(", "response", ")", "&&", "response", ".", "containsKey", "(", "DOCUMENTS_KEY", ")", ")", "{", "return", "(", "List", "<", "Map", "<", "String", ",", "Object", ">", ">", ")", "response", ".", "get", "(", "DOCUMENTS_KEY", ")", ";", "}", "}", "return", "null", ";", "}" ]
Extract the documents from the specified result. @param result the result containing the documents @return the documents
[ "Extract", "the", "documents", "from", "the", "specified", "result", "." ]
337ba446badbfbc4912cd8ccd7d50fd62d6be2cc
https://github.com/craftercms/search/blob/337ba446badbfbc4912cd8ccd7d50fd62d6be2cc/crafter-search-api/src/main/java/org/craftercms/search/utils/SearchResultUtils.java#L39-L49
10,485
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/Learner.java
Learner.createDocument
public Document createDocument(String[] tokenstring) { this.lexicon.incrementDocCount(); return new SimpleDocument(tokenstring, this.lexicon, true); }
java
public Document createDocument(String[] tokenstring) { this.lexicon.incrementDocCount(); return new SimpleDocument(tokenstring, this.lexicon, true); }
[ "public", "Document", "createDocument", "(", "String", "[", "]", "tokenstring", ")", "{", "this", ".", "lexicon", ".", "incrementDocCount", "(", ")", ";", "return", "new", "SimpleDocument", "(", "tokenstring", ",", "this", ".", "lexicon", ",", "true", ")", ";", "}" ]
Create a Document from an array of Strings
[ "Create", "a", "Document", "from", "an", "array", "of", "Strings" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/Learner.java#L87-L90
10,486
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/Learner.java
Learner.createDocument
public Document createDocument(String[] tokenstring, String label) { this.lexicon.incrementDocCount(); SimpleDocument doc = new SimpleDocument(tokenstring, this.lexicon, true); doc.setLabel(this.lexicon.getLabelIndex(label)); return doc; }
java
public Document createDocument(String[] tokenstring, String label) { this.lexicon.incrementDocCount(); SimpleDocument doc = new SimpleDocument(tokenstring, this.lexicon, true); doc.setLabel(this.lexicon.getLabelIndex(label)); return doc; }
[ "public", "Document", "createDocument", "(", "String", "[", "]", "tokenstring", ",", "String", "label", ")", "{", "this", ".", "lexicon", ".", "incrementDocCount", "(", ")", ";", "SimpleDocument", "doc", "=", "new", "SimpleDocument", "(", "tokenstring", ",", "this", ".", "lexicon", ",", "true", ")", ";", "doc", ".", "setLabel", "(", "this", ".", "lexicon", ".", "getLabelIndex", "(", "label", ")", ")", ";", "return", "doc", ";", "}" ]
Create a Document from an array of Strings and specify the label
[ "Create", "a", "Document", "from", "an", "array", "of", "Strings", "and", "specify", "the", "label" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/Learner.java#L95-L100
10,487
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/Learner.java
Learner.getLearner
public static Learner getLearner(String workdirectory, String implementationName, boolean overwrite) throws Exception { File directory = new File(workdirectory); if (directory.exists() == false) throw new Exception(workdirectory + " must exist"); if (directory.isDirectory() == false) throw new Exception(workdirectory + " must be a directory"); // create the file names String model_file_name = workdirectory + File.separator + Parameters.modelName; String lexicon_file_name = workdirectory + File.separator + Parameters.lexiconName; String vector_file_name = workdirectory + File.separator + Parameters.vectorName; String raw_file_name = workdirectory + File.separator + Parameters.rawName; Learner learner = null; // removes existing files for lexicon model and vector if (overwrite) { removeExistingFile(model_file_name); removeExistingFile(lexicon_file_name); removeExistingFile(vector_file_name); removeExistingFile(raw_file_name); } // define which implementation to use if (LibSVMModelCreator.equals(implementationName)) learner = new LibSVMModelCreator(lexicon_file_name, model_file_name, vector_file_name); else if (LibLinearModelCreator.equals(implementationName)) learner = new LibLinearModelCreator(lexicon_file_name, model_file_name, vector_file_name); else throw new Exception(implementationName + " is unknown"); // reuse the existing lexicon if (!overwrite) { Lexicon oldlexicon = new Lexicon(lexicon_file_name); if (oldlexicon != null) learner.lexicon = oldlexicon; } learner.workdirectory = directory; return learner; }
java
public static Learner getLearner(String workdirectory, String implementationName, boolean overwrite) throws Exception { File directory = new File(workdirectory); if (directory.exists() == false) throw new Exception(workdirectory + " must exist"); if (directory.isDirectory() == false) throw new Exception(workdirectory + " must be a directory"); // create the file names String model_file_name = workdirectory + File.separator + Parameters.modelName; String lexicon_file_name = workdirectory + File.separator + Parameters.lexiconName; String vector_file_name = workdirectory + File.separator + Parameters.vectorName; String raw_file_name = workdirectory + File.separator + Parameters.rawName; Learner learner = null; // removes existing files for lexicon model and vector if (overwrite) { removeExistingFile(model_file_name); removeExistingFile(lexicon_file_name); removeExistingFile(vector_file_name); removeExistingFile(raw_file_name); } // define which implementation to use if (LibSVMModelCreator.equals(implementationName)) learner = new LibSVMModelCreator(lexicon_file_name, model_file_name, vector_file_name); else if (LibLinearModelCreator.equals(implementationName)) learner = new LibLinearModelCreator(lexicon_file_name, model_file_name, vector_file_name); else throw new Exception(implementationName + " is unknown"); // reuse the existing lexicon if (!overwrite) { Lexicon oldlexicon = new Lexicon(lexicon_file_name); if (oldlexicon != null) learner.lexicon = oldlexicon; } learner.workdirectory = directory; return learner; }
[ "public", "static", "Learner", "getLearner", "(", "String", "workdirectory", ",", "String", "implementationName", ",", "boolean", "overwrite", ")", "throws", "Exception", "{", "File", "directory", "=", "new", "File", "(", "workdirectory", ")", ";", "if", "(", "directory", ".", "exists", "(", ")", "==", "false", ")", "throw", "new", "Exception", "(", "workdirectory", "+", "\" must exist\"", ")", ";", "if", "(", "directory", ".", "isDirectory", "(", ")", "==", "false", ")", "throw", "new", "Exception", "(", "workdirectory", "+", "\" must be a directory\"", ")", ";", "// create the file names\r", "String", "model_file_name", "=", "workdirectory", "+", "File", ".", "separator", "+", "Parameters", ".", "modelName", ";", "String", "lexicon_file_name", "=", "workdirectory", "+", "File", ".", "separator", "+", "Parameters", ".", "lexiconName", ";", "String", "vector_file_name", "=", "workdirectory", "+", "File", ".", "separator", "+", "Parameters", ".", "vectorName", ";", "String", "raw_file_name", "=", "workdirectory", "+", "File", ".", "separator", "+", "Parameters", ".", "rawName", ";", "Learner", "learner", "=", "null", ";", "// removes existing files for lexicon model and vector\r", "if", "(", "overwrite", ")", "{", "removeExistingFile", "(", "model_file_name", ")", ";", "removeExistingFile", "(", "lexicon_file_name", ")", ";", "removeExistingFile", "(", "vector_file_name", ")", ";", "removeExistingFile", "(", "raw_file_name", ")", ";", "}", "// define which implementation to use\r", "if", "(", "LibSVMModelCreator", ".", "equals", "(", "implementationName", ")", ")", "learner", "=", "new", "LibSVMModelCreator", "(", "lexicon_file_name", ",", "model_file_name", ",", "vector_file_name", ")", ";", "else", "if", "(", "LibLinearModelCreator", ".", "equals", "(", "implementationName", ")", ")", "learner", "=", "new", "LibLinearModelCreator", "(", "lexicon_file_name", ",", "model_file_name", ",", "vector_file_name", ")", ";", "else", "throw", "new", "Exception", "(", "implementationName", "+", "\" is unknown\"", ")", ";", "// reuse the existing lexicon\r", "if", "(", "!", "overwrite", ")", "{", "Lexicon", "oldlexicon", "=", "new", "Lexicon", "(", "lexicon_file_name", ")", ";", "if", "(", "oldlexicon", "!=", "null", ")", "learner", ".", "lexicon", "=", "oldlexicon", ";", "}", "learner", ".", "workdirectory", "=", "directory", ";", "return", "learner", ";", "}" ]
Generate an instance of Learner from an existing directory. @param overwrite deletes any existing data in the model directory @return an instance of a Learner corresponding to the implementationName @throws ClassNotFoundException @throws IllegalAccessException @throws InstantiationException
[ "Generate", "an", "instance", "of", "Learner", "from", "an", "existing", "directory", "." ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/Learner.java#L190-L236
10,488
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.count
public static int count(final String string, final String substring) { int count = 0; int idx = 0; while ((idx = string.indexOf(substring, idx)) != -1) { idx++; count++; } return count; }
java
public static int count(final String string, final String substring) { int count = 0; int idx = 0; while ((idx = string.indexOf(substring, idx)) != -1) { idx++; count++; } return count; }
[ "public", "static", "int", "count", "(", "final", "String", "string", ",", "final", "String", "substring", ")", "{", "int", "count", "=", "0", ";", "int", "idx", "=", "0", ";", "while", "(", "(", "idx", "=", "string", ".", "indexOf", "(", "substring", ",", "idx", ")", ")", "!=", "-", "1", ")", "{", "idx", "++", ";", "count", "++", ";", "}", "return", "count", ";", "}" ]
Count the number of instances of substring within a string. @param string String to look for substring in. @param substring Sub-string to look for. @return Count of substrings in string.
[ "Count", "the", "number", "of", "instances", "of", "substring", "within", "a", "string", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L570-L582
10,489
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.pad
public static String pad(final StringBuffer buff, final String string, final int count) { for (int i = 0; i < count; i++) { buff.append(string); } return buff.toString(); }
java
public static String pad(final StringBuffer buff, final String string, final int count) { for (int i = 0; i < count; i++) { buff.append(string); } return buff.toString(); }
[ "public", "static", "String", "pad", "(", "final", "StringBuffer", "buff", ",", "final", "String", "string", ",", "final", "int", "count", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "count", ";", "i", "++", ")", "{", "buff", ".", "append", "(", "string", ")", ";", "}", "return", "buff", ".", "toString", "(", ")", ";", "}" ]
Return a string padded with the given string for the given count. @param buff String buffer used for padding (buffer is not reset). @param string Pad element. @param count Pad count. @return Padded string.
[ "Return", "a", "string", "padded", "with", "the", "given", "string", "for", "the", "given", "count", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L608-L617
10,490
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.pad
public static String pad(final Object obj, final int count) { return pad(new StringBuffer(), String.valueOf(obj), count); }
java
public static String pad(final Object obj, final int count) { return pad(new StringBuffer(), String.valueOf(obj), count); }
[ "public", "static", "String", "pad", "(", "final", "Object", "obj", ",", "final", "int", "count", ")", "{", "return", "pad", "(", "new", "StringBuffer", "(", ")", ",", "String", ".", "valueOf", "(", "obj", ")", ",", "count", ")", ";", "}" ]
Return a string padded with the given string value of an object for the given count. @param obj Object to convert to a string. @param count Pad count. @return Padded string.
[ "Return", "a", "string", "padded", "with", "the", "given", "string", "value", "of", "an", "object", "for", "the", "given", "count", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L638-L641
10,491
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.capitalize
public static String capitalize(final String string) { if (string == null) throw new IllegalArgumentException("string"); if (string.equals("")) throw new IllegalArgumentException("string"); return Character.toUpperCase(string.charAt(0)) + string.substring(1); }
java
public static String capitalize(final String string) { if (string == null) throw new IllegalArgumentException("string"); if (string.equals("")) throw new IllegalArgumentException("string"); return Character.toUpperCase(string.charAt(0)) + string.substring(1); }
[ "public", "static", "String", "capitalize", "(", "final", "String", "string", ")", "{", "if", "(", "string", "==", "null", ")", "throw", "new", "IllegalArgumentException", "(", "\"string\"", ")", ";", "if", "(", "string", ".", "equals", "(", "\"\"", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"string\"", ")", ";", "return", "Character", ".", "toUpperCase", "(", "string", ".", "charAt", "(", "0", ")", ")", "+", "string", ".", "substring", "(", "1", ")", ";", "}" ]
Capitalize the first character of the given string. @param string String to capitalize. @return Capitalized string. @throws IllegalArgumentException String is <kk>null</kk> or empty.
[ "Capitalize", "the", "first", "character", "of", "the", "given", "string", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L734-L742
10,492
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.isJavaKeyword
public final static boolean isJavaKeyword(String s) { if (s == null || s.length() == 0) { return false; } for (int i = 0; i < keywords.length; i++) { if (keywords[i].equals(s)) { return true; } } return false; }
java
public final static boolean isJavaKeyword(String s) { if (s == null || s.length() == 0) { return false; } for (int i = 0; i < keywords.length; i++) { if (keywords[i].equals(s)) { return true; } } return false; }
[ "public", "final", "static", "boolean", "isJavaKeyword", "(", "String", "s", ")", "{", "if", "(", "s", "==", "null", "||", "s", ".", "length", "(", ")", "==", "0", ")", "{", "return", "false", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "keywords", ".", "length", ";", "i", "++", ")", "{", "if", "(", "keywords", "[", "i", "]", ".", "equals", "(", "s", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether the given String is a reserved Java Keyword according to the Java Language Specifications. @param s String to check @return <code>true</code> if the given String is a reserved Java keyword, <code>false</code> otherwise.
[ "Check", "whether", "the", "given", "String", "is", "a", "reserved", "Java", "Keyword", "according", "to", "the", "Java", "Language", "Specifications", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L909-L925
10,493
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.isEjbQlIdentifier
public final static boolean isEjbQlIdentifier(String s) { if (s == null || s.length() == 0) { return false; } for (int i = 0; i < ejbQlIdentifiers.length; i++) { if (ejbQlIdentifiers[i].equalsIgnoreCase(s)) { return true; } } return false; }
java
public final static boolean isEjbQlIdentifier(String s) { if (s == null || s.length() == 0) { return false; } for (int i = 0; i < ejbQlIdentifiers.length; i++) { if (ejbQlIdentifiers[i].equalsIgnoreCase(s)) { return true; } } return false; }
[ "public", "final", "static", "boolean", "isEjbQlIdentifier", "(", "String", "s", ")", "{", "if", "(", "s", "==", "null", "||", "s", ".", "length", "(", ")", "==", "0", ")", "{", "return", "false", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ejbQlIdentifiers", ".", "length", ";", "i", "++", ")", "{", "if", "(", "ejbQlIdentifiers", "[", "i", "]", ".", "equalsIgnoreCase", "(", "s", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether the given String is an identifier according to the EJB-QL definition. See The EJB 2.0 Documentation Section 11.2.6.1. @param s String to check @return <code>true</code> if the given String is a reserved identifier in EJB-QL, <code>false</code> otherwise.
[ "Check", "whether", "the", "given", "String", "is", "an", "identifier", "according", "to", "the", "EJB", "-", "QL", "definition", ".", "See", "The", "EJB", "2", ".", "0", "Documentation", "Section", "11", ".", "2", ".", "6", ".", "1", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L935-L951
10,494
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.removeWhiteSpace
public static String removeWhiteSpace(String s) { String retn = null; if (s != null) { int len = s.length(); StringBuffer sbuf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (!Character.isWhitespace(c)) sbuf.append(c); } retn = sbuf.toString(); } return retn; }
java
public static String removeWhiteSpace(String s) { String retn = null; if (s != null) { int len = s.length(); StringBuffer sbuf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (!Character.isWhitespace(c)) sbuf.append(c); } retn = sbuf.toString(); } return retn; }
[ "public", "static", "String", "removeWhiteSpace", "(", "String", "s", ")", "{", "String", "retn", "=", "null", ";", "if", "(", "s", "!=", "null", ")", "{", "int", "len", "=", "s", ".", "length", "(", ")", ";", "StringBuffer", "sbuf", "=", "new", "StringBuffer", "(", "len", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "char", "c", "=", "s", ".", "charAt", "(", "i", ")", ";", "if", "(", "!", "Character", ".", "isWhitespace", "(", "c", ")", ")", "sbuf", ".", "append", "(", "c", ")", ";", "}", "retn", "=", "sbuf", ".", "toString", "(", ")", ";", "}", "return", "retn", ";", "}" ]
Returns a new string with all the whitespace removed @param s the source string @return the string without whitespace or null
[ "Returns", "a", "new", "string", "with", "all", "the", "whitespace", "removed" ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L993-L1012
10,495
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.defaultToString
public static final String defaultToString(Object object) { if (object == null) return "null"; else return object.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(object)); }
java
public static final String defaultToString(Object object) { if (object == null) return "null"; else return object.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(object)); }
[ "public", "static", "final", "String", "defaultToString", "(", "Object", "object", ")", "{", "if", "(", "object", "==", "null", ")", "return", "\"null\"", ";", "else", "return", "object", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "'", "'", "+", "Integer", ".", "toHexString", "(", "System", ".", "identityHashCode", "(", "object", ")", ")", ";", "}" ]
The default toString implementation of an object @param object the object @return a string in the form className@hexHashCode
[ "The", "default", "toString", "implementation", "of", "an", "object" ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L1020-L1026
10,496
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.parseTimePeriod
public static long parseTimePeriod(String period) { try { String s = period.toLowerCase(); long factor; // look for suffix if (s.endsWith("msec")) { s = s.substring(0, s.lastIndexOf("msec")); factor = MSEC; } else if (s.endsWith("sec")) { s = s.substring(0, s.lastIndexOf("sec")); factor = SECS; } else if (s.endsWith("min")) { s = s.substring(0, s.lastIndexOf("min")); factor = MINS; } else if (s.endsWith("h")) { s = s.substring(0, s.lastIndexOf("h")); factor = HOUR; } else { factor = 1; } return Long.parseLong(s) * factor; } catch (RuntimeException e) { // thrown in addition when period is 'null' throw new NumberFormatException("For input time period: '" + period + "'"); } }
java
public static long parseTimePeriod(String period) { try { String s = period.toLowerCase(); long factor; // look for suffix if (s.endsWith("msec")) { s = s.substring(0, s.lastIndexOf("msec")); factor = MSEC; } else if (s.endsWith("sec")) { s = s.substring(0, s.lastIndexOf("sec")); factor = SECS; } else if (s.endsWith("min")) { s = s.substring(0, s.lastIndexOf("min")); factor = MINS; } else if (s.endsWith("h")) { s = s.substring(0, s.lastIndexOf("h")); factor = HOUR; } else { factor = 1; } return Long.parseLong(s) * factor; } catch (RuntimeException e) { // thrown in addition when period is 'null' throw new NumberFormatException("For input time period: '" + period + "'"); } }
[ "public", "static", "long", "parseTimePeriod", "(", "String", "period", ")", "{", "try", "{", "String", "s", "=", "period", ".", "toLowerCase", "(", ")", ";", "long", "factor", ";", "// look for suffix", "if", "(", "s", ".", "endsWith", "(", "\"msec\"", ")", ")", "{", "s", "=", "s", ".", "substring", "(", "0", ",", "s", ".", "lastIndexOf", "(", "\"msec\"", ")", ")", ";", "factor", "=", "MSEC", ";", "}", "else", "if", "(", "s", ".", "endsWith", "(", "\"sec\"", ")", ")", "{", "s", "=", "s", ".", "substring", "(", "0", ",", "s", ".", "lastIndexOf", "(", "\"sec\"", ")", ")", ";", "factor", "=", "SECS", ";", "}", "else", "if", "(", "s", ".", "endsWith", "(", "\"min\"", ")", ")", "{", "s", "=", "s", ".", "substring", "(", "0", ",", "s", ".", "lastIndexOf", "(", "\"min\"", ")", ")", ";", "factor", "=", "MINS", ";", "}", "else", "if", "(", "s", ".", "endsWith", "(", "\"h\"", ")", ")", "{", "s", "=", "s", ".", "substring", "(", "0", ",", "s", ".", "lastIndexOf", "(", "\"h\"", ")", ")", ";", "factor", "=", "HOUR", ";", "}", "else", "{", "factor", "=", "1", ";", "}", "return", "Long", ".", "parseLong", "(", "s", ")", "*", "factor", ";", "}", "catch", "(", "RuntimeException", "e", ")", "{", "// thrown in addition when period is 'null'", "throw", "new", "NumberFormatException", "(", "\"For input time period: '\"", "+", "period", "+", "\"'\"", ")", ";", "}", "}" ]
Parses a time period into a long. Translates possible [msec|sec|min|h] suffixes For example: "1" -> 1 (msec) "1msec -> 1 (msec) "1sec" -> 1000 (msecs) "1min" -> 60000 (msecs) "1h" -> 3600000 (msecs) Accepts negative periods, e.g. "-1" @param period the stringfied time period @return the parsed time period as long @throws NumberFormatException
[ "Parses", "a", "time", "period", "into", "a", "long", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L1078-L1117
10,497
forge/furnace
container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java
Strings.trimLeadingCharacter
public static String trimLeadingCharacter(String str, final char leadingCharacter) { return trimLeadingCharacter(str, new CharacterFilter() { @Override public boolean isCharacterLegal(char character) { return character == leadingCharacter; } }); }
java
public static String trimLeadingCharacter(String str, final char leadingCharacter) { return trimLeadingCharacter(str, new CharacterFilter() { @Override public boolean isCharacterLegal(char character) { return character == leadingCharacter; } }); }
[ "public", "static", "String", "trimLeadingCharacter", "(", "String", "str", ",", "final", "char", "leadingCharacter", ")", "{", "return", "trimLeadingCharacter", "(", "str", ",", "new", "CharacterFilter", "(", ")", "{", "@", "Override", "public", "boolean", "isCharacterLegal", "(", "char", "character", ")", "{", "return", "character", "==", "leadingCharacter", ";", "}", "}", ")", ";", "}" ]
Trim all occurences of the supplied leading character from the given String. @param str the string to check @param leadingCharacter the leading character to be trimmed @return the trimmed String
[ "Trim", "all", "occurences", "of", "the", "supplied", "leading", "character", "from", "the", "given", "String", "." ]
bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a
https://github.com/forge/furnace/blob/bbe6deaa3c0d85ba43daa3e2f7d486f2dad21e0a/container-api/src/main/java/org/jboss/forge/furnace/util/Strings.java#L1216-L1226
10,498
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/libsvm/Utils.java
Utils.readOutput
public static String readOutput(BufferedReader in) throws IOException { StringBuffer output = new StringBuffer(); String line = ""; while ((line = in.readLine()) != null) { output.append(line); output.append("\n"); } return output.toString(); }
java
public static String readOutput(BufferedReader in) throws IOException { StringBuffer output = new StringBuffer(); String line = ""; while ((line = in.readLine()) != null) { output.append(line); output.append("\n"); } return output.toString(); }
[ "public", "static", "String", "readOutput", "(", "BufferedReader", "in", ")", "throws", "IOException", "{", "StringBuffer", "output", "=", "new", "StringBuffer", "(", ")", ";", "String", "line", "=", "\"\"", ";", "while", "(", "(", "line", "=", "in", ".", "readLine", "(", ")", ")", "!=", "null", ")", "{", "output", ".", "append", "(", "line", ")", ";", "output", ".", "append", "(", "\"\\n\"", ")", ";", "}", "return", "output", ".", "toString", "(", ")", ";", "}" ]
Reads the output of the reader and delivers it at string.
[ "Reads", "the", "output", "of", "the", "reader", "and", "delivers", "it", "at", "string", "." ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/libsvm/Utils.java#L36-L44
10,499
DigitalPebble/TextClassification
src/main/java/com/digitalpebble/classification/TextClassifier.java
TextClassifier.getClassifier
public static TextClassifier getClassifier(File resourceDirectoryFile) throws Exception { // check whether we need to unzip the resources first if (resourceDirectoryFile.toString().endsWith(".zip") && resourceDirectoryFile.isFile()) { resourceDirectoryFile = UnZip.unzip(resourceDirectoryFile); } // check the existence of the path if (resourceDirectoryFile.exists() == false) throw new IOException("Directory " + resourceDirectoryFile.getAbsolutePath() + " does not exist"); // check that the lexicon files exists (e.g. its name should be simply // 'lexicon') File lexiconFile = new File(resourceDirectoryFile, Parameters.lexiconName); if (lexiconFile.exists() == false) throw new IOException("Lexicon " + lexiconFile + " does not exist"); // and that there is a model file File modelFile = new File(resourceDirectoryFile, Parameters.modelName); if (modelFile.exists() == false) throw new IOException("Model " + modelFile + " does not exist"); Lexicon lexicon = new Lexicon(lexiconFile.toString()); // ask the Lexicon for the classifier to use String classifier = lexicon.getClassifierType(); TextClassifier instance = (TextClassifier) Class.forName(classifier) .newInstance(); // set the last modification info instance.lastmodifiedLexicon = lexiconFile.lastModified(); // set the pathResourceDirectory instance.pathResourceDirectory = resourceDirectoryFile .getAbsolutePath(); // set the model instance.lexicon = lexicon; instance.loadModel(); return instance; }
java
public static TextClassifier getClassifier(File resourceDirectoryFile) throws Exception { // check whether we need to unzip the resources first if (resourceDirectoryFile.toString().endsWith(".zip") && resourceDirectoryFile.isFile()) { resourceDirectoryFile = UnZip.unzip(resourceDirectoryFile); } // check the existence of the path if (resourceDirectoryFile.exists() == false) throw new IOException("Directory " + resourceDirectoryFile.getAbsolutePath() + " does not exist"); // check that the lexicon files exists (e.g. its name should be simply // 'lexicon') File lexiconFile = new File(resourceDirectoryFile, Parameters.lexiconName); if (lexiconFile.exists() == false) throw new IOException("Lexicon " + lexiconFile + " does not exist"); // and that there is a model file File modelFile = new File(resourceDirectoryFile, Parameters.modelName); if (modelFile.exists() == false) throw new IOException("Model " + modelFile + " does not exist"); Lexicon lexicon = new Lexicon(lexiconFile.toString()); // ask the Lexicon for the classifier to use String classifier = lexicon.getClassifierType(); TextClassifier instance = (TextClassifier) Class.forName(classifier) .newInstance(); // set the last modification info instance.lastmodifiedLexicon = lexiconFile.lastModified(); // set the pathResourceDirectory instance.pathResourceDirectory = resourceDirectoryFile .getAbsolutePath(); // set the model instance.lexicon = lexicon; instance.loadModel(); return instance; }
[ "public", "static", "TextClassifier", "getClassifier", "(", "File", "resourceDirectoryFile", ")", "throws", "Exception", "{", "// check whether we need to unzip the resources first\r", "if", "(", "resourceDirectoryFile", ".", "toString", "(", ")", ".", "endsWith", "(", "\".zip\"", ")", "&&", "resourceDirectoryFile", ".", "isFile", "(", ")", ")", "{", "resourceDirectoryFile", "=", "UnZip", ".", "unzip", "(", "resourceDirectoryFile", ")", ";", "}", "// check the existence of the path\r", "if", "(", "resourceDirectoryFile", ".", "exists", "(", ")", "==", "false", ")", "throw", "new", "IOException", "(", "\"Directory \"", "+", "resourceDirectoryFile", ".", "getAbsolutePath", "(", ")", "+", "\" does not exist\"", ")", ";", "// check that the lexicon files exists (e.g. its name should be simply\r", "// 'lexicon')\r", "File", "lexiconFile", "=", "new", "File", "(", "resourceDirectoryFile", ",", "Parameters", ".", "lexiconName", ")", ";", "if", "(", "lexiconFile", ".", "exists", "(", ")", "==", "false", ")", "throw", "new", "IOException", "(", "\"Lexicon \"", "+", "lexiconFile", "+", "\" does not exist\"", ")", ";", "// and that there is a model file\r", "File", "modelFile", "=", "new", "File", "(", "resourceDirectoryFile", ",", "Parameters", ".", "modelName", ")", ";", "if", "(", "modelFile", ".", "exists", "(", ")", "==", "false", ")", "throw", "new", "IOException", "(", "\"Model \"", "+", "modelFile", "+", "\" does not exist\"", ")", ";", "Lexicon", "lexicon", "=", "new", "Lexicon", "(", "lexiconFile", ".", "toString", "(", ")", ")", ";", "// ask the Lexicon for the classifier to use\r", "String", "classifier", "=", "lexicon", ".", "getClassifierType", "(", ")", ";", "TextClassifier", "instance", "=", "(", "TextClassifier", ")", "Class", ".", "forName", "(", "classifier", ")", ".", "newInstance", "(", ")", ";", "// set the last modification info\r", "instance", ".", "lastmodifiedLexicon", "=", "lexiconFile", ".", "lastModified", "(", ")", ";", "// set the pathResourceDirectory\r", "instance", ".", "pathResourceDirectory", "=", "resourceDirectoryFile", ".", "getAbsolutePath", "(", ")", ";", "// set the model\r", "instance", ".", "lexicon", "=", "lexicon", ";", "instance", ".", "loadModel", "(", ")", ";", "return", "instance", ";", "}" ]
Returns a specific instance of a Text Classifier given a resource Directory @throws Exception
[ "Returns", "a", "specific", "instance", "of", "a", "Text", "Classifier", "given", "a", "resource", "Directory" ]
c510719c31633841af2bf393a20707d4624f865d
https://github.com/DigitalPebble/TextClassification/blob/c510719c31633841af2bf393a20707d4624f865d/src/main/java/com/digitalpebble/classification/TextClassifier.java#L46-L82