repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
structurizr/java
structurizr-core/src/com/structurizr/view/ViewSet.java
ViewSet.createFilteredView
public FilteredView createFilteredView(StaticView view, String key, String description, FilterMode mode, String... tags) { assertThatTheViewIsNotNull(view); assertThatTheViewKeyIsSpecifiedAndUnique(key); FilteredView filteredView = new FilteredView(view, key, description, mode, tags); filteredViews.add(filteredView); return filteredView; }
java
public FilteredView createFilteredView(StaticView view, String key, String description, FilterMode mode, String... tags) { assertThatTheViewIsNotNull(view); assertThatTheViewKeyIsSpecifiedAndUnique(key); FilteredView filteredView = new FilteredView(view, key, description, mode, tags); filteredViews.add(filteredView); return filteredView; }
[ "public", "FilteredView", "createFilteredView", "(", "StaticView", "view", ",", "String", "key", ",", "String", "description", ",", "FilterMode", "mode", ",", "String", "...", "tags", ")", "{", "assertThatTheViewIsNotNull", "(", "view", ")", ";", "assertThatTheVie...
Creates a FilteredView on top of an existing static view. @param view the static view to base the FilteredView upon @param key the key for the filtered view (must be unique) @param description a description @param mode whether to Include or Exclude elements/relationships based upon their tag @param tags the tags to include or exclude @return a FilteredView object
[ "Creates", "a", "FilteredView", "on", "top", "of", "an", "existing", "static", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/ViewSet.java#L235-L242
train
structurizr/java
structurizr-core/src/com/structurizr/view/ViewSet.java
ViewSet.getViewWithKey
View getViewWithKey(String key) { if (key == null) { throw new IllegalArgumentException("A key must be specified."); } Set<View> views = new HashSet<>(); views.addAll(systemLandscapeViews); views.addAll(systemContextViews); views.addAll(containerViews); views.addAll(componentViews); views.addAll(dynamicViews); views.addAll(deploymentViews); return views.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null); }
java
View getViewWithKey(String key) { if (key == null) { throw new IllegalArgumentException("A key must be specified."); } Set<View> views = new HashSet<>(); views.addAll(systemLandscapeViews); views.addAll(systemContextViews); views.addAll(containerViews); views.addAll(componentViews); views.addAll(dynamicViews); views.addAll(deploymentViews); return views.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null); }
[ "View", "getViewWithKey", "(", "String", "key", ")", "{", "if", "(", "key", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A key must be specified.\"", ")", ";", "}", "Set", "<", "View", ">", "views", "=", "new", "HashSet", "<>...
Finds the view with the specified key, or null if the view does not exist. @param key the key @return a View object, or null if a view with the specified key could not be found
[ "Finds", "the", "view", "with", "the", "specified", "key", "or", "null", "if", "the", "view", "does", "not", "exist", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/ViewSet.java#L278-L292
train
structurizr/java
structurizr-core/src/com/structurizr/view/ViewSet.java
ViewSet.getFilteredViewWithKey
FilteredView getFilteredViewWithKey(String key) { if (key == null) { throw new IllegalArgumentException("A key must be specified."); } return filteredViews.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null); }
java
FilteredView getFilteredViewWithKey(String key) { if (key == null) { throw new IllegalArgumentException("A key must be specified."); } return filteredViews.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null); }
[ "FilteredView", "getFilteredViewWithKey", "(", "String", "key", ")", "{", "if", "(", "key", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A key must be specified.\"", ")", ";", "}", "return", "filteredViews", ".", "stream", "(", ")"...
Finds the filtered view with the specified key, or null if the view does not exist. @param key the key @return a FilteredView object, or null if a view with the specified key could not be found
[ "Finds", "the", "filtered", "view", "with", "the", "specified", "key", "or", "null", "if", "the", "view", "does", "not", "exist", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/ViewSet.java#L300-L306
train
structurizr/java
structurizr-core/src/com/structurizr/model/ModelItem.java
ModelItem.getTags
public String getTags() { Set<String> setOfTags = getTagsAsSet(); if (setOfTags.isEmpty()) { return ""; } StringBuilder buf = new StringBuilder(); for (String tag : setOfTags) { buf.append(tag); buf.append(","); } String tagsAsString = buf.toString(); return tagsAsString.substring(0, tagsAsString.length()-1); }
java
public String getTags() { Set<String> setOfTags = getTagsAsSet(); if (setOfTags.isEmpty()) { return ""; } StringBuilder buf = new StringBuilder(); for (String tag : setOfTags) { buf.append(tag); buf.append(","); } String tagsAsString = buf.toString(); return tagsAsString.substring(0, tagsAsString.length()-1); }
[ "public", "String", "getTags", "(", ")", "{", "Set", "<", "String", ">", "setOfTags", "=", "getTagsAsSet", "(", ")", ";", "if", "(", "setOfTags", ".", "isEmpty", "(", ")", ")", "{", "return", "\"\"", ";", "}", "StringBuilder", "buf", "=", "new", "Str...
Gets the comma separated list of tags. @return a comma separated list of tags, or an empty string if there are no tags
[ "Gets", "the", "comma", "separated", "list", "of", "tags", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/ModelItem.java#L39-L54
train
structurizr/java
structurizr-core/src/com/structurizr/model/ModelItem.java
ModelItem.addProperty
public void addProperty(String name, String value) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("A property name must be specified."); } if (value == null || value.trim().length() == 0) { throw new IllegalArgumentException("A property value must be specified."); } properties.put(name, value); }
java
public void addProperty(String name, String value) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("A property name must be specified."); } if (value == null || value.trim().length() == 0) { throw new IllegalArgumentException("A property value must be specified."); } properties.put(name, value); }
[ "public", "void", "addProperty", "(", "String", "name", ",", "String", "value", ")", "{", "if", "(", "name", "==", "null", "||", "name", ".", "trim", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", ...
Adds a name-value pair property to this element. @param name the name of the property @param value the value of the property
[ "Adds", "a", "name", "-", "value", "pair", "property", "to", "this", "element", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/ModelItem.java#L111-L121
train
structurizr/java
structurizr-core/src/com/structurizr/model/ModelItem.java
ModelItem.addPerspective
public Perspective addPerspective(String name, String description) { if (StringUtils.isNullOrEmpty(name)) { throw new IllegalArgumentException("A name must be specified."); } if (StringUtils.isNullOrEmpty(description)) { throw new IllegalArgumentException("A description must be specified."); } if (perspectives.stream().filter(p -> p.getName().equals(name)).count() > 0) { throw new IllegalArgumentException("A perspective named \"" + name + "\" already exists."); } Perspective perspective = new Perspective(name, description); perspectives.add(perspective); return perspective; }
java
public Perspective addPerspective(String name, String description) { if (StringUtils.isNullOrEmpty(name)) { throw new IllegalArgumentException("A name must be specified."); } if (StringUtils.isNullOrEmpty(description)) { throw new IllegalArgumentException("A description must be specified."); } if (perspectives.stream().filter(p -> p.getName().equals(name)).count() > 0) { throw new IllegalArgumentException("A perspective named \"" + name + "\" already exists."); } Perspective perspective = new Perspective(name, description); perspectives.add(perspective); return perspective; }
[ "public", "Perspective", "addPerspective", "(", "String", "name", ",", "String", "description", ")", "{", "if", "(", "StringUtils", ".", "isNullOrEmpty", "(", "name", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A name must be specified.\"", ...
Adds a perspective to this model item. @param name the name of the perspective (e.g. "Security", must be unique) @param description a description of the perspective @return a Perspective object @throws IllegalArgumentException if perspective details are not specified, or the named perspective exists already
[ "Adds", "a", "perspective", "to", "this", "model", "item", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/ModelItem.java#L156-L173
train
structurizr/java
structurizr-core/src/com/structurizr/model/DeploymentNode.java
DeploymentNode.add
public ContainerInstance add(Container container, boolean replicateContainerRelationships) { ContainerInstance containerInstance = getModel().addContainerInstance(this, container, replicateContainerRelationships); this.containerInstances.add(containerInstance); return containerInstance; }
java
public ContainerInstance add(Container container, boolean replicateContainerRelationships) { ContainerInstance containerInstance = getModel().addContainerInstance(this, container, replicateContainerRelationships); this.containerInstances.add(containerInstance); return containerInstance; }
[ "public", "ContainerInstance", "add", "(", "Container", "container", ",", "boolean", "replicateContainerRelationships", ")", "{", "ContainerInstance", "containerInstance", "=", "getModel", "(", ")", ".", "addContainerInstance", "(", "this", ",", "container", ",", "rep...
Adds a container instance to this deployment node, optionally replicating all of the container-container relationships. @param container the Container to add an instance of @param replicateContainerRelationships true if the container-container relationships should be replicated between the container instances, false otherwise @return a ContainerInstance object
[ "Adds", "a", "container", "instance", "to", "this", "deployment", "node", "optionally", "replicating", "all", "of", "the", "container", "-", "container", "relationships", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/DeploymentNode.java#L50-L55
train
structurizr/java
structurizr-core/src/com/structurizr/model/DeploymentNode.java
DeploymentNode.getDeploymentNodeWithName
public DeploymentNode getDeploymentNodeWithName(String name) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("A name must be specified."); } for (DeploymentNode deploymentNode : getChildren()) { if (deploymentNode.getName().equals(name)) { return deploymentNode; } } return null; }
java
public DeploymentNode getDeploymentNodeWithName(String name) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("A name must be specified."); } for (DeploymentNode deploymentNode : getChildren()) { if (deploymentNode.getName().equals(name)) { return deploymentNode; } } return null; }
[ "public", "DeploymentNode", "getDeploymentNodeWithName", "(", "String", "name", ")", "{", "if", "(", "name", "==", "null", "||", "name", ".", "trim", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", ...
Gets the DeploymentNode with the specified name. @param name the name of the deployment node @return the DeploymentNode instance with the specified name (or null if it doesn't exist).
[ "Gets", "the", "DeploymentNode", "with", "the", "specified", "name", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/DeploymentNode.java#L106-L118
train
structurizr/java
structurizr-websequencediagrams/src/com/structurizr/io/websequencediagrams/WebSequenceDiagramsWriter.java
WebSequenceDiagramsWriter.write
public void write(Workspace workspace, Writer writer) { if (workspace != null && writer != null) { for (DynamicView view : workspace.getViews().getDynamicViews()) { write(view, writer); } } }
java
public void write(Workspace workspace, Writer writer) { if (workspace != null && writer != null) { for (DynamicView view : workspace.getViews().getDynamicViews()) { write(view, writer); } } }
[ "public", "void", "write", "(", "Workspace", "workspace", ",", "Writer", "writer", ")", "{", "if", "(", "workspace", "!=", "null", "&&", "writer", "!=", "null", ")", "{", "for", "(", "DynamicView", "view", ":", "workspace", ".", "getViews", "(", ")", "...
Writes the dynamic views in the given workspace as WebSequenceDiagrams definitions, to the specified writer. @param workspace the workspace containing the views to be written @param writer the Writer to write to
[ "Writes", "the", "dynamic", "views", "in", "the", "given", "workspace", "as", "WebSequenceDiagrams", "definitions", "to", "the", "specified", "writer", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-websequencediagrams/src/com/structurizr/io/websequencediagrams/WebSequenceDiagramsWriter.java#L34-L40
train
structurizr/java
structurizr-websequencediagrams/src/com/structurizr/io/websequencediagrams/WebSequenceDiagramsWriter.java
WebSequenceDiagramsWriter.write
public void write(Workspace workspace) { StringWriter stringWriter = new StringWriter(); write(workspace, stringWriter); System.out.println(stringWriter.toString()); }
java
public void write(Workspace workspace) { StringWriter stringWriter = new StringWriter(); write(workspace, stringWriter); System.out.println(stringWriter.toString()); }
[ "public", "void", "write", "(", "Workspace", "workspace", ")", "{", "StringWriter", "stringWriter", "=", "new", "StringWriter", "(", ")", ";", "write", "(", "workspace", ",", "stringWriter", ")", ";", "System", ".", "out", ".", "println", "(", "stringWriter"...
Writes the dynamic views in the given workspace as WebSequenceDiagrams definitions, to stdout. @param workspace the workspace containing the views to be written
[ "Writes", "the", "dynamic", "views", "in", "the", "given", "workspace", "as", "WebSequenceDiagrams", "definitions", "to", "stdout", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-websequencediagrams/src/com/structurizr/io/websequencediagrams/WebSequenceDiagramsWriter.java#L47-L51
train
structurizr/java
structurizr-core/src/com/structurizr/view/Branding.java
Branding.setLogo
public void setLogo(String url) { if (url != null && url.trim().length() > 0) { if (Url.isUrl(url) || url.startsWith("data:image/")) { this.logo = url.trim(); } else { throw new IllegalArgumentException(url + " is not a valid URL."); } } }
java
public void setLogo(String url) { if (url != null && url.trim().length() > 0) { if (Url.isUrl(url) || url.startsWith("data:image/")) { this.logo = url.trim(); } else { throw new IllegalArgumentException(url + " is not a valid URL."); } } }
[ "public", "void", "setLogo", "(", "String", "url", ")", "{", "if", "(", "url", "!=", "null", "&&", "url", ".", "trim", "(", ")", ".", "length", "(", ")", ">", "0", ")", "{", "if", "(", "Url", ".", "isUrl", "(", "url", ")", "||", "url", ".", ...
Sets the URL of an image representing a logo. @param url a URL as a String
[ "Sets", "the", "URL", "of", "an", "image", "representing", "a", "logo", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/Branding.java#L26-L34
train
structurizr/java
structurizr-core/src/com/structurizr/model/ContainerInstance.java
ContainerInstance.addHealthCheck
@Nonnull public HttpHealthCheck addHealthCheck(String name, String url, int interval, long timeout) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("The name must not be null or empty."); } if (url == null || url.trim().length() == 0) { throw new IllegalArgumentException("The URL must not be null or empty."); } if (!Url.isUrl(url)) { throw new IllegalArgumentException(url + " is not a valid URL."); } if (interval < 0) { throw new IllegalArgumentException("The polling interval must be zero or a positive integer."); } if (timeout < 0) { throw new IllegalArgumentException("The timeout must be zero or a positive integer."); } HttpHealthCheck healthCheck = new HttpHealthCheck(name, url, interval, timeout); healthChecks.add(healthCheck); return healthCheck; }
java
@Nonnull public HttpHealthCheck addHealthCheck(String name, String url, int interval, long timeout) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("The name must not be null or empty."); } if (url == null || url.trim().length() == 0) { throw new IllegalArgumentException("The URL must not be null or empty."); } if (!Url.isUrl(url)) { throw new IllegalArgumentException(url + " is not a valid URL."); } if (interval < 0) { throw new IllegalArgumentException("The polling interval must be zero or a positive integer."); } if (timeout < 0) { throw new IllegalArgumentException("The timeout must be zero or a positive integer."); } HttpHealthCheck healthCheck = new HttpHealthCheck(name, url, interval, timeout); healthChecks.add(healthCheck); return healthCheck; }
[ "@", "Nonnull", "public", "HttpHealthCheck", "addHealthCheck", "(", "String", "name", ",", "String", "url", ",", "int", "interval", ",", "long", "timeout", ")", "{", "if", "(", "name", "==", "null", "||", "name", ".", "trim", "(", ")", ".", "length", "...
Adds a new health check. @param name the name of the health check @param url the URL of the health check @param interval the polling interval, in seconds @param timeout the timeout, in milliseconds @return a HttpHealthCheck instance representing the health check that has been added @throws IllegalArgumentException if the name is empty, the URL is not a well-formed URL, or the interval/timeout is not zero/a positive integer
[ "Adds", "a", "new", "health", "check", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/ContainerInstance.java#L145-L171
train
structurizr/java
structurizr-client/src/com/structurizr/util/WorkspaceUtils.java
WorkspaceUtils.loadWorkspaceFromJson
public static Workspace loadWorkspaceFromJson(File file) throws Exception { if (file == null) { throw new IllegalArgumentException("The path to a JSON file must be specified."); } else if (!file.exists()) { throw new IllegalArgumentException("The specified JSON file does not exist."); } return new JsonReader().read(new FileReader(file)); }
java
public static Workspace loadWorkspaceFromJson(File file) throws Exception { if (file == null) { throw new IllegalArgumentException("The path to a JSON file must be specified."); } else if (!file.exists()) { throw new IllegalArgumentException("The specified JSON file does not exist."); } return new JsonReader().read(new FileReader(file)); }
[ "public", "static", "Workspace", "loadWorkspaceFromJson", "(", "File", "file", ")", "throws", "Exception", "{", "if", "(", "file", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"The path to a JSON file must be specified.\"", ")", ";", "}...
Loads a workspace from a JSON definition saved as a file. @param file a File representing the JSON definition @return a Workspace object @throws Exception if something goes wrong
[ "Loads", "a", "workspace", "from", "a", "JSON", "definition", "saved", "as", "a", "file", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/util/WorkspaceUtils.java#L22-L30
train
structurizr/java
structurizr-client/src/com/structurizr/util/WorkspaceUtils.java
WorkspaceUtils.saveWorkspaceToJson
public static void saveWorkspaceToJson(Workspace workspace, File file) throws Exception { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } else if (file == null) { throw new IllegalArgumentException("The path to a JSON file must be specified."); } OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); new JsonWriter(true).write(workspace, writer); writer.flush(); writer.close(); }
java
public static void saveWorkspaceToJson(Workspace workspace, File file) throws Exception { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } else if (file == null) { throw new IllegalArgumentException("The path to a JSON file must be specified."); } OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); new JsonWriter(true).write(workspace, writer); writer.flush(); writer.close(); }
[ "public", "static", "void", "saveWorkspaceToJson", "(", "Workspace", "workspace", ",", "File", "file", ")", "throws", "Exception", "{", "if", "(", "workspace", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A workspace must be provided.\...
Saves a workspace to a JSON definition as a file. @param workspace a Workspace object @param file a File representing the JSON definition @throws Exception if something goes wrong
[ "Saves", "a", "workspace", "to", "a", "JSON", "definition", "as", "a", "file", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/util/WorkspaceUtils.java#L39-L50
train
structurizr/java
structurizr-client/src/com/structurizr/util/WorkspaceUtils.java
WorkspaceUtils.printWorkspaceAsJson
public static void printWorkspaceAsJson(Workspace workspace) { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } try { System.out.println(toJson(workspace, true)); } catch (Exception e) { e.printStackTrace(); } }
java
public static void printWorkspaceAsJson(Workspace workspace) { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } try { System.out.println(toJson(workspace, true)); } catch (Exception e) { e.printStackTrace(); } }
[ "public", "static", "void", "printWorkspaceAsJson", "(", "Workspace", "workspace", ")", "{", "if", "(", "workspace", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A workspace must be provided.\"", ")", ";", "}", "try", "{", "System", ...
Prints a workspace as JSON to stdout - useful for debugging purposes. @param workspace the workspace to print
[ "Prints", "a", "workspace", "as", "JSON", "to", "stdout", "-", "useful", "for", "debugging", "purposes", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/util/WorkspaceUtils.java#L57-L67
train
structurizr/java
structurizr-client/src/com/structurizr/util/WorkspaceUtils.java
WorkspaceUtils.toJson
public static String toJson(Workspace workspace, boolean indentOutput) throws Exception { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } JsonWriter jsonWriter = new JsonWriter(indentOutput); StringWriter stringWriter = new StringWriter(); jsonWriter.write(workspace, stringWriter); stringWriter.flush(); stringWriter.close(); return stringWriter.toString(); }
java
public static String toJson(Workspace workspace, boolean indentOutput) throws Exception { if (workspace == null) { throw new IllegalArgumentException("A workspace must be provided."); } JsonWriter jsonWriter = new JsonWriter(indentOutput); StringWriter stringWriter = new StringWriter(); jsonWriter.write(workspace, stringWriter); stringWriter.flush(); stringWriter.close(); return stringWriter.toString(); }
[ "public", "static", "String", "toJson", "(", "Workspace", "workspace", ",", "boolean", "indentOutput", ")", "throws", "Exception", "{", "if", "(", "workspace", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A workspace must be provided.\...
Serializes the specified workspace to a JSON string. @param workspace a Workspace instance @param indentOutput whether to indent the output (prettify) @return a JSON string @throws Exception if something goes wrong
[ "Serializes", "the", "specified", "workspace", "to", "a", "JSON", "string", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/util/WorkspaceUtils.java#L77-L89
train
structurizr/java
structurizr-client/src/com/structurizr/util/WorkspaceUtils.java
WorkspaceUtils.fromJson
public static Workspace fromJson(String json) throws Exception { if (json == null || json.trim().length() == 0) { throw new IllegalArgumentException("A JSON string must be provided."); } StringReader stringReader = new StringReader(json); return new JsonReader().read(stringReader); }
java
public static Workspace fromJson(String json) throws Exception { if (json == null || json.trim().length() == 0) { throw new IllegalArgumentException("A JSON string must be provided."); } StringReader stringReader = new StringReader(json); return new JsonReader().read(stringReader); }
[ "public", "static", "Workspace", "fromJson", "(", "String", "json", ")", "throws", "Exception", "{", "if", "(", "json", "==", "null", "||", "json", ".", "trim", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IllegalArgumentExc...
Converts the specified JSON string to a Workspace instance. @param json the JSON definition of the workspace @return a Workspace instance @throws Exception if the JSON can not be deserialized
[ "Converts", "the", "specified", "JSON", "string", "to", "a", "Workspace", "instance", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/util/WorkspaceUtils.java#L98-L105
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java
ComponentFinder.findComponents
public Set<Component> findComponents() throws Exception { Set<Component> componentsFound = new HashSet<>(); for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentFinderStrategy.beforeFindComponents(); } for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentsFound.addAll(componentFinderStrategy.findComponents()); } for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentFinderStrategy.afterFindComponents(); } return componentsFound; }
java
public Set<Component> findComponents() throws Exception { Set<Component> componentsFound = new HashSet<>(); for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentFinderStrategy.beforeFindComponents(); } for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentsFound.addAll(componentFinderStrategy.findComponents()); } for (ComponentFinderStrategy componentFinderStrategy : componentFinderStrategies) { componentFinderStrategy.afterFindComponents(); } return componentsFound; }
[ "public", "Set", "<", "Component", ">", "findComponents", "(", ")", "throws", "Exception", "{", "Set", "<", "Component", ">", "componentsFound", "=", "new", "HashSet", "<>", "(", ")", ";", "for", "(", "ComponentFinderStrategy", "componentFinderStrategy", ":", ...
Find components, using all of the configured component finder strategies in the order they were added. @return the set of Components that were found @throws Exception if something goes wrong
[ "Find", "components", "using", "all", "of", "the", "configured", "component", "finder", "strategies", "in", "the", "order", "they", "were", "added", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java#L69-L85
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java
ComponentFinder.exclude
public void exclude(String... regexes) { if (regexes != null) { for (String regex : regexes) { this.exclusions.add(Pattern.compile(regex)); } } }
java
public void exclude(String... regexes) { if (regexes != null) { for (String regex : regexes) { this.exclusions.add(Pattern.compile(regex)); } } }
[ "public", "void", "exclude", "(", "String", "...", "regexes", ")", "{", "if", "(", "regexes", "!=", "null", ")", "{", "for", "(", "String", "regex", ":", "regexes", ")", "{", "this", ".", "exclusions", ".", "add", "(", "Pattern", ".", "compile", "(",...
Adds one or more regexes to the set of regexes that define which types should be excluded during the component finding process. @param regexes one or more regular expressions, as Strings
[ "Adds", "one", "or", "more", "regexes", "to", "the", "set", "of", "regexes", "that", "define", "which", "types", "should", "be", "excluded", "during", "the", "component", "finding", "process", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java#L132-L138
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java
ComponentFinder.getTypeRepository
public TypeRepository getTypeRepository() { if (typeRepository == null) { typeRepository = new DefaultTypeRepository(getPackageNames(), getExclusions(), getUrlClassLoader()); } return typeRepository; }
java
public TypeRepository getTypeRepository() { if (typeRepository == null) { typeRepository = new DefaultTypeRepository(getPackageNames(), getExclusions(), getUrlClassLoader()); } return typeRepository; }
[ "public", "TypeRepository", "getTypeRepository", "(", ")", "{", "if", "(", "typeRepository", "==", "null", ")", "{", "typeRepository", "=", "new", "DefaultTypeRepository", "(", "getPackageNames", "(", ")", ",", "getExclusions", "(", ")", ",", "getUrlClassLoader", ...
Gets the type repository used to analyse java classes. @return the type supplied type repository, or a default implementation
[ "Gets", "the", "type", "repository", "used", "to", "analyse", "java", "classes", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/ComponentFinder.java#L179-L184
train
structurizr/java
structurizr-core/src/com/structurizr/view/View.java
View.setAutomaticLayout
public void setAutomaticLayout(boolean enable) { if (enable) { this.setAutomaticLayout(AutomaticLayout.RankDirection.TopBottom, 300, 600, 200, false); } else { this.automaticLayout = null; } }
java
public void setAutomaticLayout(boolean enable) { if (enable) { this.setAutomaticLayout(AutomaticLayout.RankDirection.TopBottom, 300, 600, 200, false); } else { this.automaticLayout = null; } }
[ "public", "void", "setAutomaticLayout", "(", "boolean", "enable", ")", "{", "if", "(", "enable", ")", "{", "this", ".", "setAutomaticLayout", "(", "AutomaticLayout", ".", "RankDirection", ".", "TopBottom", ",", "300", ",", "600", ",", "200", ",", "false", ...
Enables the automatic layout for this view, with some default settings. @param enable a boolean
[ "Enables", "the", "automatic", "layout", "for", "this", "view", "with", "some", "default", "settings", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/View.java#L152-L158
train
structurizr/java
structurizr-core/src/com/structurizr/view/View.java
View.setAutomaticLayout
public void setAutomaticLayout(AutomaticLayout.RankDirection rankDirection, int rankSeparation, int nodeSeparation, int edgeSeparation, boolean vertices) { this.automaticLayout = new AutomaticLayout(rankDirection, rankSeparation, nodeSeparation, edgeSeparation, vertices); }
java
public void setAutomaticLayout(AutomaticLayout.RankDirection rankDirection, int rankSeparation, int nodeSeparation, int edgeSeparation, boolean vertices) { this.automaticLayout = new AutomaticLayout(rankDirection, rankSeparation, nodeSeparation, edgeSeparation, vertices); }
[ "public", "void", "setAutomaticLayout", "(", "AutomaticLayout", ".", "RankDirection", "rankDirection", ",", "int", "rankSeparation", ",", "int", "nodeSeparation", ",", "int", "edgeSeparation", ",", "boolean", "vertices", ")", "{", "this", ".", "automaticLayout", "="...
Enables the automatic layout for this view, with the specified settings. @param rankDirection the rank direction @param rankSeparation the separation between ranks (in pixels, a positive integer) @param nodeSeparation the separation between nodes within the same rank (in pixels, a positive integer) @param edgeSeparation the separation between edges (in pixels, a positive integer) @param vertices whether vertices should be created during automatic layout
[ "Enables", "the", "automatic", "layout", "for", "this", "view", "with", "the", "specified", "settings", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/View.java#L169-L171
train
structurizr/java
structurizr-core/src/com/structurizr/view/View.java
View.remove
public void remove(Relationship relationship) { if (relationship != null) { RelationshipView relationshipView = new RelationshipView(relationship); relationshipViews.remove(relationshipView); } }
java
public void remove(Relationship relationship) { if (relationship != null) { RelationshipView relationshipView = new RelationshipView(relationship); relationshipViews.remove(relationshipView); } }
[ "public", "void", "remove", "(", "Relationship", "relationship", ")", "{", "if", "(", "relationship", "!=", "null", ")", "{", "RelationshipView", "relationshipView", "=", "new", "RelationshipView", "(", "relationship", ")", ";", "relationshipViews", ".", "remove",...
Removes a relationship from this view. @param relationship the Relationship to remove
[ "Removes", "a", "relationship", "from", "this", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/View.java#L291-L296
train
structurizr/java
structurizr-core/src/com/structurizr/view/View.java
View.removeRelationshipsNotConnectedToElement
public void removeRelationshipsNotConnectedToElement(Element element) { if (element != null) { getRelationships().stream() .map(RelationshipView::getRelationship) .filter(r -> !r.getSource().equals(element) && !r.getDestination().equals(element)) .forEach(this::remove); } }
java
public void removeRelationshipsNotConnectedToElement(Element element) { if (element != null) { getRelationships().stream() .map(RelationshipView::getRelationship) .filter(r -> !r.getSource().equals(element) && !r.getDestination().equals(element)) .forEach(this::remove); } }
[ "public", "void", "removeRelationshipsNotConnectedToElement", "(", "Element", "element", ")", "{", "if", "(", "element", "!=", "null", ")", "{", "getRelationships", "(", ")", ".", "stream", "(", ")", ".", "map", "(", "RelationshipView", "::", "getRelationship", ...
Removes relationships that are not connected to the specified element. @param element the Element to test against
[ "Removes", "relationships", "that", "are", "not", "connected", "to", "the", "specified", "element", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/View.java#L303-L310
train
structurizr/java
structurizr-core/src/com/structurizr/view/View.java
View.removeElementsWithNoRelationships
public void removeElementsWithNoRelationships() { Set<RelationshipView> relationships = getRelationships(); Set<String> elementIds = new HashSet<>(); relationships.forEach(rv -> elementIds.add(rv.getRelationship().getSourceId())); relationships.forEach(rv -> elementIds.add(rv.getRelationship().getDestinationId())); for (ElementView elementView : getElements()) { if (!elementIds.contains(elementView.getId())) { removeElement(elementView.getElement()); } } }
java
public void removeElementsWithNoRelationships() { Set<RelationshipView> relationships = getRelationships(); Set<String> elementIds = new HashSet<>(); relationships.forEach(rv -> elementIds.add(rv.getRelationship().getSourceId())); relationships.forEach(rv -> elementIds.add(rv.getRelationship().getDestinationId())); for (ElementView elementView : getElements()) { if (!elementIds.contains(elementView.getId())) { removeElement(elementView.getElement()); } } }
[ "public", "void", "removeElementsWithNoRelationships", "(", ")", "{", "Set", "<", "RelationshipView", ">", "relationships", "=", "getRelationships", "(", ")", ";", "Set", "<", "String", ">", "elementIds", "=", "new", "HashSet", "<>", "(", ")", ";", "relationsh...
Removes all elements that have no relationships to other elements in this view.
[ "Removes", "all", "elements", "that", "have", "no", "relationships", "to", "other", "elements", "in", "this", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/View.java#L345-L357
train
structurizr/java
structurizr-core/src/com/structurizr/model/Model.java
Model.getDeploymentNodeWithName
public DeploymentNode getDeploymentNodeWithName(String name, String environment) { for (DeploymentNode deploymentNode : getDeploymentNodes()) { if (deploymentNode.getEnvironment().equals(environment) && deploymentNode.getName().equals(name)) { return deploymentNode; } } return null; }
java
public DeploymentNode getDeploymentNodeWithName(String name, String environment) { for (DeploymentNode deploymentNode : getDeploymentNodes()) { if (deploymentNode.getEnvironment().equals(environment) && deploymentNode.getName().equals(name)) { return deploymentNode; } } return null; }
[ "public", "DeploymentNode", "getDeploymentNodeWithName", "(", "String", "name", ",", "String", "environment", ")", "{", "for", "(", "DeploymentNode", "deploymentNode", ":", "getDeploymentNodes", "(", ")", ")", "{", "if", "(", "deploymentNode", ".", "getEnvironment",...
Gets the deployment node with the specified name and environment. @param name the name of the deployment node @param environment the name of the deployment environment @return the DeploymentNode instance with the specified name (or null if it doesn't exist).
[ "Gets", "the", "deployment", "node", "with", "the", "specified", "name", "and", "environment", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/Model.java#L690-L698
train
structurizr/java
structurizr-core/src/com/structurizr/model/Model.java
Model.getElementWithCanonicalName
public Element getElementWithCanonicalName(String canonicalName) { if (canonicalName == null || canonicalName.trim().length() == 0) { throw new IllegalArgumentException("A canonical name must be specified."); } // canonical names start with a leading slash, so add this if it's missing if (!canonicalName.startsWith("/")) { canonicalName = "/" + canonicalName; } for (Element element : getElements()) { if (element.getCanonicalName().equals(canonicalName)) { return element; } } return null; }
java
public Element getElementWithCanonicalName(String canonicalName) { if (canonicalName == null || canonicalName.trim().length() == 0) { throw new IllegalArgumentException("A canonical name must be specified."); } // canonical names start with a leading slash, so add this if it's missing if (!canonicalName.startsWith("/")) { canonicalName = "/" + canonicalName; } for (Element element : getElements()) { if (element.getCanonicalName().equals(canonicalName)) { return element; } } return null; }
[ "public", "Element", "getElementWithCanonicalName", "(", "String", "canonicalName", ")", "{", "if", "(", "canonicalName", "==", "null", "||", "canonicalName", ".", "trim", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IllegalArgume...
Gets the element with the specified canonical name. @param canonicalName the canonical name (e.g. /SoftwareSystem/Container) @return the Element with the given canonical name, or null if one doesn't exist @throws IllegalArgumentException if the canonical name is null or empty
[ "Gets", "the", "element", "with", "the", "specified", "canonical", "name", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/Model.java#L755-L772
train
structurizr/java
structurizr-core/src/com/structurizr/model/Model.java
Model.modifyRelationship
public void modifyRelationship(Relationship relationship, String description, String technology) { if (relationship == null) { throw new IllegalArgumentException("A relationship must be specified."); } Relationship newRelationship = new Relationship(relationship.getSource(), relationship.getDestination(), description, technology, relationship.getInteractionStyle()); if (!relationship.getSource().has(newRelationship)) { relationship.setDescription(description); relationship.setTechnology(technology); } else { throw new IllegalArgumentException("This relationship exists already: " + newRelationship); } }
java
public void modifyRelationship(Relationship relationship, String description, String technology) { if (relationship == null) { throw new IllegalArgumentException("A relationship must be specified."); } Relationship newRelationship = new Relationship(relationship.getSource(), relationship.getDestination(), description, technology, relationship.getInteractionStyle()); if (!relationship.getSource().has(newRelationship)) { relationship.setDescription(description); relationship.setTechnology(technology); } else { throw new IllegalArgumentException("This relationship exists already: " + newRelationship); } }
[ "public", "void", "modifyRelationship", "(", "Relationship", "relationship", ",", "String", "description", ",", "String", "technology", ")", "{", "if", "(", "relationship", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A relationship mu...
Provides a way for the description and technology to be modified on an existing relationship. @param relationship a Relationship instance @param description the new description @param technology the new technology
[ "Provides", "a", "way", "for", "the", "description", "and", "technology", "to", "be", "modified", "on", "an", "existing", "relationship", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/Model.java#L795-L807
train
structurizr/java
structurizr-core/src/com/structurizr/model/Element.java
Element.setUrl
public void setUrl(String url) { if (url != null && url.trim().length() > 0) { if (Url.isUrl(url)) { this.url = url; } else { throw new IllegalArgumentException(url + " is not a valid URL."); } } }
java
public void setUrl(String url) { if (url != null && url.trim().length() > 0) { if (Url.isUrl(url)) { this.url = url; } else { throw new IllegalArgumentException(url + " is not a valid URL."); } } }
[ "public", "void", "setUrl", "(", "String", "url", ")", "{", "if", "(", "url", "!=", "null", "&&", "url", ".", "trim", "(", ")", ".", "length", "(", ")", ">", "0", ")", "{", "if", "(", "Url", ".", "isUrl", "(", "url", ")", ")", "{", "this", ...
Sets the URL where more information about this element can be found. @param url the URL as a String @throws IllegalArgumentException if the URL is not a well-formed URL
[ "Sets", "the", "URL", "where", "more", "information", "about", "this", "element", "can", "be", "found", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/Element.java#L72-L80
train
structurizr/java
structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java
DocumentationTemplate.addSection
public Section addSection(String title, File... files) throws IOException { return add(null, title, files); }
java
public Section addSection(String title, File... files) throws IOException { return add(null, title, files); }
[ "public", "Section", "addSection", "(", "String", "title", ",", "File", "...", "files", ")", "throws", "IOException", "{", "return", "add", "(", "null", ",", "title", ",", "files", ")", ";", "}" ]
Adds a custom section from one or more files, that isn't related to any element in the model. @param title the section title @param files one or more File objects that point to the documentation content @return a documentation {@link Section} @throws IOException if there is an error reading the files
[ "Adds", "a", "custom", "section", "from", "one", "or", "more", "files", "that", "isn", "t", "related", "to", "any", "element", "in", "the", "model", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java#L47-L49
train
structurizr/java
structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java
DocumentationTemplate.addSection
@Nonnull public Section addSection(String title, Format format, String content) { return add(null, title, format, content); }
java
@Nonnull public Section addSection(String title, Format format, String content) { return add(null, title, format, content); }
[ "@", "Nonnull", "public", "Section", "addSection", "(", "String", "title", ",", "Format", "format", ",", "String", "content", ")", "{", "return", "add", "(", "null", ",", "title", ",", "format", ",", "content", ")", ";", "}" ]
Adds a custom section, that isn't related to any element in the model. @param title the section title @param format the {@link Format} of the documentation content @param content a String containing the documentation content @return a documentation {@link Section}
[ "Adds", "a", "custom", "section", "that", "isn", "t", "related", "to", "any", "element", "in", "the", "model", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java#L59-L62
train
structurizr/java
structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java
DocumentationTemplate.addImage
public Image addImage(File file) throws IOException { String contentType = ImageUtils.getContentType(file); String base64Content = ImageUtils.getImageAsBase64(file); Image image = new Image(file.getName(), contentType, base64Content); documentation.addImage(image); return image; }
java
public Image addImage(File file) throws IOException { String contentType = ImageUtils.getContentType(file); String base64Content = ImageUtils.getImageAsBase64(file); Image image = new Image(file.getName(), contentType, base64Content); documentation.addImage(image); return image; }
[ "public", "Image", "addImage", "(", "File", "file", ")", "throws", "IOException", "{", "String", "contentType", "=", "ImageUtils", ".", "getContentType", "(", "file", ")", ";", "String", "base64Content", "=", "ImageUtils", ".", "getImageAsBase64", "(", "file", ...
Adds an image from the given file to the workspace. @param file a File descriptor representing an image file on disk @return an Image object representing the image added @throws IOException if there is an error reading the image
[ "Adds", "an", "image", "from", "the", "given", "file", "to", "the", "workspace", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/documentation/DocumentationTemplate.java#L240-L248
train
structurizr/java
structurizr-core/src/com/structurizr/configuration/WorkspaceConfiguration.java
WorkspaceConfiguration.addUser
public void addUser(String username, Role role) { if (StringUtils.isNullOrEmpty(username)) { throw new IllegalArgumentException("A username must be specified."); } if (role == null) { throw new IllegalArgumentException("A role must be specified."); } users.add(new User(username, role)); }
java
public void addUser(String username, Role role) { if (StringUtils.isNullOrEmpty(username)) { throw new IllegalArgumentException("A username must be specified."); } if (role == null) { throw new IllegalArgumentException("A role must be specified."); } users.add(new User(username, role)); }
[ "public", "void", "addUser", "(", "String", "username", ",", "Role", "role", ")", "{", "if", "(", "StringUtils", ".", "isNullOrEmpty", "(", "username", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A username must be specified.\"", ")", ";",...
Adds a user, with the specified username and role. @param username the username (e.g. an e-mail address) @param role the user's role
[ "Adds", "a", "user", "with", "the", "specified", "username", "and", "role", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/configuration/WorkspaceConfiguration.java#L39-L49
train
structurizr/java
structurizr-core/src/com/structurizr/view/ComponentView.java
ComponentView.add
public void add(Container container, boolean addRelationships) { if (container != null && !container.equals(getContainer())) { addElement(container, addRelationships); } }
java
public void add(Container container, boolean addRelationships) { if (container != null && !container.equals(getContainer())) { addElement(container, addRelationships); } }
[ "public", "void", "add", "(", "Container", "container", ",", "boolean", "addRelationships", ")", "{", "if", "(", "container", "!=", "null", "&&", "!", "container", ".", "equals", "(", "getContainer", "(", ")", ")", ")", "{", "addElement", "(", "container",...
Adds an individual container to this view. @param container the Container to add @param addRelationships whether to add relationships to/from the container
[ "Adds", "an", "individual", "container", "to", "this", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/ComponentView.java#L105-L109
train
structurizr/java
structurizr-core/src/com/structurizr/view/ComponentView.java
ComponentView.add
public void add(Component component, boolean addRelationships) { if (component != null) { if (!component.getContainer().equals(getContainer())) { throw new IllegalArgumentException("Only components belonging to " + container.getName() + " can be added to this view."); } addElement(component, addRelationships); } }
java
public void add(Component component, boolean addRelationships) { if (component != null) { if (!component.getContainer().equals(getContainer())) { throw new IllegalArgumentException("Only components belonging to " + container.getName() + " can be added to this view."); } addElement(component, addRelationships); } }
[ "public", "void", "add", "(", "Component", "component", ",", "boolean", "addRelationships", ")", "{", "if", "(", "component", "!=", "null", ")", "{", "if", "(", "!", "component", ".", "getContainer", "(", ")", ".", "equals", "(", "getContainer", "(", ")"...
Adds an individual component to this view. @param component the Component to add @param addRelationships whether to add relationships to/from the component
[ "Adds", "an", "individual", "component", "to", "this", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/ComponentView.java#L133-L141
train
structurizr/java
structurizr-core/src/com/structurizr/view/StaticView.java
StaticView.removeElementsThatAreUnreachableFrom
public void removeElementsThatAreUnreachableFrom(Element element) { if (element != null) { Set<Element> elementsToShow = new HashSet<>(); Set<Element> elementsVisited = new HashSet<>(); findElementsToShow(element, element, elementsToShow, elementsVisited); for (ElementView elementView : getElements()) { if (!elementsToShow.contains(elementView.getElement()) && canBeRemoved(elementView.getElement())) { removeElement(elementView.getElement()); } } } }
java
public void removeElementsThatAreUnreachableFrom(Element element) { if (element != null) { Set<Element> elementsToShow = new HashSet<>(); Set<Element> elementsVisited = new HashSet<>(); findElementsToShow(element, element, elementsToShow, elementsVisited); for (ElementView elementView : getElements()) { if (!elementsToShow.contains(elementView.getElement()) && canBeRemoved(elementView.getElement())) { removeElement(elementView.getElement()); } } } }
[ "public", "void", "removeElementsThatAreUnreachableFrom", "(", "Element", "element", ")", "{", "if", "(", "element", "!=", "null", ")", "{", "Set", "<", "Element", ">", "elementsToShow", "=", "new", "HashSet", "<>", "(", ")", ";", "Set", "<", "Element", ">...
Removes all elements that cannot be reached by traversing the graph of relationships starting with the specified element. @param element the starting element
[ "Removes", "all", "elements", "that", "cannot", "be", "reached", "by", "traversing", "the", "graph", "of", "relationships", "starting", "with", "the", "specified", "element", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/StaticView.java#L143-L155
train
structurizr/java
structurizr-core/src/com/structurizr/view/StaticView.java
StaticView.addAnimation
public void addAnimation(Element... elements) { if (elements == null || elements.length == 0) { throw new IllegalArgumentException("One or more elements must be specified."); } Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>(); Set<Element> elementsInThisAnimationStep = new HashSet<>(); Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>(); for (Element element : elements) { if (isElementInView(element)) { elementIdsInPreviousAnimationSteps.add(element.getId()); elementsInThisAnimationStep.add(element); } } if (elementsInThisAnimationStep.size() == 0) { throw new IllegalArgumentException("None of the specified elements exist in this view."); } for (Animation animationStep : animations) { elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements()); } for (RelationshipView relationshipView : this.getRelationships()) { if ( (elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) || (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination())) ) { relationshipsInThisAnimationStep.add(relationshipView.getRelationship()); } } animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep)); }
java
public void addAnimation(Element... elements) { if (elements == null || elements.length == 0) { throw new IllegalArgumentException("One or more elements must be specified."); } Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>(); Set<Element> elementsInThisAnimationStep = new HashSet<>(); Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>(); for (Element element : elements) { if (isElementInView(element)) { elementIdsInPreviousAnimationSteps.add(element.getId()); elementsInThisAnimationStep.add(element); } } if (elementsInThisAnimationStep.size() == 0) { throw new IllegalArgumentException("None of the specified elements exist in this view."); } for (Animation animationStep : animations) { elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements()); } for (RelationshipView relationshipView : this.getRelationships()) { if ( (elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) || (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination())) ) { relationshipsInThisAnimationStep.add(relationshipView.getRelationship()); } } animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep)); }
[ "public", "void", "addAnimation", "(", "Element", "...", "elements", ")", "{", "if", "(", "elements", "==", "null", "||", "elements", ".", "length", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"One or more elements must be specified.\""...
Adds an animation step, with the specified elements. @param elements the elements that should be shown in the animation step
[ "Adds", "an", "animation", "step", "with", "the", "specified", "elements", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/StaticView.java#L198-L232
train
structurizr/java
structurizr-client/src/com/structurizr/io/json/JsonWriter.java
JsonWriter.write
public void write(Workspace workspace, Writer writer) throws WorkspaceWriterException { if (workspace == null) { throw new IllegalArgumentException("Workspace cannot be null."); } if (writer == null) { throw new IllegalArgumentException("Writer cannot be null."); } try { ObjectMapper objectMapper = new ObjectMapper(); if (indentOutput) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new ISO8601DateFormat()); writer.write(objectMapper.writeValueAsString(workspace)); } catch (IOException ioe) { throw new WorkspaceWriterException("Could not write as JSON", ioe); } }
java
public void write(Workspace workspace, Writer writer) throws WorkspaceWriterException { if (workspace == null) { throw new IllegalArgumentException("Workspace cannot be null."); } if (writer == null) { throw new IllegalArgumentException("Writer cannot be null."); } try { ObjectMapper objectMapper = new ObjectMapper(); if (indentOutput) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new ISO8601DateFormat()); writer.write(objectMapper.writeValueAsString(workspace)); } catch (IOException ioe) { throw new WorkspaceWriterException("Could not write as JSON", ioe); } }
[ "public", "void", "write", "(", "Workspace", "workspace", ",", "Writer", "writer", ")", "throws", "WorkspaceWriterException", "{", "if", "(", "workspace", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Workspace cannot be null.\"", ")", ...
Writes a workspace definition as a JSON string to the specified Writer object. @param workspace the Workspace object to write @param writer the Writer object to write the workspace to @throws WorkspaceWriterException if something goes wrong
[ "Writes", "a", "workspace", "definition", "as", "a", "JSON", "string", "to", "the", "specified", "Writer", "object", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/io/json/JsonWriter.java#L32-L55
train
structurizr/java
structurizr-core/src/com/structurizr/documentation/AutomaticDocumentationTemplate.java
AutomaticDocumentationTemplate.addSections
public List<Section> addSections(SoftwareSystem softwareSystem, File directory) throws IOException { if (softwareSystem == null) { throw new IllegalArgumentException("A software system must be specified."); } return add(softwareSystem, directory); }
java
public List<Section> addSections(SoftwareSystem softwareSystem, File directory) throws IOException { if (softwareSystem == null) { throw new IllegalArgumentException("A software system must be specified."); } return add(softwareSystem, directory); }
[ "public", "List", "<", "Section", ">", "addSections", "(", "SoftwareSystem", "softwareSystem", ",", "File", "directory", ")", "throws", "IOException", "{", "if", "(", "softwareSystem", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A...
Adds all files in the specified directory, each in its own section, related to a software system. @param directory the directory to scan @param softwareSystem the SoftwareSystem to associate the documentation with @return a List of Section objects @throws IOException if there is an error reading the files in the directory
[ "Adds", "all", "files", "in", "the", "specified", "directory", "each", "in", "its", "own", "section", "related", "to", "a", "software", "system", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/documentation/AutomaticDocumentationTemplate.java#L45-L51
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java
TypeUtils.getVisibility
public static TypeVisibility getVisibility(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); int modifiers = type.getModifiers(); if (Modifier.isPrivate(modifiers)) { return TypeVisibility.PRIVATE; } else if (Modifier.isPublic(modifiers)) { return TypeVisibility.PUBLIC; } else if (Modifier.isProtected(modifiers)) { return TypeVisibility.PROTECTED; } else { return TypeVisibility.PACKAGE; } } catch (ClassNotFoundException e) { log.warn("Visibility for type " + typeName + " could not be found."); return null; } }
java
public static TypeVisibility getVisibility(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); int modifiers = type.getModifiers(); if (Modifier.isPrivate(modifiers)) { return TypeVisibility.PRIVATE; } else if (Modifier.isPublic(modifiers)) { return TypeVisibility.PUBLIC; } else if (Modifier.isProtected(modifiers)) { return TypeVisibility.PROTECTED; } else { return TypeVisibility.PACKAGE; } } catch (ClassNotFoundException e) { log.warn("Visibility for type " + typeName + " could not be found."); return null; } }
[ "public", "static", "TypeVisibility", "getVisibility", "(", "TypeRepository", "typeRepository", ",", "String", "typeName", ")", "{", "try", "{", "Class", "<", "?", ">", "type", "=", "typeRepository", ".", "loadClass", "(", "typeName", ")", ";", "int", "modifie...
Finds the visibility of a given type. @param typeRepository the repository where types should be loaded from @param typeName the fully qualified type name @return a TypeVisibility object representing the visibility (e.g. public, package, etc)
[ "Finds", "the", "visibility", "of", "a", "given", "type", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java#L25-L42
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java
TypeUtils.getCategory
public static TypeCategory getCategory(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); if (type.isInterface()) { return TypeCategory.INTERFACE; } else if (type.isEnum()) { return TypeCategory.ENUM; } else { if (Modifier.isAbstract(type.getModifiers())) { return TypeCategory.ABSTRACT_CLASS; } else{ return TypeCategory.CLASS; } } } catch (ClassNotFoundException e) { log.warn("Category for type " + typeName + " could not be found."); return null; } }
java
public static TypeCategory getCategory(TypeRepository typeRepository, String typeName) { try { Class<?> type = typeRepository.loadClass(typeName); if (type.isInterface()) { return TypeCategory.INTERFACE; } else if (type.isEnum()) { return TypeCategory.ENUM; } else { if (Modifier.isAbstract(type.getModifiers())) { return TypeCategory.ABSTRACT_CLASS; } else{ return TypeCategory.CLASS; } } } catch (ClassNotFoundException e) { log.warn("Category for type " + typeName + " could not be found."); return null; } }
[ "public", "static", "TypeCategory", "getCategory", "(", "TypeRepository", "typeRepository", ",", "String", "typeName", ")", "{", "try", "{", "Class", "<", "?", ">", "type", "=", "typeRepository", ".", "loadClass", "(", "typeName", ")", ";", "if", "(", "type"...
Finds the category of a given type. @param typeRepository the repository where types should be loaded from @param typeName the fully qualified type name @return a TypeCategory object representing the category (e.g. class, interface, enum, etc)
[ "Finds", "the", "category", "of", "a", "given", "type", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java#L51-L69
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java
TypeUtils.findTypesAnnotatedWith
public static Set<Class<?>> findTypesAnnotatedWith(Class<? extends Annotation> annotation, Set<Class<?>> types) { if (annotation == null) { throw new IllegalArgumentException("An annotation type must be specified."); } return types.stream().filter(c -> c.isAnnotationPresent(annotation)).collect(Collectors.toSet()); }
java
public static Set<Class<?>> findTypesAnnotatedWith(Class<? extends Annotation> annotation, Set<Class<?>> types) { if (annotation == null) { throw new IllegalArgumentException("An annotation type must be specified."); } return types.stream().filter(c -> c.isAnnotationPresent(annotation)).collect(Collectors.toSet()); }
[ "public", "static", "Set", "<", "Class", "<", "?", ">", ">", "findTypesAnnotatedWith", "(", "Class", "<", "?", "extends", "Annotation", ">", "annotation", ",", "Set", "<", "Class", "<", "?", ">", ">", "types", ")", "{", "if", "(", "annotation", "==", ...
Finds the set of types that are annotated with the specified annotation. @param annotation the Annotation to find @param types the set of Class objects to search through @return a Set of Class objects, or an empty set of none could be found
[ "Finds", "the", "set", "of", "types", "that", "are", "annotated", "with", "the", "specified", "annotation", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java#L78-L84
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java
TypeUtils.findFirstImplementationOfInterface
public static Class findFirstImplementationOfInterface(Class interfaceType, Set<Class<?>> types) { if (interfaceType == null) { throw new IllegalArgumentException("An interface type must be provided."); } else if (!interfaceType.isInterface()) { throw new IllegalArgumentException("The interface type must represent an interface."); } if (types == null) { throw new IllegalArgumentException("The set of types to search through must be provided."); } for (Class<?> type : types) { boolean isInterface = type.isInterface(); boolean isAbstract = Modifier.isAbstract(type.getModifiers()); boolean isAssignable = interfaceType.isAssignableFrom(type); if (!isInterface && !isAbstract && isAssignable) { return type; } } return null; }
java
public static Class findFirstImplementationOfInterface(Class interfaceType, Set<Class<?>> types) { if (interfaceType == null) { throw new IllegalArgumentException("An interface type must be provided."); } else if (!interfaceType.isInterface()) { throw new IllegalArgumentException("The interface type must represent an interface."); } if (types == null) { throw new IllegalArgumentException("The set of types to search through must be provided."); } for (Class<?> type : types) { boolean isInterface = type.isInterface(); boolean isAbstract = Modifier.isAbstract(type.getModifiers()); boolean isAssignable = interfaceType.isAssignableFrom(type); if (!isInterface && !isAbstract && isAssignable) { return type; } } return null; }
[ "public", "static", "Class", "findFirstImplementationOfInterface", "(", "Class", "interfaceType", ",", "Set", "<", "Class", "<", "?", ">", ">", "types", ")", "{", "if", "(", "interfaceType", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "...
Finds the first implementation of the given interface. @param interfaceType a Class object representing the interface type @param types the set of Class objects to search through @return the first concrete implementation class of the given interface, or null if one can't be found
[ "Finds", "the", "first", "implementation", "of", "the", "given", "interface", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/TypeUtils.java#L94-L115
train
structurizr/java
structurizr-dot/src/com/structurizr/io/dot/DotWriter.java
DotWriter.write
public void write(Workspace workspace, Writer writer) { workspace.getViews().getSystemContextViews().forEach(v -> write(v, null, writer)); workspace.getViews().getContainerViews().forEach(v -> write(v, v.getSoftwareSystem(), writer)); workspace.getViews().getComponentViews().forEach(v -> write(v, v.getContainer(), writer)); }
java
public void write(Workspace workspace, Writer writer) { workspace.getViews().getSystemContextViews().forEach(v -> write(v, null, writer)); workspace.getViews().getContainerViews().forEach(v -> write(v, v.getSoftwareSystem(), writer)); workspace.getViews().getComponentViews().forEach(v -> write(v, v.getContainer(), writer)); }
[ "public", "void", "write", "(", "Workspace", "workspace", ",", "Writer", "writer", ")", "{", "workspace", ".", "getViews", "(", ")", ".", "getSystemContextViews", "(", ")", ".", "forEach", "(", "v", "->", "write", "(", "v", ",", "null", ",", "writer", ...
Writes the views in the given workspace as DOT notation, to the specified Writer. @param workspace the workspace containing the views to be written @param writer the Writer to write to
[ "Writes", "the", "views", "in", "the", "given", "workspace", "as", "DOT", "notation", "to", "the", "specified", "Writer", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-dot/src/com/structurizr/io/dot/DotWriter.java#L30-L34
train
structurizr/java
structurizr-core/src/com/structurizr/model/HttpHealthCheck.java
HttpHealthCheck.addHeader
public void addHeader(String name, String value) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("The header name must not be null or empty."); } if (value == null) { throw new IllegalArgumentException("The header value must not be null."); } this.headers.put(name, value); }
java
public void addHeader(String name, String value) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("The header name must not be null or empty."); } if (value == null) { throw new IllegalArgumentException("The header value must not be null."); } this.headers.put(name, value); }
[ "public", "void", "addHeader", "(", "String", "name", ",", "String", "value", ")", "{", "if", "(", "name", "==", "null", "||", "name", ".", "trim", "(", ")", ".", "length", "(", ")", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(...
Adds a HTTP header, which will be sent with the HTTP request to the health check URL. @param name the name of the header @param value the value of the header
[ "Adds", "a", "HTTP", "header", "which", "will", "be", "sent", "with", "the", "HTTP", "request", "to", "the", "health", "check", "URL", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/model/HttpHealthCheck.java#L68-L78
train
structurizr/java
structurizr-core/src/com/structurizr/util/Url.java
Url.isUrl
public static boolean isUrl(String urlAsString) { if (urlAsString != null && urlAsString.trim().length() > 0) { try { new URL(urlAsString); return true; } catch (MalformedURLException murle) { return false; } } return false; }
java
public static boolean isUrl(String urlAsString) { if (urlAsString != null && urlAsString.trim().length() > 0) { try { new URL(urlAsString); return true; } catch (MalformedURLException murle) { return false; } } return false; }
[ "public", "static", "boolean", "isUrl", "(", "String", "urlAsString", ")", "{", "if", "(", "urlAsString", "!=", "null", "&&", "urlAsString", ".", "trim", "(", ")", ".", "length", "(", ")", ">", "0", ")", "{", "try", "{", "new", "URL", "(", "urlAsStri...
Determines whether the supplied string is a valid URL. @param urlAsString the URL, as a String @return true if the URL is valid, false otherwise
[ "Determines", "whether", "the", "supplied", "string", "is", "a", "valid", "URL", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/util/Url.java#L17-L28
train
structurizr/java
structurizr-analysis/src/com/structurizr/analysis/DefaultTypeRepository.java
DefaultTypeRepository.findReferencedTypes
public Set<Class<?>> findReferencedTypes(String typeName) { Set<Class<?>> referencedTypes = new HashSet<>(); // use the cached version if possible if (referencedTypesCache.containsKey(typeName)) { return referencedTypesCache.get(typeName); } try { CtClass cc = classPool.get(typeName); for (Object referencedType : cc.getRefClasses()) { String referencedTypeName = (String)referencedType; if (!isExcluded(referencedTypeName)) { try { referencedTypes.add(loadClass(referencedTypeName)); } catch (Throwable t) { log.debug("Could not find " + referencedTypeName + " ... ignoring."); } } } // remove the type itself referencedTypes.remove(loadClass(typeName)); } catch (Exception e) { log.debug("Error finding referenced types for " + typeName + " ... ignoring."); // since there was an error, we can't find the set of referenced types from it, so... referencedTypesCache.put(typeName, new HashSet<>()); } // cache for the next time referencedTypesCache.put(typeName, referencedTypes); return referencedTypes; }
java
public Set<Class<?>> findReferencedTypes(String typeName) { Set<Class<?>> referencedTypes = new HashSet<>(); // use the cached version if possible if (referencedTypesCache.containsKey(typeName)) { return referencedTypesCache.get(typeName); } try { CtClass cc = classPool.get(typeName); for (Object referencedType : cc.getRefClasses()) { String referencedTypeName = (String)referencedType; if (!isExcluded(referencedTypeName)) { try { referencedTypes.add(loadClass(referencedTypeName)); } catch (Throwable t) { log.debug("Could not find " + referencedTypeName + " ... ignoring."); } } } // remove the type itself referencedTypes.remove(loadClass(typeName)); } catch (Exception e) { log.debug("Error finding referenced types for " + typeName + " ... ignoring."); // since there was an error, we can't find the set of referenced types from it, so... referencedTypesCache.put(typeName, new HashSet<>()); } // cache for the next time referencedTypesCache.put(typeName, referencedTypes); return referencedTypes; }
[ "public", "Set", "<", "Class", "<", "?", ">", ">", "findReferencedTypes", "(", "String", "typeName", ")", "{", "Set", "<", "Class", "<", "?", ">", ">", "referencedTypes", "=", "new", "HashSet", "<>", "(", ")", ";", "// use the cached version if possible", ...
Finds the set of types referenced by the specified type. @param typeName the starting type @return a Set of Class objects, or an empty set if none were found
[ "Finds", "the", "set", "of", "types", "referenced", "by", "the", "specified", "type", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-analysis/src/com/structurizr/analysis/DefaultTypeRepository.java#L118-L153
train
structurizr/java
structurizr-client/src/com/structurizr/io/json/EncryptedJsonWriter.java
EncryptedJsonWriter.write
public void write(EncryptedWorkspace workspace, Writer writer) throws WorkspaceWriterException { if (workspace == null) { throw new IllegalArgumentException("EncryptedWorkspace cannot be null."); } if (writer == null) { throw new IllegalArgumentException("Writer cannot be null."); } try { ObjectMapper objectMapper = new ObjectMapper(); if (indentOutput) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new ISO8601DateFormat()); writer.write(objectMapper.writeValueAsString(workspace)); } catch (Exception e) { throw new WorkspaceWriterException("Could not write as JSON", e); } }
java
public void write(EncryptedWorkspace workspace, Writer writer) throws WorkspaceWriterException { if (workspace == null) { throw new IllegalArgumentException("EncryptedWorkspace cannot be null."); } if (writer == null) { throw new IllegalArgumentException("Writer cannot be null."); } try { ObjectMapper objectMapper = new ObjectMapper(); if (indentOutput) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new ISO8601DateFormat()); writer.write(objectMapper.writeValueAsString(workspace)); } catch (Exception e) { throw new WorkspaceWriterException("Could not write as JSON", e); } }
[ "public", "void", "write", "(", "EncryptedWorkspace", "workspace", ",", "Writer", "writer", ")", "throws", "WorkspaceWriterException", "{", "if", "(", "workspace", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"EncryptedWorkspace cannot be...
Writes an encrypted workspace definition as a JSON string to the specified Writer object. @param workspace the Workspace object to write @param writer the Writer object to write the workspace to @throws WorkspaceWriterException if something goes wrong
[ "Writes", "an", "encrypted", "workspace", "definition", "as", "a", "JSON", "string", "to", "the", "specified", "Writer", "object", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-client/src/com/structurizr/io/json/EncryptedJsonWriter.java#L27-L50
train
structurizr/java
structurizr-core/src/com/structurizr/view/DynamicView.java
DynamicView.checkElement
private void checkElement(Element elementToBeAdded) { if (!(elementToBeAdded instanceof Person) && !(elementToBeAdded instanceof SoftwareSystem) && !(elementToBeAdded instanceof Container) && !(elementToBeAdded instanceof Component)) { throw new IllegalArgumentException("Only people, software systems, containers and components can be added to dynamic views."); } // people can always be added if (elementToBeAdded instanceof Person) { return; } // if the scope of this dynamic view is a software system, we only want: // - containers inside that software system // - other software systems if (element instanceof SoftwareSystem) { if (elementToBeAdded.equals(element)) { throw new IllegalArgumentException(elementToBeAdded.getName() + " is already the scope of this view and cannot be added to it."); } if (elementToBeAdded instanceof Container && !elementToBeAdded.getParent().equals(element)) { throw new IllegalArgumentException("Only containers that reside inside " + element.getName() + " can be added to this view."); } if (elementToBeAdded instanceof Component) { throw new IllegalArgumentException("Components can't be added to a dynamic view when the scope is a software system."); } } // if the scope of this dynamic view is a container, we only want other containers inside the same software system // and other components inside the container if (element instanceof Container) { if (elementToBeAdded.equals(element) || elementToBeAdded.equals(element.getParent())) { throw new IllegalArgumentException(elementToBeAdded.getName() + " is already the scope of this view and cannot be added to it."); } if (elementToBeAdded instanceof Container && !elementToBeAdded.getParent().equals(element.getParent())) { throw new IllegalArgumentException("Only containers that reside inside " + element.getParent().getName() + " can be added to this view."); } if (elementToBeAdded instanceof Component && !elementToBeAdded.getParent().equals(element)) { throw new IllegalArgumentException("Only components that reside inside " + element.getName() + " can be added to this view."); } } if (element == null) { if (!(elementToBeAdded instanceof SoftwareSystem)) { throw new IllegalArgumentException("Only people and software systems can be added to this dynamic view."); } } }
java
private void checkElement(Element elementToBeAdded) { if (!(elementToBeAdded instanceof Person) && !(elementToBeAdded instanceof SoftwareSystem) && !(elementToBeAdded instanceof Container) && !(elementToBeAdded instanceof Component)) { throw new IllegalArgumentException("Only people, software systems, containers and components can be added to dynamic views."); } // people can always be added if (elementToBeAdded instanceof Person) { return; } // if the scope of this dynamic view is a software system, we only want: // - containers inside that software system // - other software systems if (element instanceof SoftwareSystem) { if (elementToBeAdded.equals(element)) { throw new IllegalArgumentException(elementToBeAdded.getName() + " is already the scope of this view and cannot be added to it."); } if (elementToBeAdded instanceof Container && !elementToBeAdded.getParent().equals(element)) { throw new IllegalArgumentException("Only containers that reside inside " + element.getName() + " can be added to this view."); } if (elementToBeAdded instanceof Component) { throw new IllegalArgumentException("Components can't be added to a dynamic view when the scope is a software system."); } } // if the scope of this dynamic view is a container, we only want other containers inside the same software system // and other components inside the container if (element instanceof Container) { if (elementToBeAdded.equals(element) || elementToBeAdded.equals(element.getParent())) { throw new IllegalArgumentException(elementToBeAdded.getName() + " is already the scope of this view and cannot be added to it."); } if (elementToBeAdded instanceof Container && !elementToBeAdded.getParent().equals(element.getParent())) { throw new IllegalArgumentException("Only containers that reside inside " + element.getParent().getName() + " can be added to this view."); } if (elementToBeAdded instanceof Component && !elementToBeAdded.getParent().equals(element)) { throw new IllegalArgumentException("Only components that reside inside " + element.getName() + " can be added to this view."); } } if (element == null) { if (!(elementToBeAdded instanceof SoftwareSystem)) { throw new IllegalArgumentException("Only people and software systems can be added to this dynamic view."); } } }
[ "private", "void", "checkElement", "(", "Element", "elementToBeAdded", ")", "{", "if", "(", "!", "(", "elementToBeAdded", "instanceof", "Person", ")", "&&", "!", "(", "elementToBeAdded", "instanceof", "SoftwareSystem", ")", "&&", "!", "(", "elementToBeAdded", "i...
This checks that only appropriate elements can be added to the view.
[ "This", "checks", "that", "only", "appropriate", "elements", "can", "be", "added", "to", "the", "view", "." ]
4b204f077877a24bcac363f5ecf0e129a0f9f4c5
https://github.com/structurizr/java/blob/4b204f077877a24bcac363f5ecf0e129a0f9f4c5/structurizr-core/src/com/structurizr/view/DynamicView.java#L123-L168
train
jgilfelt/android-sqlite-asset-helper
library/src/main/java/com/readystatesoftware/sqliteasset/VersionComparator.java
VersionComparator.compare
@Override public int compare(String file0, String file1) { Matcher m0 = pattern.matcher(file0); Matcher m1 = pattern.matcher(file1); if (!m0.matches()) { Log.w(TAG, "could not parse upgrade script file: " + file0); throw new SQLiteAssetException("Invalid upgrade script file"); } if (!m1.matches()) { Log.w(TAG, "could not parse upgrade script file: " + file1); throw new SQLiteAssetException("Invalid upgrade script file"); } int v0_from = Integer.valueOf(m0.group(1)); int v1_from = Integer.valueOf(m1.group(1)); int v0_to = Integer.valueOf(m0.group(2)); int v1_to = Integer.valueOf(m1.group(2)); if (v0_from == v1_from) { // 'from' versions match for both; check 'to' version next if (v0_to == v1_to) { return 0; } return v0_to < v1_to ? -1 : 1; } return v0_from < v1_from ? -1 : 1; }
java
@Override public int compare(String file0, String file1) { Matcher m0 = pattern.matcher(file0); Matcher m1 = pattern.matcher(file1); if (!m0.matches()) { Log.w(TAG, "could not parse upgrade script file: " + file0); throw new SQLiteAssetException("Invalid upgrade script file"); } if (!m1.matches()) { Log.w(TAG, "could not parse upgrade script file: " + file1); throw new SQLiteAssetException("Invalid upgrade script file"); } int v0_from = Integer.valueOf(m0.group(1)); int v1_from = Integer.valueOf(m1.group(1)); int v0_to = Integer.valueOf(m0.group(2)); int v1_to = Integer.valueOf(m1.group(2)); if (v0_from == v1_from) { // 'from' versions match for both; check 'to' version next if (v0_to == v1_to) { return 0; } return v0_to < v1_to ? -1 : 1; } return v0_from < v1_from ? -1 : 1; }
[ "@", "Override", "public", "int", "compare", "(", "String", "file0", ",", "String", "file1", ")", "{", "Matcher", "m0", "=", "pattern", ".", "matcher", "(", "file0", ")", ";", "Matcher", "m1", "=", "pattern", ".", "matcher", "(", "file1", ")", ";", "...
Compares the two specified upgrade script strings to determine their relative ordering considering their two version numbers. Assumes all database names used are the same, as this function only compares the two version numbers. @param file0 an upgrade script file name @param file1 a second upgrade script file name to compare with file0 @return an integer < 0 if file0 should be applied before file1, 0 if they are equal (though that shouldn't happen), and > 0 if file0 should be applied after file1. @exception SQLiteAssetException thrown if the strings are not in the correct upgrade script format of: <code>databasename_fromVersionInteger_toVersionInteger</code>
[ "Compares", "the", "two", "specified", "upgrade", "script", "strings", "to", "determine", "their", "relative", "ordering", "considering", "their", "two", "version", "numbers", ".", "Assumes", "all", "database", "names", "used", "are", "the", "same", "as", "this"...
74a9b0d68aeb1bb0b9778c5598e37da573919ce1
https://github.com/jgilfelt/android-sqlite-asset-helper/blob/74a9b0d68aeb1bb0b9778c5598e37da573919ce1/library/src/main/java/com/readystatesoftware/sqliteasset/VersionComparator.java#L49-L80
train
traex/RippleEffect
library/src/main/java/com/andexert/library/RippleView.java
RippleView.init
private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(R.color.rippelColor)); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); }
java
private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(R.color.rippelColor)); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); }
[ "private", "void", "init", "(", "final", "Context", "context", ",", "final", "AttributeSet", "attrs", ")", "{", "if", "(", "isInEditMode", "(", ")", ")", "return", ";", "final", "TypedArray", "typedArray", "=", "context", ".", "obtainStyledAttributes", "(", ...
Method that initializes all fields and sets listeners @param context Context used to create this view @param attrs Attribute used to initialize fields
[ "Method", "that", "initializes", "all", "fields", "and", "sets", "listeners" ]
df5f9e4456eae8a8e98e2827a3c6f9e7185596e1
https://github.com/traex/RippleEffect/blob/df5f9e4456eae8a8e98e2827a3c6f9e7185596e1/library/src/main/java/com/andexert/library/RippleView.java#L111-L156
train
traex/RippleEffect
library/src/main/java/com/andexert/library/RippleView.java
RippleView.createAnimation
private void createAnimation(final float x, final float y) { if (this.isEnabled() && !animationRunning) { if (hasToZoom) this.startAnimation(scaleAnimation); radiusMax = Math.max(WIDTH, HEIGHT); if (rippleType != 2) radiusMax /= 2; radiusMax -= ripplePadding; if (isCentered || rippleType == 1) { this.x = getMeasuredWidth() / 2; this.y = getMeasuredHeight() / 2; } else { this.x = x; this.y = y; } animationRunning = true; if (rippleType == 1 && originBitmap == null) originBitmap = getDrawingCache(true); invalidate(); } }
java
private void createAnimation(final float x, final float y) { if (this.isEnabled() && !animationRunning) { if (hasToZoom) this.startAnimation(scaleAnimation); radiusMax = Math.max(WIDTH, HEIGHT); if (rippleType != 2) radiusMax /= 2; radiusMax -= ripplePadding; if (isCentered || rippleType == 1) { this.x = getMeasuredWidth() / 2; this.y = getMeasuredHeight() / 2; } else { this.x = x; this.y = y; } animationRunning = true; if (rippleType == 1 && originBitmap == null) originBitmap = getDrawingCache(true); invalidate(); } }
[ "private", "void", "createAnimation", "(", "final", "float", "x", ",", "final", "float", "y", ")", "{", "if", "(", "this", ".", "isEnabled", "(", ")", "&&", "!", "animationRunning", ")", "{", "if", "(", "hasToZoom", ")", "this", ".", "startAnimation", ...
Create Ripple animation centered at x, y @param x Horizontal position of the ripple center @param y Vertical position of the ripple center
[ "Create", "Ripple", "animation", "centered", "at", "x", "y" ]
df5f9e4456eae8a8e98e2827a3c6f9e7185596e1
https://github.com/traex/RippleEffect/blob/df5f9e4456eae8a8e98e2827a3c6f9e7185596e1/library/src/main/java/com/andexert/library/RippleView.java#L249-L276
train
traex/RippleEffect
library/src/main/java/com/andexert/library/RippleView.java
RippleView.sendClickEvent
private void sendClickEvent(final Boolean isLongClick) { if (getParent() instanceof AdapterView) { final AdapterView adapterView = (AdapterView) getParent(); final int position = adapterView.getPositionForView(this); final long id = adapterView.getItemIdAtPosition(position); if (isLongClick) { if (adapterView.getOnItemLongClickListener() != null) adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id); } else { if (adapterView.getOnItemClickListener() != null) adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id); } } }
java
private void sendClickEvent(final Boolean isLongClick) { if (getParent() instanceof AdapterView) { final AdapterView adapterView = (AdapterView) getParent(); final int position = adapterView.getPositionForView(this); final long id = adapterView.getItemIdAtPosition(position); if (isLongClick) { if (adapterView.getOnItemLongClickListener() != null) adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id); } else { if (adapterView.getOnItemClickListener() != null) adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id); } } }
[ "private", "void", "sendClickEvent", "(", "final", "Boolean", "isLongClick", ")", "{", "if", "(", "getParent", "(", ")", "instanceof", "AdapterView", ")", "{", "final", "AdapterView", "adapterView", "=", "(", "AdapterView", ")", "getParent", "(", ")", ";", "...
Send a click event if parent view is a Listview instance @param isLongClick Is the event a long click ?
[ "Send", "a", "click", "event", "if", "parent", "view", "is", "a", "Listview", "instance" ]
df5f9e4456eae8a8e98e2827a3c6f9e7185596e1
https://github.com/traex/RippleEffect/blob/df5f9e4456eae8a8e98e2827a3c6f9e7185596e1/library/src/main/java/com/andexert/library/RippleView.java#L298-L311
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/GeometryAdapterFactory.java
GeometryAdapterFactory.create
public static TypeAdapterFactory create() { if (geometryTypeFactory == null) { geometryTypeFactory = RuntimeTypeAdapterFactory.of(Geometry.class, "type", true) .registerSubtype(GeometryCollection.class, "GeometryCollection") .registerSubtype(Point.class, "Point") .registerSubtype(MultiPoint.class, "MultiPoint") .registerSubtype(LineString.class, "LineString") .registerSubtype(MultiLineString.class, "MultiLineString") .registerSubtype(Polygon.class, "Polygon") .registerSubtype(MultiPolygon.class, "MultiPolygon"); } return geometryTypeFactory; }
java
public static TypeAdapterFactory create() { if (geometryTypeFactory == null) { geometryTypeFactory = RuntimeTypeAdapterFactory.of(Geometry.class, "type", true) .registerSubtype(GeometryCollection.class, "GeometryCollection") .registerSubtype(Point.class, "Point") .registerSubtype(MultiPoint.class, "MultiPoint") .registerSubtype(LineString.class, "LineString") .registerSubtype(MultiLineString.class, "MultiLineString") .registerSubtype(Polygon.class, "Polygon") .registerSubtype(MultiPolygon.class, "MultiPolygon"); } return geometryTypeFactory; }
[ "public", "static", "TypeAdapterFactory", "create", "(", ")", "{", "if", "(", "geometryTypeFactory", "==", "null", ")", "{", "geometryTypeFactory", "=", "RuntimeTypeAdapterFactory", ".", "of", "(", "Geometry", ".", "class", ",", "\"type\"", ",", "true", ")", "...
Create a new instance of Geometry type adapter factory, this is passed into the Gson Builder. @return a new GSON TypeAdapterFactory @since 4.4.0
[ "Create", "a", "new", "instance", "of", "Geometry", "type", "adapter", "factory", "this", "is", "passed", "into", "the", "Gson", "Builder", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/GeometryAdapterFactory.java#L26-L39
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/MultiLineString.java
MultiLineString.lineStrings
public List<LineString> lineStrings() { List<List<Point>> coordinates = coordinates(); List<LineString> lineStrings = new ArrayList<>(coordinates.size()); for (List<Point> points : coordinates) { lineStrings.add(LineString.fromLngLats(points)); } return lineStrings; }
java
public List<LineString> lineStrings() { List<List<Point>> coordinates = coordinates(); List<LineString> lineStrings = new ArrayList<>(coordinates.size()); for (List<Point> points : coordinates) { lineStrings.add(LineString.fromLngLats(points)); } return lineStrings; }
[ "public", "List", "<", "LineString", ">", "lineStrings", "(", ")", "{", "List", "<", "List", "<", "Point", ">>", "coordinates", "=", "coordinates", "(", ")", ";", "List", "<", "LineString", ">", "lineStrings", "=", "new", "ArrayList", "<>", "(", "coordin...
Returns a list of LineStrings which are currently making up this MultiLineString. @return a list of {@link LineString}s @since 3.0.0
[ "Returns", "a", "list", "of", "LineStrings", "which", "are", "currently", "making", "up", "this", "MultiLineString", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/MultiLineString.java#L255-L262
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatCoordinate
public static String formatCoordinate(double coordinate) { DecimalFormat decimalFormat = new DecimalFormat("0.######", new DecimalFormatSymbols(Locale.US)); return String.format(Locale.US, "%s", decimalFormat.format(coordinate)); }
java
public static String formatCoordinate(double coordinate) { DecimalFormat decimalFormat = new DecimalFormat("0.######", new DecimalFormatSymbols(Locale.US)); return String.format(Locale.US, "%s", decimalFormat.format(coordinate)); }
[ "public", "static", "String", "formatCoordinate", "(", "double", "coordinate", ")", "{", "DecimalFormat", "decimalFormat", "=", "new", "DecimalFormat", "(", "\"0.######\"", ",", "new", "DecimalFormatSymbols", "(", "Locale", ".", "US", ")", ")", ";", "return", "S...
Useful to remove any trailing zeros and prevent a coordinate being over 7 significant figures. @param coordinate a double value representing a coordinate. @return a formatted string. @since 2.1.0
[ "Useful", "to", "remove", "any", "trailing", "zeros", "and", "prevent", "a", "coordinate", "being", "over", "7", "significant", "figures", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L67-L72
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatCoordinate
public static String formatCoordinate(double coordinate, int precision) { String pattern = "0." + new String(new char[precision]).replace("\0", "0"); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US); df.applyPattern(pattern); df.setRoundingMode(RoundingMode.FLOOR); return df.format(coordinate); }
java
public static String formatCoordinate(double coordinate, int precision) { String pattern = "0." + new String(new char[precision]).replace("\0", "0"); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US); df.applyPattern(pattern); df.setRoundingMode(RoundingMode.FLOOR); return df.format(coordinate); }
[ "public", "static", "String", "formatCoordinate", "(", "double", "coordinate", ",", "int", "precision", ")", "{", "String", "pattern", "=", "\"0.\"", "+", "new", "String", "(", "new", "char", "[", "precision", "]", ")", ".", "replace", "(", "\"\\0\"", ",",...
Allows the specific adjusting of a coordinates precision. @param coordinate a double value representing a coordinate. @param precision an integer value you'd like the precision to be at. @return a formatted string. @since 2.1.0
[ "Allows", "the", "specific", "adjusting", "of", "a", "coordinates", "precision", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L82-L88
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatRadiuses
public static String formatRadiuses(double[] radiuses) { if (radiuses == null || radiuses.length == 0) { return null; } String[] radiusesFormatted = new String[radiuses.length]; for (int i = 0; i < radiuses.length; i++) { if (radiuses[i] == Double.POSITIVE_INFINITY) { radiusesFormatted[i] = "unlimited"; } else { radiusesFormatted[i] = String.format(Locale.US, "%s", TextUtils.formatCoordinate(radiuses[i])); } } return join(";", radiusesFormatted); }
java
public static String formatRadiuses(double[] radiuses) { if (radiuses == null || radiuses.length == 0) { return null; } String[] radiusesFormatted = new String[radiuses.length]; for (int i = 0; i < radiuses.length; i++) { if (radiuses[i] == Double.POSITIVE_INFINITY) { radiusesFormatted[i] = "unlimited"; } else { radiusesFormatted[i] = String.format(Locale.US, "%s", TextUtils.formatCoordinate(radiuses[i])); } } return join(";", radiusesFormatted); }
[ "public", "static", "String", "formatRadiuses", "(", "double", "[", "]", "radiuses", ")", "{", "if", "(", "radiuses", "==", "null", "||", "radiuses", ".", "length", "==", "0", ")", "{", "return", "null", ";", "}", "String", "[", "]", "radiusesFormatted",...
Used in various APIs to format the user provided radiuses to a String matching the APIs format. @param radiuses a double array which represents the radius values @return a String ready for being passed into the Retrofit call @since 3.0.0
[ "Used", "in", "various", "APIs", "to", "format", "the", "user", "provided", "radiuses", "to", "a", "String", "matching", "the", "APIs", "format", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L97-L112
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatBearing
public static String formatBearing(List<Double[]> bearings) { if (bearings.isEmpty()) { return null; } String[] bearingFormatted = new String[bearings.size()]; for (int i = 0; i < bearings.size(); i++) { if (bearings.get(i).length == 0) { bearingFormatted[i] = ""; } else { bearingFormatted[i] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(bearings.get(i)[0]), TextUtils.formatCoordinate(bearings.get(i)[1])); } } return TextUtils.join(";", bearingFormatted); }
java
public static String formatBearing(List<Double[]> bearings) { if (bearings.isEmpty()) { return null; } String[] bearingFormatted = new String[bearings.size()]; for (int i = 0; i < bearings.size(); i++) { if (bearings.get(i).length == 0) { bearingFormatted[i] = ""; } else { bearingFormatted[i] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(bearings.get(i)[0]), TextUtils.formatCoordinate(bearings.get(i)[1])); } } return TextUtils.join(";", bearingFormatted); }
[ "public", "static", "String", "formatBearing", "(", "List", "<", "Double", "[", "]", ">", "bearings", ")", "{", "if", "(", "bearings", ".", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "String", "[", "]", "bearingFormatted", "=", "new", ...
Formats the bearing variables from the raw values to a string which can than be used for the request URL. @param bearings a List of doubles representing bearing values @return a string with the bearing values @since 3.0.0
[ "Formats", "the", "bearing", "variables", "from", "the", "raw", "values", "to", "a", "string", "which", "can", "than", "be", "used", "for", "the", "request", "URL", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L122-L138
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatDistributions
public static String formatDistributions(List<Integer[]> distributions) { if (distributions.isEmpty()) { return null; } String[] distributionsFormatted = new String[distributions.size()]; for (int i = 0; i < distributions.size(); i++) { if (distributions.get(i).length == 0) { distributionsFormatted[i] = ""; } else { distributionsFormatted[i] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(distributions.get(i)[0]), TextUtils.formatCoordinate(distributions.get(i)[1])); } } return TextUtils.join(";", distributionsFormatted); }
java
public static String formatDistributions(List<Integer[]> distributions) { if (distributions.isEmpty()) { return null; } String[] distributionsFormatted = new String[distributions.size()]; for (int i = 0; i < distributions.size(); i++) { if (distributions.get(i).length == 0) { distributionsFormatted[i] = ""; } else { distributionsFormatted[i] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(distributions.get(i)[0]), TextUtils.formatCoordinate(distributions.get(i)[1])); } } return TextUtils.join(";", distributionsFormatted); }
[ "public", "static", "String", "formatDistributions", "(", "List", "<", "Integer", "[", "]", ">", "distributions", ")", "{", "if", "(", "distributions", ".", "isEmpty", "(", ")", ")", "{", "return", "null", ";", "}", "String", "[", "]", "distributionsFormat...
converts the list of integer arrays to a string ready for API consumption. @param distributions the list of integer arrays representing the distribution @return a string with the distribution values @since 3.0.0
[ "converts", "the", "list", "of", "integer", "arrays", "to", "a", "string", "ready", "for", "API", "consumption", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L147-L163
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatApproaches
public static String formatApproaches(String[] approaches) { for (int i = 0; i < approaches.length; i++) { if (approaches[i] == null) { approaches[i] = ""; } else if (!approaches[i].equals("unrestricted") && !approaches[i].equals("curb") && !approaches[i].isEmpty()) { return null; } } return TextUtils.join(";", approaches); }
java
public static String formatApproaches(String[] approaches) { for (int i = 0; i < approaches.length; i++) { if (approaches[i] == null) { approaches[i] = ""; } else if (!approaches[i].equals("unrestricted") && !approaches[i].equals("curb") && !approaches[i].isEmpty()) { return null; } } return TextUtils.join(";", approaches); }
[ "public", "static", "String", "formatApproaches", "(", "String", "[", "]", "approaches", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "approaches", ".", "length", ";", "i", "++", ")", "{", "if", "(", "approaches", "[", "i", "]", "==",...
Converts String array with approaches values to a string ready for API consumption. An approach could be unrestricted, curb or null. @param approaches a string representing approaches to each coordinate. @return a formatted string. @since 3.2.0
[ "Converts", "String", "array", "with", "approaches", "values", "to", "a", "string", "ready", "for", "API", "consumption", ".", "An", "approach", "could", "be", "unrestricted", "curb", "or", "null", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L174-L184
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
TextUtils.formatWaypointNames
public static String formatWaypointNames(String[] waypointNames) { for (int i = 0; i < waypointNames.length; i++) { if (waypointNames[i] == null) { waypointNames[i] = ""; } } return TextUtils.join(";", waypointNames); }
java
public static String formatWaypointNames(String[] waypointNames) { for (int i = 0; i < waypointNames.length; i++) { if (waypointNames[i] == null) { waypointNames[i] = ""; } } return TextUtils.join(";", waypointNames); }
[ "public", "static", "String", "formatWaypointNames", "(", "String", "[", "]", "waypointNames", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "waypointNames", ".", "length", ";", "i", "++", ")", "{", "if", "(", "waypointNames", "[", "i", ...
Converts String array with waypoint_names values to a string ready for API consumption. @param waypointNames a string representing approaches to each coordinate. @return a formatted string. @since 3.3.0
[ "Converts", "String", "array", "with", "waypoint_names", "values", "to", "a", "string", "ready", "for", "API", "consumption", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/TextUtils.java#L194-L201
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Point.java
Point.fromLngLat
public static Point fromLngLat( @FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double longitude, @FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double latitude) { List<Double> coordinates = CoordinateShifterManager.getCoordinateShifter().shiftLonLat(longitude, latitude); return new Point(TYPE, null, coordinates); }
java
public static Point fromLngLat( @FloatRange(from = MIN_LONGITUDE, to = MAX_LONGITUDE) double longitude, @FloatRange(from = MIN_LATITUDE, to = MAX_LATITUDE) double latitude) { List<Double> coordinates = CoordinateShifterManager.getCoordinateShifter().shiftLonLat(longitude, latitude); return new Point(TYPE, null, coordinates); }
[ "public", "static", "Point", "fromLngLat", "(", "@", "FloatRange", "(", "from", "=", "MIN_LONGITUDE", ",", "to", "=", "MAX_LONGITUDE", ")", "double", "longitude", ",", "@", "FloatRange", "(", "from", "=", "MIN_LATITUDE", ",", "to", "=", "MAX_LATITUDE", ")", ...
Create a new instance of this class defining a longitude and latitude value in that respective order. Longitude values are limited to a -180 to 180 range and latitude's limited to -90 to 90 as the spec defines. While no limit is placed on decimal precision, for performance reasons when serializing and deserializing it is suggested to limit decimal precision to within 6 decimal places. @param longitude a double value between -180 to 180 representing the x position of this point @param latitude a double value between -90 to 90 representing the y position of this point @return a new instance of this class defined by the values passed inside this static factory method @since 3.0.0
[ "Create", "a", "new", "instance", "of", "this", "class", "defining", "a", "longitude", "and", "latitude", "value", "in", "that", "respective", "order", ".", "Longitude", "values", "are", "limited", "to", "a", "-", "180", "to", "180", "range", "and", "latit...
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Point.java#L101-L108
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Polygon.java
Polygon.isLinearRing
private static boolean isLinearRing(LineString lineString) { if (lineString.coordinates().size() < 4) { throw new GeoJsonException("LinearRings need to be made up of 4 or more coordinates."); } if (!(lineString.coordinates().get(0).equals( lineString.coordinates().get(lineString.coordinates().size() - 1)))) { throw new GeoJsonException("LinearRings require first and last coordinate to be identical."); } return true; }
java
private static boolean isLinearRing(LineString lineString) { if (lineString.coordinates().size() < 4) { throw new GeoJsonException("LinearRings need to be made up of 4 or more coordinates."); } if (!(lineString.coordinates().get(0).equals( lineString.coordinates().get(lineString.coordinates().size() - 1)))) { throw new GeoJsonException("LinearRings require first and last coordinate to be identical."); } return true; }
[ "private", "static", "boolean", "isLinearRing", "(", "LineString", "lineString", ")", "{", "if", "(", "lineString", ".", "coordinates", "(", ")", ".", "size", "(", ")", "<", "4", ")", "{", "throw", "new", "GeoJsonException", "(", "\"LinearRings need to be made...
Checks to ensure that the LineStrings defining the polygon correctly and adhering to the linear ring rules. @param lineString {@link LineString} the polygon geometry @return true if number of coordinates are 4 or more, and first and last coordinates are identical, else false @throws GeoJsonException if number of coordinates are less than 4, or first and last coordinates are not identical @since 3.0.0
[ "Checks", "to", "ensure", "that", "the", "LineStrings", "defining", "the", "polygon", "correctly", "and", "adhering", "to", "the", "linear", "ring", "rules", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Polygon.java#L385-L394
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/MapboxService.java
MapboxService.getService
protected S getService() { // No need to recreate it if (service != null) { return service; } Retrofit.Builder retrofitBuilder = new Retrofit.Builder() .baseUrl(baseUrl()) .addConverterFactory(GsonConverterFactory.create(getGsonBuilder().create())); if (getCallFactory() != null) { retrofitBuilder.callFactory(getCallFactory()); } else { retrofitBuilder.client(getOkHttpClient()); } retrofit = retrofitBuilder.build(); service = (S) retrofit.create(serviceType); return service; }
java
protected S getService() { // No need to recreate it if (service != null) { return service; } Retrofit.Builder retrofitBuilder = new Retrofit.Builder() .baseUrl(baseUrl()) .addConverterFactory(GsonConverterFactory.create(getGsonBuilder().create())); if (getCallFactory() != null) { retrofitBuilder.callFactory(getCallFactory()); } else { retrofitBuilder.client(getOkHttpClient()); } retrofit = retrofitBuilder.build(); service = (S) retrofit.create(serviceType); return service; }
[ "protected", "S", "getService", "(", ")", "{", "// No need to recreate it", "if", "(", "service", "!=", "null", ")", "{", "return", "service", ";", "}", "Retrofit", ".", "Builder", "retrofitBuilder", "=", "new", "Retrofit", ".", "Builder", "(", ")", ".", "...
Creates the Retrofit object and the service if they are not already created. Subclasses can override getGsonBuilder to add anything to the GsonBuilder. @return new service if not already created, otherwise the existing service @since 3.0.0
[ "Creates", "the", "Retrofit", "object", "and", "the", "service", "if", "they", "are", "not", "already", "created", ".", "Subclasses", "can", "override", "getGsonBuilder", "to", "add", "anything", "to", "the", "GsonBuilder", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/MapboxService.java#L125-L144
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/MapboxService.java
MapboxService.getOkHttpClient
protected synchronized OkHttpClient getOkHttpClient() { if (okHttpClient == null) { if (isEnableDebug()) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(logging); okHttpClient = httpClient.build(); } else { okHttpClient = new OkHttpClient(); } } return okHttpClient; }
java
protected synchronized OkHttpClient getOkHttpClient() { if (okHttpClient == null) { if (isEnableDebug()) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(logging); okHttpClient = httpClient.build(); } else { okHttpClient = new OkHttpClient(); } } return okHttpClient; }
[ "protected", "synchronized", "OkHttpClient", "getOkHttpClient", "(", ")", "{", "if", "(", "okHttpClient", "==", "null", ")", "{", "if", "(", "isEnableDebug", "(", ")", ")", "{", "HttpLoggingInterceptor", "logging", "=", "new", "HttpLoggingInterceptor", "(", ")",...
Used Internally. @return OkHttpClient @since 1.0.0
[ "Used", "Internally", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/MapboxService.java#L212-L225
train
mapbox/mapbox-java
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
MapboxDirections.formatWaypointTargets
private static String formatWaypointTargets(Point[] waypointTargets) { String[] coordinatesFormatted = new String[waypointTargets.length]; int index = 0; for (Point target : waypointTargets) { if (target == null) { coordinatesFormatted[index++] = ""; } else { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(target.longitude()), TextUtils.formatCoordinate(target.latitude())); } } return TextUtils.join(";", coordinatesFormatted); }
java
private static String formatWaypointTargets(Point[] waypointTargets) { String[] coordinatesFormatted = new String[waypointTargets.length]; int index = 0; for (Point target : waypointTargets) { if (target == null) { coordinatesFormatted[index++] = ""; } else { coordinatesFormatted[index++] = String.format(Locale.US, "%s,%s", TextUtils.formatCoordinate(target.longitude()), TextUtils.formatCoordinate(target.latitude())); } } return TextUtils.join(";", coordinatesFormatted); }
[ "private", "static", "String", "formatWaypointTargets", "(", "Point", "[", "]", "waypointTargets", ")", "{", "String", "[", "]", "coordinatesFormatted", "=", "new", "String", "[", "waypointTargets", ".", "length", "]", ";", "int", "index", "=", "0", ";", "fo...
Converts array of Points with waypoint_targets values to a string ready for API consumption. @param waypointTargets a string representing approaches to each coordinate. @return a formatted string. @since 4.3.0
[ "Converts", "array", "of", "Points", "with", "waypoint_targets", "values", "to", "a", "string", "ready", "for", "API", "consumption", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java#L230-L243
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/MultiPolygon.java
MultiPolygon.polygons
public List<Polygon> polygons() { List<List<List<Point>>> coordinates = coordinates(); List<Polygon> polygons = new ArrayList<>(coordinates.size()); for (List<List<Point>> points : coordinates) { polygons.add(Polygon.fromLngLats(points)); } return polygons; }
java
public List<Polygon> polygons() { List<List<List<Point>>> coordinates = coordinates(); List<Polygon> polygons = new ArrayList<>(coordinates.size()); for (List<List<Point>> points : coordinates) { polygons.add(Polygon.fromLngLats(points)); } return polygons; }
[ "public", "List", "<", "Polygon", ">", "polygons", "(", ")", "{", "List", "<", "List", "<", "List", "<", "Point", ">>>", "coordinates", "=", "coordinates", "(", ")", ";", "List", "<", "Polygon", ">", "polygons", "=", "new", "ArrayList", "<>", "(", "c...
Returns a list of polygons which make up this MultiPolygon instance. @return a list of {@link Polygon}s which make up this MultiPolygon instance @since 3.0.0
[ "Returns", "a", "list", "of", "polygons", "which", "make", "up", "this", "MultiPolygon", "instance", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/MultiPolygon.java#L232-L239
train
mapbox/mapbox-java
services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsJsonObject.java
DirectionsJsonObject.toJson
public String toJson() { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter()); return gson.create().toJson(this); }
java
public String toJson() { GsonBuilder gson = new GsonBuilder(); gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); gson.registerTypeAdapter(Point.class, new PointAsCoordinatesTypeAdapter()); return gson.create().toJson(this); }
[ "public", "String", "toJson", "(", ")", "{", "GsonBuilder", "gson", "=", "new", "GsonBuilder", "(", ")", ";", "gson", ".", "registerTypeAdapterFactory", "(", "DirectionsAdapterFactory", ".", "create", "(", ")", ")", ";", "gson", ".", "registerTypeAdapter", "("...
This takes the currently defined values found inside this instance and converts it to a json string. @return a JSON string which represents this DirectionsJsonObject @since 3.4.0
[ "This", "takes", "the", "currently", "defined", "values", "found", "inside", "this", "instance", "and", "converts", "it", "to", "a", "json", "string", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-directions/src/main/java/com/mapbox/api/directions/v5/models/DirectionsJsonObject.java#L24-L29
train
mapbox/mapbox-java
services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/MapboxStaticMap.java
MapboxStaticMap.url
public HttpUrl url() { HttpUrl.Builder urlBuilder = HttpUrl.parse(baseUrl()).newBuilder() .addPathSegment("styles") .addPathSegment("v1") .addPathSegment(user()) .addPathSegment(styleId()) .addPathSegment("static") .addQueryParameter("access_token", accessToken()); List<String> annotations = new ArrayList<>(); if (staticMarkerAnnotations() != null) { List<String> markerStrings = new ArrayList<>(staticMarkerAnnotations().size()); for (StaticMarkerAnnotation marker : staticMarkerAnnotations()) { markerStrings.add(marker.url()); } annotations.addAll(markerStrings); } if (staticPolylineAnnotations() != null) { String[] polylineStringArray = new String[staticPolylineAnnotations().size()]; for (StaticPolylineAnnotation polyline : staticPolylineAnnotations()) { polylineStringArray[staticPolylineAnnotations().indexOf(polyline)] = polyline.url(); } annotations.addAll(Arrays.asList(polylineStringArray)); } if (geoJson() != null) { annotations.add(String.format(Locale.US, "geojson(%s)", geoJson().toJson())); } if (!annotations.isEmpty()) { urlBuilder.addPathSegment(TextUtils.join(",", annotations.toArray())); } urlBuilder.addPathSegment(cameraAuto() ? CAMERA_AUTO : generateLocationPathSegment()); if (beforeLayer() != null) { urlBuilder.addQueryParameter(BEFORE_LAYER, beforeLayer()); } if (!attribution()) { urlBuilder.addQueryParameter("attribution", "false"); } if (!logo()) { urlBuilder.addQueryParameter("logo", "false"); } // Has to be last segment in URL urlBuilder.addPathSegment(generateSizePathSegment()); return urlBuilder.build(); }
java
public HttpUrl url() { HttpUrl.Builder urlBuilder = HttpUrl.parse(baseUrl()).newBuilder() .addPathSegment("styles") .addPathSegment("v1") .addPathSegment(user()) .addPathSegment(styleId()) .addPathSegment("static") .addQueryParameter("access_token", accessToken()); List<String> annotations = new ArrayList<>(); if (staticMarkerAnnotations() != null) { List<String> markerStrings = new ArrayList<>(staticMarkerAnnotations().size()); for (StaticMarkerAnnotation marker : staticMarkerAnnotations()) { markerStrings.add(marker.url()); } annotations.addAll(markerStrings); } if (staticPolylineAnnotations() != null) { String[] polylineStringArray = new String[staticPolylineAnnotations().size()]; for (StaticPolylineAnnotation polyline : staticPolylineAnnotations()) { polylineStringArray[staticPolylineAnnotations().indexOf(polyline)] = polyline.url(); } annotations.addAll(Arrays.asList(polylineStringArray)); } if (geoJson() != null) { annotations.add(String.format(Locale.US, "geojson(%s)", geoJson().toJson())); } if (!annotations.isEmpty()) { urlBuilder.addPathSegment(TextUtils.join(",", annotations.toArray())); } urlBuilder.addPathSegment(cameraAuto() ? CAMERA_AUTO : generateLocationPathSegment()); if (beforeLayer() != null) { urlBuilder.addQueryParameter(BEFORE_LAYER, beforeLayer()); } if (!attribution()) { urlBuilder.addQueryParameter("attribution", "false"); } if (!logo()) { urlBuilder.addQueryParameter("logo", "false"); } // Has to be last segment in URL urlBuilder.addPathSegment(generateSizePathSegment()); return urlBuilder.build(); }
[ "public", "HttpUrl", "url", "(", ")", "{", "HttpUrl", ".", "Builder", "urlBuilder", "=", "HttpUrl", ".", "parse", "(", "baseUrl", "(", ")", ")", ".", "newBuilder", "(", ")", ".", "addPathSegment", "(", "\"styles\"", ")", ".", "addPathSegment", "(", "\"v1...
Returns the formatted URL string meant to be passed to your Http client for retrieval of the actual Mapbox Static Image. @return a {@link HttpUrl} which can be used for making the request for the image @since 3.0.0
[ "Returns", "the", "formatted", "URL", "string", "meant", "to", "be", "passed", "to", "your", "Http", "client", "for", "retrieval", "of", "the", "actual", "Mapbox", "Static", "Image", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/MapboxStaticMap.java#L95-L146
train
mapbox/mapbox-java
samples/src/main/java/com/mapbox/samples/BasicDirections.java
BasicDirections.simpleMapboxDirectionsRequest
private static void simpleMapboxDirectionsRequest() throws IOException { MapboxDirections.Builder builder = MapboxDirections.builder(); // 1. Pass in all the required information to get a simple directions route. builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN); builder.origin(Point.fromLngLat(-95.6332, 29.7890)); builder.destination(Point.fromLngLat(-95.3591, 29.7576)); // 2. That's it! Now execute the command and get the response. Response<DirectionsResponse> response = builder.build().executeCall(); // 3. Log information from the response System.out.printf("Check that the GET response is successful %b", response.isSuccessful()); System.out.printf("%nGet the first routes distance from origin to destination: %f", response.body().routes().get(0).distance()); }
java
private static void simpleMapboxDirectionsRequest() throws IOException { MapboxDirections.Builder builder = MapboxDirections.builder(); // 1. Pass in all the required information to get a simple directions route. builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN); builder.origin(Point.fromLngLat(-95.6332, 29.7890)); builder.destination(Point.fromLngLat(-95.3591, 29.7576)); // 2. That's it! Now execute the command and get the response. Response<DirectionsResponse> response = builder.build().executeCall(); // 3. Log information from the response System.out.printf("Check that the GET response is successful %b", response.isSuccessful()); System.out.printf("%nGet the first routes distance from origin to destination: %f", response.body().routes().get(0).distance()); }
[ "private", "static", "void", "simpleMapboxDirectionsRequest", "(", ")", "throws", "IOException", "{", "MapboxDirections", ".", "Builder", "builder", "=", "MapboxDirections", ".", "builder", "(", ")", ";", "// 1. Pass in all the required information to get a simple directions ...
Demonstrates how to make the most basic GET directions request. @throws IOException signals that an I/O exception of some sort has occurred
[ "Demonstrates", "how", "to", "make", "the", "most", "basic", "GET", "directions", "request", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/samples/src/main/java/com/mapbox/samples/BasicDirections.java#L31-L47
train
mapbox/mapbox-java
samples/src/main/java/com/mapbox/samples/BasicDirections.java
BasicDirections.asyncMapboxDirectionsRequest
private static void asyncMapboxDirectionsRequest() { // 1. Pass in all the required information to get a route. MapboxDirections request = MapboxDirections.builder() .accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN) .origin(Point.fromLngLat(-95.6332, 29.7890)) .destination(Point.fromLngLat(-95.3591, 29.7576)) .profile(DirectionsCriteria.PROFILE_CYCLING) .steps(true) .build(); // 2. Now request the route using a async call request.enqueueCall(new Callback<DirectionsResponse>() { @Override public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) { // 3. Log information from the response if (response.isSuccessful()) { System.out.printf("%nGet the street name of the first step along the route: %s", response.body().routes().get(0).legs().get(0).steps().get(0).name()); } } @Override public void onFailure(Call<DirectionsResponse> call, Throwable throwable) { System.err.println(throwable); } }); }
java
private static void asyncMapboxDirectionsRequest() { // 1. Pass in all the required information to get a route. MapboxDirections request = MapboxDirections.builder() .accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN) .origin(Point.fromLngLat(-95.6332, 29.7890)) .destination(Point.fromLngLat(-95.3591, 29.7576)) .profile(DirectionsCriteria.PROFILE_CYCLING) .steps(true) .build(); // 2. Now request the route using a async call request.enqueueCall(new Callback<DirectionsResponse>() { @Override public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) { // 3. Log information from the response if (response.isSuccessful()) { System.out.printf("%nGet the street name of the first step along the route: %s", response.body().routes().get(0).legs().get(0).steps().get(0).name()); } } @Override public void onFailure(Call<DirectionsResponse> call, Throwable throwable) { System.err.println(throwable); } }); }
[ "private", "static", "void", "asyncMapboxDirectionsRequest", "(", ")", "{", "// 1. Pass in all the required information to get a route.", "MapboxDirections", "request", "=", "MapboxDirections", ".", "builder", "(", ")", ".", "accessToken", "(", "BuildConfig", ".", "MAPBOX_A...
Demonstrates how to make an asynchronous directions request.
[ "Demonstrates", "how", "to", "make", "an", "asynchronous", "directions", "request", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/samples/src/main/java/com/mapbox/samples/BasicDirections.java#L73-L100
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Feature.java
Feature.getStringProperty
public String getStringProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsString(); }
java
public String getStringProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsString(); }
[ "public", "String", "getStringProperty", "(", "String", "key", ")", "{", "JsonElement", "propertyKey", "=", "properties", "(", ")", ".", "get", "(", "key", ")", ";", "return", "propertyKey", "==", "null", "?", "null", ":", "propertyKey", ".", "getAsString", ...
Convenience method to get a String member. @param key name of the member @return the value of the member, null if it doesn't exist @since 1.0.0
[ "Convenience", "method", "to", "get", "a", "String", "member", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Feature.java#L362-L365
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Feature.java
Feature.getNumberProperty
public Number getNumberProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsNumber(); }
java
public Number getNumberProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsNumber(); }
[ "public", "Number", "getNumberProperty", "(", "String", "key", ")", "{", "JsonElement", "propertyKey", "=", "properties", "(", ")", ".", "get", "(", "key", ")", ";", "return", "propertyKey", "==", "null", "?", "null", ":", "propertyKey", ".", "getAsNumber", ...
Convenience method to get a Number member. @param key name of the member @return the value of the member, null if it doesn't exist @since 1.0.0
[ "Convenience", "method", "to", "get", "a", "Number", "member", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Feature.java#L374-L377
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Feature.java
Feature.getBooleanProperty
public Boolean getBooleanProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsBoolean(); }
java
public Boolean getBooleanProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsBoolean(); }
[ "public", "Boolean", "getBooleanProperty", "(", "String", "key", ")", "{", "JsonElement", "propertyKey", "=", "properties", "(", ")", ".", "get", "(", "key", ")", ";", "return", "propertyKey", "==", "null", "?", "null", ":", "propertyKey", ".", "getAsBoolean...
Convenience method to get a Boolean member. @param key name of the member @return the value of the member, null if it doesn't exist @since 1.0.0
[ "Convenience", "method", "to", "get", "a", "Boolean", "member", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Feature.java#L386-L389
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/Feature.java
Feature.getCharacterProperty
public Character getCharacterProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsCharacter(); }
java
public Character getCharacterProperty(String key) { JsonElement propertyKey = properties().get(key); return propertyKey == null ? null : propertyKey.getAsCharacter(); }
[ "public", "Character", "getCharacterProperty", "(", "String", "key", ")", "{", "JsonElement", "propertyKey", "=", "properties", "(", ")", ".", "get", "(", "key", ")", ";", "return", "propertyKey", "==", "null", "?", "null", ":", "propertyKey", ".", "getAsCha...
Convenience method to get a Character member. @param key name of the member @return the value of the member, null if it doesn't exist @since 1.0.0
[ "Convenience", "method", "to", "get", "a", "Character", "member", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/Feature.java#L398-L401
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/gson/PointSerializer.java
PointSerializer.serialize
@Override public JsonElement serialize(Point src, Type typeOfSrc, JsonSerializationContext context) { JsonArray rawCoordinates = new JsonArray(); // Unshift coordinates List<Double> unshiftedCoordinates = CoordinateShifterManager.getCoordinateShifter().unshiftPoint(src); rawCoordinates.add(new JsonPrimitive(GeoJsonUtils.trim(unshiftedCoordinates.get(0)))); rawCoordinates.add(new JsonPrimitive(GeoJsonUtils.trim(unshiftedCoordinates.get(1)))); // Includes altitude if (src.hasAltitude()) { rawCoordinates.add(new JsonPrimitive(unshiftedCoordinates.get(2))); } return rawCoordinates; }
java
@Override public JsonElement serialize(Point src, Type typeOfSrc, JsonSerializationContext context) { JsonArray rawCoordinates = new JsonArray(); // Unshift coordinates List<Double> unshiftedCoordinates = CoordinateShifterManager.getCoordinateShifter().unshiftPoint(src); rawCoordinates.add(new JsonPrimitive(GeoJsonUtils.trim(unshiftedCoordinates.get(0)))); rawCoordinates.add(new JsonPrimitive(GeoJsonUtils.trim(unshiftedCoordinates.get(1)))); // Includes altitude if (src.hasAltitude()) { rawCoordinates.add(new JsonPrimitive(unshiftedCoordinates.get(2))); } return rawCoordinates; }
[ "@", "Override", "public", "JsonElement", "serialize", "(", "Point", "src", ",", "Type", "typeOfSrc", ",", "JsonSerializationContext", "context", ")", "{", "JsonArray", "rawCoordinates", "=", "new", "JsonArray", "(", ")", ";", "// Unshift coordinates", "List", "<"...
Required to handle the special case where the altitude might be a Double.NaN, which isn't a valid double value as per JSON specification. @param src A {@link Point} defined by a longitude, latitude, and optionally, an altitude. @param typeOfSrc Common superinterface for all types in the Java. @param context Context for deserialization that is passed to a custom deserializer during invocation of its {@link com.google.gson.JsonDeserializationContext} method. @return a JsonArray containing the raw coordinates. @since 1.0.0
[ "Required", "to", "handle", "the", "special", "case", "where", "the", "altitude", "might", "be", "a", "Double", ".", "NaN", "which", "isn", "t", "a", "valid", "double", "value", "as", "per", "JSON", "specification", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/gson/PointSerializer.java#L47-L64
train
mapbox/mapbox-java
services-core/src/main/java/com/mapbox/core/utils/MapboxUtils.java
MapboxUtils.isAccessTokenValid
public static boolean isAccessTokenValid(String accessToken) { return !TextUtils.isEmpty(accessToken) && !(!accessToken.startsWith("pk.") && !accessToken.startsWith("sk.") && !accessToken.startsWith("tk.")); }
java
public static boolean isAccessTokenValid(String accessToken) { return !TextUtils.isEmpty(accessToken) && !(!accessToken.startsWith("pk.") && !accessToken.startsWith("sk.") && !accessToken.startsWith("tk.")); }
[ "public", "static", "boolean", "isAccessTokenValid", "(", "String", "accessToken", ")", "{", "return", "!", "TextUtils", ".", "isEmpty", "(", "accessToken", ")", "&&", "!", "(", "!", "accessToken", ".", "startsWith", "(", "\"pk.\"", ")", "&&", "!", "accessTo...
Checks that the provided access token is not empty or null, and that it starts with the right prefixes. Note that this method does not check Mapbox servers to verify that it actually belongs to an account. @param accessToken A Mapbox access token. @return true if the provided access token is valid, false otherwise. @since 1.0.0
[ "Checks", "that", "the", "provided", "access", "token", "is", "not", "empty", "or", "null", "and", "that", "it", "starts", "with", "the", "right", "prefixes", ".", "Note", "that", "this", "method", "does", "not", "check", "Mapbox", "servers", "to", "verify...
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-core/src/main/java/com/mapbox/core/utils/MapboxUtils.java#L23-L26
train
mapbox/mapbox-java
services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java
TurfAssertions.geojsonType
public static void geojsonType(GeoJson value, String type, String name) { if (type == null || type.length() == 0 || name == null || name.length() == 0) { throw new TurfException("Type and name required"); } if (value == null || !value.type().equals(type)) { throw new TurfException("Invalid input to " + name + ": must be a " + type + ", given " + (value != null ? value.type() : " null")); } }
java
public static void geojsonType(GeoJson value, String type, String name) { if (type == null || type.length() == 0 || name == null || name.length() == 0) { throw new TurfException("Type and name required"); } if (value == null || !value.type().equals(type)) { throw new TurfException("Invalid input to " + name + ": must be a " + type + ", given " + (value != null ? value.type() : " null")); } }
[ "public", "static", "void", "geojsonType", "(", "GeoJson", "value", ",", "String", "type", ",", "String", "name", ")", "{", "if", "(", "type", "==", "null", "||", "type", ".", "length", "(", ")", "==", "0", "||", "name", "==", "null", "||", "name", ...
Enforce expectations about types of GeoJson objects for Turf. @param value any GeoJson object @param type expected GeoJson type @param name name of calling function @see <a href="http://turfjs.org/docs/#geojsontype">Turf geojsonType documentation</a> @since 1.2.0
[ "Enforce", "expectations", "about", "types", "of", "GeoJson", "objects", "for", "Turf", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java#L44-L52
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/BoundingBox.java
BoundingBox.fromCoordinates
@Deprecated public static BoundingBox fromCoordinates( @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double west, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double south, @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double east, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double north) { return fromLngLats(west, south, east, north); }
java
@Deprecated public static BoundingBox fromCoordinates( @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double west, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double south, @FloatRange(from = MIN_LONGITUDE, to = GeoJsonConstants.MAX_LONGITUDE) double east, @FloatRange(from = MIN_LATITUDE, to = GeoJsonConstants.MAX_LATITUDE) double north) { return fromLngLats(west, south, east, north); }
[ "@", "Deprecated", "public", "static", "BoundingBox", "fromCoordinates", "(", "@", "FloatRange", "(", "from", "=", "MIN_LONGITUDE", ",", "to", "=", "GeoJsonConstants", ".", "MAX_LONGITUDE", ")", "double", "west", ",", "@", "FloatRange", "(", "from", "=", "MIN_...
Define a new instance of this class by passing in four coordinates in the same order they would appear in the serialized GeoJson form. Limits are placed on the minimum and maximum coordinate values which can exist and comply with the GeoJson spec. @param west the left side of the bounding box when the map is facing due north @param south the bottom side of the bounding box when the map is facing due north @param east the right side of the bounding box when the map is facing due north @param north the top side of the bounding box when the map is facing due north @return a new instance of this class defined by the provided coordinates @since 3.0.0 @deprecated As of 3.1.0, use {@link #fromLngLats} instead.
[ "Define", "a", "new", "instance", "of", "this", "class", "by", "passing", "in", "four", "coordinates", "in", "the", "same", "order", "they", "would", "appear", "in", "the", "serialized", "GeoJson", "form", ".", "Limits", "are", "placed", "on", "the", "mini...
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/BoundingBox.java#L83-L90
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
PolylineUtils.encode
@NonNull public static String encode(@NonNull final List<Point> path, int precision) { long lastLat = 0; long lastLng = 0; final StringBuilder result = new StringBuilder(); // OSRM uses precision=6, the default Polyline spec divides by 1E5, capping at precision=5 double factor = Math.pow(10, precision); for (final Point point : path) { long lat = Math.round(point.latitude() * factor); long lng = Math.round(point.longitude() * factor); long varLat = lat - lastLat; long varLng = lng - lastLng; encode(varLat, result); encode(varLng, result); lastLat = lat; lastLng = lng; } return result.toString(); }
java
@NonNull public static String encode(@NonNull final List<Point> path, int precision) { long lastLat = 0; long lastLng = 0; final StringBuilder result = new StringBuilder(); // OSRM uses precision=6, the default Polyline spec divides by 1E5, capping at precision=5 double factor = Math.pow(10, precision); for (final Point point : path) { long lat = Math.round(point.latitude() * factor); long lng = Math.round(point.longitude() * factor); long varLat = lat - lastLat; long varLng = lng - lastLng; encode(varLat, result); encode(varLng, result); lastLat = lat; lastLng = lng; } return result.toString(); }
[ "@", "NonNull", "public", "static", "String", "encode", "(", "@", "NonNull", "final", "List", "<", "Point", ">", "path", ",", "int", "precision", ")", "{", "long", "lastLat", "=", "0", ";", "long", "lastLng", "=", "0", ";", "final", "StringBuilder", "r...
Encodes a sequence of Points into an encoded path string. @param path list of {@link Point}s making up the line @param precision OSRMv4 uses 6, OSRMv5 and Google uses 5 @return a String representing a path string @since 1.0.0
[ "Encodes", "a", "sequence", "of", "Points", "into", "an", "encoded", "path", "string", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java#L88-L112
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
PolylineUtils.getSqDist
private static double getSqDist(Point p1, Point p2) { double dx = p1.longitude() - p2.longitude(); double dy = p1.latitude() - p2.latitude(); return dx * dx + dy * dy; }
java
private static double getSqDist(Point p1, Point p2) { double dx = p1.longitude() - p2.longitude(); double dy = p1.latitude() - p2.latitude(); return dx * dx + dy * dy; }
[ "private", "static", "double", "getSqDist", "(", "Point", "p1", ",", "Point", "p2", ")", "{", "double", "dx", "=", "p1", ".", "longitude", "(", ")", "-", "p2", ".", "longitude", "(", ")", ";", "double", "dy", "=", "p1", ".", "latitude", "(", ")", ...
Square distance between 2 points. @param p1 first {@link Point} @param p2 second Point @return square of the distance between two input points
[ "Square", "distance", "between", "2", "points", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java#L209-L213
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
PolylineUtils.getSqSegDist
private static double getSqSegDist(Point point, Point p1, Point p2) { double horizontal = p1.longitude(); double vertical = p1.latitude(); double diffHorizontal = p2.longitude() - horizontal; double diffVertical = p2.latitude() - vertical; if (diffHorizontal != 0 || diffVertical != 0) { double total = ((point.longitude() - horizontal) * diffHorizontal + (point.latitude() - vertical) * diffVertical) / (diffHorizontal * diffHorizontal + diffVertical * diffVertical); if (total > 1) { horizontal = p2.longitude(); vertical = p2.latitude(); } else if (total > 0) { horizontal += diffHorizontal * total; vertical += diffVertical * total; } } diffHorizontal = point.longitude() - horizontal; diffVertical = point.latitude() - vertical; return diffHorizontal * diffHorizontal + diffVertical * diffVertical; }
java
private static double getSqSegDist(Point point, Point p1, Point p2) { double horizontal = p1.longitude(); double vertical = p1.latitude(); double diffHorizontal = p2.longitude() - horizontal; double diffVertical = p2.latitude() - vertical; if (diffHorizontal != 0 || diffVertical != 0) { double total = ((point.longitude() - horizontal) * diffHorizontal + (point.latitude() - vertical) * diffVertical) / (diffHorizontal * diffHorizontal + diffVertical * diffVertical); if (total > 1) { horizontal = p2.longitude(); vertical = p2.latitude(); } else if (total > 0) { horizontal += diffHorizontal * total; vertical += diffVertical * total; } } diffHorizontal = point.longitude() - horizontal; diffVertical = point.latitude() - vertical; return diffHorizontal * diffHorizontal + diffVertical * diffVertical; }
[ "private", "static", "double", "getSqSegDist", "(", "Point", "point", ",", "Point", "p1", ",", "Point", "p2", ")", "{", "double", "horizontal", "=", "p1", ".", "longitude", "(", ")", ";", "double", "vertical", "=", "p1", ".", "latitude", "(", ")", ";",...
Square distance from a point to a segment. @param point {@link Point} whose distance from segment needs to be determined @param p1,p2 points defining the segment @return square of the distance between first input point and segment defined by other two input points
[ "Square", "distance", "from", "a", "point", "to", "a", "segment", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java#L223-L247
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
PolylineUtils.simplifyRadialDist
private static List<Point> simplifyRadialDist(List<Point> points, double sqTolerance) { Point prevPoint = points.get(0); ArrayList<Point> newPoints = new ArrayList<>(); newPoints.add(prevPoint); Point point = null; for (int i = 1, len = points.size(); i < len; i++) { point = points.get(i); if (getSqDist(point, prevPoint) > sqTolerance) { newPoints.add(point); prevPoint = point; } } if (!prevPoint.equals(point)) { newPoints.add(point); } return newPoints; }
java
private static List<Point> simplifyRadialDist(List<Point> points, double sqTolerance) { Point prevPoint = points.get(0); ArrayList<Point> newPoints = new ArrayList<>(); newPoints.add(prevPoint); Point point = null; for (int i = 1, len = points.size(); i < len; i++) { point = points.get(i); if (getSqDist(point, prevPoint) > sqTolerance) { newPoints.add(point); prevPoint = point; } } if (!prevPoint.equals(point)) { newPoints.add(point); } return newPoints; }
[ "private", "static", "List", "<", "Point", ">", "simplifyRadialDist", "(", "List", "<", "Point", ">", "points", ",", "double", "sqTolerance", ")", "{", "Point", "prevPoint", "=", "points", ".", "get", "(", "0", ")", ";", "ArrayList", "<", "Point", ">", ...
Basic distance-based simplification. @param points a list of points to be simplified @param sqTolerance square of amount of simplification @return a list of simplified points
[ "Basic", "distance", "-", "based", "simplification", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java#L256-L275
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java
PolylineUtils.simplifyDouglasPeucker
private static List<Point> simplifyDouglasPeucker(List<Point> points, double sqTolerance) { int last = points.size() - 1; ArrayList<Point> simplified = new ArrayList<>(); simplified.add(points.get(0)); simplified.addAll(simplifyDpStep(points, 0, last, sqTolerance, simplified)); simplified.add(points.get(last)); return simplified; }
java
private static List<Point> simplifyDouglasPeucker(List<Point> points, double sqTolerance) { int last = points.size() - 1; ArrayList<Point> simplified = new ArrayList<>(); simplified.add(points.get(0)); simplified.addAll(simplifyDpStep(points, 0, last, sqTolerance, simplified)); simplified.add(points.get(last)); return simplified; }
[ "private", "static", "List", "<", "Point", ">", "simplifyDouglasPeucker", "(", "List", "<", "Point", ">", "points", ",", "double", "sqTolerance", ")", "{", "int", "last", "=", "points", ".", "size", "(", ")", "-", "1", ";", "ArrayList", "<", "Point", "...
Simplification using Ramer-Douglas-Peucker algorithm. @param points a list of points to be simplified @param sqTolerance square of amount of simplification @return a list of simplified points
[ "Simplification", "using", "Ramer", "-", "Douglas", "-", "Peucker", "algorithm", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java#L314-L321
train
mapbox/mapbox-java
services-geojson/src/main/java/com/mapbox/geojson/utils/GeoJsonUtils.java
GeoJsonUtils.trim
public static double trim(double value) { if (value > MAX_DOUBLE_TO_ROUND || value < -MAX_DOUBLE_TO_ROUND) { return value; } return Math.round(value * ROUND_PRECISION) / ROUND_PRECISION; }
java
public static double trim(double value) { if (value > MAX_DOUBLE_TO_ROUND || value < -MAX_DOUBLE_TO_ROUND) { return value; } return Math.round(value * ROUND_PRECISION) / ROUND_PRECISION; }
[ "public", "static", "double", "trim", "(", "double", "value", ")", "{", "if", "(", "value", ">", "MAX_DOUBLE_TO_ROUND", "||", "value", "<", "-", "MAX_DOUBLE_TO_ROUND", ")", "{", "return", "value", ";", "}", "return", "Math", ".", "round", "(", "value", "...
Trims a double value to have only 7 digits after period. @param value to be trimed @return trimmed value
[ "Trims", "a", "double", "value", "to", "have", "only", "7", "digits", "after", "period", "." ]
c0be138f462f91441388584c668f3760ba0e18e2
https://github.com/mapbox/mapbox-java/blob/c0be138f462f91441388584c668f3760ba0e18e2/services-geojson/src/main/java/com/mapbox/geojson/utils/GeoJsonUtils.java#L19-L24
train
jaredrummler/ColorPicker
library/src/main/java/com/jaredrummler/android/colorpicker/ColorPanelView.java
ColorPanelView.showHint
public void showHint() { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } StringBuilder hint = new StringBuilder("#"); if (Color.alpha(color) != 255) { hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH)); } else { hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH)); } Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); }
java
public void showHint() { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } StringBuilder hint = new StringBuilder("#"); if (Color.alpha(color) != 255) { hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH)); } else { hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH)); } Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); }
[ "public", "void", "showHint", "(", ")", "{", "final", "int", "[", "]", "screenPos", "=", "new", "int", "[", "2", "]", ";", "final", "Rect", "displayFrame", "=", "new", "Rect", "(", ")", ";", "getLocationOnScreen", "(", "screenPos", ")", ";", "getWindow...
Show a toast message with the hex color code below the view.
[ "Show", "a", "toast", "message", "with", "the", "hex", "color", "code", "below", "the", "view", "." ]
ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a
https://github.com/jaredrummler/ColorPicker/blob/ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPanelView.java#L278-L307
train
jaredrummler/ColorPicker
library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java
ColorPickerDialog.createPickerView
View createPickerView() { View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_color_picker, null); colorPicker = (ColorPickerView) contentView.findViewById(R.id.cpv_color_picker_view); ColorPanelView oldColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_old); newColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_new); ImageView arrowRight = (ImageView) contentView.findViewById(R.id.cpv_arrow_right); hexEditText = (EditText) contentView.findViewById(R.id.cpv_hex); try { final TypedValue value = new TypedValue(); TypedArray typedArray = getActivity().obtainStyledAttributes(value.data, new int[] { android.R.attr.textColorPrimary }); int arrowColor = typedArray.getColor(0, Color.BLACK); typedArray.recycle(); arrowRight.setColorFilter(arrowColor); } catch (Exception ignored) { } colorPicker.setAlphaSliderVisible(showAlphaSlider); oldColorPanel.setColor(getArguments().getInt(ARG_COLOR)); colorPicker.setColor(color, true); newColorPanel.setColor(color); setHex(color); if (!showAlphaSlider) { hexEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) }); } newColorPanel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (newColorPanel.getColor() == color) { onColorSelected(color); dismiss(); } } }); contentView.setOnTouchListener(onPickerTouchListener); colorPicker.setOnColorChangedListener(this); hexEditText.addTextChangedListener(this); hexEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(hexEditText, InputMethodManager.SHOW_IMPLICIT); } } }); return contentView; }
java
View createPickerView() { View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_color_picker, null); colorPicker = (ColorPickerView) contentView.findViewById(R.id.cpv_color_picker_view); ColorPanelView oldColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_old); newColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_new); ImageView arrowRight = (ImageView) contentView.findViewById(R.id.cpv_arrow_right); hexEditText = (EditText) contentView.findViewById(R.id.cpv_hex); try { final TypedValue value = new TypedValue(); TypedArray typedArray = getActivity().obtainStyledAttributes(value.data, new int[] { android.R.attr.textColorPrimary }); int arrowColor = typedArray.getColor(0, Color.BLACK); typedArray.recycle(); arrowRight.setColorFilter(arrowColor); } catch (Exception ignored) { } colorPicker.setAlphaSliderVisible(showAlphaSlider); oldColorPanel.setColor(getArguments().getInt(ARG_COLOR)); colorPicker.setColor(color, true); newColorPanel.setColor(color); setHex(color); if (!showAlphaSlider) { hexEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) }); } newColorPanel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (newColorPanel.getColor() == color) { onColorSelected(color); dismiss(); } } }); contentView.setOnTouchListener(onPickerTouchListener); colorPicker.setOnColorChangedListener(this); hexEditText.addTextChangedListener(this); hexEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(hexEditText, InputMethodManager.SHOW_IMPLICIT); } } }); return contentView; }
[ "View", "createPickerView", "(", ")", "{", "View", "contentView", "=", "View", ".", "inflate", "(", "getActivity", "(", ")", ",", "R", ".", "layout", ".", "cpv_dialog_color_picker", ",", "null", ")", ";", "colorPicker", "=", "(", "ColorPickerView", ")", "c...
region Custom Picker
[ "region", "Custom", "Picker" ]
ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a
https://github.com/jaredrummler/ColorPicker/blob/ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java#L275-L326
train
jaredrummler/ColorPicker
library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java
ColorPickerDialog.createPresetsView
View createPresetsView() { View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_presets, null); shadesLayout = (LinearLayout) contentView.findViewById(R.id.shades_layout); transparencySeekBar = (SeekBar) contentView.findViewById(R.id.transparency_seekbar); transparencyPercText = (TextView) contentView.findViewById(R.id.transparency_text); GridView gridView = (GridView) contentView.findViewById(R.id.gridView); loadPresets(); if (showColorShades) { createColorShades(color); } else { shadesLayout.setVisibility(View.GONE); contentView.findViewById(R.id.shades_divider).setVisibility(View.GONE); } adapter = new ColorPaletteAdapter(new ColorPaletteAdapter.OnColorSelectedListener() { @Override public void onColorSelected(int newColor) { if (color == newColor) { // Double tab selects the color ColorPickerDialog.this.onColorSelected(color); dismiss(); return; } color = newColor; if (showColorShades) { createColorShades(color); } } }, presets, getSelectedItemPosition(), colorShape); gridView.setAdapter(adapter); if (showAlphaSlider) { setupTransparency(); } else { contentView.findViewById(R.id.transparency_layout).setVisibility(View.GONE); contentView.findViewById(R.id.transparency_title).setVisibility(View.GONE); } return contentView; }
java
View createPresetsView() { View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_presets, null); shadesLayout = (LinearLayout) contentView.findViewById(R.id.shades_layout); transparencySeekBar = (SeekBar) contentView.findViewById(R.id.transparency_seekbar); transparencyPercText = (TextView) contentView.findViewById(R.id.transparency_text); GridView gridView = (GridView) contentView.findViewById(R.id.gridView); loadPresets(); if (showColorShades) { createColorShades(color); } else { shadesLayout.setVisibility(View.GONE); contentView.findViewById(R.id.shades_divider).setVisibility(View.GONE); } adapter = new ColorPaletteAdapter(new ColorPaletteAdapter.OnColorSelectedListener() { @Override public void onColorSelected(int newColor) { if (color == newColor) { // Double tab selects the color ColorPickerDialog.this.onColorSelected(color); dismiss(); return; } color = newColor; if (showColorShades) { createColorShades(color); } } }, presets, getSelectedItemPosition(), colorShape); gridView.setAdapter(adapter); if (showAlphaSlider) { setupTransparency(); } else { contentView.findViewById(R.id.transparency_layout).setVisibility(View.GONE); contentView.findViewById(R.id.transparency_title).setVisibility(View.GONE); } return contentView; }
[ "View", "createPresetsView", "(", ")", "{", "View", "contentView", "=", "View", ".", "inflate", "(", "getActivity", "(", ")", ",", "R", ".", "layout", ".", "cpv_dialog_presets", ",", "null", ")", ";", "shadesLayout", "=", "(", "LinearLayout", ")", "content...
region Presets Picker
[ "region", "Presets", "Picker" ]
ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a
https://github.com/jaredrummler/ColorPicker/blob/ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java#L428-L469
train
jaredrummler/ColorPicker
library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerView.java
ColorPickerView.setColor
public void setColor(int color, boolean callback) { int alpha = Color.alpha(color); int red = Color.red(color); int blue = Color.blue(color); int green = Color.green(color); float[] hsv = new float[3]; Color.RGBToHSV(red, green, blue, hsv); this.alpha = alpha; hue = hsv[0]; sat = hsv[1]; val = hsv[2]; if (callback && onColorChangedListener != null) { onColorChangedListener.onColorChanged(Color.HSVToColor(this.alpha, new float[] { hue, sat, val })); } invalidate(); }
java
public void setColor(int color, boolean callback) { int alpha = Color.alpha(color); int red = Color.red(color); int blue = Color.blue(color); int green = Color.green(color); float[] hsv = new float[3]; Color.RGBToHSV(red, green, blue, hsv); this.alpha = alpha; hue = hsv[0]; sat = hsv[1]; val = hsv[2]; if (callback && onColorChangedListener != null) { onColorChangedListener.onColorChanged(Color.HSVToColor(this.alpha, new float[] { hue, sat, val })); } invalidate(); }
[ "public", "void", "setColor", "(", "int", "color", ",", "boolean", "callback", ")", "{", "int", "alpha", "=", "Color", ".", "alpha", "(", "color", ")", ";", "int", "red", "=", "Color", ".", "red", "(", "color", ")", ";", "int", "blue", "=", "Color"...
Set the color this view should show. @param color The color that should be selected. #argb @param callback If you want to get a callback to your OnColorChangedListener.
[ "Set", "the", "color", "this", "view", "should", "show", "." ]
ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a
https://github.com/jaredrummler/ColorPicker/blob/ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerView.java#L835-L856
train
jaredrummler/ColorPicker
library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerView.java
ColorPickerView.setAlphaSliderVisible
public void setAlphaSliderVisible(boolean visible) { if (showAlphaPanel != visible) { showAlphaPanel = visible; /* * Force recreation. */ valShader = null; satShader = null; alphaShader = null; hueBackgroundCache = null; satValBackgroundCache = null; requestLayout(); } }
java
public void setAlphaSliderVisible(boolean visible) { if (showAlphaPanel != visible) { showAlphaPanel = visible; /* * Force recreation. */ valShader = null; satShader = null; alphaShader = null; hueBackgroundCache = null; satValBackgroundCache = null; requestLayout(); } }
[ "public", "void", "setAlphaSliderVisible", "(", "boolean", "visible", ")", "{", "if", "(", "showAlphaPanel", "!=", "visible", ")", "{", "showAlphaPanel", "=", "visible", ";", "/*\n * Force recreation.\n */", "valShader", "=", "null", ";", "satShader", "=...
Set if the user is allowed to adjust the alpha panel. Default is false. If it is set to false no alpha will be set. @param visible {@code true} to show the alpha slider
[ "Set", "if", "the", "user", "is", "allowed", "to", "adjust", "the", "alpha", "panel", ".", "Default", "is", "false", ".", "If", "it", "is", "set", "to", "false", "no", "alpha", "will", "be", "set", "." ]
ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a
https://github.com/jaredrummler/ColorPicker/blob/ab06208ddcfbd7ab1b1fde140f10b3ca06d8175a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerView.java#L864-L879
train
HaraldWalker/user-agent-utils
src/main/java/eu/bitwalker/useragentutils/UserAgent.java
UserAgent.valueOf
public static UserAgent valueOf(int id) { OperatingSystem operatingSystem = OperatingSystem.valueOf((short) (id >> 16)); Browser browser = Browser.valueOf( (short) (id & 0x0FFFF)); return new UserAgent(operatingSystem,browser); }
java
public static UserAgent valueOf(int id) { OperatingSystem operatingSystem = OperatingSystem.valueOf((short) (id >> 16)); Browser browser = Browser.valueOf( (short) (id & 0x0FFFF)); return new UserAgent(operatingSystem,browser); }
[ "public", "static", "UserAgent", "valueOf", "(", "int", "id", ")", "{", "OperatingSystem", "operatingSystem", "=", "OperatingSystem", ".", "valueOf", "(", "(", "short", ")", "(", "id", ">>", "16", ")", ")", ";", "Browser", "browser", "=", "Browser", ".", ...
Returns UserAgent based on specified unique id @param id Id value of the user agent. @return UserAgent
[ "Returns", "UserAgent", "based", "on", "specified", "unique", "id" ]
7f954514298f76afff8a75723bc25205bfe30d1b
https://github.com/HaraldWalker/user-agent-utils/blob/7f954514298f76afff8a75723bc25205bfe30d1b/src/main/java/eu/bitwalker/useragentutils/UserAgent.java#L167-L172
train
HaraldWalker/user-agent-utils
src/main/java/eu/bitwalker/useragentutils/UserAgent.java
UserAgent.valueOf
public static UserAgent valueOf(String name) { if (name == null) throw new NullPointerException("Name is null"); String[] elements = name.split("-"); if (elements.length == 2) { OperatingSystem operatingSystem = OperatingSystem.valueOf(elements[0]); Browser browser = Browser.valueOf(elements[1]); return new UserAgent(operatingSystem,browser); } throw new IllegalArgumentException( "Invalid string for userAgent " + name); }
java
public static UserAgent valueOf(String name) { if (name == null) throw new NullPointerException("Name is null"); String[] elements = name.split("-"); if (elements.length == 2) { OperatingSystem operatingSystem = OperatingSystem.valueOf(elements[0]); Browser browser = Browser.valueOf(elements[1]); return new UserAgent(operatingSystem,browser); } throw new IllegalArgumentException( "Invalid string for userAgent " + name); }
[ "public", "static", "UserAgent", "valueOf", "(", "String", "name", ")", "{", "if", "(", "name", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"Name is null\"", ")", ";", "String", "[", "]", "elements", "=", "name", ".", "split", "(", ...
Returns UserAgent based on combined string representation @param name Name of the user agent. @return UserAgent
[ "Returns", "UserAgent", "based", "on", "combined", "string", "representation" ]
7f954514298f76afff8a75723bc25205bfe30d1b
https://github.com/HaraldWalker/user-agent-utils/blob/7f954514298f76afff8a75723bc25205bfe30d1b/src/main/java/eu/bitwalker/useragentutils/UserAgent.java#L179-L195
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java
ByteBufferInput.reset
public ByteBuffer reset(ByteBuffer input) { ByteBuffer old = this.input; this.input = checkNotNull(input, "input ByteBuffer is null").slice(); isRead = false; return old; }
java
public ByteBuffer reset(ByteBuffer input) { ByteBuffer old = this.input; this.input = checkNotNull(input, "input ByteBuffer is null").slice(); isRead = false; return old; }
[ "public", "ByteBuffer", "reset", "(", "ByteBuffer", "input", ")", "{", "ByteBuffer", "old", "=", "this", ".", "input", ";", "this", ".", "input", "=", "checkNotNull", "(", "input", ",", "\"input ByteBuffer is null\"", ")", ".", "slice", "(", ")", ";", "isR...
Reset buffer. @param input new buffer @return the old buffer
[ "Reset", "buffer", "." ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java#L42-L48
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java
MessagePacker.packString
public MessagePacker packString(String s) throws IOException { if (s.length() <= 0) { packRawStringHeader(0); return this; } else if (CORRUPTED_CHARSET_ENCODER || s.length() < smallStringOptimizationThreshold) { // Using String.getBytes is generally faster for small strings. // Also, when running on a platform that has a corrupted CharsetEncoder (i.e. Android 4.x), avoid using it. packStringWithGetBytes(s); return this; } else if (s.length() < (1 << 8)) { // ensure capacity for 2-byte raw string header + the maximum string size (+ 1 byte for falback code) ensureCapacity(2 + s.length() * UTF_8_MAX_CHAR_SIZE + 1); // keep 2-byte header region and write raw string int written = encodeStringToBufferAt(position + 2, s); if (written >= 0) { if (str8FormatSupport && written < (1 << 8)) { buffer.putByte(position++, STR8); buffer.putByte(position++, (byte) written); position += written; } else { if (written >= (1 << 16)) { // this must not happen because s.length() is less than 2^8 and (2^8) * UTF_8_MAX_CHAR_SIZE is less than 2^16 throw new IllegalArgumentException("Unexpected UTF-8 encoder state"); } // move 1 byte backward to expand 3-byte header region to 3 bytes buffer.putMessageBuffer(position + 3, buffer, position + 2, written); // write 3-byte header buffer.putByte(position++, STR16); buffer.putShort(position, (short) written); position += 2; position += written; } return this; } } else if (s.length() < (1 << 16)) { // ensure capacity for 3-byte raw string header + the maximum string size (+ 2 bytes for fallback code) ensureCapacity(3 + s.length() * UTF_8_MAX_CHAR_SIZE + 2); // keep 3-byte header region and write raw string int written = encodeStringToBufferAt(position + 3, s); if (written >= 0) { if (written < (1 << 16)) { buffer.putByte(position++, STR16); buffer.putShort(position, (short) written); position += 2; position += written; } else { if (written >= (1L << 32)) { // this check does nothing because (1L << 32) is larger than Integer.MAX_VALUE // this must not happen because s.length() is less than 2^16 and (2^16) * UTF_8_MAX_CHAR_SIZE is less than 2^32 throw new IllegalArgumentException("Unexpected UTF-8 encoder state"); } // move 2 bytes backward to expand 3-byte header region to 5 bytes buffer.putMessageBuffer(position + 5, buffer, position + 3, written); // write 3-byte header header buffer.putByte(position++, STR32); buffer.putInt(position, written); position += 4; position += written; } return this; } } // Here doesn't use above optimized code for s.length() < (1 << 32) so that // ensureCapacity is not called with an integer larger than (3 + ((1 << 16) * UTF_8_MAX_CHAR_SIZE) + 2). // This makes it sure that MessageBufferOutput.next won't be called a size larger than // 384KB, which is OK size to keep in memory. // fallback packStringWithGetBytes(s); return this; }
java
public MessagePacker packString(String s) throws IOException { if (s.length() <= 0) { packRawStringHeader(0); return this; } else if (CORRUPTED_CHARSET_ENCODER || s.length() < smallStringOptimizationThreshold) { // Using String.getBytes is generally faster for small strings. // Also, when running on a platform that has a corrupted CharsetEncoder (i.e. Android 4.x), avoid using it. packStringWithGetBytes(s); return this; } else if (s.length() < (1 << 8)) { // ensure capacity for 2-byte raw string header + the maximum string size (+ 1 byte for falback code) ensureCapacity(2 + s.length() * UTF_8_MAX_CHAR_SIZE + 1); // keep 2-byte header region and write raw string int written = encodeStringToBufferAt(position + 2, s); if (written >= 0) { if (str8FormatSupport && written < (1 << 8)) { buffer.putByte(position++, STR8); buffer.putByte(position++, (byte) written); position += written; } else { if (written >= (1 << 16)) { // this must not happen because s.length() is less than 2^8 and (2^8) * UTF_8_MAX_CHAR_SIZE is less than 2^16 throw new IllegalArgumentException("Unexpected UTF-8 encoder state"); } // move 1 byte backward to expand 3-byte header region to 3 bytes buffer.putMessageBuffer(position + 3, buffer, position + 2, written); // write 3-byte header buffer.putByte(position++, STR16); buffer.putShort(position, (short) written); position += 2; position += written; } return this; } } else if (s.length() < (1 << 16)) { // ensure capacity for 3-byte raw string header + the maximum string size (+ 2 bytes for fallback code) ensureCapacity(3 + s.length() * UTF_8_MAX_CHAR_SIZE + 2); // keep 3-byte header region and write raw string int written = encodeStringToBufferAt(position + 3, s); if (written >= 0) { if (written < (1 << 16)) { buffer.putByte(position++, STR16); buffer.putShort(position, (short) written); position += 2; position += written; } else { if (written >= (1L << 32)) { // this check does nothing because (1L << 32) is larger than Integer.MAX_VALUE // this must not happen because s.length() is less than 2^16 and (2^16) * UTF_8_MAX_CHAR_SIZE is less than 2^32 throw new IllegalArgumentException("Unexpected UTF-8 encoder state"); } // move 2 bytes backward to expand 3-byte header region to 5 bytes buffer.putMessageBuffer(position + 5, buffer, position + 3, written); // write 3-byte header header buffer.putByte(position++, STR32); buffer.putInt(position, written); position += 4; position += written; } return this; } } // Here doesn't use above optimized code for s.length() < (1 << 32) so that // ensureCapacity is not called with an integer larger than (3 + ((1 << 16) * UTF_8_MAX_CHAR_SIZE) + 2). // This makes it sure that MessageBufferOutput.next won't be called a size larger than // 384KB, which is OK size to keep in memory. // fallback packStringWithGetBytes(s); return this; }
[ "public", "MessagePacker", "packString", "(", "String", "s", ")", "throws", "IOException", "{", "if", "(", "s", ".", "length", "(", ")", "<=", "0", ")", "{", "packRawStringHeader", "(", "0", ")", ";", "return", "this", ";", "}", "else", "if", "(", "C...
Writes a String vlaue in UTF-8 encoding. <p> This method writes a UTF-8 string using the smallest format from the str format family by default. If {@link MessagePack.PackerConfig#withStr8FormatSupport(boolean)} is set to false, smallest format from the str format family excepting str8 format. @param s the string to be written @return this @throws IOException when underlying output throws IOException
[ "Writes", "a", "String", "vlaue", "in", "UTF", "-", "8", "encoding", "." ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java#L722-L799
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
MessageBuffer.newMessageBuffer
private static MessageBuffer newMessageBuffer(byte[] arr, int off, int len) { checkNotNull(arr); if (mbArrConstructor != null) { return newInstance(mbArrConstructor, arr, off, len); } return new MessageBuffer(arr, off, len); }
java
private static MessageBuffer newMessageBuffer(byte[] arr, int off, int len) { checkNotNull(arr); if (mbArrConstructor != null) { return newInstance(mbArrConstructor, arr, off, len); } return new MessageBuffer(arr, off, len); }
[ "private", "static", "MessageBuffer", "newMessageBuffer", "(", "byte", "[", "]", "arr", ",", "int", "off", ",", "int", "len", ")", "{", "checkNotNull", "(", "arr", ")", ";", "if", "(", "mbArrConstructor", "!=", "null", ")", "{", "return", "newInstance", ...
Creates a new MessageBuffer instance backed by a java heap array @param arr @return
[ "Creates", "a", "new", "MessageBuffer", "instance", "backed", "by", "a", "java", "heap", "array" ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java#L273-L280
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
MessageBuffer.newMessageBuffer
private static MessageBuffer newMessageBuffer(ByteBuffer bb) { checkNotNull(bb); if (mbBBConstructor != null) { return newInstance(mbBBConstructor, bb); } return new MessageBuffer(bb); }
java
private static MessageBuffer newMessageBuffer(ByteBuffer bb) { checkNotNull(bb); if (mbBBConstructor != null) { return newInstance(mbBBConstructor, bb); } return new MessageBuffer(bb); }
[ "private", "static", "MessageBuffer", "newMessageBuffer", "(", "ByteBuffer", "bb", ")", "{", "checkNotNull", "(", "bb", ")", ";", "if", "(", "mbBBConstructor", "!=", "null", ")", "{", "return", "newInstance", "(", "mbBBConstructor", ",", "bb", ")", ";", "}",...
Creates a new MessageBuffer instance backed by ByteBuffer @param bb @return
[ "Creates", "a", "new", "MessageBuffer", "instance", "backed", "by", "ByteBuffer" ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java#L288-L295
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
MessageBuffer.newInstance
private static MessageBuffer newInstance(Constructor<?> constructor, Object... args) { try { // We need to use reflection to create MessageBuffer instances in order to prevent TypeProfile generation for getInt method. TypeProfile will be // generated to resolve one of the method references when two or more classes overrides the method. return (MessageBuffer) constructor.newInstance(args); } catch (InstantiationException e) { // should never happen throw new IllegalStateException(e); } catch (IllegalAccessException e) { // should never happen unless security manager restricts this reflection throw new IllegalStateException(e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { // underlying constructor may throw RuntimeException throw (RuntimeException) e.getCause(); } else if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } // should never happen throw new IllegalStateException(e.getCause()); } }
java
private static MessageBuffer newInstance(Constructor<?> constructor, Object... args) { try { // We need to use reflection to create MessageBuffer instances in order to prevent TypeProfile generation for getInt method. TypeProfile will be // generated to resolve one of the method references when two or more classes overrides the method. return (MessageBuffer) constructor.newInstance(args); } catch (InstantiationException e) { // should never happen throw new IllegalStateException(e); } catch (IllegalAccessException e) { // should never happen unless security manager restricts this reflection throw new IllegalStateException(e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { // underlying constructor may throw RuntimeException throw (RuntimeException) e.getCause(); } else if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } // should never happen throw new IllegalStateException(e.getCause()); } }
[ "private", "static", "MessageBuffer", "newInstance", "(", "Constructor", "<", "?", ">", "constructor", ",", "Object", "...", "args", ")", "{", "try", "{", "// We need to use reflection to create MessageBuffer instances in order to prevent TypeProfile generation for getInt method....
Creates a new MessageBuffer instance @param constructor A MessageBuffer constructor @return new MessageBuffer instance
[ "Creates", "a", "new", "MessageBuffer", "instance" ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java#L303-L329
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
MessageBuffer.getInt
public int getInt(int index) { // Reading little-endian value int i = unsafe.getInt(base, address + index); // Reversing the endian return Integer.reverseBytes(i); }
java
public int getInt(int index) { // Reading little-endian value int i = unsafe.getInt(base, address + index); // Reversing the endian return Integer.reverseBytes(i); }
[ "public", "int", "getInt", "(", "int", "index", ")", "{", "// Reading little-endian value", "int", "i", "=", "unsafe", ".", "getInt", "(", "base", ",", "address", "+", "index", ")", ";", "// Reversing the endian", "return", "Integer", ".", "reverseBytes", "(",...
Read a big-endian int value at the specified index @param index @return
[ "Read", "a", "big", "-", "endian", "int", "value", "at", "the", "specified", "index" ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java#L443-L449
train
msgpack/msgpack-java
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
MessageBuffer.putInt
public void putInt(int index, int v) { // Reversing the endian v = Integer.reverseBytes(v); unsafe.putInt(base, address + index, v); }
java
public void putInt(int index, int v) { // Reversing the endian v = Integer.reverseBytes(v); unsafe.putInt(base, address + index, v); }
[ "public", "void", "putInt", "(", "int", "index", ",", "int", "v", ")", "{", "// Reversing the endian", "v", "=", "Integer", ".", "reverseBytes", "(", "v", ")", ";", "unsafe", ".", "putInt", "(", "base", ",", "address", "+", "index", ",", "v", ")", ";...
Write a big-endian integer value to the memory @param index @param v
[ "Write", "a", "big", "-", "endian", "integer", "value", "to", "the", "memory" ]
16e370e348215a72a14c210b42d448d513aee015
https://github.com/msgpack/msgpack-java/blob/16e370e348215a72a14c210b42d448d513aee015/msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java#L503-L508
train