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
5,900
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Media.java
Media.get
public static MediaFile get(final BandwidthClient client, final String id) throws Exception { final String mediaUri = client.getUserResourceInstanceUri(BandwidthConstants.MEDIA_URI_PATH, id); final JSONObject jsonObject = toJSONObject(client.get(mediaUri, null)); return new MediaFile(client, jsonObject); }
java
public static MediaFile get(final BandwidthClient client, final String id) throws Exception { final String mediaUri = client.getUserResourceInstanceUri(BandwidthConstants.MEDIA_URI_PATH, id); final JSONObject jsonObject = toJSONObject(client.get(mediaUri, null)); return new MediaFile(client, jsonObject); }
[ "public", "static", "MediaFile", "get", "(", "final", "BandwidthClient", "client", ",", "final", "String", "id", ")", "throws", "Exception", "{", "final", "String", "mediaUri", "=", "client", ".", "getUserResourceInstanceUri", "(", "BandwidthConstants", ".", "MEDIA_URI_PATH", ",", "id", ")", ";", "final", "JSONObject", "jsonObject", "=", "toJSONObject", "(", "client", ".", "get", "(", "mediaUri", ",", "null", ")", ")", ";", "return", "new", "MediaFile", "(", "client", ",", "jsonObject", ")", ";", "}" ]
Gets information about a previously sent or received MediaFile. @param client the client. @param id MediaFile id @return information about MediaFile @throws IOException unexpected error.
[ "Gets", "information", "about", "a", "previously", "sent", "or", "received", "MediaFile", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Media.java#L39-L45
5,901
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Media.java
Media.upload
public MediaFile upload(final String mediaName, final File file, final MediaMimeType contentType) throws IOException, AppPlatformException { final String uri = StringUtils.join(new String[]{ getUri(), mediaName }, '/'); client.upload(uri, file, contentType.toString()); final List<MediaFile> mediaFiles = list(client, 0, 25); for (final MediaFile mediaFile : mediaFiles) { if (StringUtils.equals(mediaFile.getMediaName(), mediaName)) return mediaFile; } return null; }
java
public MediaFile upload(final String mediaName, final File file, final MediaMimeType contentType) throws IOException, AppPlatformException { final String uri = StringUtils.join(new String[]{ getUri(), mediaName }, '/'); client.upload(uri, file, contentType.toString()); final List<MediaFile> mediaFiles = list(client, 0, 25); for (final MediaFile mediaFile : mediaFiles) { if (StringUtils.equals(mediaFile.getMediaName(), mediaName)) return mediaFile; } return null; }
[ "public", "MediaFile", "upload", "(", "final", "String", "mediaName", ",", "final", "File", "file", ",", "final", "MediaMimeType", "contentType", ")", "throws", "IOException", ",", "AppPlatformException", "{", "final", "String", "uri", "=", "StringUtils", ".", "join", "(", "new", "String", "[", "]", "{", "getUri", "(", ")", ",", "mediaName", "}", ",", "'", "'", ")", ";", "client", ".", "upload", "(", "uri", ",", "file", ",", "contentType", ".", "toString", "(", ")", ")", ";", "final", "List", "<", "MediaFile", ">", "mediaFiles", "=", "list", "(", "client", ",", "0", ",", "25", ")", ";", "for", "(", "final", "MediaFile", "mediaFile", ":", "mediaFiles", ")", "{", "if", "(", "StringUtils", ".", "equals", "(", "mediaFile", ".", "getMediaName", "(", ")", ",", "mediaName", ")", ")", "return", "mediaFile", ";", "}", "return", "null", ";", "}" ]
Uploads media file. @param mediaName new name of media file @param file source file for uploading @param contentType MIME type of file or <code>null</code> @return new media file object @throws IOException unexpected error. @throws AppPlatformException unexpected exception.
[ "Uploads", "media", "file", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Media.java#L126-L140
5,902
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Media.java
Media.download
public void download(final String mediaName, final File file) throws IOException { final String uri = client.getUserResourceInstanceUri(BandwidthConstants.MEDIA_URI_PATH, mediaName); client.download(uri, file); }
java
public void download(final String mediaName, final File file) throws IOException { final String uri = client.getUserResourceInstanceUri(BandwidthConstants.MEDIA_URI_PATH, mediaName); client.download(uri, file); }
[ "public", "void", "download", "(", "final", "String", "mediaName", ",", "final", "File", "file", ")", "throws", "IOException", "{", "final", "String", "uri", "=", "client", ".", "getUserResourceInstanceUri", "(", "BandwidthConstants", ".", "MEDIA_URI_PATH", ",", "mediaName", ")", ";", "client", ".", "download", "(", "uri", ",", "file", ")", ";", "}" ]
Downloads existing media file from server. @param mediaName name of media @param file file for putting content. Will be overridden. @throws IOException unexpected error.
[ "Downloads", "existing", "media", "file", "from", "server", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Media.java#L149-L154
5,903
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/ResourceList.java
ResourceList.initialize
public void initialize() { final JSONObject params = new JSONObject(); params.put("page", page); params.put("size", size); getPage(params); }
java
public void initialize() { final JSONObject params = new JSONObject(); params.put("page", page); params.put("size", size); getPage(params); }
[ "public", "void", "initialize", "(", ")", "{", "final", "JSONObject", "params", "=", "new", "JSONObject", "(", ")", ";", "params", ".", "put", "(", "\"page\"", ",", "page", ")", ";", "params", ".", "put", "(", "\"size\"", ",", "size", ")", ";", "getPage", "(", "params", ")", ";", "}" ]
initializes ArrayList with first page from BW API
[ "initializes", "ArrayList", "with", "first", "page", "from", "BW", "API" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/ResourceList.java#L65-L72
5,904
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/ResourceList.java
ResourceList.iterator
public Iterator<E> iterator() { final Iterator<E> it = new Iterator<E>() { @Override public boolean hasNext() { return (index < size()); } @Override public E next() { final E elem = get(index++); if (index >= size() && nextLink != null) { getNextPage(); } return elem; } @Override public void remove() { // TODO Auto-generated method stub } }; return it; // return super.iterator(); }
java
public Iterator<E> iterator() { final Iterator<E> it = new Iterator<E>() { @Override public boolean hasNext() { return (index < size()); } @Override public E next() { final E elem = get(index++); if (index >= size() && nextLink != null) { getNextPage(); } return elem; } @Override public void remove() { // TODO Auto-generated method stub } }; return it; // return super.iterator(); }
[ "public", "Iterator", "<", "E", ">", "iterator", "(", ")", "{", "final", "Iterator", "<", "E", ">", "it", "=", "new", "Iterator", "<", "E", ">", "(", ")", "{", "@", "Override", "public", "boolean", "hasNext", "(", ")", "{", "return", "(", "index", "<", "size", "(", ")", ")", ";", "}", "@", "Override", "public", "E", "next", "(", ")", "{", "final", "E", "elem", "=", "get", "(", "index", "++", ")", ";", "if", "(", "index", ">=", "size", "(", ")", "&&", "nextLink", "!=", "null", ")", "{", "getNextPage", "(", ")", ";", "}", "return", "elem", ";", "}", "@", "Override", "public", "void", "remove", "(", ")", "{", "// TODO Auto-generated method stub", "}", "}", ";", "return", "it", ";", "// return super.iterator();", "}" ]
Customer iterator calls out to BW API when there is more data to retrieve
[ "Customer", "iterator", "calls", "out", "to", "BW", "API", "when", "there", "is", "more", "data", "to", "retrieve" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/ResourceList.java#L77-L106
5,905
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/ResourceList.java
ResourceList.getNextPage
protected void getNextPage() { final JSONObject params = new JSONObject(); page++; params.put("page", page); params.put("size", size); clear(); getPage(params); }
java
protected void getNextPage() { final JSONObject params = new JSONObject(); page++; params.put("page", page); params.put("size", size); clear(); getPage(params); }
[ "protected", "void", "getNextPage", "(", ")", "{", "final", "JSONObject", "params", "=", "new", "JSONObject", "(", ")", ";", "page", "++", ";", "params", ".", "put", "(", "\"page\"", ",", "page", ")", ";", "params", ".", "put", "(", "\"size\"", ",", "size", ")", ";", "clear", "(", ")", ";", "getPage", "(", "params", ")", ";", "}" ]
This method updates the page value, creates the params for the API call and clears the current list
[ "This", "method", "updates", "the", "page", "value", "creates", "the", "params", "for", "the", "API", "call", "and", "clears", "the", "current", "list" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/ResourceList.java#L111-L124
5,906
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/ResourceList.java
ResourceList.getPage
protected void getPage(final JSONObject params) { if (this.client == null) client = BandwidthClient.getInstance(); try { final RestResponse response = client.get(resourceUri, params); final JSONArray array = Utils.response2JSONArray(response); for (final Object obj : array) { final E elem = clazz.getConstructor(BandwidthClient.class, JSONObject.class).newInstance(client, (JSONObject) obj); add(elem); } // if anything comes back, reset the index if (array.size() > 0) this.index = 0; // set the next links this.setNextLink(response.getNextLink()); this.setFirstLink(response.getFirstLink()); this.setPreviousLink(response.getPreviousLink()); } catch(final Exception e) { e.printStackTrace(); } }
java
protected void getPage(final JSONObject params) { if (this.client == null) client = BandwidthClient.getInstance(); try { final RestResponse response = client.get(resourceUri, params); final JSONArray array = Utils.response2JSONArray(response); for (final Object obj : array) { final E elem = clazz.getConstructor(BandwidthClient.class, JSONObject.class).newInstance(client, (JSONObject) obj); add(elem); } // if anything comes back, reset the index if (array.size() > 0) this.index = 0; // set the next links this.setNextLink(response.getNextLink()); this.setFirstLink(response.getFirstLink()); this.setPreviousLink(response.getPreviousLink()); } catch(final Exception e) { e.printStackTrace(); } }
[ "protected", "void", "getPage", "(", "final", "JSONObject", "params", ")", "{", "if", "(", "this", ".", "client", "==", "null", ")", "client", "=", "BandwidthClient", ".", "getInstance", "(", ")", ";", "try", "{", "final", "RestResponse", "response", "=", "client", ".", "get", "(", "resourceUri", ",", "params", ")", ";", "final", "JSONArray", "array", "=", "Utils", ".", "response2JSONArray", "(", "response", ")", ";", "for", "(", "final", "Object", "obj", ":", "array", ")", "{", "final", "E", "elem", "=", "clazz", ".", "getConstructor", "(", "BandwidthClient", ".", "class", ",", "JSONObject", ".", "class", ")", ".", "newInstance", "(", "client", ",", "(", "JSONObject", ")", "obj", ")", ";", "add", "(", "elem", ")", ";", "}", "// if anything comes back, reset the index", "if", "(", "array", ".", "size", "(", ")", ">", "0", ")", "this", ".", "index", "=", "0", ";", "// set the next links", "this", ".", "setNextLink", "(", "response", ".", "getNextLink", "(", ")", ")", ";", "this", ".", "setFirstLink", "(", "response", ".", "getFirstLink", "(", ")", ")", ";", "this", ".", "setPreviousLink", "(", "response", ".", "getPreviousLink", "(", ")", ")", ";", "}", "catch", "(", "final", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
This method makes the API call to get the list value for the specified resource. It loads the return from the API into the arrayList, updates the index if necessary and sets the new link values @param params the params
[ "This", "method", "makes", "the", "API", "call", "to", "get", "the", "list", "value", "for", "the", "specified", "resource", ".", "It", "loads", "the", "return", "from", "the", "API", "into", "the", "arrayList", "updates", "the", "index", "if", "necessary", "and", "sets", "the", "new", "link", "values" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/ResourceList.java#L131-L158
5,907
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Account.java
Account.getAccountInfo
public AccountInfo getAccountInfo() throws Exception { final JSONObject jsonObject = toJSONObject(client.get(getUri(), null)); return new AccountInfo(client, jsonObject); }
java
public AccountInfo getAccountInfo() throws Exception { final JSONObject jsonObject = toJSONObject(client.get(getUri(), null)); return new AccountInfo(client, jsonObject); }
[ "public", "AccountInfo", "getAccountInfo", "(", ")", "throws", "Exception", "{", "final", "JSONObject", "jsonObject", "=", "toJSONObject", "(", "client", ".", "get", "(", "getUri", "(", ")", ",", "null", ")", ")", ";", "return", "new", "AccountInfo", "(", "client", ",", "jsonObject", ")", ";", "}" ]
Gets your current account information. @return information account information @throws IOException unexpected error.
[ "Gets", "your", "current", "account", "information", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Account.java#L47-L53
5,908
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Endpoint.java
Endpoint.create
public static Endpoint create(final BandwidthClient client, final String domainId, final Map<String, Object>params) throws AppPlatformException, ParseException, Exception { assert (client!= null && params != null); final String endpointsUri = String.format(client.getUserResourceUri(BandwidthConstants.ENDPOINTS_URI_PATH), domainId); final RestResponse response = client.post(endpointsUri, params); final JSONObject callObj = toJSONObject(client.get(response.getLocation(), null)); return new Endpoint(client, callObj); }
java
public static Endpoint create(final BandwidthClient client, final String domainId, final Map<String, Object>params) throws AppPlatformException, ParseException, Exception { assert (client!= null && params != null); final String endpointsUri = String.format(client.getUserResourceUri(BandwidthConstants.ENDPOINTS_URI_PATH), domainId); final RestResponse response = client.post(endpointsUri, params); final JSONObject callObj = toJSONObject(client.get(response.getLocation(), null)); return new Endpoint(client, callObj); }
[ "public", "static", "Endpoint", "create", "(", "final", "BandwidthClient", "client", ",", "final", "String", "domainId", ",", "final", "Map", "<", "String", ",", "Object", ">", "params", ")", "throws", "AppPlatformException", ",", "ParseException", ",", "Exception", "{", "assert", "(", "client", "!=", "null", "&&", "params", "!=", "null", ")", ";", "final", "String", "endpointsUri", "=", "String", ".", "format", "(", "client", ".", "getUserResourceUri", "(", "BandwidthConstants", ".", "ENDPOINTS_URI_PATH", ")", ",", "domainId", ")", ";", "final", "RestResponse", "response", "=", "client", ".", "post", "(", "endpointsUri", ",", "params", ")", ";", "final", "JSONObject", "callObj", "=", "toJSONObject", "(", "client", ".", "get", "(", "response", ".", "getLocation", "(", ")", ",", "null", ")", ")", ";", "return", "new", "Endpoint", "(", "client", ",", "callObj", ")", ";", "}" ]
Convenience factory method to create a Endpoint object from a map of parameters @param client the bandwidth client configuration. @param domainId the domain id. @param params the request parameters. @return the created endpoint. @throws AppPlatformException API Exception @throws ParseException Error parsing data @throws Exception error
[ "Convenience", "factory", "method", "to", "create", "a", "Endpoint", "object", "from", "a", "map", "of", "parameters" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Endpoint.java#L238-L244
5,909
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Endpoint.java
Endpoint.delete
public static void delete(final String domainId, final String endpointId) throws AppPlatformException, IOException { assert(endpointId != null); final BandwidthClient client = BandwidthClient.getInstance(); client.delete(String.format(client.getUserResourceUri(BandwidthConstants.ENDPOINTS_URI_PATH), domainId)+ "/"+endpointId); }
java
public static void delete(final String domainId, final String endpointId) throws AppPlatformException, IOException { assert(endpointId != null); final BandwidthClient client = BandwidthClient.getInstance(); client.delete(String.format(client.getUserResourceUri(BandwidthConstants.ENDPOINTS_URI_PATH), domainId)+ "/"+endpointId); }
[ "public", "static", "void", "delete", "(", "final", "String", "domainId", ",", "final", "String", "endpointId", ")", "throws", "AppPlatformException", ",", "IOException", "{", "assert", "(", "endpointId", "!=", "null", ")", ";", "final", "BandwidthClient", "client", "=", "BandwidthClient", ".", "getInstance", "(", ")", ";", "client", ".", "delete", "(", "String", ".", "format", "(", "client", ".", "getUserResourceUri", "(", "BandwidthConstants", ".", "ENDPOINTS_URI_PATH", ")", ",", "domainId", ")", "+", "\"/\"", "+", "endpointId", ")", ";", "}" ]
Permanently deletes the Endpoint. @param domainId the domain id. @param endpointId the Endpoint id. @throws AppPlatformException API Exception @throws IOException unexpected error
[ "Permanently", "deletes", "the", "Endpoint", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Endpoint.java#L425-L429
5,910
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.create
public static Domain create(final BandwidthClient client, final String name, final String description) throws AppPlatformException, ParseException, Exception { assert (name != null); final Map<String, Object> params = new HashMap<String, Object>(); params.put("name", name); if(!StringUtils.isBlank(description)) { params.put("description", description); } return create(client, params); }
java
public static Domain create(final BandwidthClient client, final String name, final String description) throws AppPlatformException, ParseException, Exception { assert (name != null); final Map<String, Object> params = new HashMap<String, Object>(); params.put("name", name); if(!StringUtils.isBlank(description)) { params.put("description", description); } return create(client, params); }
[ "public", "static", "Domain", "create", "(", "final", "BandwidthClient", "client", ",", "final", "String", "name", ",", "final", "String", "description", ")", "throws", "AppPlatformException", ",", "ParseException", ",", "Exception", "{", "assert", "(", "name", "!=", "null", ")", ";", "final", "Map", "<", "String", ",", "Object", ">", "params", "=", "new", "HashMap", "<", "String", ",", "Object", ">", "(", ")", ";", "params", ".", "put", "(", "\"name\"", ",", "name", ")", ";", "if", "(", "!", "StringUtils", ".", "isBlank", "(", "description", ")", ")", "{", "params", ".", "put", "(", "\"description\"", ",", "description", ")", ";", "}", "return", "create", "(", "client", ",", "params", ")", ";", "}" ]
Convenience method to create a Domain. @param client the client @param name the domain name. @param description the optional domain description. @return the created domain @throws AppPlatformException API Exception @throws ParseException Error parsing data @throws Exception error
[ "Convenience", "method", "to", "create", "a", "Domain", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L71-L79
5,911
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.create
public static Domain create(final BandwidthClient client, final Map<String, Object>params) throws AppPlatformException, ParseException, Exception { assert (client!= null && params != null); final String domainsUri = client.getUserResourceUri(BandwidthConstants.DOMAINS_URI_PATH); final RestResponse response = client.post(domainsUri, params); final JSONObject callObj = toJSONObject(client.get(response.getLocation(), null)); return new Domain(client, callObj); }
java
public static Domain create(final BandwidthClient client, final Map<String, Object>params) throws AppPlatformException, ParseException, Exception { assert (client!= null && params != null); final String domainsUri = client.getUserResourceUri(BandwidthConstants.DOMAINS_URI_PATH); final RestResponse response = client.post(domainsUri, params); final JSONObject callObj = toJSONObject(client.get(response.getLocation(), null)); return new Domain(client, callObj); }
[ "public", "static", "Domain", "create", "(", "final", "BandwidthClient", "client", ",", "final", "Map", "<", "String", ",", "Object", ">", "params", ")", "throws", "AppPlatformException", ",", "ParseException", ",", "Exception", "{", "assert", "(", "client", "!=", "null", "&&", "params", "!=", "null", ")", ";", "final", "String", "domainsUri", "=", "client", ".", "getUserResourceUri", "(", "BandwidthConstants", ".", "DOMAINS_URI_PATH", ")", ";", "final", "RestResponse", "response", "=", "client", ".", "post", "(", "domainsUri", ",", "params", ")", ";", "final", "JSONObject", "callObj", "=", "toJSONObject", "(", "client", ".", "get", "(", "response", ".", "getLocation", "(", ")", ",", "null", ")", ")", ";", "return", "new", "Domain", "(", "client", ",", "callObj", ")", ";", "}" ]
Convenience factory method to create a Domain. @param client the client. @param params the request parameters. @return the created domain. @throws AppPlatformException API Exception @throws ParseException Error parsing data @throws Exception error
[ "Convenience", "factory", "method", "to", "create", "a", "Domain", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L90-L96
5,912
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.get
public static Domain get(final String id) throws ParseException, Exception { final BandwidthClient client = BandwidthClient.getInstance(); return get(client, id); }
java
public static Domain get(final String id) throws ParseException, Exception { final BandwidthClient client = BandwidthClient.getInstance(); return get(client, id); }
[ "public", "static", "Domain", "get", "(", "final", "String", "id", ")", "throws", "ParseException", ",", "Exception", "{", "final", "BandwidthClient", "client", "=", "BandwidthClient", ".", "getInstance", "(", ")", ";", "return", "get", "(", "client", ",", "id", ")", ";", "}" ]
Convenience method to get information about a specific Domain @param id the domain id. @return information about a specific Domain @throws ParseException Error parsing data @throws Exception error
[ "Convenience", "method", "to", "get", "information", "about", "a", "specific", "Domain" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L105-L108
5,913
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.get
public static Domain get(final BandwidthClient client, final String id) throws ParseException, Exception { assert(client != null); final String domainsUri = client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id); final JSONObject jsonObject = toJSONObject(client.get(domainsUri, null)); return new Domain(client, jsonObject); }
java
public static Domain get(final BandwidthClient client, final String id) throws ParseException, Exception { assert(client != null); final String domainsUri = client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id); final JSONObject jsonObject = toJSONObject(client.get(domainsUri, null)); return new Domain(client, jsonObject); }
[ "public", "static", "Domain", "get", "(", "final", "BandwidthClient", "client", ",", "final", "String", "id", ")", "throws", "ParseException", ",", "Exception", "{", "assert", "(", "client", "!=", "null", ")", ";", "final", "String", "domainsUri", "=", "client", ".", "getUserResourceInstanceUri", "(", "BandwidthConstants", ".", "DOMAINS_URI_PATH", ",", "id", ")", ";", "final", "JSONObject", "jsonObject", "=", "toJSONObject", "(", "client", ".", "get", "(", "domainsUri", ",", "null", ")", ")", ";", "return", "new", "Domain", "(", "client", ",", "jsonObject", ")", ";", "}" ]
Convenience method to return a Domain @param client the client. @param id the domain id. @return the domain object. @throws ParseException Error parsing data @throws Exception error
[ "Convenience", "method", "to", "return", "a", "Domain" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L118-L123
5,914
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.list
public static ResourceList<Domain> list(final BandwidthClient client, final int page, final int size) { final String resourceUri = client.getUserResourceUri(BandwidthConstants.DOMAINS_URI_PATH); final ResourceList<Domain> domains = new ResourceList<Domain>(resourceUri, Domain.class); domains.setClient(client); domains.initialize(); return domains; }
java
public static ResourceList<Domain> list(final BandwidthClient client, final int page, final int size) { final String resourceUri = client.getUserResourceUri(BandwidthConstants.DOMAINS_URI_PATH); final ResourceList<Domain> domains = new ResourceList<Domain>(resourceUri, Domain.class); domains.setClient(client); domains.initialize(); return domains; }
[ "public", "static", "ResourceList", "<", "Domain", ">", "list", "(", "final", "BandwidthClient", "client", ",", "final", "int", "page", ",", "final", "int", "size", ")", "{", "final", "String", "resourceUri", "=", "client", ".", "getUserResourceUri", "(", "BandwidthConstants", ".", "DOMAINS_URI_PATH", ")", ";", "final", "ResourceList", "<", "Domain", ">", "domains", "=", "new", "ResourceList", "<", "Domain", ">", "(", "resourceUri", ",", "Domain", ".", "class", ")", ";", "domains", ".", "setClient", "(", "client", ")", ";", "domains", ".", "initialize", "(", ")", ";", "return", "domains", ";", "}" ]
Factory method to list the Domains. @param client The Bandwidth client @param page the starting page. @param size the page size. @return the Domain list.
[ "Factory", "method", "to", "list", "the", "Domains", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L150-L156
5,915
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.update
public static Domain update(final BandwidthClient client, final String id, final Map<String, Object>params) throws AppPlatformException, ParseException, IOException, Exception { assert(client != null && id != null); final String domainsUri = client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id); final RestResponse response = client.post(domainsUri, params); final JSONObject jsonObject = toJSONObject(client.get(domainsUri, null)); return new Domain(client, jsonObject); }
java
public static Domain update(final BandwidthClient client, final String id, final Map<String, Object>params) throws AppPlatformException, ParseException, IOException, Exception { assert(client != null && id != null); final String domainsUri = client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id); final RestResponse response = client.post(domainsUri, params); final JSONObject jsonObject = toJSONObject(client.get(domainsUri, null)); return new Domain(client, jsonObject); }
[ "public", "static", "Domain", "update", "(", "final", "BandwidthClient", "client", ",", "final", "String", "id", ",", "final", "Map", "<", "String", ",", "Object", ">", "params", ")", "throws", "AppPlatformException", ",", "ParseException", ",", "IOException", ",", "Exception", "{", "assert", "(", "client", "!=", "null", "&&", "id", "!=", "null", ")", ";", "final", "String", "domainsUri", "=", "client", ".", "getUserResourceInstanceUri", "(", "BandwidthConstants", ".", "DOMAINS_URI_PATH", ",", "id", ")", ";", "final", "RestResponse", "response", "=", "client", ".", "post", "(", "domainsUri", ",", "params", ")", ";", "final", "JSONObject", "jsonObject", "=", "toJSONObject", "(", "client", ".", "get", "(", "domainsUri", ",", "null", ")", ")", ";", "return", "new", "Domain", "(", "client", ",", "jsonObject", ")", ";", "}" ]
Convenience method to return a Domain. @param client the client. @param id the domain id. @param params the params @return the domain object. @throws AppPlatformException API Exception @throws ParseException Error parsing data @throws IOException unexpected error @throws Exception error
[ "Convenience", "method", "to", "return", "a", "Domain", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L220-L226
5,916
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Domain.java
Domain.delete
public static void delete(final String id) throws AppPlatformException, IOException { assert(id != null); final BandwidthClient client = BandwidthClient.getInstance(); client.delete(client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id)); }
java
public static void delete(final String id) throws AppPlatformException, IOException { assert(id != null); final BandwidthClient client = BandwidthClient.getInstance(); client.delete(client.getUserResourceInstanceUri(BandwidthConstants.DOMAINS_URI_PATH, id)); }
[ "public", "static", "void", "delete", "(", "final", "String", "id", ")", "throws", "AppPlatformException", ",", "IOException", "{", "assert", "(", "id", "!=", "null", ")", ";", "final", "BandwidthClient", "client", "=", "BandwidthClient", ".", "getInstance", "(", ")", ";", "client", ".", "delete", "(", "client", ".", "getUserResourceInstanceUri", "(", "BandwidthConstants", ".", "DOMAINS_URI_PATH", ",", "id", ")", ")", ";", "}" ]
Permanently deletes the Domain. @param id the Domain id. @throws AppPlatformException API Exception @throws IOException unexpected error
[ "Permanently", "deletes", "the", "Domain", "." ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Domain.java#L234-L238
5,917
Bandwidth/java-bandwidth
src/main/java/com/bandwidth/sdk/model/Recording.java
Recording.get
public static Recording get(final BandwidthClient client, final String id) throws Exception { final String recordingsUri = client.getUserResourceUri(BandwidthConstants.RECORDINGS_URI_PATH); final String uri = StringUtils.join(new String[]{ recordingsUri, id }, '/'); final JSONObject jsonObject = toJSONObject(client.get(uri, null)); return new Recording(client, recordingsUri, jsonObject); }
java
public static Recording get(final BandwidthClient client, final String id) throws Exception { final String recordingsUri = client.getUserResourceUri(BandwidthConstants.RECORDINGS_URI_PATH); final String uri = StringUtils.join(new String[]{ recordingsUri, id }, '/'); final JSONObject jsonObject = toJSONObject(client.get(uri, null)); return new Recording(client, recordingsUri, jsonObject); }
[ "public", "static", "Recording", "get", "(", "final", "BandwidthClient", "client", ",", "final", "String", "id", ")", "throws", "Exception", "{", "final", "String", "recordingsUri", "=", "client", ".", "getUserResourceUri", "(", "BandwidthConstants", ".", "RECORDINGS_URI_PATH", ")", ";", "final", "String", "uri", "=", "StringUtils", ".", "join", "(", "new", "String", "[", "]", "{", "recordingsUri", ",", "id", "}", ",", "'", "'", ")", ";", "final", "JSONObject", "jsonObject", "=", "toJSONObject", "(", "client", ".", "get", "(", "uri", ",", "null", ")", ")", ";", "return", "new", "Recording", "(", "client", ",", "recordingsUri", ",", "jsonObject", ")", ";", "}" ]
Recording factory method. Returns recording object from id @param client the client @param id the recording id @return the recording @throws IOException unexpected error
[ "Recording", "factory", "method", ".", "Returns", "recording", "object", "from", "id" ]
2124c85148ad6a54d2f2949cb952eb3985830e2a
https://github.com/Bandwidth/java-bandwidth/blob/2124c85148ad6a54d2f2949cb952eb3985830e2a/src/main/java/com/bandwidth/sdk/model/Recording.java#L80-L89
5,918
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/Faker.java
Faker.fill
public void fill(View view) { validateNotNullableView(view); try { if(view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for(int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); fill(child); } } else { if(mIds == null) { fillView(view); } else if(mIds.contains(view.getId())) { fillView(view); } } } catch (Exception e) { e.printStackTrace(); } finally { mFaker = null; } }
java
public void fill(View view) { validateNotNullableView(view); try { if(view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for(int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); fill(child); } } else { if(mIds == null) { fillView(view); } else if(mIds.contains(view.getId())) { fillView(view); } } } catch (Exception e) { e.printStackTrace(); } finally { mFaker = null; } }
[ "public", "void", "fill", "(", "View", "view", ")", "{", "validateNotNullableView", "(", "view", ")", ";", "try", "{", "if", "(", "view", "instanceof", "ViewGroup", ")", "{", "ViewGroup", "viewGroup", "=", "(", "ViewGroup", ")", "view", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "viewGroup", ".", "getChildCount", "(", ")", ";", "i", "++", ")", "{", "View", "child", "=", "viewGroup", ".", "getChildAt", "(", "i", ")", ";", "fill", "(", "child", ")", ";", "}", "}", "else", "{", "if", "(", "mIds", "==", "null", ")", "{", "fillView", "(", "view", ")", ";", "}", "else", "if", "(", "mIds", ".", "contains", "(", "view", ".", "getId", "(", ")", ")", ")", "{", "fillView", "(", "view", ")", ";", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "finally", "{", "mFaker", "=", "null", ";", "}", "}" ]
Fill a view with random data @param view target view
[ "Fill", "a", "view", "with", "random", "data" ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/Faker.java#L74-L96
5,919
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/Faker.java
Faker.fillWithText
public void fillWithText(TextView view, FakerTextComponent component) { validateNotNullableView(view); validateIfIsATextView(view); validateNotNullableFakerComponent(component); view.setText(component.randomText()); }
java
public void fillWithText(TextView view, FakerTextComponent component) { validateNotNullableView(view); validateIfIsATextView(view); validateNotNullableFakerComponent(component); view.setText(component.randomText()); }
[ "public", "void", "fillWithText", "(", "TextView", "view", ",", "FakerTextComponent", "component", ")", "{", "validateNotNullableView", "(", "view", ")", ";", "validateIfIsATextView", "(", "view", ")", ";", "validateNotNullableFakerComponent", "(", "component", ")", ";", "view", ".", "setText", "(", "component", ".", "randomText", "(", ")", ")", ";", "}" ]
Fill a TextView with a specific FakerTextComponent @param view @param component
[ "Fill", "a", "TextView", "with", "a", "specific", "FakerTextComponent" ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/Faker.java#L103-L109
5,920
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/Faker.java
Faker.fillWithNumber
public void fillWithNumber(TextView view, FakerNumericComponent component) { validateNotNullableView(view); validateIfIsATextView(view); validateNotNullableFakerComponent(component); view.setText(String.valueOf(component.randomNumber())); }
java
public void fillWithNumber(TextView view, FakerNumericComponent component) { validateNotNullableView(view); validateIfIsATextView(view); validateNotNullableFakerComponent(component); view.setText(String.valueOf(component.randomNumber())); }
[ "public", "void", "fillWithNumber", "(", "TextView", "view", ",", "FakerNumericComponent", "component", ")", "{", "validateNotNullableView", "(", "view", ")", ";", "validateIfIsATextView", "(", "view", ")", ";", "validateNotNullableFakerComponent", "(", "component", ")", ";", "view", ".", "setText", "(", "String", ".", "valueOf", "(", "component", ".", "randomNumber", "(", ")", ")", ")", ";", "}" ]
Fill a TextView with a specific FakerNumericComponent @param view @param component
[ "Fill", "a", "TextView", "with", "a", "specific", "FakerNumericComponent" ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/Faker.java#L125-L131
5,921
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/Faker.java
Faker.fillWithColor
public void fillWithColor(View view, FakerColorComponent component) { validateNotNullableView(view); validateNotNullableFakerComponent(component); view.setBackgroundColor(component.randomColor()); }
java
public void fillWithColor(View view, FakerColorComponent component) { validateNotNullableView(view); validateNotNullableFakerComponent(component); view.setBackgroundColor(component.randomColor()); }
[ "public", "void", "fillWithColor", "(", "View", "view", ",", "FakerColorComponent", "component", ")", "{", "validateNotNullableView", "(", "view", ")", ";", "validateNotNullableFakerComponent", "(", "component", ")", ";", "view", ".", "setBackgroundColor", "(", "component", ".", "randomColor", "(", ")", ")", ";", "}" ]
Fill view with a random color @param view @param component
[ "Fill", "view", "with", "a", "random", "color" ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/Faker.java#L138-L143
5,922
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/Faker.java
Faker.fillWithCheckState
public void fillWithCheckState(CompoundButton view) { validateNotNullableView(view); validateIfIsACompoundButton(view); view.setChecked(new Random().nextBoolean()); }
java
public void fillWithCheckState(CompoundButton view) { validateNotNullableView(view); validateIfIsACompoundButton(view); view.setChecked(new Random().nextBoolean()); }
[ "public", "void", "fillWithCheckState", "(", "CompoundButton", "view", ")", "{", "validateNotNullableView", "(", "view", ")", ";", "validateIfIsACompoundButton", "(", "view", ")", ";", "view", ".", "setChecked", "(", "new", "Random", "(", ")", ".", "nextBoolean", "(", ")", ")", ";", "}" ]
Set a random check or uncheck state @param view
[ "Set", "a", "random", "check", "or", "uncheck", "state" ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/Faker.java#L149-L154
5,923
thiagokimo/Faker
faker-core/src/main/java/io/kimo/lib/faker/component/text/LoremComponent.java
LoremComponent.words
@Override public String words() { int numberOfWords = DEFAULT_RANDOM_NUMBERS_POOL[new Random().nextInt(DEFAULT_RANDOM_NUMBERS_POOL.length)]; return words(numberOfWords); }
java
@Override public String words() { int numberOfWords = DEFAULT_RANDOM_NUMBERS_POOL[new Random().nextInt(DEFAULT_RANDOM_NUMBERS_POOL.length)]; return words(numberOfWords); }
[ "@", "Override", "public", "String", "words", "(", ")", "{", "int", "numberOfWords", "=", "DEFAULT_RANDOM_NUMBERS_POOL", "[", "new", "Random", "(", ")", ".", "nextInt", "(", "DEFAULT_RANDOM_NUMBERS_POOL", ".", "length", ")", "]", ";", "return", "words", "(", "numberOfWords", ")", ";", "}" ]
Provies random words from the words list. The amount of words varies from 3 to 7. @return a String with the words
[ "Provies", "random", "words", "from", "the", "words", "list", ".", "The", "amount", "of", "words", "varies", "from", "3", "to", "7", "." ]
8b0eccd499817a2bc3377db0c6e1b50736d0f034
https://github.com/thiagokimo/Faker/blob/8b0eccd499817a2bc3377db0c6e1b50736d0f034/faker-core/src/main/java/io/kimo/lib/faker/component/text/LoremComponent.java#L63-L67
5,924
XDean/Java-EX
src/main/java/xdean/jex/util/lang/PrimitiveTypeUtil.java
PrimitiveTypeUtil.sizeOf
public static int sizeOf(Class<?> clz) throws IllegalArgumentException { switch (clz.getName()) { case "int": return Integer.BYTES; case "short": return Short.BYTES; case "long": return Long.BYTES; case "double": return Double.BYTES; case "float": return Float.BYTES; case "boolean": return 1; case "char": return Character.BYTES; case "byte": return 1; default: throw new IllegalArgumentException("Not a primitive type."); } }
java
public static int sizeOf(Class<?> clz) throws IllegalArgumentException { switch (clz.getName()) { case "int": return Integer.BYTES; case "short": return Short.BYTES; case "long": return Long.BYTES; case "double": return Double.BYTES; case "float": return Float.BYTES; case "boolean": return 1; case "char": return Character.BYTES; case "byte": return 1; default: throw new IllegalArgumentException("Not a primitive type."); } }
[ "public", "static", "int", "sizeOf", "(", "Class", "<", "?", ">", "clz", ")", "throws", "IllegalArgumentException", "{", "switch", "(", "clz", ".", "getName", "(", ")", ")", "{", "case", "\"int\"", ":", "return", "Integer", ".", "BYTES", ";", "case", "\"short\"", ":", "return", "Short", ".", "BYTES", ";", "case", "\"long\"", ":", "return", "Long", ".", "BYTES", ";", "case", "\"double\"", ":", "return", "Double", ".", "BYTES", ";", "case", "\"float\"", ":", "return", "Float", ".", "BYTES", ";", "case", "\"boolean\"", ":", "return", "1", ";", "case", "\"char\"", ":", "return", "Character", ".", "BYTES", ";", "case", "\"byte\"", ":", "return", "1", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", "\"Not a primitive type.\"", ")", ";", "}", "}" ]
Get the size of a primitive type. @param clz @throws IllegalArgumentException If the class is not primitive type. @return
[ "Get", "the", "size", "of", "a", "primitive", "type", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/lang/PrimitiveTypeUtil.java#L168-L189
5,925
XDean/Java-EX
src/main/java/xdean/jex/util/lang/PrimitiveTypeUtil.java
PrimitiveTypeUtil.parse
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> clz, String objectValue) { switch (clz.getName()) { case "int": return (T) Integer.valueOf(objectValue); case "short": return (T) Short.valueOf(objectValue); case "long": if (objectValue.endsWith("L") || objectValue.endsWith("l")) { objectValue = objectValue.substring(0, objectValue.length() - 1); } return (T) Long.valueOf(objectValue); case "double": return (T) Double.valueOf(objectValue); case "float": return (T) Float.valueOf(objectValue); case "boolean": if (objectValue.equalsIgnoreCase(Boolean.TRUE.toString())) { return (T) Boolean.TRUE; } else if (objectValue.equalsIgnoreCase(Boolean.FALSE.toString())) { return (T) Boolean.FALSE; } else { throw new IllegalArgumentException( String.format("The String %s cannot parse as boolean.", objectValue)); } case "char": if (objectValue.length() == 1) { return (T) new Character(objectValue.charAt(0)); } else { throw new IllegalArgumentException(String.format("The String %s cannot parse as char.", objectValue)); } case "byte": return (T) Byte.valueOf(objectValue); default: return null; } }
java
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> clz, String objectValue) { switch (clz.getName()) { case "int": return (T) Integer.valueOf(objectValue); case "short": return (T) Short.valueOf(objectValue); case "long": if (objectValue.endsWith("L") || objectValue.endsWith("l")) { objectValue = objectValue.substring(0, objectValue.length() - 1); } return (T) Long.valueOf(objectValue); case "double": return (T) Double.valueOf(objectValue); case "float": return (T) Float.valueOf(objectValue); case "boolean": if (objectValue.equalsIgnoreCase(Boolean.TRUE.toString())) { return (T) Boolean.TRUE; } else if (objectValue.equalsIgnoreCase(Boolean.FALSE.toString())) { return (T) Boolean.FALSE; } else { throw new IllegalArgumentException( String.format("The String %s cannot parse as boolean.", objectValue)); } case "char": if (objectValue.length() == 1) { return (T) new Character(objectValue.charAt(0)); } else { throw new IllegalArgumentException(String.format("The String %s cannot parse as char.", objectValue)); } case "byte": return (T) Byte.valueOf(objectValue); default: return null; } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", ">", "T", "parse", "(", "Class", "<", "T", ">", "clz", ",", "String", "objectValue", ")", "{", "switch", "(", "clz", ".", "getName", "(", ")", ")", "{", "case", "\"int\"", ":", "return", "(", "T", ")", "Integer", ".", "valueOf", "(", "objectValue", ")", ";", "case", "\"short\"", ":", "return", "(", "T", ")", "Short", ".", "valueOf", "(", "objectValue", ")", ";", "case", "\"long\"", ":", "if", "(", "objectValue", ".", "endsWith", "(", "\"L\"", ")", "||", "objectValue", ".", "endsWith", "(", "\"l\"", ")", ")", "{", "objectValue", "=", "objectValue", ".", "substring", "(", "0", ",", "objectValue", ".", "length", "(", ")", "-", "1", ")", ";", "}", "return", "(", "T", ")", "Long", ".", "valueOf", "(", "objectValue", ")", ";", "case", "\"double\"", ":", "return", "(", "T", ")", "Double", ".", "valueOf", "(", "objectValue", ")", ";", "case", "\"float\"", ":", "return", "(", "T", ")", "Float", ".", "valueOf", "(", "objectValue", ")", ";", "case", "\"boolean\"", ":", "if", "(", "objectValue", ".", "equalsIgnoreCase", "(", "Boolean", ".", "TRUE", ".", "toString", "(", ")", ")", ")", "{", "return", "(", "T", ")", "Boolean", ".", "TRUE", ";", "}", "else", "if", "(", "objectValue", ".", "equalsIgnoreCase", "(", "Boolean", ".", "FALSE", ".", "toString", "(", ")", ")", ")", "{", "return", "(", "T", ")", "Boolean", ".", "FALSE", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "String", ".", "format", "(", "\"The String %s cannot parse as boolean.\"", ",", "objectValue", ")", ")", ";", "}", "case", "\"char\"", ":", "if", "(", "objectValue", ".", "length", "(", ")", "==", "1", ")", "{", "return", "(", "T", ")", "new", "Character", "(", "objectValue", ".", "charAt", "(", "0", ")", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "String", ".", "format", "(", "\"The String %s cannot parse as char.\"", ",", "objectValue", ")", ")", ";", "}", "case", "\"byte\"", ":", "return", "(", "T", ")", "Byte", ".", "valueOf", "(", "objectValue", ")", ";", "default", ":", "return", "null", ";", "}", "}" ]
Parse the string value to a primitive type @param clz @param objectValue @return a wrapper type value
[ "Parse", "the", "string", "value", "to", "a", "primitive", "type" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/lang/PrimitiveTypeUtil.java#L198-L234
5,926
XDean/Java-EX
src/main/java/xdean/jex/util/string/StringUtil.java
StringUtil.notExistChars
public static Iterator<Character> notExistChars(String s) { return new Iterator<Character>() { IntList collect = IntList.create(s.chars().distinct().sorted().toArray()); int current = 128; Character next = null; @Override public Character next() { if (calcNext()) { Character c = next; next = null; return c; } else { throw new NoSuchElementException("No next non-exist character."); } } @Override public boolean hasNext() { return calcNext(); } private boolean calcNext() { if (next == null) { while (++current < Integer.MAX_VALUE) { if (collect.remove(current) == false) { next = (char) current; return true; } } return false; } return true; } }; }
java
public static Iterator<Character> notExistChars(String s) { return new Iterator<Character>() { IntList collect = IntList.create(s.chars().distinct().sorted().toArray()); int current = 128; Character next = null; @Override public Character next() { if (calcNext()) { Character c = next; next = null; return c; } else { throw new NoSuchElementException("No next non-exist character."); } } @Override public boolean hasNext() { return calcNext(); } private boolean calcNext() { if (next == null) { while (++current < Integer.MAX_VALUE) { if (collect.remove(current) == false) { next = (char) current; return true; } } return false; } return true; } }; }
[ "public", "static", "Iterator", "<", "Character", ">", "notExistChars", "(", "String", "s", ")", "{", "return", "new", "Iterator", "<", "Character", ">", "(", ")", "{", "IntList", "collect", "=", "IntList", ".", "create", "(", "s", ".", "chars", "(", ")", ".", "distinct", "(", ")", ".", "sorted", "(", ")", ".", "toArray", "(", ")", ")", ";", "int", "current", "=", "128", ";", "Character", "next", "=", "null", ";", "@", "Override", "public", "Character", "next", "(", ")", "{", "if", "(", "calcNext", "(", ")", ")", "{", "Character", "c", "=", "next", ";", "next", "=", "null", ";", "return", "c", ";", "}", "else", "{", "throw", "new", "NoSuchElementException", "(", "\"No next non-exist character.\"", ")", ";", "}", "}", "@", "Override", "public", "boolean", "hasNext", "(", ")", "{", "return", "calcNext", "(", ")", ";", "}", "private", "boolean", "calcNext", "(", ")", "{", "if", "(", "next", "==", "null", ")", "{", "while", "(", "++", "current", "<", "Integer", ".", "MAX_VALUE", ")", "{", "if", "(", "collect", ".", "remove", "(", "current", ")", "==", "false", ")", "{", "next", "=", "(", "char", ")", "current", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}", "return", "true", ";", "}", "}", ";", "}" ]
Get a list of not exist chars in given string. You can use these chars as placeholder to replace string safety. @param s @return
[ "Get", "a", "list", "of", "not", "exist", "chars", "in", "given", "string", ".", "You", "can", "use", "these", "chars", "as", "placeholder", "to", "replace", "string", "safety", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/string/StringUtil.java#L30-L65
5,927
XDean/Java-EX
src/main/java/xdean/jex/util/string/StringUtil.java
StringUtil.balancePair
public static int[] balancePair(String str, String left, String right) { int count = 0; int offset = 0; int firstLeft = -1; while (true) { int leftIndex = str.indexOf(left, offset); int rightIndex = str.indexOf(right, offset); if (leftIndex == rightIndex) { return new int[] { firstLeft, -1 }; } else if ((leftIndex < rightIndex && leftIndex != -1) || rightIndex == -1) { if (firstLeft == -1) { firstLeft = leftIndex; } count++; offset = leftIndex + 1; } else { count--; offset = rightIndex + 1; if (count < 0) { return new int[] { firstLeft, -1 }; } if (count == 0) { return new int[] { firstLeft, rightIndex }; } } } }
java
public static int[] balancePair(String str, String left, String right) { int count = 0; int offset = 0; int firstLeft = -1; while (true) { int leftIndex = str.indexOf(left, offset); int rightIndex = str.indexOf(right, offset); if (leftIndex == rightIndex) { return new int[] { firstLeft, -1 }; } else if ((leftIndex < rightIndex && leftIndex != -1) || rightIndex == -1) { if (firstLeft == -1) { firstLeft = leftIndex; } count++; offset = leftIndex + 1; } else { count--; offset = rightIndex + 1; if (count < 0) { return new int[] { firstLeft, -1 }; } if (count == 0) { return new int[] { firstLeft, rightIndex }; } } } }
[ "public", "static", "int", "[", "]", "balancePair", "(", "String", "str", ",", "String", "left", ",", "String", "right", ")", "{", "int", "count", "=", "0", ";", "int", "offset", "=", "0", ";", "int", "firstLeft", "=", "-", "1", ";", "while", "(", "true", ")", "{", "int", "leftIndex", "=", "str", ".", "indexOf", "(", "left", ",", "offset", ")", ";", "int", "rightIndex", "=", "str", ".", "indexOf", "(", "right", ",", "offset", ")", ";", "if", "(", "leftIndex", "==", "rightIndex", ")", "{", "return", "new", "int", "[", "]", "{", "firstLeft", ",", "-", "1", "}", ";", "}", "else", "if", "(", "(", "leftIndex", "<", "rightIndex", "&&", "leftIndex", "!=", "-", "1", ")", "||", "rightIndex", "==", "-", "1", ")", "{", "if", "(", "firstLeft", "==", "-", "1", ")", "{", "firstLeft", "=", "leftIndex", ";", "}", "count", "++", ";", "offset", "=", "leftIndex", "+", "1", ";", "}", "else", "{", "count", "--", ";", "offset", "=", "rightIndex", "+", "1", ";", "if", "(", "count", "<", "0", ")", "{", "return", "new", "int", "[", "]", "{", "firstLeft", ",", "-", "1", "}", ";", "}", "if", "(", "count", "==", "0", ")", "{", "return", "new", "int", "[", "]", "{", "firstLeft", ",", "rightIndex", "}", ";", "}", "}", "}", "}" ]
Get the first balance pair substring index. @param str the string @param left left symbol @param right right symbol @return (leftIndex, rightIndex) If not found, rightIndex is -1.
[ "Get", "the", "first", "balance", "pair", "substring", "index", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/string/StringUtil.java#L118-L144
5,928
XDean/Java-EX
src/main/java/xdean/jex/util/lang/MockException.java
MockException.period
public static <E extends Exception> void period(Object key, int period, Supplier<E> exceptionFactory) throws E { int index = cache(MockException.class, key, () -> 0) + 1; set(MockException.class, key, index); if (index % period == 0) { throw exceptionFactory.get(); } }
java
public static <E extends Exception> void period(Object key, int period, Supplier<E> exceptionFactory) throws E { int index = cache(MockException.class, key, () -> 0) + 1; set(MockException.class, key, index); if (index % period == 0) { throw exceptionFactory.get(); } }
[ "public", "static", "<", "E", "extends", "Exception", ">", "void", "period", "(", "Object", "key", ",", "int", "period", ",", "Supplier", "<", "E", ">", "exceptionFactory", ")", "throws", "E", "{", "int", "index", "=", "cache", "(", "MockException", ".", "class", ",", "key", ",", "(", ")", "->", "0", ")", "+", "1", ";", "set", "(", "MockException", ".", "class", ",", "key", ",", "index", ")", ";", "if", "(", "index", "%", "period", "==", "0", ")", "{", "throw", "exceptionFactory", ".", "get", "(", ")", ";", "}", "}" ]
Mock exception happens by period @param key the unique key to decide these invocation are grouped @param period how many invocations will occur an exception @param exceptionFactory exception to throw @throws E exception type
[ "Mock", "exception", "happens", "by", "period" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/lang/MockException.java#L28-L34
5,929
XDean/Java-EX
src/main/java/xdean/jex/util/lang/MockException.java
MockException.possible
public static <E extends Exception> void possible(double possible, Supplier<E> exceptionFactory) throws E { if (Math.random() < possible) { throw exceptionFactory.get(); } }
java
public static <E extends Exception> void possible(double possible, Supplier<E> exceptionFactory) throws E { if (Math.random() < possible) { throw exceptionFactory.get(); } }
[ "public", "static", "<", "E", "extends", "Exception", ">", "void", "possible", "(", "double", "possible", ",", "Supplier", "<", "E", ">", "exceptionFactory", ")", "throws", "E", "{", "if", "(", "Math", ".", "random", "(", ")", "<", "possible", ")", "{", "throw", "exceptionFactory", ".", "get", "(", ")", ";", "}", "}" ]
Mock exception happens by possibility @param possible @param exceptionFactory @throws E
[ "Mock", "exception", "happens", "by", "possibility" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/lang/MockException.java#L47-L51
5,930
XDean/Java-EX
src/main/java/xdean/jex/util/task/TaskUtil.java
TaskUtil.firstFail
@SafeVarargs @SuppressWarnings("unchecked") public static <T extends Exception> Optional<T> firstFail(ActionE0<T>... tasks) { for (ActionE0<T> task : tasks) { try { task.call(); } catch (Exception t) { return Optional.of((T) t); } } return Optional.empty(); }
java
@SafeVarargs @SuppressWarnings("unchecked") public static <T extends Exception> Optional<T> firstFail(ActionE0<T>... tasks) { for (ActionE0<T> task : tasks) { try { task.call(); } catch (Exception t) { return Optional.of((T) t); } } return Optional.empty(); }
[ "@", "SafeVarargs", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", "extends", "Exception", ">", "Optional", "<", "T", ">", "firstFail", "(", "ActionE0", "<", "T", ">", "...", "tasks", ")", "{", "for", "(", "ActionE0", "<", "T", ">", "task", ":", "tasks", ")", "{", "try", "{", "task", ".", "call", "(", ")", ";", "}", "catch", "(", "Exception", "t", ")", "{", "return", "Optional", ".", "of", "(", "(", "T", ")", "t", ")", ";", "}", "}", "return", "Optional", ".", "empty", "(", ")", ";", "}" ]
Run the given tasks until any exception happen @param tasks @return the exception
[ "Run", "the", "given", "tasks", "until", "any", "exception", "happen" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/task/TaskUtil.java#L77-L88
5,931
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/TypeVisitor.java
TypeVisitor.of
public static <T> T of(Type type, Function<TypeVisitor<T>, T> function) { return function.apply(create(type)); }
java
public static <T> T of(Type type, Function<TypeVisitor<T>, T> function) { return function.apply(create(type)); }
[ "public", "static", "<", "T", ">", "T", "of", "(", "Type", "type", ",", "Function", "<", "TypeVisitor", "<", "T", ">", ",", "T", ">", "function", ")", "{", "return", "function", ".", "apply", "(", "create", "(", "type", ")", ")", ";", "}" ]
Because eclipse's type inference is so bad, use this method you can free from angle brackets. @param type @param function @return
[ "Because", "eclipse", "s", "type", "inference", "is", "so", "bad", "use", "this", "method", "you", "can", "free", "from", "angle", "brackets", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/TypeVisitor.java#L26-L28
5,932
XDean/Java-EX
src/main/java/xdean/jex/util/collection/MapUtil.java
MapUtil.getOrPutDefault
@Deprecated public static <K, V> V getOrPutDefault(Map<K, V> map, K key, Supplier<V> defaultGetter) { return map.computeIfAbsent(key, k -> defaultGetter.get()); }
java
@Deprecated public static <K, V> V getOrPutDefault(Map<K, V> map, K key, Supplier<V> defaultGetter) { return map.computeIfAbsent(key, k -> defaultGetter.get()); }
[ "@", "Deprecated", "public", "static", "<", "K", ",", "V", ">", "V", "getOrPutDefault", "(", "Map", "<", "K", ",", "V", ">", "map", ",", "K", "key", ",", "Supplier", "<", "V", ">", "defaultGetter", ")", "{", "return", "map", ".", "computeIfAbsent", "(", "key", ",", "k", "->", "defaultGetter", ".", "get", "(", ")", ")", ";", "}" ]
Get the value of the key. If absent, put the default value. @param map @param key @param defaultGetter @return
[ "Get", "the", "value", "of", "the", "key", ".", "If", "absent", "put", "the", "default", "value", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/collection/MapUtil.java#L27-L30
5,933
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/GenericUtil.java
GenericUtil.getActualType
private static Type getActualType(Map<TypeVariable<?>, Type> map, Type type) { return TypeVisitor.of(type, b -> b .onClass(c -> c) .onTypeVariable(tv -> map.containsKey(tv) ? getActualType(map, map.get(tv)) : tv) .onParameterizedType(pt -> TypeVisitor.of(pt.getRawType(), bb -> bb .onClass(c -> createParameterizedType(c, pt.getOwnerType(), Arrays.stream(pt.getActualTypeArguments()).map(t -> getActualType(map, t)).toArray(Type[]::new))) .result())) .onWildcardType(wt -> createWildcardType( Arrays.stream(wt.getUpperBounds()).map(t -> getActualType(map, t)).toArray(Type[]::new), Arrays.stream(wt.getLowerBounds()).map(t -> getActualType(map, t)).toArray(Type[]::new))) .onGenericArrayType(gat -> createGenericArrayType(getActualType(map, gat.getGenericComponentType()))) .result(type)); }
java
private static Type getActualType(Map<TypeVariable<?>, Type> map, Type type) { return TypeVisitor.of(type, b -> b .onClass(c -> c) .onTypeVariable(tv -> map.containsKey(tv) ? getActualType(map, map.get(tv)) : tv) .onParameterizedType(pt -> TypeVisitor.of(pt.getRawType(), bb -> bb .onClass(c -> createParameterizedType(c, pt.getOwnerType(), Arrays.stream(pt.getActualTypeArguments()).map(t -> getActualType(map, t)).toArray(Type[]::new))) .result())) .onWildcardType(wt -> createWildcardType( Arrays.stream(wt.getUpperBounds()).map(t -> getActualType(map, t)).toArray(Type[]::new), Arrays.stream(wt.getLowerBounds()).map(t -> getActualType(map, t)).toArray(Type[]::new))) .onGenericArrayType(gat -> createGenericArrayType(getActualType(map, gat.getGenericComponentType()))) .result(type)); }
[ "private", "static", "Type", "getActualType", "(", "Map", "<", "TypeVariable", "<", "?", ">", ",", "Type", ">", "map", ",", "Type", "type", ")", "{", "return", "TypeVisitor", ".", "of", "(", "type", ",", "b", "->", "b", ".", "onClass", "(", "c", "->", "c", ")", ".", "onTypeVariable", "(", "tv", "->", "map", ".", "containsKey", "(", "tv", ")", "?", "getActualType", "(", "map", ",", "map", ".", "get", "(", "tv", ")", ")", ":", "tv", ")", ".", "onParameterizedType", "(", "pt", "->", "TypeVisitor", ".", "of", "(", "pt", ".", "getRawType", "(", ")", ",", "bb", "->", "bb", ".", "onClass", "(", "c", "->", "createParameterizedType", "(", "c", ",", "pt", ".", "getOwnerType", "(", ")", ",", "Arrays", ".", "stream", "(", "pt", ".", "getActualTypeArguments", "(", ")", ")", ".", "map", "(", "t", "->", "getActualType", "(", "map", ",", "t", ")", ")", ".", "toArray", "(", "Type", "[", "]", "::", "new", ")", ")", ")", ".", "result", "(", ")", ")", ")", ".", "onWildcardType", "(", "wt", "->", "createWildcardType", "(", "Arrays", ".", "stream", "(", "wt", ".", "getUpperBounds", "(", ")", ")", ".", "map", "(", "t", "->", "getActualType", "(", "map", ",", "t", ")", ")", ".", "toArray", "(", "Type", "[", "]", "::", "new", ")", ",", "Arrays", ".", "stream", "(", "wt", ".", "getLowerBounds", "(", ")", ")", ".", "map", "(", "t", "->", "getActualType", "(", "map", ",", "t", ")", ")", ".", "toArray", "(", "Type", "[", "]", "::", "new", ")", ")", ")", ".", "onGenericArrayType", "(", "gat", "->", "createGenericArrayType", "(", "getActualType", "(", "map", ",", "gat", ".", "getGenericComponentType", "(", ")", ")", ")", ")", ".", "result", "(", "type", ")", ")", ";", "}" ]
Get actual type by the type map. @param map @param type @return The actual type. Return itself if it's already the most explicit type.
[ "Get", "actual", "type", "by", "the", "type", "map", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/GenericUtil.java#L132-L145
5,934
aseovic/npm-maven-plugin
src/main/java/com/seovic/maven/plugins/npm/Package.java
Package.parse
public static Package parse(File file) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(file, Package.class); }
java
public static Package parse(File file) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(file, Package.class); }
[ "public", "static", "Package", "parse", "(", "File", "file", ")", "throws", "IOException", "{", "ObjectMapper", "mapper", "=", "new", "ObjectMapper", "(", ")", ";", "return", "mapper", ".", "readValue", "(", "file", ",", "Package", ".", "class", ")", ";", "}" ]
Parse package.json. @param file the file to parse @return a new Package instance for the specified file @throws IOException if an error occurs
[ "Parse", "package", ".", "json", "." ]
3257fbf68f53f6a52249433910b876e47a7ac7f6
https://github.com/aseovic/npm-maven-plugin/blob/3257fbf68f53f6a52249433910b876e47a7ac7f6/src/main/java/com/seovic/maven/plugins/npm/Package.java#L32-L36
5,935
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/FunctionInterfaceUtil.java
FunctionInterfaceUtil.getFunctionInterfaceMethod
public static <T> Method getFunctionInterfaceMethod(Class<?> clz) { if (!clz.isInterface()) { return null; } Method[] ms = Stream.of(clz.getMethods()) .filter(m -> !(m.isDefault() || m.isBridge() || m.isSynthetic() || Modifier.isStatic(m.getModifiers()))) .toArray(Method[]::new); if (ms.length != 1) { return null; } return ms[0]; }
java
public static <T> Method getFunctionInterfaceMethod(Class<?> clz) { if (!clz.isInterface()) { return null; } Method[] ms = Stream.of(clz.getMethods()) .filter(m -> !(m.isDefault() || m.isBridge() || m.isSynthetic() || Modifier.isStatic(m.getModifiers()))) .toArray(Method[]::new); if (ms.length != 1) { return null; } return ms[0]; }
[ "public", "static", "<", "T", ">", "Method", "getFunctionInterfaceMethod", "(", "Class", "<", "?", ">", "clz", ")", "{", "if", "(", "!", "clz", ".", "isInterface", "(", ")", ")", "{", "return", "null", ";", "}", "Method", "[", "]", "ms", "=", "Stream", ".", "of", "(", "clz", ".", "getMethods", "(", ")", ")", ".", "filter", "(", "m", "->", "!", "(", "m", ".", "isDefault", "(", ")", "||", "m", ".", "isBridge", "(", ")", "||", "m", ".", "isSynthetic", "(", ")", "||", "Modifier", ".", "isStatic", "(", "m", ".", "getModifiers", "(", ")", ")", ")", ")", ".", "toArray", "(", "Method", "[", "]", "::", "new", ")", ";", "if", "(", "ms", ".", "length", "!=", "1", ")", "{", "return", "null", ";", "}", "return", "ms", "[", "0", "]", ";", "}" ]
Get the method from a function interface @param clz @return null if the given class is not a function interface
[ "Get", "the", "method", "from", "a", "function", "interface" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/FunctionInterfaceUtil.java#L33-L44
5,936
XDean/Java-EX
src/main/java/xdean/jex/extra/tryto/Try.java
Try.to
public static <T> Try<T> to(FuncE0<T, Exception> code, ActionE0<Exception> onFinally) { try { return new Success<>(code.call()); } catch (Exception e) { return new Failure<>(e); } finally { if (onFinally != null) { try { onFinally.call(); } catch (Exception e) { LogFactory.from(Try.class).trace().log(e.getMessage(), e); } } } }
java
public static <T> Try<T> to(FuncE0<T, Exception> code, ActionE0<Exception> onFinally) { try { return new Success<>(code.call()); } catch (Exception e) { return new Failure<>(e); } finally { if (onFinally != null) { try { onFinally.call(); } catch (Exception e) { LogFactory.from(Try.class).trace().log(e.getMessage(), e); } } } }
[ "public", "static", "<", "T", ">", "Try", "<", "T", ">", "to", "(", "FuncE0", "<", "T", ",", "Exception", ">", "code", ",", "ActionE0", "<", "Exception", ">", "onFinally", ")", "{", "try", "{", "return", "new", "Success", "<>", "(", "code", ".", "call", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "new", "Failure", "<>", "(", "e", ")", ";", "}", "finally", "{", "if", "(", "onFinally", "!=", "null", ")", "{", "try", "{", "onFinally", ".", "call", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "LogFactory", ".", "from", "(", "Try", ".", "class", ")", ".", "trace", "(", ")", ".", "log", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}", "}", "}" ]
Constructs a `Try` using a code as a supplier.
[ "Constructs", "a", "Try", "using", "a", "code", "as", "a", "supplier", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/tryto/Try.java#L24-L38
5,937
XDean/Java-EX
src/main/java/xdean/jex/extra/tryto/Try.java
Try.orElse
public Try<T> orElse(Supplier<Try<T>> defaultValue) { try { return isSuccess() ? this : defaultValue.get(); } catch (RuntimeException e) { return new Failure<>(e); } }
java
public Try<T> orElse(Supplier<Try<T>> defaultValue) { try { return isSuccess() ? this : defaultValue.get(); } catch (RuntimeException e) { return new Failure<>(e); } }
[ "public", "Try", "<", "T", ">", "orElse", "(", "Supplier", "<", "Try", "<", "T", ">", ">", "defaultValue", ")", "{", "try", "{", "return", "isSuccess", "(", ")", "?", "this", ":", "defaultValue", ".", "get", "(", ")", ";", "}", "catch", "(", "RuntimeException", "e", ")", "{", "return", "new", "Failure", "<>", "(", "e", ")", ";", "}", "}" ]
Returns this `Try` if it's a `Success` or the given `default` argument if this is a `Failure`.
[ "Returns", "this", "Try", "if", "it", "s", "a", "Success", "or", "the", "given", "default", "argument", "if", "this", "is", "a", "Failure", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/tryto/Try.java#L94-L100
5,938
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/AnnotationUtil.java
AnnotationUtil.createAnnotationFromMap
@SuppressWarnings("unchecked") public static <T extends Annotation> T createAnnotationFromMap(Class<T> annotationClass, Map<String, Object> valuesMap) { Map<String, Object> map = getAnnotationDefaultMap(annotationClass); map.putAll(valuesMap); return AccessController .doPrivileged((PrivilegedAction<T>) () -> (T) Proxy.newProxyInstance( annotationClass.getClassLoader(), new Class[] { annotationClass }, uncheck( () -> (InvocationHandler) AnnotationInvocationHandler_constructor.newInstance(annotationClass, map)))); }
java
@SuppressWarnings("unchecked") public static <T extends Annotation> T createAnnotationFromMap(Class<T> annotationClass, Map<String, Object> valuesMap) { Map<String, Object> map = getAnnotationDefaultMap(annotationClass); map.putAll(valuesMap); return AccessController .doPrivileged((PrivilegedAction<T>) () -> (T) Proxy.newProxyInstance( annotationClass.getClassLoader(), new Class[] { annotationClass }, uncheck( () -> (InvocationHandler) AnnotationInvocationHandler_constructor.newInstance(annotationClass, map)))); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", "extends", "Annotation", ">", "T", "createAnnotationFromMap", "(", "Class", "<", "T", ">", "annotationClass", ",", "Map", "<", "String", ",", "Object", ">", "valuesMap", ")", "{", "Map", "<", "String", ",", "Object", ">", "map", "=", "getAnnotationDefaultMap", "(", "annotationClass", ")", ";", "map", ".", "putAll", "(", "valuesMap", ")", ";", "return", "AccessController", ".", "doPrivileged", "(", "(", "PrivilegedAction", "<", "T", ">", ")", "(", ")", "->", "(", "T", ")", "Proxy", ".", "newProxyInstance", "(", "annotationClass", ".", "getClassLoader", "(", ")", ",", "new", "Class", "[", "]", "{", "annotationClass", "}", ",", "uncheck", "(", "(", ")", "->", "(", "InvocationHandler", ")", "AnnotationInvocationHandler_constructor", ".", "newInstance", "(", "annotationClass", ",", "map", ")", ")", ")", ")", ";", "}" ]
Create annotation from the given map. @param annotationClass @param valuesMap @return
[ "Create", "annotation", "from", "the", "given", "map", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/AnnotationUtil.java#L294-L305
5,939
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.add
public Tree<T> add(Tree<T> node) { node.removeFromParent(); node.parent = this; children.add(node); return node; }
java
public Tree<T> add(Tree<T> node) { node.removeFromParent(); node.parent = this; children.add(node); return node; }
[ "public", "Tree", "<", "T", ">", "add", "(", "Tree", "<", "T", ">", "node", ")", "{", "node", ".", "removeFromParent", "(", ")", ";", "node", ".", "parent", "=", "this", ";", "children", ".", "add", "(", "node", ")", ";", "return", "node", ";", "}" ]
Add the node as child @param node @return the child node
[ "Add", "the", "node", "as", "child" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L56-L61
5,940
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.remove
public boolean remove(Tree<T> node) { return getChild(node) .map(function(n -> n.parent = null)) .map(children::remove) .orElse(false); }
java
public boolean remove(Tree<T> node) { return getChild(node) .map(function(n -> n.parent = null)) .map(children::remove) .orElse(false); }
[ "public", "boolean", "remove", "(", "Tree", "<", "T", ">", "node", ")", "{", "return", "getChild", "(", "node", ")", ".", "map", "(", "function", "(", "n", "->", "n", ".", "parent", "=", "null", ")", ")", ".", "map", "(", "children", "::", "remove", ")", ".", "orElse", "(", "false", ")", ";", "}" ]
Remove the node from children @param node @return has removed
[ "Remove", "the", "node", "from", "children" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L81-L86
5,941
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.removeFromParent
public Optional<Tree<T>> removeFromParent() { Tree<T> theParent = this.parent; if (parent != null) { parent.remove(this); } return Optional.ofNullable(theParent); }
java
public Optional<Tree<T>> removeFromParent() { Tree<T> theParent = this.parent; if (parent != null) { parent.remove(this); } return Optional.ofNullable(theParent); }
[ "public", "Optional", "<", "Tree", "<", "T", ">", ">", "removeFromParent", "(", ")", "{", "Tree", "<", "T", ">", "theParent", "=", "this", ".", "parent", ";", "if", "(", "parent", "!=", "null", ")", "{", "parent", ".", "remove", "(", "this", ")", ";", "}", "return", "Optional", ".", "ofNullable", "(", "theParent", ")", ";", "}" ]
Remove this node from its parent @return the old parent
[ "Remove", "this", "node", "from", "its", "parent" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L93-L99
5,942
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.getChild
public Optional<Tree<T>> getChild(T value) { return children.stream().filter(its(n -> n.value, isEquals(value))).findFirst(); }
java
public Optional<Tree<T>> getChild(T value) { return children.stream().filter(its(n -> n.value, isEquals(value))).findFirst(); }
[ "public", "Optional", "<", "Tree", "<", "T", ">", ">", "getChild", "(", "T", "value", ")", "{", "return", "children", ".", "stream", "(", ")", ".", "filter", "(", "its", "(", "n", "->", "n", ".", "value", ",", "isEquals", "(", "value", ")", ")", ")", ".", "findFirst", "(", ")", ";", "}" ]
Get the first matched child with the given value from children @param value @return
[ "Get", "the", "first", "matched", "child", "with", "the", "given", "value", "from", "children" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L126-L128
5,943
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.getChild
public Optional<Tree<T>> getChild(Tree<T> node) { return children.stream().filter(is(node)).findFirst(); }
java
public Optional<Tree<T>> getChild(Tree<T> node) { return children.stream().filter(is(node)).findFirst(); }
[ "public", "Optional", "<", "Tree", "<", "T", ">", ">", "getChild", "(", "Tree", "<", "T", ">", "node", ")", "{", "return", "children", ".", "stream", "(", ")", ".", "filter", "(", "is", "(", "node", ")", ")", ".", "findFirst", "(", ")", ";", "}" ]
Return the given node if it's this node's child @param node @return
[ "Return", "the", "given", "node", "if", "it", "s", "this", "node", "s", "child" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L136-L138
5,944
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.commonParent
public Optional<Tree<T>> commonParent(Tree<T> other) { List<Tree<T>> myParents = parents().startWith(this).toList().blockingGet(); return other.parents() .startWith(other) .filter(myParents::contains) .map(Optional::of) .blockingFirst(Optional.empty()); }
java
public Optional<Tree<T>> commonParent(Tree<T> other) { List<Tree<T>> myParents = parents().startWith(this).toList().blockingGet(); return other.parents() .startWith(other) .filter(myParents::contains) .map(Optional::of) .blockingFirst(Optional.empty()); }
[ "public", "Optional", "<", "Tree", "<", "T", ">", ">", "commonParent", "(", "Tree", "<", "T", ">", "other", ")", "{", "List", "<", "Tree", "<", "T", ">>", "myParents", "=", "parents", "(", ")", ".", "startWith", "(", "this", ")", ".", "toList", "(", ")", ".", "blockingGet", "(", ")", ";", "return", "other", ".", "parents", "(", ")", ".", "startWith", "(", "other", ")", ".", "filter", "(", "myParents", "::", "contains", ")", ".", "map", "(", "Optional", "::", "of", ")", ".", "blockingFirst", "(", "Optional", ".", "empty", "(", ")", ")", ";", "}" ]
Get the first common parent of this node and the given node @param other @return the common parent
[ "Get", "the", "first", "common", "parent", "of", "this", "node", "and", "the", "given", "node" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L172-L179
5,945
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.swap
public void swap(Tree<T> node) { Tree<T> thisParent = this.parent; List<Tree<T>> thisChildren = new ArrayList<>(this.children); this.removeFromParent(); if (node.parent != null) { node.parent.add(this); } node.children.forEach(this::add); node.removeFromParent(); if (thisParent != null) { thisParent.add(node); } thisChildren.forEach(node::add); }
java
public void swap(Tree<T> node) { Tree<T> thisParent = this.parent; List<Tree<T>> thisChildren = new ArrayList<>(this.children); this.removeFromParent(); if (node.parent != null) { node.parent.add(this); } node.children.forEach(this::add); node.removeFromParent(); if (thisParent != null) { thisParent.add(node); } thisChildren.forEach(node::add); }
[ "public", "void", "swap", "(", "Tree", "<", "T", ">", "node", ")", "{", "Tree", "<", "T", ">", "thisParent", "=", "this", ".", "parent", ";", "List", "<", "Tree", "<", "T", ">", ">", "thisChildren", "=", "new", "ArrayList", "<>", "(", "this", ".", "children", ")", ";", "this", ".", "removeFromParent", "(", ")", ";", "if", "(", "node", ".", "parent", "!=", "null", ")", "{", "node", ".", "parent", ".", "add", "(", "this", ")", ";", "}", "node", ".", "children", ".", "forEach", "(", "this", "::", "add", ")", ";", "node", ".", "removeFromParent", "(", ")", ";", "if", "(", "thisParent", "!=", "null", ")", "{", "thisParent", ".", "add", "(", "node", ")", ";", "}", "thisChildren", ".", "forEach", "(", "node", "::", "add", ")", ";", "}" ]
Swap with the given node. Even they are in different trees. @param node
[ "Swap", "with", "the", "given", "node", ".", "Even", "they", "are", "in", "different", "trees", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L221-L236
5,946
XDean/Java-EX
src/main/java/xdean/jex/extra/collection/Tree.java
Tree.parents
public Flowable<Tree<T>> parents() { return Flowable.generate(() -> Wrapper.of(this), (n, e) -> { Tree<T> parent = n.get().getParent(); if (parent != null) { e.onNext(parent); n.set(parent); } else { e.onComplete(); } }); }
java
public Flowable<Tree<T>> parents() { return Flowable.generate(() -> Wrapper.of(this), (n, e) -> { Tree<T> parent = n.get().getParent(); if (parent != null) { e.onNext(parent); n.set(parent); } else { e.onComplete(); } }); }
[ "public", "Flowable", "<", "Tree", "<", "T", ">", ">", "parents", "(", ")", "{", "return", "Flowable", ".", "generate", "(", "(", ")", "->", "Wrapper", ".", "of", "(", "this", ")", ",", "(", "n", ",", "e", ")", "->", "{", "Tree", "<", "T", ">", "parent", "=", "n", ".", "get", "(", ")", ".", "getParent", "(", ")", ";", "if", "(", "parent", "!=", "null", ")", "{", "e", ".", "onNext", "(", "parent", ")", ";", "n", ".", "set", "(", "parent", ")", ";", "}", "else", "{", "e", ".", "onComplete", "(", ")", ";", "}", "}", ")", ";", "}" ]
Get all of the node's parent @return
[ "Get", "all", "of", "the", "node", "s", "parent" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/extra/collection/Tree.java#L247-L257
5,947
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getRootExecutable
@SuppressWarnings("unchecked") public static <T extends Executable> T getRootExecutable(T m) { return (T) EXECUTABLE_GET_ROOT.apply(m); }
java
@SuppressWarnings("unchecked") public static <T extends Executable> T getRootExecutable(T m) { return (T) EXECUTABLE_GET_ROOT.apply(m); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", "extends", "Executable", ">", "T", "getRootExecutable", "(", "T", "m", ")", "{", "return", "(", "T", ")", "EXECUTABLE_GET_ROOT", ".", "apply", "(", "m", ")", ";", "}" ]
Get root of the executable.
[ "Get", "root", "of", "the", "executable", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L61-L64
5,948
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getFieldValue
@SuppressWarnings("unchecked") public static <T, O> O getFieldValue(Class<T> clz, T t, String fieldName) throws NoSuchFieldException { Field field = clz.getDeclaredField(fieldName); field.setAccessible(true); try { return (O) field.get(t); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
java
@SuppressWarnings("unchecked") public static <T, O> O getFieldValue(Class<T> clz, T t, String fieldName) throws NoSuchFieldException { Field field = clz.getDeclaredField(fieldName); field.setAccessible(true); try { return (O) field.get(t); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", ",", "O", ">", "O", "getFieldValue", "(", "Class", "<", "T", ">", "clz", ",", "T", "t", ",", "String", "fieldName", ")", "throws", "NoSuchFieldException", "{", "Field", "field", "=", "clz", ".", "getDeclaredField", "(", "fieldName", ")", ";", "field", ".", "setAccessible", "(", "true", ")", ";", "try", "{", "return", "(", "O", ")", "field", ".", "get", "(", "t", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "e", ")", ";", "}", "}" ]
Get field value by name @param clz @param t @param fieldName @return @throws NoSuchFieldException
[ "Get", "field", "value", "by", "name" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L96-L105
5,949
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getAllMethods
public static Method[] getAllMethods(Class<?> clz) { Set<Method> set = new HashSet<>(); List<Class<?>> classes = new ArrayList<>(); classes.add(clz); classes.addAll(Arrays.asList(getAllSuperClasses(clz))); classes.addAll(Arrays.asList(getAllInterfaces(clz))); for (Class<?> c : classes) { set.addAll(Arrays.asList(c.getDeclaredMethods())); } return set.toArray(new Method[set.size()]); }
java
public static Method[] getAllMethods(Class<?> clz) { Set<Method> set = new HashSet<>(); List<Class<?>> classes = new ArrayList<>(); classes.add(clz); classes.addAll(Arrays.asList(getAllSuperClasses(clz))); classes.addAll(Arrays.asList(getAllInterfaces(clz))); for (Class<?> c : classes) { set.addAll(Arrays.asList(c.getDeclaredMethods())); } return set.toArray(new Method[set.size()]); }
[ "public", "static", "Method", "[", "]", "getAllMethods", "(", "Class", "<", "?", ">", "clz", ")", "{", "Set", "<", "Method", ">", "set", "=", "new", "HashSet", "<>", "(", ")", ";", "List", "<", "Class", "<", "?", ">", ">", "classes", "=", "new", "ArrayList", "<>", "(", ")", ";", "classes", ".", "add", "(", "clz", ")", ";", "classes", ".", "addAll", "(", "Arrays", ".", "asList", "(", "getAllSuperClasses", "(", "clz", ")", ")", ")", ";", "classes", ".", "addAll", "(", "Arrays", ".", "asList", "(", "getAllInterfaces", "(", "clz", ")", ")", ")", ";", "for", "(", "Class", "<", "?", ">", "c", ":", "classes", ")", "{", "set", ".", "addAll", "(", "Arrays", ".", "asList", "(", "c", ".", "getDeclaredMethods", "(", ")", ")", ")", ";", "}", "return", "set", ".", "toArray", "(", "new", "Method", "[", "set", ".", "size", "(", ")", "]", ")", ";", "}" ]
Get all methods @param clz @return
[ "Get", "all", "methods" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L140-L150
5,950
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getAllSuperClasses
public static Class<?>[] getAllSuperClasses(Class<?> clz) { List<Class<?>> list = new ArrayList<>(); while ((clz = clz.getSuperclass()) != null) { list.add(clz); } return list.toArray(new Class<?>[list.size()]); }
java
public static Class<?>[] getAllSuperClasses(Class<?> clz) { List<Class<?>> list = new ArrayList<>(); while ((clz = clz.getSuperclass()) != null) { list.add(clz); } return list.toArray(new Class<?>[list.size()]); }
[ "public", "static", "Class", "<", "?", ">", "[", "]", "getAllSuperClasses", "(", "Class", "<", "?", ">", "clz", ")", "{", "List", "<", "Class", "<", "?", ">", ">", "list", "=", "new", "ArrayList", "<>", "(", ")", ";", "while", "(", "(", "clz", "=", "clz", ".", "getSuperclass", "(", ")", ")", "!=", "null", ")", "{", "list", ".", "add", "(", "clz", ")", ";", "}", "return", "list", ".", "toArray", "(", "new", "Class", "<", "?", ">", "[", "list", ".", "size", "(", ")", "]", ")", ";", "}" ]
Get all super classes @param clz @return
[ "Get", "all", "super", "classes" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L158-L164
5,951
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getAllInterfaces
public static Class<?>[] getAllInterfaces(Class<?> clz) { HashSet<Class<?>> set = new HashSet<>(); getAllInterfaces(clz, set); return set.toArray(new Class<?>[set.size()]); }
java
public static Class<?>[] getAllInterfaces(Class<?> clz) { HashSet<Class<?>> set = new HashSet<>(); getAllInterfaces(clz, set); return set.toArray(new Class<?>[set.size()]); }
[ "public", "static", "Class", "<", "?", ">", "[", "]", "getAllInterfaces", "(", "Class", "<", "?", ">", "clz", ")", "{", "HashSet", "<", "Class", "<", "?", ">", ">", "set", "=", "new", "HashSet", "<>", "(", ")", ";", "getAllInterfaces", "(", "clz", ",", "set", ")", ";", "return", "set", ".", "toArray", "(", "new", "Class", "<", "?", ">", "[", "set", ".", "size", "(", ")", "]", ")", ";", "}" ]
Get all interfaces @param clz @return
[ "Get", "all", "interfaces" ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L172-L176
5,952
XDean/Java-EX
src/main/java/xdean/jex/util/reflect/ReflectUtil.java
ReflectUtil.getCaller
public static StackTraceElement getCaller(int deep, boolean ignoreSameClass) { // index 0 is Thread.getStackTrace // index 1 is ReflectUtil.getCallerClassName StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); StackTraceElement currentStack = stElements[1]; int found = deep + 1; for (int i = 1; i < stElements.length; i++) { StackTraceElement nextStack = stElements[i]; if (nextStack.getClassName().equals(ReflectUtil.class.getName())) { continue; } if (!ignoreSameClass || !currentStack.getClassName().equals(nextStack.getClassName())) { currentStack = nextStack; found--; } if (found == 0) { return currentStack; } } throw new IllegalArgumentException("Stack don't have such deep."); }
java
public static StackTraceElement getCaller(int deep, boolean ignoreSameClass) { // index 0 is Thread.getStackTrace // index 1 is ReflectUtil.getCallerClassName StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); StackTraceElement currentStack = stElements[1]; int found = deep + 1; for (int i = 1; i < stElements.length; i++) { StackTraceElement nextStack = stElements[i]; if (nextStack.getClassName().equals(ReflectUtil.class.getName())) { continue; } if (!ignoreSameClass || !currentStack.getClassName().equals(nextStack.getClassName())) { currentStack = nextStack; found--; } if (found == 0) { return currentStack; } } throw new IllegalArgumentException("Stack don't have such deep."); }
[ "public", "static", "StackTraceElement", "getCaller", "(", "int", "deep", ",", "boolean", "ignoreSameClass", ")", "{", "// index 0 is Thread.getStackTrace\r", "// index 1 is ReflectUtil.getCallerClassName\r", "StackTraceElement", "[", "]", "stElements", "=", "Thread", ".", "currentThread", "(", ")", ".", "getStackTrace", "(", ")", ";", "StackTraceElement", "currentStack", "=", "stElements", "[", "1", "]", ";", "int", "found", "=", "deep", "+", "1", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "stElements", ".", "length", ";", "i", "++", ")", "{", "StackTraceElement", "nextStack", "=", "stElements", "[", "i", "]", ";", "if", "(", "nextStack", ".", "getClassName", "(", ")", ".", "equals", "(", "ReflectUtil", ".", "class", ".", "getName", "(", ")", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "ignoreSameClass", "||", "!", "currentStack", ".", "getClassName", "(", ")", ".", "equals", "(", "nextStack", ".", "getClassName", "(", ")", ")", ")", "{", "currentStack", "=", "nextStack", ";", "found", "--", ";", "}", "if", "(", "found", "==", "0", ")", "{", "return", "currentStack", ";", "}", "}", "throw", "new", "IllegalArgumentException", "(", "\"Stack don't have such deep.\"", ")", ";", "}" ]
Get caller stack info. @param deep Deep to search the caller class.If deep is 0, it returns the class who calls this method. @param ignoreSameClass If it is true, calling in same class will be ignored.
[ "Get", "caller", "stack", "info", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/reflect/ReflectUtil.java#L224-L244
5,953
XDean/Java-EX
src/main/java/xdean/jex/util/lang/UnsafeUtil.java
UnsafeUtil.addressOf
public static long addressOf(Object o) { Object[] array = new Object[] { o }; long baseOffset = THE_UNSAFE.arrayBaseOffset(Object[].class); long objectAddress; switch (ADDRESS_SIZE) { case 4: objectAddress = THE_UNSAFE.getInt(array, baseOffset); break; case 8: objectAddress = THE_UNSAFE.getLong(array, baseOffset); break; default: throw new IllegalStateException("unsupported address size: " + ADDRESS_SIZE); } return objectAddress; }
java
public static long addressOf(Object o) { Object[] array = new Object[] { o }; long baseOffset = THE_UNSAFE.arrayBaseOffset(Object[].class); long objectAddress; switch (ADDRESS_SIZE) { case 4: objectAddress = THE_UNSAFE.getInt(array, baseOffset); break; case 8: objectAddress = THE_UNSAFE.getLong(array, baseOffset); break; default: throw new IllegalStateException("unsupported address size: " + ADDRESS_SIZE); } return objectAddress; }
[ "public", "static", "long", "addressOf", "(", "Object", "o", ")", "{", "Object", "[", "]", "array", "=", "new", "Object", "[", "]", "{", "o", "}", ";", "long", "baseOffset", "=", "THE_UNSAFE", ".", "arrayBaseOffset", "(", "Object", "[", "]", ".", "class", ")", ";", "long", "objectAddress", ";", "switch", "(", "ADDRESS_SIZE", ")", "{", "case", "4", ":", "objectAddress", "=", "THE_UNSAFE", ".", "getInt", "(", "array", ",", "baseOffset", ")", ";", "break", ";", "case", "8", ":", "objectAddress", "=", "THE_UNSAFE", ".", "getLong", "(", "array", ",", "baseOffset", ")", ";", "break", ";", "default", ":", "throw", "new", "IllegalStateException", "(", "\"unsupported address size: \"", "+", "ADDRESS_SIZE", ")", ";", "}", "return", "objectAddress", ";", "}" ]
Get the memory address of the given object. @param o @return
[ "Get", "the", "memory", "address", "of", "the", "given", "object", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/lang/UnsafeUtil.java#L42-L57
5,954
XDean/Java-EX
src/main/java/xdean/jex/util/task/If.java
If.result
public T result() throws NoSuchElementException { if (result == NULL_RESULT) { if (parent != null) { return parent.result(); } throw new NoSuchElementException("There is no result"); } return result; }
java
public T result() throws NoSuchElementException { if (result == NULL_RESULT) { if (parent != null) { return parent.result(); } throw new NoSuchElementException("There is no result"); } return result; }
[ "public", "T", "result", "(", ")", "throws", "NoSuchElementException", "{", "if", "(", "result", "==", "NULL_RESULT", ")", "{", "if", "(", "parent", "!=", "null", ")", "{", "return", "parent", ".", "result", "(", ")", ";", "}", "throw", "new", "NoSuchElementException", "(", "\"There is no result\"", ")", ";", "}", "return", "result", ";", "}" ]
Get the result. @return @throws NoSuchElementException If there is no result be set.
[ "Get", "the", "result", "." ]
9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7
https://github.com/XDean/Java-EX/blob/9208ba71c5b2af9f9bd979d01fab2ff5e433b3e7/src/main/java/xdean/jex/util/task/If.java#L109-L117
5,955
FXMisc/WellBehavedFX
src/main/java/org/fxmisc/wellbehaved/event/Nodes.java
Nodes.addInputMap
public static void addInputMap(Node node, InputMap<?> im) { // getInputMap calls init, so can use unsafe setter setInputMapUnsafe(node, InputMap.sequence(im, getInputMap(node))); }
java
public static void addInputMap(Node node, InputMap<?> im) { // getInputMap calls init, so can use unsafe setter setInputMapUnsafe(node, InputMap.sequence(im, getInputMap(node))); }
[ "public", "static", "void", "addInputMap", "(", "Node", "node", ",", "InputMap", "<", "?", ">", "im", ")", "{", "// getInputMap calls init, so can use unsafe setter", "setInputMapUnsafe", "(", "node", ",", "InputMap", ".", "sequence", "(", "im", ",", "getInputMap", "(", "node", ")", ")", ")", ";", "}" ]
Adds the given input map to the start of the node's list of input maps, so that an event will be pattern-matched against the given input map before being pattern-matched against any other input maps currently "installed" in the node.
[ "Adds", "the", "given", "input", "map", "to", "the", "start", "of", "the", "node", "s", "list", "of", "input", "maps", "so", "that", "an", "event", "will", "be", "pattern", "-", "matched", "against", "the", "given", "input", "map", "before", "being", "pattern", "-", "matched", "against", "any", "other", "input", "maps", "currently", "installed", "in", "the", "node", "." ]
ca889734481f5439655ca8deb6f742964b5654b0
https://github.com/FXMisc/WellBehavedFX/blob/ca889734481f5439655ca8deb6f742964b5654b0/src/main/java/org/fxmisc/wellbehaved/event/Nodes.java#L51-L54
5,956
FXMisc/WellBehavedFX
src/main/java/org/fxmisc/wellbehaved/event/Nodes.java
Nodes.addFallbackInputMap
public static void addFallbackInputMap(Node node, InputMap<?> im) { // getInputMap calls init, so can use unsafe setter setInputMapUnsafe(node, InputMap.sequence(getInputMap(node), im)); }
java
public static void addFallbackInputMap(Node node, InputMap<?> im) { // getInputMap calls init, so can use unsafe setter setInputMapUnsafe(node, InputMap.sequence(getInputMap(node), im)); }
[ "public", "static", "void", "addFallbackInputMap", "(", "Node", "node", ",", "InputMap", "<", "?", ">", "im", ")", "{", "// getInputMap calls init, so can use unsafe setter", "setInputMapUnsafe", "(", "node", ",", "InputMap", ".", "sequence", "(", "getInputMap", "(", "node", ")", ",", "im", ")", ")", ";", "}" ]
Adds the given input map to the end of the node's list of input maps, so that an event will be pattern-matched against all other input maps currently "installed" in the node before being pattern-matched against the given input map.
[ "Adds", "the", "given", "input", "map", "to", "the", "end", "of", "the", "node", "s", "list", "of", "input", "maps", "so", "that", "an", "event", "will", "be", "pattern", "-", "matched", "against", "all", "other", "input", "maps", "currently", "installed", "in", "the", "node", "before", "being", "pattern", "-", "matched", "against", "the", "given", "input", "map", "." ]
ca889734481f5439655ca8deb6f742964b5654b0
https://github.com/FXMisc/WellBehavedFX/blob/ca889734481f5439655ca8deb6f742964b5654b0/src/main/java/org/fxmisc/wellbehaved/event/Nodes.java#L61-L64
5,957
FXMisc/WellBehavedFX
src/main/java/org/fxmisc/wellbehaved/event/template/InputMapTemplate.java
InputMapTemplate.sequence
@SafeVarargs public static <S, E extends Event> InputMapTemplate<S, E> sequence(InputMapTemplate<S, ? extends E>... templates) { return new TemplateChain<>(templates); }
java
@SafeVarargs public static <S, E extends Event> InputMapTemplate<S, E> sequence(InputMapTemplate<S, ? extends E>... templates) { return new TemplateChain<>(templates); }
[ "@", "SafeVarargs", "public", "static", "<", "S", ",", "E", "extends", "Event", ">", "InputMapTemplate", "<", "S", ",", "E", ">", "sequence", "(", "InputMapTemplate", "<", "S", ",", "?", "extends", "E", ">", "...", "templates", ")", "{", "return", "new", "TemplateChain", "<>", "(", "templates", ")", ";", "}" ]
Creates a single InputMapTemplate that pattern matches a given event type against all the given InputMapTemplates. This is often the InputMapTemplate installed on a given node since it contains all the other InputMapTemplates.
[ "Creates", "a", "single", "InputMapTemplate", "that", "pattern", "matches", "a", "given", "event", "type", "against", "all", "the", "given", "InputMapTemplates", ".", "This", "is", "often", "the", "InputMapTemplate", "installed", "on", "a", "given", "node", "since", "it", "contains", "all", "the", "other", "InputMapTemplates", "." ]
ca889734481f5439655ca8deb6f742964b5654b0
https://github.com/FXMisc/WellBehavedFX/blob/ca889734481f5439655ca8deb6f742964b5654b0/src/main/java/org/fxmisc/wellbehaved/event/template/InputMapTemplate.java#L147-L150
5,958
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.split
public List<String> split(String content, String separatorCssSelector) { return split(content, separatorCssSelector, JoinSeparator.NO); }
java
public List<String> split(String content, String separatorCssSelector) { return split(content, separatorCssSelector, JoinSeparator.NO); }
[ "public", "List", "<", "String", ">", "split", "(", "String", "content", ",", "String", "separatorCssSelector", ")", "{", "return", "split", "(", "content", ",", "separatorCssSelector", ",", "JoinSeparator", ".", "NO", ")", ";", "}" ]
Splits the given HTML content into partitions based on the given separator selector. The separators themselves are dropped from the results. @param content HTML content to split @param separatorCssSelector CSS selector for separators. @return a list of HTML partitions split on separator locations, but without the separators. @since 1.0 @see #split(String, String, JoinSeparator)
[ "Splits", "the", "given", "HTML", "content", "into", "partitions", "based", "on", "the", "given", "separator", "selector", ".", "The", "separators", "themselves", "are", "dropped", "from", "the", "results", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L119-L121
5,959
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.outerHtml
private static String outerHtml(List<Element> elements) { switch (elements.size()) { case 0: return ""; case 1: return elements.get(0).outerHtml(); default: { // more than one element // wrap into <div> which we will remove afterwards Element root = new Element(Tag.valueOf("div"), ""); for (Element elem : elements) { root.appendChild(elem); } return root.html(); } } }
java
private static String outerHtml(List<Element> elements) { switch (elements.size()) { case 0: return ""; case 1: return elements.get(0).outerHtml(); default: { // more than one element // wrap into <div> which we will remove afterwards Element root = new Element(Tag.valueOf("div"), ""); for (Element elem : elements) { root.appendChild(elem); } return root.html(); } } }
[ "private", "static", "String", "outerHtml", "(", "List", "<", "Element", ">", "elements", ")", "{", "switch", "(", "elements", ".", "size", "(", ")", ")", "{", "case", "0", ":", "return", "\"\"", ";", "case", "1", ":", "return", "elements", ".", "get", "(", "0", ")", ".", "outerHtml", "(", ")", ";", "default", ":", "{", "// more than one element", "// wrap into <div> which we will remove afterwards", "Element", "root", "=", "new", "Element", "(", "Tag", ".", "valueOf", "(", "\"div\"", ")", ",", "\"\"", ")", ";", "for", "(", "Element", "elem", ":", "elements", ")", "{", "root", ".", "appendChild", "(", "elem", ")", ";", "}", "return", "root", ".", "html", "(", ")", ";", "}", "}", "}" ]
Outputs the list of partition root elements to HTML. @param elements @return
[ "Outputs", "the", "list", "of", "partition", "root", "elements", "to", "HTML", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L320-L338
5,960
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.extractElements
private List<Element> extractElements(String content, String selector, int amount) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { elements = filterParents(elements); if (amount >= 0) { // limit to the indicated amount elements = elements.subList(0, Math.min(amount, elements.size())); } // remove all from their parents for (Element element : elements) { element.remove(); } } List<Element> results = new ArrayList<Element>(); // first element is the body results.add(body); results.addAll(elements); return results; }
java
private List<Element> extractElements(String content, String selector, int amount) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { elements = filterParents(elements); if (amount >= 0) { // limit to the indicated amount elements = elements.subList(0, Math.min(amount, elements.size())); } // remove all from their parents for (Element element : elements) { element.remove(); } } List<Element> results = new ArrayList<Element>(); // first element is the body results.add(body); results.addAll(elements); return results; }
[ "private", "List", "<", "Element", ">", "extractElements", "(", "String", "content", ",", "String", "selector", ",", "int", "amount", ")", "{", "Element", "body", "=", "parseContent", "(", "content", ")", ";", "List", "<", "Element", ">", "elements", "=", "body", ".", "select", "(", "selector", ")", ";", "if", "(", "elements", ".", "size", "(", ")", ">", "0", ")", "{", "elements", "=", "filterParents", "(", "elements", ")", ";", "if", "(", "amount", ">=", "0", ")", "{", "// limit to the indicated amount", "elements", "=", "elements", ".", "subList", "(", "0", ",", "Math", ".", "min", "(", "amount", ",", "elements", ".", "size", "(", ")", ")", ")", ";", "}", "// remove all from their parents", "for", "(", "Element", "element", ":", "elements", ")", "{", "element", ".", "remove", "(", ")", ";", "}", "}", "List", "<", "Element", ">", "results", "=", "new", "ArrayList", "<", "Element", ">", "(", ")", ";", "// first element is the body", "results", ".", "add", "(", "body", ")", ";", "results", ".", "addAll", "(", "elements", ")", ";", "return", "results", ";", "}" ]
Extracts elements from the HTML content. @param content @param selector @param amount @return the remainder and a list of extracted elements. The main body (remainder after extraction) is always returned as the first element of the list.
[ "Extracts", "elements", "from", "the", "HTML", "content", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L437-L462
5,961
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.filterParents
private static List<Element> filterParents(List<Element> elements) { List<Element> filtered = new ArrayList<Element>(); for (Element element : elements) { // get the intersection of parents and selected elements List<Element> parentsInter = element.parents(); parentsInter.retainAll(elements); if (parentsInter.isEmpty()) { // no intersection - element's parents are not in the selected list filtered.add(element); } } return filtered; }
java
private static List<Element> filterParents(List<Element> elements) { List<Element> filtered = new ArrayList<Element>(); for (Element element : elements) { // get the intersection of parents and selected elements List<Element> parentsInter = element.parents(); parentsInter.retainAll(elements); if (parentsInter.isEmpty()) { // no intersection - element's parents are not in the selected list filtered.add(element); } } return filtered; }
[ "private", "static", "List", "<", "Element", ">", "filterParents", "(", "List", "<", "Element", ">", "elements", ")", "{", "List", "<", "Element", ">", "filtered", "=", "new", "ArrayList", "<", "Element", ">", "(", ")", ";", "for", "(", "Element", "element", ":", "elements", ")", "{", "// get the intersection of parents and selected elements", "List", "<", "Element", ">", "parentsInter", "=", "element", ".", "parents", "(", ")", ";", "parentsInter", ".", "retainAll", "(", "elements", ")", ";", "if", "(", "parentsInter", ".", "isEmpty", "(", ")", ")", "{", "// no intersection - element's parents are not in the selected list", "filtered", ".", "add", "(", "element", ")", ";", "}", "}", "return", "filtered", ";", "}" ]
Filters the list of elements to only contain parent elements. This is to avoid both parent and child being in the list of elements. @param elements @return
[ "Filters", "the", "list", "of", "elements", "to", "only", "contain", "parent", "elements", ".", "This", "is", "to", "avoid", "both", "parent", "and", "child", "being", "in", "the", "list", "of", "elements", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L471-L484
5,962
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.setAttr
public String setAttr(String content, String selector, String attributeKey, String value) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { for (Element element : elements) { element.attr(attributeKey, value); } return body.html(); } else { // nothing to update return content; } }
java
public String setAttr(String content, String selector, String attributeKey, String value) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { for (Element element : elements) { element.attr(attributeKey, value); } return body.html(); } else { // nothing to update return content; } }
[ "public", "String", "setAttr", "(", "String", "content", ",", "String", "selector", ",", "String", "attributeKey", ",", "String", "value", ")", "{", "Element", "body", "=", "parseContent", "(", "content", ")", ";", "List", "<", "Element", ">", "elements", "=", "body", ".", "select", "(", "selector", ")", ";", "if", "(", "elements", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "Element", "element", ":", "elements", ")", "{", "element", ".", "attr", "(", "attributeKey", ",", "value", ")", ";", "}", "return", "body", ".", "html", "(", ")", ";", "}", "else", "{", "// nothing to update", "return", "content", ";", "}", "}" ]
Sets attribute to the given value on elements in HTML. @param content HTML content to set attributes on @param selector CSS selector for elements to modify @param attributeKey Attribute name @param value Attribute value @return HTML content with modified elements. If no elements are found, the original content is returned. @since 1.0
[ "Sets", "attribute", "to", "the", "given", "value", "on", "elements", "in", "HTML", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L584-L600
5,963
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.getAttr
public List<String> getAttr(String content, String selector, String attributeKey) { Element body = parseContent(content); List<Element> elements = body.select(selector); List<String> attrs = new ArrayList<String>(); for (Element element : elements) { String attrValue = element.attr(attributeKey); attrs.add(attrValue); } return attrs; }
java
public List<String> getAttr(String content, String selector, String attributeKey) { Element body = parseContent(content); List<Element> elements = body.select(selector); List<String> attrs = new ArrayList<String>(); for (Element element : elements) { String attrValue = element.attr(attributeKey); attrs.add(attrValue); } return attrs; }
[ "public", "List", "<", "String", ">", "getAttr", "(", "String", "content", ",", "String", "selector", ",", "String", "attributeKey", ")", "{", "Element", "body", "=", "parseContent", "(", "content", ")", ";", "List", "<", "Element", ">", "elements", "=", "body", ".", "select", "(", "selector", ")", ";", "List", "<", "String", ">", "attrs", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "for", "(", "Element", "element", ":", "elements", ")", "{", "String", "attrValue", "=", "element", ".", "attr", "(", "attributeKey", ")", ";", "attrs", ".", "add", "(", "attrValue", ")", ";", "}", "return", "attrs", ";", "}" ]
Retrieves attribute value on elements in HTML. Will return all attribute values for the selector, since there can be more than one element. @param content HTML content to read attributes from @param selector CSS selector for elements to find @param attributeKey Attribute name @return Attribute values for all matching elements. If no elements are found, empty list is returned. @since 1.0
[ "Retrieves", "attribute", "value", "on", "elements", "in", "HTML", ".", "Will", "return", "all", "attribute", "values", "for", "the", "selector", "since", "there", "can", "be", "more", "than", "one", "element", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L628-L641
5,964
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.addClass
public String addClass(String content, String selector, String className) { return addClass(content, selector, Collections.singletonList(className)); }
java
public String addClass(String content, String selector, String className) { return addClass(content, selector, Collections.singletonList(className)); }
[ "public", "String", "addClass", "(", "String", "content", ",", "String", "selector", ",", "String", "className", ")", "{", "return", "addClass", "(", "content", ",", "selector", ",", "Collections", ".", "singletonList", "(", "className", ")", ")", ";", "}" ]
Adds given class to the elements in HTML. @param content HTML content to modify @param selector CSS selector for elements to add the class to @param className Name of class to add to the selected elements @return HTML content with modified elements. If no elements are found, the original content is returned. @since 1.0
[ "Adds", "given", "class", "to", "the", "elements", "in", "HTML", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L713-L715
5,965
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.wrap
public String wrap(String content, String selector, String wrapHtml, int amount) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (amount >= 0) { // limit to the indicated amount elements = elements.subList(0, Math.min(amount, elements.size())); } if (elements.size() > 0) { for (Element element : elements) { element.wrap(wrapHtml); } return body.html(); } else { // nothing to update return content; } }
java
public String wrap(String content, String selector, String wrapHtml, int amount) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (amount >= 0) { // limit to the indicated amount elements = elements.subList(0, Math.min(amount, elements.size())); } if (elements.size() > 0) { for (Element element : elements) { element.wrap(wrapHtml); } return body.html(); } else { // nothing to update return content; } }
[ "public", "String", "wrap", "(", "String", "content", ",", "String", "selector", ",", "String", "wrapHtml", ",", "int", "amount", ")", "{", "Element", "body", "=", "parseContent", "(", "content", ")", ";", "List", "<", "Element", ">", "elements", "=", "body", ".", "select", "(", "selector", ")", ";", "if", "(", "amount", ">=", "0", ")", "{", "// limit to the indicated amount", "elements", "=", "elements", ".", "subList", "(", "0", ",", "Math", ".", "min", "(", "amount", ",", "elements", ".", "size", "(", ")", ")", ")", ";", "}", "if", "(", "elements", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "Element", "element", ":", "elements", ")", "{", "element", ".", "wrap", "(", "wrapHtml", ")", ";", "}", "return", "body", ".", "html", "(", ")", ";", "}", "else", "{", "// nothing to update", "return", "content", ";", "}", "}" ]
Wraps elements in HTML with the given HTML. @param content HTML content to modify @param selector CSS selector for elements to wrap @param wrapHtml HTML to use for wrapping the selected elements @param amount Maximum number of elements to modify @return HTML content with modified elements. If no elements are found, the original content is returned. @since 1.0
[ "Wraps", "elements", "in", "HTML", "with", "the", "given", "HTML", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L732-L753
5,966
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.remove
public String remove(String content, String selector) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { for (Element element : elements) { element.remove(); } return body.html(); } else { // nothing changed return content; } }
java
public String remove(String content, String selector) { Element body = parseContent(content); List<Element> elements = body.select(selector); if (elements.size() > 0) { for (Element element : elements) { element.remove(); } return body.html(); } else { // nothing changed return content; } }
[ "public", "String", "remove", "(", "String", "content", ",", "String", "selector", ")", "{", "Element", "body", "=", "parseContent", "(", "content", ")", ";", "List", "<", "Element", ">", "elements", "=", "body", ".", "select", "(", "selector", ")", ";", "if", "(", "elements", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "Element", "element", ":", "elements", ")", "{", "element", ".", "remove", "(", ")", ";", "}", "return", "body", ".", "html", "(", ")", ";", "}", "else", "{", "// nothing changed", "return", "content", ";", "}", "}" ]
Removes elements from HTML. @param content HTML content to modify @param selector CSS selector for elements to remove @return HTML content with removed elements. If no elements are found, the original content is returned. @since 1.0
[ "Removes", "elements", "from", "HTML", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L766-L781
5,967
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.anchorToId
private static void anchorToId(Element heading, Element anchor) { if ("a".equals(anchor.tagName()) && heading.id().isEmpty()) { String aName = anchor.attr("name"); if (!aName.isEmpty()) { // set the anchor name as heading ID heading.attr("id", aName); // remove the anchor anchor.remove(); } } }
java
private static void anchorToId(Element heading, Element anchor) { if ("a".equals(anchor.tagName()) && heading.id().isEmpty()) { String aName = anchor.attr("name"); if (!aName.isEmpty()) { // set the anchor name as heading ID heading.attr("id", aName); // remove the anchor anchor.remove(); } } }
[ "private", "static", "void", "anchorToId", "(", "Element", "heading", ",", "Element", "anchor", ")", "{", "if", "(", "\"a\"", ".", "equals", "(", "anchor", ".", "tagName", "(", ")", ")", "&&", "heading", ".", "id", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "String", "aName", "=", "anchor", ".", "attr", "(", "\"name\"", ")", ";", "if", "(", "!", "aName", ".", "isEmpty", "(", ")", ")", "{", "// set the anchor name as heading ID", "heading", ".", "attr", "(", "\"id\"", ",", "aName", ")", ";", "// remove the anchor", "anchor", ".", "remove", "(", ")", ";", "}", "}", "}" ]
Moves anchor name to heading id, if one does not exist. Removes the anchor. @param heading @param anchor
[ "Moves", "anchor", "name", "to", "heading", "id", "if", "one", "does", "not", "exist", ".", "Removes", "the", "anchor", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L954-L966
5,968
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.concat
public static List<String> concat(List<String> elements, String text, boolean append) { List<String> concats = new ArrayList<String>(); for (String element : elements) { concats.add(append ? element + text : text + element); } return concats; }
java
public static List<String> concat(List<String> elements, String text, boolean append) { List<String> concats = new ArrayList<String>(); for (String element : elements) { concats.add(append ? element + text : text + element); } return concats; }
[ "public", "static", "List", "<", "String", ">", "concat", "(", "List", "<", "String", ">", "elements", ",", "String", "text", ",", "boolean", "append", ")", "{", "List", "<", "String", ">", "concats", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "for", "(", "String", "element", ":", "elements", ")", "{", "concats", ".", "add", "(", "append", "?", "element", "+", "text", ":", "text", "+", "element", ")", ";", "}", "return", "concats", ";", "}" ]
Utility method to concatenate a String to a list of Strings. The text can be either appended or prepended. @param elements list of elements to append/prepend the text to @param text the given text to append/prepend @param append if {@code true}, text will be appended to the elements. If {@code false}, it will be prepended @return list of elements with the text appended/prepended @since 1.0
[ "Utility", "method", "to", "concatenate", "a", "String", "to", "a", "list", "of", "Strings", ".", "The", "text", "can", "be", "either", "appended", "or", "prepended", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L983-L991
5,969
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.generateUniqueId
private static String generateUniqueId(Set<String> ids, String idBase) { String id = idBase; int counter = 1; while (ids.contains(id)) { id = idBase + String.valueOf(counter++); } // put the newly generated one into the set ids.add(id); return id; }
java
private static String generateUniqueId(Set<String> ids, String idBase) { String id = idBase; int counter = 1; while (ids.contains(id)) { id = idBase + String.valueOf(counter++); } // put the newly generated one into the set ids.add(id); return id; }
[ "private", "static", "String", "generateUniqueId", "(", "Set", "<", "String", ">", "ids", ",", "String", "idBase", ")", "{", "String", "id", "=", "idBase", ";", "int", "counter", "=", "1", ";", "while", "(", "ids", ".", "contains", "(", "id", ")", ")", "{", "id", "=", "idBase", "+", "String", ".", "valueOf", "(", "counter", "++", ")", ";", "}", "// put the newly generated one into the set", "ids", ".", "add", "(", "id", ")", ";", "return", "id", ";", "}" ]
Generated a unique ID within the given set of IDs. Appends an incrementing number for duplicates. @param ids @param idBase @return
[ "Generated", "a", "unique", "ID", "within", "the", "given", "set", "of", "IDs", ".", "Appends", "an", "incrementing", "number", "for", "duplicates", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L1065-L1075
5,970
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.adaptSlug
private static String adaptSlug(String input, String separator) { String nowhitespace = WHITESPACE.matcher(input).replaceAll(separator); String normalized = Normalizer.normalize(nowhitespace, Form.NFD); return NONLATIN.matcher(normalized).replaceAll(""); }
java
private static String adaptSlug(String input, String separator) { String nowhitespace = WHITESPACE.matcher(input).replaceAll(separator); String normalized = Normalizer.normalize(nowhitespace, Form.NFD); return NONLATIN.matcher(normalized).replaceAll(""); }
[ "private", "static", "String", "adaptSlug", "(", "String", "input", ",", "String", "separator", ")", "{", "String", "nowhitespace", "=", "WHITESPACE", ".", "matcher", "(", "input", ")", ".", "replaceAll", "(", "separator", ")", ";", "String", "normalized", "=", "Normalizer", ".", "normalize", "(", "nowhitespace", ",", "Form", ".", "NFD", ")", ";", "return", "NONLATIN", ".", "matcher", "(", "normalized", ")", ".", "replaceAll", "(", "\"\"", ")", ";", "}" ]
Creates a slug but does not change capitalization. @param input @param separator @return
[ "Creates", "a", "slug", "but", "does", "not", "change", "capitalization", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L1157-L1161
5,971
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java
HtmlTool.parseBodyFragment
public static Element parseBodyFragment(String content) { Document doc = Jsoup.parseBodyFragment(content); return doc.body(); }
java
public static Element parseBodyFragment(String content) { Document doc = Jsoup.parseBodyFragment(content); return doc.body(); }
[ "public", "static", "Element", "parseBodyFragment", "(", "String", "content", ")", "{", "Document", "doc", "=", "Jsoup", ".", "parseBodyFragment", "(", "content", ")", ";", "return", "doc", ".", "body", "(", ")", ";", "}" ]
A generic method to use jsoup parser on an arbitrary HTML body fragment. Allows writing HTML manipulations in the template without adding Java code to the class. @param content HTML content to parse @return the wrapper element for the parsed content (i.e. the body element as if the content was body contents). @since 1.0
[ "A", "generic", "method", "to", "use", "jsoup", "parser", "on", "an", "arbitrary", "HTML", "body", "fragment", ".", "Allows", "writing", "HTML", "manipulations", "in", "the", "template", "without", "adding", "Java", "code", "to", "the", "class", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/HtmlTool.java#L1308-L1312
5,972
andriusvelykis/reflow-maven-skin
reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/SkinConfigTool.java
SkinConfigTool.getChild
private Xpp3Dom getChild(Xpp3Dom parentNode, String name) { Xpp3Dom child = parentNode.getChild(name); if (child != null) { return child; } return parentNode.getChild(namespace + name); }
java
private Xpp3Dom getChild(Xpp3Dom parentNode, String name) { Xpp3Dom child = parentNode.getChild(name); if (child != null) { return child; } return parentNode.getChild(namespace + name); }
[ "private", "Xpp3Dom", "getChild", "(", "Xpp3Dom", "parentNode", ",", "String", "name", ")", "{", "Xpp3Dom", "child", "=", "parentNode", ".", "getChild", "(", "name", ")", ";", "if", "(", "child", "!=", "null", ")", "{", "return", "child", ";", "}", "return", "parentNode", ".", "getChild", "(", "namespace", "+", "name", ")", ";", "}" ]
Retrieves the child node. Tests both default name and with namespace. @param parentNode @param name @return
[ "Retrieves", "the", "child", "node", ".", "Tests", "both", "default", "name", "and", "with", "namespace", "." ]
01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2
https://github.com/andriusvelykis/reflow-maven-skin/blob/01170ae1426a1adfe7cc9c199e77aaa2ecb37ef2/reflow-velocity-tools/src/main/java/lt/velykis/maven/skins/reflow/SkinConfigTool.java#L220-L227
5,973
terma/java-nio-tcp-proxy
src/com/github/terma/javaniotcpproxy/TcpProxyBuffer.java
TcpProxyBuffer.writeTo
public void writeTo(SocketChannel channel) throws IOException { channel.write(buffer); // only if buffer is empty if (buffer.remaining() == 0) { buffer.clear(); state = BufferState.READY_TO_WRITE; } }
java
public void writeTo(SocketChannel channel) throws IOException { channel.write(buffer); // only if buffer is empty if (buffer.remaining() == 0) { buffer.clear(); state = BufferState.READY_TO_WRITE; } }
[ "public", "void", "writeTo", "(", "SocketChannel", "channel", ")", "throws", "IOException", "{", "channel", ".", "write", "(", "buffer", ")", ";", "// only if buffer is empty\r", "if", "(", "buffer", ".", "remaining", "(", ")", "==", "0", ")", "{", "buffer", ".", "clear", "(", ")", ";", "state", "=", "BufferState", ".", "READY_TO_WRITE", ";", "}", "}" ]
This method try to write data from buffer to channel. Buffer changes state to READY_TO_READ only if all data were wrote to channel, in other case you should call this method again @param channel - channel @throws IOException
[ "This", "method", "try", "to", "write", "data", "from", "buffer", "to", "channel", ".", "Buffer", "changes", "state", "to", "READY_TO_READ", "only", "if", "all", "data", "were", "wrote", "to", "channel", "in", "other", "case", "you", "should", "call", "this", "method", "again" ]
280010510f9af42e69cf6fc428b66da16138f748
https://github.com/terma/java-nio-tcp-proxy/blob/280010510f9af42e69cf6fc428b66da16138f748/src/com/github/terma/javaniotcpproxy/TcpProxyBuffer.java#L63-L71
5,974
terma/java-nio-tcp-proxy
src/com/github/terma/javaniotcpserver/TcpServer.java
TcpServer.start
public void start() { if (workers != null) throw new UnsupportedOperationException("Please shutdown connector!"); if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Starting " + name + " with " + config.getWorkerCount() + " workers"); handlers = new ConcurrentLinkedQueue<TcpServerHandler>(); handlers.add(new TcpServerAcceptor(config, handlers)); workers = new Thread[config.getWorkerCount()]; for (int i = 0; i < workers.length; i++) { workers[i] = new TcpServerWorker(handlers); } for (final Thread worker : workers) worker.start(); if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " started"); }
java
public void start() { if (workers != null) throw new UnsupportedOperationException("Please shutdown connector!"); if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Starting " + name + " with " + config.getWorkerCount() + " workers"); handlers = new ConcurrentLinkedQueue<TcpServerHandler>(); handlers.add(new TcpServerAcceptor(config, handlers)); workers = new Thread[config.getWorkerCount()]; for (int i = 0; i < workers.length; i++) { workers[i] = new TcpServerWorker(handlers); } for (final Thread worker : workers) worker.start(); if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " started"); }
[ "public", "void", "start", "(", ")", "{", "if", "(", "workers", "!=", "null", ")", "throw", "new", "UnsupportedOperationException", "(", "\"Please shutdown connector!\"", ")", ";", "if", "(", "LOGGER", ".", "isLoggable", "(", "Level", ".", "INFO", ")", ")", "LOGGER", ".", "info", "(", "\"Starting \"", "+", "name", "+", "\" with \"", "+", "config", ".", "getWorkerCount", "(", ")", "+", "\" workers\"", ")", ";", "handlers", "=", "new", "ConcurrentLinkedQueue", "<", "TcpServerHandler", ">", "(", ")", ";", "handlers", ".", "add", "(", "new", "TcpServerAcceptor", "(", "config", ",", "handlers", ")", ")", ";", "workers", "=", "new", "Thread", "[", "config", ".", "getWorkerCount", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "workers", ".", "length", ";", "i", "++", ")", "{", "workers", "[", "i", "]", "=", "new", "TcpServerWorker", "(", "handlers", ")", ";", "}", "for", "(", "final", "Thread", "worker", ":", "workers", ")", "worker", ".", "start", "(", ")", ";", "if", "(", "LOGGER", ".", "isLoggable", "(", "Level", ".", "INFO", ")", ")", "LOGGER", ".", "info", "(", "name", "+", "\" started\"", ")", ";", "}" ]
This method starts waiting incoming connections for proxy to remote host. Method return control when all worker will be started, it isn't block. @throws UnsupportedOperationException - if you try to start already started connector
[ "This", "method", "starts", "waiting", "incoming", "connections", "for", "proxy", "to", "remote", "host", ".", "Method", "return", "control", "when", "all", "worker", "will", "be", "started", "it", "isn", "t", "block", "." ]
280010510f9af42e69cf6fc428b66da16138f748
https://github.com/terma/java-nio-tcp-proxy/blob/280010510f9af42e69cf6fc428b66da16138f748/src/com/github/terma/javaniotcpserver/TcpServer.java#L73-L91
5,975
terma/java-nio-tcp-proxy
src/com/github/terma/javaniotcpserver/TcpServer.java
TcpServer.shutdown
public void shutdown() { if (workers == null) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " already been shutdown"); return; } if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Starting shutdown " + name); for (final Thread worker : workers) { worker.interrupt(); try { worker.join(); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } } workers = null; TcpServerHandler handler; while ((handler = handlers.poll()) != null) handler.destroy(); handlers = null; if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " was shutdown"); }
java
public void shutdown() { if (workers == null) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " already been shutdown"); return; } if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Starting shutdown " + name); for (final Thread worker : workers) { worker.interrupt(); try { worker.join(); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } } workers = null; TcpServerHandler handler; while ((handler = handlers.poll()) != null) handler.destroy(); handlers = null; if (LOGGER.isLoggable(Level.INFO)) LOGGER.info(name + " was shutdown"); }
[ "public", "void", "shutdown", "(", ")", "{", "if", "(", "workers", "==", "null", ")", "{", "if", "(", "LOGGER", ".", "isLoggable", "(", "Level", ".", "INFO", ")", ")", "LOGGER", ".", "info", "(", "name", "+", "\" already been shutdown\"", ")", ";", "return", ";", "}", "if", "(", "LOGGER", ".", "isLoggable", "(", "Level", ".", "INFO", ")", ")", "LOGGER", ".", "info", "(", "\"Starting shutdown \"", "+", "name", ")", ";", "for", "(", "final", "Thread", "worker", ":", "workers", ")", "{", "worker", ".", "interrupt", "(", ")", ";", "try", "{", "worker", ".", "join", "(", ")", ";", "}", "catch", "(", "InterruptedException", "exception", ")", "{", "Thread", ".", "currentThread", "(", ")", ".", "interrupt", "(", ")", ";", "}", "}", "workers", "=", "null", ";", "TcpServerHandler", "handler", ";", "while", "(", "(", "handler", "=", "handlers", ".", "poll", "(", ")", ")", "!=", "null", ")", "handler", ".", "destroy", "(", ")", ";", "handlers", "=", "null", ";", "if", "(", "LOGGER", ".", "isLoggable", "(", "Level", ".", "INFO", ")", ")", "LOGGER", ".", "info", "(", "name", "+", "\" was shutdown\"", ")", ";", "}" ]
Shutdown connector. This method wait when all resources will be closed. You can call this method any time. No problem and exceptions if you try to shutdown connector twice without start.
[ "Shutdown", "connector", "." ]
280010510f9af42e69cf6fc428b66da16138f748
https://github.com/terma/java-nio-tcp-proxy/blob/280010510f9af42e69cf6fc428b66da16138f748/src/com/github/terma/javaniotcpserver/TcpServer.java#L100-L126
5,976
DARIAH-DE/shib-http-client
src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java
ShibHttpClient.isSamlSoapResponse
protected boolean isSamlSoapResponse(HttpResponse res) { boolean isSamlSoap = false; if (res.getFirstHeader(HttpHeaders.CONTENT_TYPE) != null) { ContentType contentType = ContentType.parse(res.getFirstHeader(HttpHeaders.CONTENT_TYPE) .getValue()); isSamlSoap = MIME_TYPE_PAOS.equals(contentType.getMimeType()); } return isSamlSoap; }
java
protected boolean isSamlSoapResponse(HttpResponse res) { boolean isSamlSoap = false; if (res.getFirstHeader(HttpHeaders.CONTENT_TYPE) != null) { ContentType contentType = ContentType.parse(res.getFirstHeader(HttpHeaders.CONTENT_TYPE) .getValue()); isSamlSoap = MIME_TYPE_PAOS.equals(contentType.getMimeType()); } return isSamlSoap; }
[ "protected", "boolean", "isSamlSoapResponse", "(", "HttpResponse", "res", ")", "{", "boolean", "isSamlSoap", "=", "false", ";", "if", "(", "res", ".", "getFirstHeader", "(", "HttpHeaders", ".", "CONTENT_TYPE", ")", "!=", "null", ")", "{", "ContentType", "contentType", "=", "ContentType", ".", "parse", "(", "res", ".", "getFirstHeader", "(", "HttpHeaders", ".", "CONTENT_TYPE", ")", ".", "getValue", "(", ")", ")", ";", "isSamlSoap", "=", "MIME_TYPE_PAOS", ".", "equals", "(", "contentType", ".", "getMimeType", "(", ")", ")", ";", "}", "return", "isSamlSoap", ";", "}" ]
Checks whether the HttpResponse is a SAML SOAP message @param res the HttpResponse to check @return true if the HttpResponse is a SAML SOAP message, false if not
[ "Checks", "whether", "the", "HttpResponse", "is", "a", "SAML", "SOAP", "message" ]
32b7ec769751c42283f4a2f96b58bd152d931137
https://github.com/DARIAH-DE/shib-http-client/blob/32b7ec769751c42283f4a2f96b58bd152d931137/src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java#L363-L372
5,977
DARIAH-DE/shib-http-client
src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java
ShibHttpClient.captureRelayState
protected org.opensaml.saml2.ecp.RelayState captureRelayState(org.opensaml.ws.soap.soap11.Envelope soapEnvelope) { RelayState relayState = null; if (!soapEnvelope.getHeader() .getUnknownXMLObjects(RelayState.DEFAULT_ELEMENT_NAME).isEmpty()) { relayState = (RelayState) soapEnvelope.getHeader() .getUnknownXMLObjects(RelayState.DEFAULT_ELEMENT_NAME).get(0); relayState.detach(); log.trace("Relay state: captured"); } return relayState; }
java
protected org.opensaml.saml2.ecp.RelayState captureRelayState(org.opensaml.ws.soap.soap11.Envelope soapEnvelope) { RelayState relayState = null; if (!soapEnvelope.getHeader() .getUnknownXMLObjects(RelayState.DEFAULT_ELEMENT_NAME).isEmpty()) { relayState = (RelayState) soapEnvelope.getHeader() .getUnknownXMLObjects(RelayState.DEFAULT_ELEMENT_NAME).get(0); relayState.detach(); log.trace("Relay state: captured"); } return relayState; }
[ "protected", "org", ".", "opensaml", ".", "saml2", ".", "ecp", ".", "RelayState", "captureRelayState", "(", "org", ".", "opensaml", ".", "ws", ".", "soap", ".", "soap11", ".", "Envelope", "soapEnvelope", ")", "{", "RelayState", "relayState", "=", "null", ";", "if", "(", "!", "soapEnvelope", ".", "getHeader", "(", ")", ".", "getUnknownXMLObjects", "(", "RelayState", ".", "DEFAULT_ELEMENT_NAME", ")", ".", "isEmpty", "(", ")", ")", "{", "relayState", "=", "(", "RelayState", ")", "soapEnvelope", ".", "getHeader", "(", ")", ".", "getUnknownXMLObjects", "(", "RelayState", ".", "DEFAULT_ELEMENT_NAME", ")", ".", "get", "(", "0", ")", ";", "relayState", ".", "detach", "(", ")", ";", "log", ".", "trace", "(", "\"Relay state: captured\"", ")", ";", "}", "return", "relayState", ";", "}" ]
Captures the ECP relay state in a SAML SOAP message @param soapEnvelope the SOAP message to check for the ECP relay state @return relayState the ECP relay state in the SOAP message
[ "Captures", "the", "ECP", "relay", "state", "in", "a", "SAML", "SOAP", "message" ]
32b7ec769751c42283f4a2f96b58bd152d931137
https://github.com/DARIAH-DE/shib-http-client/blob/32b7ec769751c42283f4a2f96b58bd152d931137/src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java#L379-L390
5,978
DARIAH-DE/shib-http-client
src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java
ShibHttpClient.getSoapMessage
protected org.opensaml.ws.soap.soap11.Envelope getSoapMessage(HttpEntity entity) throws ClientProtocolException, IllegalStateException, IOException { Envelope soapEnvelope = (Envelope) unmarshallMessage(parserPool, entity.getContent()); EntityUtils.consumeQuietly(entity); return soapEnvelope; }
java
protected org.opensaml.ws.soap.soap11.Envelope getSoapMessage(HttpEntity entity) throws ClientProtocolException, IllegalStateException, IOException { Envelope soapEnvelope = (Envelope) unmarshallMessage(parserPool, entity.getContent()); EntityUtils.consumeQuietly(entity); return soapEnvelope; }
[ "protected", "org", ".", "opensaml", ".", "ws", ".", "soap", ".", "soap11", ".", "Envelope", "getSoapMessage", "(", "HttpEntity", "entity", ")", "throws", "ClientProtocolException", ",", "IllegalStateException", ",", "IOException", "{", "Envelope", "soapEnvelope", "=", "(", "Envelope", ")", "unmarshallMessage", "(", "parserPool", ",", "entity", ".", "getContent", "(", ")", ")", ";", "EntityUtils", ".", "consumeQuietly", "(", "entity", ")", ";", "return", "soapEnvelope", ";", "}" ]
Extracts the SOAP message from the HttpResponse @param entity the HttpEntity to retrieve the SOAP message from @return soapEnvelope the SOAP message @throws IOException @throws IllegalStateException @throws ClientProtocolException
[ "Extracts", "the", "SOAP", "message", "from", "the", "HttpResponse" ]
32b7ec769751c42283f4a2f96b58bd152d931137
https://github.com/DARIAH-DE/shib-http-client/blob/32b7ec769751c42283f4a2f96b58bd152d931137/src/main/java/de/tudarmstadt/ukp/shibhttpclient/ShibHttpClient.java#L400-L407
5,979
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/requestor/RequestBuilder.java
RequestBuilder.set
public RequestBuilder<Resource> set(final String name, final File file) { return set(name, file != null ? new FileBody(file) : null); }
java
public RequestBuilder<Resource> set(final String name, final File file) { return set(name, file != null ? new FileBody(file) : null); }
[ "public", "RequestBuilder", "<", "Resource", ">", "set", "(", "final", "String", "name", ",", "final", "File", "file", ")", "{", "return", "set", "(", "name", ",", "file", "!=", "null", "?", "new", "FileBody", "(", "file", ")", ":", "null", ")", ";", "}" ]
Adds a file to the request also making the request to become a multi-part post request or removes any file registered under the given name if the file value is null.
[ "Adds", "a", "file", "to", "the", "request", "also", "making", "the", "request", "to", "become", "a", "multi", "-", "part", "post", "request", "or", "removes", "any", "file", "registered", "under", "the", "given", "name", "if", "the", "file", "value", "is", "null", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/requestor/RequestBuilder.java#L127-L129
5,980
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/requestor/RequestBuilder.java
RequestBuilder.set
public RequestBuilder<Resource> set(final String name, final ContentBody contentBody) { if(contentBody != null) files.put(name, contentBody); else files.remove(name); return this; }
java
public RequestBuilder<Resource> set(final String name, final ContentBody contentBody) { if(contentBody != null) files.put(name, contentBody); else files.remove(name); return this; }
[ "public", "RequestBuilder", "<", "Resource", ">", "set", "(", "final", "String", "name", ",", "final", "ContentBody", "contentBody", ")", "{", "if", "(", "contentBody", "!=", "null", ")", "files", ".", "put", "(", "name", ",", "contentBody", ")", ";", "else", "files", ".", "remove", "(", "name", ")", ";", "return", "this", ";", "}" ]
Adds an ContentBody object.
[ "Adds", "an", "ContentBody", "object", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/requestor/RequestBuilder.java#L132-L138
5,981
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/parameters/Parameters.java
Parameters.get
public String [] get(final String name) { if(has(name)) { List<String> values = parameters.get(name).getValues(); Collections.sort(values); return values.toArray(new String [values.size()]); } else return null; }
java
public String [] get(final String name) { if(has(name)) { List<String> values = parameters.get(name).getValues(); Collections.sort(values); return values.toArray(new String [values.size()]); } else return null; }
[ "public", "String", "[", "]", "get", "(", "final", "String", "name", ")", "{", "if", "(", "has", "(", "name", ")", ")", "{", "List", "<", "String", ">", "values", "=", "parameters", ".", "get", "(", "name", ")", ".", "getValues", "(", ")", ";", "Collections", ".", "sort", "(", "values", ")", ";", "return", "values", ".", "toArray", "(", "new", "String", "[", "values", ".", "size", "(", ")", "]", ")", ";", "}", "else", "return", "null", ";", "}" ]
Returns the current values of the parameters in natural sort order or null if none.
[ "Returns", "the", "current", "values", "of", "the", "parameters", "in", "natural", "sort", "order", "or", "null", "if", "none", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/parameters/Parameters.java#L51-L59
5,982
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/parameters/Parameters.java
Parameters.getNames
public String [] getNames() { String [] result = new String[parameters.size()]; parameters.keySet().toArray(result); return result; }
java
public String [] getNames() { String [] result = new String[parameters.size()]; parameters.keySet().toArray(result); return result; }
[ "public", "String", "[", "]", "getNames", "(", ")", "{", "String", "[", "]", "result", "=", "new", "String", "[", "parameters", ".", "size", "(", ")", "]", ";", "parameters", ".", "keySet", "(", ")", ".", "toArray", "(", "result", ")", ";", "return", "result", ";", "}" ]
Returns the parameter names in the order they where added.
[ "Returns", "the", "parameter", "names", "in", "the", "order", "they", "where", "added", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/parameters/Parameters.java#L62-L66
5,983
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/headers/Headers.java
Headers.get
public String [] get(final String name) { if(has(name)) { List<String> values = headers.get(name).getValues(); return values.toArray(new String [values.size()]); } else return null; }
java
public String [] get(final String name) { if(has(name)) { List<String> values = headers.get(name).getValues(); return values.toArray(new String [values.size()]); } else return null; }
[ "public", "String", "[", "]", "get", "(", "final", "String", "name", ")", "{", "if", "(", "has", "(", "name", ")", ")", "{", "List", "<", "String", ">", "values", "=", "headers", ".", "get", "(", "name", ")", ".", "getValues", "(", ")", ";", "return", "values", ".", "toArray", "(", "new", "String", "[", "values", ".", "size", "(", ")", "]", ")", ";", "}", "else", "return", "null", ";", "}" ]
Returns the current values of the headers in natural sort order or null if none.
[ "Returns", "the", "current", "values", "of", "the", "headers", "in", "natural", "sort", "order", "or", "null", "if", "none", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/headers/Headers.java#L44-L51
5,984
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/headers/Headers.java
Headers.getNames
public String [] getNames() { String [] result = new String[headers.size()]; headers.keySet().toArray(result); return result; }
java
public String [] getNames() { String [] result = new String[headers.size()]; headers.keySet().toArray(result); return result; }
[ "public", "String", "[", "]", "getNames", "(", ")", "{", "String", "[", "]", "result", "=", "new", "String", "[", "headers", ".", "size", "(", ")", "]", ";", "headers", ".", "keySet", "(", ")", ".", "toArray", "(", "result", ")", ";", "return", "result", ";", "}" ]
Returns the header names in the order they where added.
[ "Returns", "the", "header", "names", "in", "the", "order", "they", "where", "added", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/headers/Headers.java#L54-L58
5,985
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/Util.java
Util.newFile
public static File newFile(String fileName) { File file = new File(fileName); if(file.exists()) file.delete(); return file; }
java
public static File newFile(String fileName) { File file = new File(fileName); if(file.exists()) file.delete(); return file; }
[ "public", "static", "File", "newFile", "(", "String", "fileName", ")", "{", "File", "file", "=", "new", "File", "(", "fileName", ")", ";", "if", "(", "file", ".", "exists", "(", ")", ")", "file", ".", "delete", "(", ")", ";", "return", "file", ";", "}" ]
Returns a new File object from the given fileName and deleting the file if already exists.
[ "Returns", "a", "new", "File", "object", "from", "the", "given", "fileName", "and", "deleting", "the", "file", "if", "already", "exists", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/Util.java#L40-L45
5,986
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/impl/MechanizeAgent.java
MechanizeAgent.setupClient
private void setupClient(final AbstractHttpClient client) { this.client.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { Header header = response.getFirstHeader("Location"); if (header!=null) context.setAttribute("Location", header.getValue()); } }); }
java
private void setupClient(final AbstractHttpClient client) { this.client.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { Header header = response.getFirstHeader("Location"); if (header!=null) context.setAttribute("Location", header.getValue()); } }); }
[ "private", "void", "setupClient", "(", "final", "AbstractHttpClient", "client", ")", "{", "this", ".", "client", ".", "addResponseInterceptor", "(", "new", "HttpResponseInterceptor", "(", ")", "{", "@", "Override", "public", "void", "process", "(", "final", "HttpResponse", "response", ",", "final", "HttpContext", "context", ")", "throws", "HttpException", ",", "IOException", "{", "Header", "header", "=", "response", ".", "getFirstHeader", "(", "\"Location\"", ")", ";", "if", "(", "header", "!=", "null", ")", "context", ".", "setAttribute", "(", "\"Location\"", ",", "header", ".", "getValue", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
This method is used to capture Location headers after HttpClient redirect handling.
[ "This", "method", "is", "used", "to", "capture", "Location", "headers", "after", "HttpClient", "redirect", "handling", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/impl/MechanizeAgent.java#L109-L119
5,987
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/impl/MechanizeAgent.java
MechanizeAgent.request
@SuppressWarnings("unchecked") @Override public <T extends Resource> T request(final HttpRequestBase request) { try { HttpResponse response = execute(client, request); Resource resource = toPage(request, response); return (T)resource; } catch (Exception e) { throw MechanizeExceptionFactory.newException(e); } }
java
@SuppressWarnings("unchecked") @Override public <T extends Resource> T request(final HttpRequestBase request) { try { HttpResponse response = execute(client, request); Resource resource = toPage(request, response); return (T)resource; } catch (Exception e) { throw MechanizeExceptionFactory.newException(e); } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "@", "Override", "public", "<", "T", "extends", "Resource", ">", "T", "request", "(", "final", "HttpRequestBase", "request", ")", "{", "try", "{", "HttpResponse", "response", "=", "execute", "(", "client", ",", "request", ")", ";", "Resource", "resource", "=", "toPage", "(", "request", ",", "response", ")", ";", "return", "(", "T", ")", "resource", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "MechanizeExceptionFactory", ".", "newException", "(", "e", ")", ";", "}", "}" ]
Returns the resource received uppon the request. The resource can be casted to any expected subclass of resource but will fail with ClassCastException if the expected type of resource is not the actual returned resource.
[ "Returns", "the", "resource", "received", "uppon", "the", "request", ".", "The", "resource", "can", "be", "casted", "to", "any", "expected", "subclass", "of", "resource", "but", "will", "fail", "with", "ClassCastException", "if", "the", "expected", "type", "of", "resource", "is", "not", "the", "actual", "returned", "resource", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/impl/MechanizeAgent.java#L178-L188
5,988
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/css_query/TagChecker.java
TagChecker.addGeneralSiblingElements
private void addGeneralSiblingElements() { for (Node node : nodes) { Node n = helper.getNextSibling(node); while (n != null) { String tag = selector.getTagName(); if (helper.nameMatches(n, tag)) result.add(n); n = helper.getNextSibling(n); } } }
java
private void addGeneralSiblingElements() { for (Node node : nodes) { Node n = helper.getNextSibling(node); while (n != null) { String tag = selector.getTagName(); if (helper.nameMatches(n, tag)) result.add(n); n = helper.getNextSibling(n); } } }
[ "private", "void", "addGeneralSiblingElements", "(", ")", "{", "for", "(", "Node", "node", ":", "nodes", ")", "{", "Node", "n", "=", "helper", ".", "getNextSibling", "(", "node", ")", ";", "while", "(", "n", "!=", "null", ")", "{", "String", "tag", "=", "selector", ".", "getTagName", "(", ")", ";", "if", "(", "helper", ".", "nameMatches", "(", "n", ",", "tag", ")", ")", "result", ".", "add", "(", "n", ")", ";", "n", "=", "helper", ".", "getNextSibling", "(", "n", ")", ";", "}", "}", "}" ]
Add general sibling elements. @see <a href="http://www.w3.org/TR/css3-selectors/#general-sibling-combinators">General sibling combinator</a>
[ "Add", "general", "sibling", "elements", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/css_query/TagChecker.java#L144-L155
5,989
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/document/link/Link.java
Link.click
@SuppressWarnings("unchecked") public <T extends Resource> T click() { return (T) (hasAttribute("href") ? doRequest(href()).get() : null); }
java
@SuppressWarnings("unchecked") public <T extends Resource> T click() { return (T) (hasAttribute("href") ? doRequest(href()).get() : null); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "<", "T", "extends", "Resource", ">", "T", "click", "(", ")", "{", "return", "(", "T", ")", "(", "hasAttribute", "(", "\"href\"", ")", "?", "doRequest", "(", "href", "(", ")", ")", ".", "get", "(", ")", ":", "null", ")", ";", "}" ]
Follows the link by using the original agent.
[ "Follows", "the", "link", "by", "using", "the", "original", "agent", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/document/link/Link.java#L27-L30
5,990
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/cookie/Cookies.java
Cookies.get
public Cookie get(String name, String domain) { for(Cookie cookie : this) { if(cookie.getName().equals(name) && cookie.getDomain().equals(domain)) return cookie; } return null; }
java
public Cookie get(String name, String domain) { for(Cookie cookie : this) { if(cookie.getName().equals(name) && cookie.getDomain().equals(domain)) return cookie; } return null; }
[ "public", "Cookie", "get", "(", "String", "name", ",", "String", "domain", ")", "{", "for", "(", "Cookie", "cookie", ":", "this", ")", "{", "if", "(", "cookie", ".", "getName", "(", ")", ".", "equals", "(", "name", ")", "&&", "cookie", ".", "getDomain", "(", ")", ".", "equals", "(", "domain", ")", ")", "return", "cookie", ";", "}", "return", "null", ";", "}" ]
Returns the cookie with the given name and for the given domain or null.
[ "Returns", "the", "cookie", "with", "the", "given", "name", "and", "for", "the", "given", "domain", "or", "null", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/cookie/Cookies.java#L47-L53
5,991
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/cookie/Cookies.java
Cookies.getAll
public List<Cookie> getAll() { List<Cookie> cookies = new ArrayList<Cookie>(); for(org.apache.http.cookie.Cookie cookie : getStore().getCookies()) cookies.add(getCookie(cookie)); return cookies; }
java
public List<Cookie> getAll() { List<Cookie> cookies = new ArrayList<Cookie>(); for(org.apache.http.cookie.Cookie cookie : getStore().getCookies()) cookies.add(getCookie(cookie)); return cookies; }
[ "public", "List", "<", "Cookie", ">", "getAll", "(", ")", "{", "List", "<", "Cookie", ">", "cookies", "=", "new", "ArrayList", "<", "Cookie", ">", "(", ")", ";", "for", "(", "org", ".", "apache", ".", "http", ".", "cookie", ".", "Cookie", "cookie", ":", "getStore", "(", ")", ".", "getCookies", "(", ")", ")", "cookies", ".", "(", "getCookie", "(", "cookie", ")", ")", ";", "return", "cookies", ";", "}" ]
Returns a list of all cookies currently managed by the underlying http client.
[ "Returns", "a", "list", "of", "all", "cookies", "currently", "managed", "by", "the", "underlying", "http", "client", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/cookie/Cookies.java#L56-L61
5,992
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/cookie/Cookies.java
Cookies.addAllCloned
public void addAllCloned(List<Cookie> cookies) { for(Cookie cookie : cookies) { Cookie clone = new Cookie(cookie); getStore().addCookie(clone.getHttpCookie()); } }
java
public void addAllCloned(List<Cookie> cookies) { for(Cookie cookie : cookies) { Cookie clone = new Cookie(cookie); getStore().addCookie(clone.getHttpCookie()); } }
[ "public", "void", "addAllCloned", "(", "List", "<", "Cookie", ">", "cookies", ")", "{", "for", "(", "Cookie", "cookie", ":", "cookies", ")", "{", "Cookie", "clone", "=", "new", "Cookie", "(", "cookie", ")", ";", "getStore", "(", ")", ".", "addCookie", "(", "clone", ".", "getHttpCookie", "(", ")", ")", ";", "}", "}" ]
Adds all cookies by actually cloning them.
[ "Adds", "all", "cookies", "by", "actually", "cloning", "them", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/cookie/Cookies.java#L77-L82
5,993
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/cookie/Cookies.java
Cookies.remove
public void remove(Cookie cookie) { cookie.getHttpCookie().setExpiryDate(new Date(0)); cookieRepresentationCache.remove(cookie.getHttpCookie()); getStore().clearExpired(new Date(1)); }
java
public void remove(Cookie cookie) { cookie.getHttpCookie().setExpiryDate(new Date(0)); cookieRepresentationCache.remove(cookie.getHttpCookie()); getStore().clearExpired(new Date(1)); }
[ "public", "void", "remove", "(", "Cookie", "cookie", ")", "{", "cookie", ".", "getHttpCookie", "(", ")", ".", "setExpiryDate", "(", "new", "Date", "(", "0", ")", ")", ";", "cookieRepresentationCache", ".", "remove", "(", "cookie", ".", "getHttpCookie", "(", ")", ")", ";", "getStore", "(", ")", ".", "clearExpired", "(", "new", "Date", "(", "1", ")", ")", ";", "}" ]
Removes the current cookie by changing the expired date and force the store to remove all expired for a given date. The date will be set to a time of 1970.
[ "Removes", "the", "current", "cookie", "by", "changing", "the", "expired", "date", "and", "force", "the", "store", "to", "remove", "all", "expired", "for", "a", "given", "date", ".", "The", "date", "will", "be", "set", "to", "a", "time", "of", "1970", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/cookie/Cookies.java#L90-L94
5,994
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/document/html/HtmlDocument.java
HtmlDocument.getTitle
@Override public String getTitle() { HtmlElement title = htmlElements().find("title"); return title != null ? title.getText() : null; }
java
@Override public String getTitle() { HtmlElement title = htmlElements().find("title"); return title != null ? title.getText() : null; }
[ "@", "Override", "public", "String", "getTitle", "(", ")", "{", "HtmlElement", "title", "=", "htmlElements", "(", ")", ".", "find", "(", "\"title\"", ")", ";", "return", "title", "!=", "null", "?", "title", ".", "getText", "(", ")", ":", "null", ";", "}" ]
Returns the title of the page or null.
[ "Returns", "the", "title", "of", "the", "page", "or", "null", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/document/html/HtmlDocument.java#L111-L115
5,995
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/document/html/JsoupDataUtil.java
JsoupDataUtil.getCharsetFromContentType
public static String getCharsetFromContentType(Header header) { if (header == null || header.getValue()==null || "".equals(header.getValue())) return null; Matcher m = charsetPattern.matcher(header.getValue()); if (m.find()) { return m.group(1).trim().toUpperCase(); } return null; }
java
public static String getCharsetFromContentType(Header header) { if (header == null || header.getValue()==null || "".equals(header.getValue())) return null; Matcher m = charsetPattern.matcher(header.getValue()); if (m.find()) { return m.group(1).trim().toUpperCase(); } return null; }
[ "public", "static", "String", "getCharsetFromContentType", "(", "Header", "header", ")", "{", "if", "(", "header", "==", "null", "||", "header", ".", "getValue", "(", ")", "==", "null", "||", "\"\"", ".", "equals", "(", "header", ".", "getValue", "(", ")", ")", ")", "return", "null", ";", "Matcher", "m", "=", "charsetPattern", ".", "matcher", "(", "header", ".", "getValue", "(", ")", ")", ";", "if", "(", "m", ".", "find", "(", ")", ")", "{", "return", "m", ".", "group", "(", "1", ")", ".", "trim", "(", ")", ".", "toUpperCase", "(", ")", ";", "}", "return", "null", ";", "}" ]
Parse out a charset from a content type header. @param header e.g. "text/html; charset=EUC-JP" @return "EUC-JP", or null if not found. Charset is trimmed and uppercased.
[ "Parse", "out", "a", "charset", "from", "a", "content", "type", "header", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/document/html/JsoupDataUtil.java#L34-L41
5,996
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java
URIBuilder.setUserInfo
public URIBuilder setUserInfo(final String userInfo) { this.userInfo = userInfo; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; this.encodedUserInfo = null; return this; }
java
public URIBuilder setUserInfo(final String userInfo) { this.userInfo = userInfo; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; this.encodedUserInfo = null; return this; }
[ "public", "URIBuilder", "setUserInfo", "(", "final", "String", "userInfo", ")", "{", "this", ".", "userInfo", "=", "userInfo", ";", "this", ".", "encodedSchemeSpecificPart", "=", "null", ";", "this", ".", "encodedAuthority", "=", "null", ";", "this", ".", "encodedUserInfo", "=", "null", ";", "return", "this", ";", "}" ]
Sets URI user info. The value is expected to be unescaped and may contain non ASCII characters.
[ "Sets", "URI", "user", "info", ".", "The", "value", "is", "expected", "to", "be", "unescaped", "and", "may", "contain", "non", "ASCII", "characters", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java#L186-L192
5,997
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java
URIBuilder.setHost
public URIBuilder setHost(final String host) { this.host = host; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; return this; }
java
public URIBuilder setHost(final String host) { this.host = host; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; return this; }
[ "public", "URIBuilder", "setHost", "(", "final", "String", "host", ")", "{", "this", ".", "host", "=", "host", ";", "this", ".", "encodedSchemeSpecificPart", "=", "null", ";", "this", ".", "encodedAuthority", "=", "null", ";", "return", "this", ";", "}" ]
Sets URI host.
[ "Sets", "URI", "host", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java#L205-L210
5,998
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java
URIBuilder.setPort
public URIBuilder setPort(final int port) { this.port = port < 0 ? -1 : port; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; return this; }
java
public URIBuilder setPort(final int port) { this.port = port < 0 ? -1 : port; this.encodedSchemeSpecificPart = null; this.encodedAuthority = null; return this; }
[ "public", "URIBuilder", "setPort", "(", "final", "int", "port", ")", "{", "this", ".", "port", "=", "port", "<", "0", "?", "-", "1", ":", "port", ";", "this", ".", "encodedSchemeSpecificPart", "=", "null", ";", "this", ".", "encodedAuthority", "=", "null", ";", "return", "this", ";", "}" ]
Sets URI port.
[ "Sets", "URI", "port", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java#L215-L220
5,999
GistLabs/mechanize
src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java
URIBuilder.setPath
public URIBuilder setPath(final String path) { this.path = path; this.encodedSchemeSpecificPart = null; this.encodedPath = null; return this; }
java
public URIBuilder setPath(final String path) { this.path = path; this.encodedSchemeSpecificPart = null; this.encodedPath = null; return this; }
[ "public", "URIBuilder", "setPath", "(", "final", "String", "path", ")", "{", "this", ".", "path", "=", "path", ";", "this", ".", "encodedSchemeSpecificPart", "=", "null", ";", "this", ".", "encodedPath", "=", "null", ";", "return", "this", ";", "}" ]
Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.
[ "Sets", "URI", "path", ".", "The", "value", "is", "expected", "to", "be", "unescaped", "and", "may", "contain", "non", "ASCII", "characters", "." ]
32ddd0774439a4c08513c05d7ac7416a3899efed
https://github.com/GistLabs/mechanize/blob/32ddd0774439a4c08513c05d7ac7416a3899efed/src/main/java/com/gistlabs/mechanize/util/apache/URIBuilder.java#L225-L230