code
stringlengths
73
34.1k
label
stringclasses
1 value
public void drawNodeWithTransforms(final Context2D context) { context.save(); context.transform(m_ltog); m_prim.drawWithTransforms(context, getNodeParentsAlpha(m_prim.asNode()), null); context.restore(); }
java
private final double getNodeParentsAlpha(Node<?> node) { double alpha = 1; node = node.getParent(); while (null != node) { alpha = alpha * node.getAttributes().getAlpha(); node = node.getParent(); if ((null != node) && (node.getNodeType() == No...
java
public void dragUpdate(final INodeXYEvent event) { m_evtx = event.getX(); m_evty = event.getY(); m_dstx = m_evtx - m_begx; m_dsty = m_evty - m_begy; final Point2D p2 = new Point2D(0, 0); m_gtol.transform(new Point2D(m_dstx, m_dsty), p2); m_lclp.setX(p2.g...
java
@Override protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) { final double w = attr.getWidth(); final double h = attr.getHeight(); final double r = attr.getCornerRadius(); if ((w > 0) && (h > 0)) { context.beginPa...
java
public void marshal(File file, final List<RouteDefinition> routeDefinitionList) throws Exception { marshal(file, new Model2Model() { @Override public XmlModel transform(XmlModel model) { copyRoutesToElement(routeDefinitionList, model.getContextElement()); ...
java
public void marshalToDoc(XmlModel model) throws JAXBException { Marshaller marshaller = jaxbContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, java.lang.Boolean.TRUE); try { marshaller.setProperty("com.sun.xml.bind.indentString", " "); } c...
java
public static boolean isSpecialColorName(final String colorName) { for (final String name : SPECIAL_COLOR_NAMES) { if (name.equalsIgnoreCase(colorName)) { return true; } } return false; }
java
@Override public C setLocation(final Point2D p) { setX(p.getX()); setY(p.getY()); return cast(); }
java
@Override public C setScale(final double x, final double y) { getAttributes().setScale(x, y); return cast(); }
java
@Override public C setShear(final double x, final double y) { getAttributes().setShear(x, y); return cast(); }
java
@Override public C setOffset(final double x, final double y) { getAttributes().setOffset(x, y); return cast(); }
java
@Override public void attachToLayerColorMap() { final Layer layer = getLayer(); if (null != layer) { final NFastArrayList<T> list = getChildNodes(); if (null != list) { final int size = list.size(); for (int i = 0; i ...
java
private Node insertEndpointBefore(Node camel) { // if there is endpoints then the cut-off is after the last Node endpoint = null; for (int i = 0; i < camel.getChildNodes().getLength(); i++) { Node found = camel.getChildNodes().item(i); String name = found.getNodeName(); ...
java
public static InputStream documentToPrettyInputStream(Node document) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(document); Result outputTarget = new StreamResult(outputStream); Transformer transformer = Transform...
java
public static String nodeToString(Node document) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(document); Result outputTarget = new StreamResult(outputStream); Transformer transformer = TransformerFactory.newInstanc...
java
@Override protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) { final Point2DArray list = attr.getPoints(); if ((null != list) && (list.size() == 2)) { if (attr.isDefined(Attribute.DASH_ARRAY)) { if (false...
java
protected void drawDashedLine(final Context2D context, double x, double y, final double x2, final double y2, final double[] da, final double plus) { final int dashCount = da.length; final double dx = (x2 - x); final double dy = (y2 - y); final boolean xbig = (Math.abs(dx) > Math.a...
java
public static Object convertValueToSafeJson(Converter converter, Object value) { value = Proxies.unwrap(value); if (isJsonObject(value)) { return value; } if (converter != null) { // TODO converters ususally go from String -> CustomType? try { ...
java
protected static Object toSafeJsonValue(Object value) { if (value == null) { return null; } else { if (value instanceof Boolean || value instanceof String || value instanceof Number) { return value; } if (value instanceof Iterable) { ...
java
public static String generateJavaCore() throws Throwable { final String filePath; if (javaDumpMethod != null) { // If javaDumpMethod has been assigned a value then the JVM // appears to have the appropriate IBM Java classes to take // a java core. filePath = takeJavaCore(); } else { ...
java
private static String takeJavaCore() throws Throwable { logger.entry("takeJavaCore"); String filePath; try { javaDumpMethod.invoke(null); File javacoreFile = getLatestJavacoreFile(); filePath = javacoreFile.getAbsolutePath(); } catch (final InvocationTargetException invocationExcept...
java
public static final double distance(final Point2D a, final Point2D b) { return Point2DJSO.distance(a.getJSO(), b.getJSO()); }
java
public static final boolean collinear(final Point2D p1, final Point2D p2, final Point2D p3) { return Geometry.collinear(p1, p2, p3); }
java
public static final Point2D polar(final double radius, final double angle) { return new Point2D(radius * Math.cos(angle), radius * Math.sin(angle)); }
java
public static String dumpModelAsXml(Object definition, ClassLoader classLoader, boolean includeEndTag, int indent) throws JAXBException, XMLStreamException { JAXBContext jaxbContext = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGES, classLoader); StringWriter buffer = new StringWriter(); // we d...
java
private static String collapseNode(String xml, String name) { String answer = xml; Pattern pattern = Pattern.compile("<" + name + "(.*)></" + name + ">"); Matcher matcher = pattern.matcher(answer); if (matcher.find()) { answer = matcher.replaceAll("<" + name + "$1/>"); ...
java
public static Object xmlAsModel(Node node, ClassLoader classLoader) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(JAXB_CONTEXT_PACKAGES, classLoader); Unmarshaller marshaller = jaxbContext.createUnmarshaller(); Object answer = marshaller.unmarshal(node); retu...
java
public static void addPrivateKey(KeyStore keyStore, File pemKeyFile, char[] passwordChars, List<Certificate> certChain) throws IOException, GeneralSecurityException { final String methodName = "addPrivateKey"; logger.entry(methodName, pemKeyFile, certChain); PrivateKey privateKey = createPrivat...
java
@Override public final void fireEvent(final GwtEvent<?> event) { final NFastArrayList<Layer> layers = getChildNodes(); if (null != layers) { final int size = layers.size(); for (int i = size - 1; i >= 0; i--) { final Layer layer = lay...
java
@Override public final Scene moveDown(final Layer layer) { if ((null != layer) && (LienzoCore.IS_CANVAS_SUPPORTED)) { final int size = getElement().getChildCount(); if (size < 2) { return this; } final DivElement elemen...
java
@Override public final Scene moveUp(final Layer layer) { if ((null != layer) && (LienzoCore.IS_CANVAS_SUPPORTED)) { final int size = getElement().getChildCount(); if (size < 2) { return this; } final DivElement element ...
java
@Override public final Scene moveToTop(final Layer layer) { if ((null != layer) && (LienzoCore.IS_CANVAS_SUPPORTED)) { final int size = getElement().getChildCount(); if (size < 2) { return this; } final DivElement eleme...
java
public WiresMagnet[] getMagnetsOnAutoConnection(final WiresShape headS, final WiresShape tailS) { final WiresConnection headC = getHeadConnection(); final WiresConnection tailC = getTailConnection(); if (!(headC.isAutoConnection() || tailC.isAutoConnection())) { // at l...
java
public static <T> T first(Iterable<T> objects) { if (objects != null) { for (T object : objects) { return object; } } return null; }
java
public static <T> T last(Iterable<T> objects) { T answer = null; if (objects != null) { for (T object : objects) { answer = object; } } return answer; }
java
public static Matrix identity(final int N) { final Matrix I = new Matrix(N, N); for (int i = 0; i < N; i++) { I.m_data[i][i] = 1; } return I; }
java
private void swap(final int i, final int j) { final double[] temp = m_data[i]; m_data[i] = m_data[j]; m_data[j] = temp; }
java
public Matrix transpose() { final Matrix A = new Matrix(m_columns, m_rows); for (int i = 0; i < m_rows; i++) { for (int j = 0; j < m_columns; j++) { A.m_data[j][i] = this.m_data[i][j]; } } return A; }
java
public Matrix plus(final Matrix B) { final Matrix A = this; if ((B.m_rows != A.m_rows) || (B.m_columns != A.m_columns)) { throw new GeometryException("Illegal matrix dimensions"); } final Matrix C = new Matrix(m_rows, m_columns); for (int i = 0...
java
public boolean eq(final Matrix B) { final Matrix A = this; if ((B.m_rows != A.m_rows) || (B.m_columns != A.m_columns)) { return false; } for (int i = 0; i < m_rows; i++) { for (int j = 0; j < m_columns; j++) { ...
java
public Matrix solve(final Matrix rhs) { if ((m_rows != m_columns) || (rhs.m_rows != m_columns) || (rhs.m_columns != 1)) { throw new GeometryException("Illegal matrix dimensions"); } // create copies of the data final Matrix A = new Matrix(this); ...
java
public static ArchetypeCatalog getArchetypeCatalog(Artifact artifact) throws Exception { File file = artifact.getFile(); if (file != null) { URL url = new URL("file", (String) null, file.getAbsolutePath()); URLClassLoader loader = new URLClassLoader(new URL[]{url}); I...
java
public static boolean isGE(String base, String other) { ComparableVersion v1 = new ComparableVersion(base); ComparableVersion v2 = new ComparableVersion(other); return v2.compareTo(v1) >= 0; }
java
@SuppressWarnings("unchecked") private final Shape<?> doCheckEnterExitShape(final INodeXYEvent event) { final int x = event.getX(); final int y = event.getY(); final Shape<?> shape = findShapeAtPoint(x, y); if (shape != null) { final IPrimitive<?> prim = sh...
java
public void updateUserRepositories(List<RepositoryDTO> repositoryDTOs) { for (RepositoryDTO repositoryDTO : repositoryDTOs) { String fullName = repositoryDTO.getFullName(); userCache.put(fullName, repositoryDTO); } }
java
public RepositoryDTO getOrFindUserRepository(String user, String repositoryName, GitRepoClient repoClient) { RepositoryDTO repository = getUserRepository(user, repositoryName); if (repository == null) { List<RepositoryDTO> repositoryDTOs = repoClient.listRepositories(); updateUse...
java
public Triangle setPoints(final Point2D a, final Point2D b, final Point2D c) { return setPoint2DArray(new Point2DArray(a, b, c)); }
java
@Override protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) { final Point2DArray list = getPolygon();// is null for invalid arrow definition if ((null != list) && (list.size() > 2)) { Point2D point = list.get(0); conte...
java
public Movie setVolume(final double volume) { getAttributes().setVolume(volume); if (null != m_video) { m_video.setVolume(getVolume()); } return this; }
java
public Movie pause() { if ((null != m_video) && (false == isPaused())) { m_pause = true; m_video.pause(); } return this; }
java
public Movie setLoop(final boolean loop) { getAttributes().setLoop(loop); if (null != m_video) { m_video.setLoop(loop); } return this; }
java
public int getWidth() { if (getAttributes().isDefined(Attribute.WIDTH)) { final int wide = (int) (getAttributes().getWidth() + 0.5); if (wide > 0) { return wide; } } if (null != m_video) { return m_v...
java
public int getHeight() { if (getAttributes().isDefined(Attribute.HEIGHT)) { final int high = (int) (getAttributes().getHeight() + 0.5); if (high > 0) { return high; } } if (null != m_video) { return ...
java
public Magnets createMagnets(final WiresShape wiresShape, final Direction[] requestedCardinals) { final IPrimitive<?> primTarget = wiresShape.getGroup(); final Point2DArray points = getWiresIntersectionPoints(wiresShape, requestedCardinals); final ControlHandleList list = new ControlHandleLi...
java
public boolean matches(Request req) { if (!method.equals(req.getMethod())) return false; if (useRegexForPath) { if (!req.getPath().getPath().matches(basePath)) return false; } else { if (!basePath.equals(req.getPath().getPath())) return false; } if (!queri...
java
public final RadialGradient addColorStop(final double stop, final IColor color) { m_jso.addColorStop(stop, color.getColorString()); return this; }
java
private static String getThreadInfo(Thread thread) { final StringBuilder sb = new StringBuilder(); sb.append("Thread: "); sb.append(thread.getId()); sb.append(" ("); sb.append(thread.getName()); sb.append(")"); sb.append(lineSeparator); final StackTraceElement[] stack = thread.getSt...
java
@GET @Path("commitTree/{commitId}") public List<CommitTreeInfo> getCommitTree(final @PathParam("commitId") String commitId) throws Exception { return gitReadOperation(new GitOperation<List<CommitTreeInfo>>() { @Override public List<CommitTreeInfo> call(Git git, GitContext context...
java
public static TailResults tailLog(String uri, TailResults previousResults, Function<String, Void> lineProcessor) throws IOException { URL logURL = new URL(uri); try (InputStream inputStream = logURL.openStream()) { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)...
java
public static String getPatternName(OptionalIdentifiedDefinition camelNode) { // we should grab the annotation instead XmlRootElement root = camelNode.getClass().getAnnotation(XmlRootElement.class); if (root != null) { return root.name(); } String simpleName = Strings...
java
public static final IEventFilter not(final IEventFilter filter) { return new AbstractEventFilter() { @Override public final boolean test(final GwtEvent<?> event) { return (false == filter.test(event)); } }; }
java
public static String fabric8ArchetypesVersion() { String version = System.getenv(ENV_FABRIC8_ARCHETYPES_VERSION); if (Strings.isNotBlank(version)) { return version; } return MavenHelpers.getVersion("io.fabric8.archetypes", "archetypes-catalog"); }
java
@Override protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) { context.save(); if (false == context.isSelection()) { context.setGlobalAlpha(alpha); if (attr.hasShadow()) { doApplyShadow(conte...
java
public final SelectionLayer getSelectionLayer() { if (isListening()) { if (null == m_select) { m_select = new SelectionLayer(); m_select.setPixelSize(getWidth(), getHeight()); } return m_select; } return...
java
final void attachShapeToColorMap(final Shape<?> shape) { if (null != shape) { String color = shape.getColorKey(); if (null != color) { m_shape_color_map.remove(color); shape.setColorKey(null); } int count =...
java
void setPixelSize(final int wide, final int high) { m_wide = wide; m_high = high; if (LienzoCore.IS_CANVAS_SUPPORTED) { if (false == isSelection()) { getElement().getStyle().setWidth(wide, Unit.PX); getElement().getStyle().se...
java
@Override public Layer setListening(final boolean listening) { super.setListening(listening); if (listening) { if (isShowSelectionLayer()) { if (null != getSelectionLayer()) { doShowSelectionLayer(true); ...
java
@Override public Layer setVisible(final boolean visible) { super.setVisible(visible); getElement().getStyle().setVisibility(visible ? Visibility.VISIBLE : Visibility.HIDDEN); return this; }
java
public void clear() { if (LienzoCore.get().getLayerClearMode() == LayerClearMode.CLEAR) { final Context2D context = getContext(); if (null != context) { context.clearRect(0, 0, getWidth(), getHeight()); } } else ...
java
@SuppressWarnings("unchecked") @Override public Layer moveUp() { final Node<?> parent = getParent(); if (null != parent) { final IContainer<?, Layer> container = (IContainer<?, Layer>) parent.asContainer(); if (null != container) { ...
java
public void setFillColor(final IColor color) { m_jso.setFillColor((null != color) ? color.getColorString() : null); }
java
public void setStrokeColor(final IColor color) { m_jso.setStrokeColor((null != color) ? color.getColorString() : null); }
java
public static void sortSpecial(final double[] d) { boolean flip; double temp; do { flip = false; for (int i = 0; i < (d.length - 1); i++) { if (((d[i + 1] >= 0) && (d[i] > d[i + 1])) || ((d[i] < 0) && (d[i + 1] >= 0))) ...
java
public static final double getAngleBetweenTwoLines(final Point2D p0, final Point2D p1, final Point2D p2) { return getAngleFromSSS(p0.distance(p1), p1.distance(p2), p0.distance(p2)); }
java
public static double getClockwiseAngleBetweenThreePoints(final Point2D p0, final Point2D c, final Point2D p1) { final Point2D a = c.sub(p1); final Point2D b = c.sub(p0); return Math.atan2(a.getY(), a.getX()) - Math.atan2(b.getY(), b.getX()); }
java
private static final double getCappedOffset(final Point2D p0, final Point2D p2, final Point2D p4, final double offset) { final double radius = Math.min(p2.sub(p0).getLength(), p2.sub(p4).getLength()) / 2;// it must be half, as there may be another radius on the other side, and they should not cross over. ...
java
public static final Point2DArray intersectLineArcTo(final Point2D a0, final Point2D a1, final Point2D p0, final Point2D p1, final Point2D p2, final double r) { final Point2DArray arcPoints = getCanvasArcToPoints(p0, p1, p2, r); final Point2DArray circleIntersectPoints = intersectLineCircle(a0, ...
java
public static final Point2DArray getCanvasArcToPoints(final Point2D p0, final Point2D p1, final Point2D p2, final double r) { // see tangents drawn from same point to a circle // http://www.mathcaptain.com/geometry/tangent-of-a-circle.html final double a0 = getAngleBetweenTwoLines(p0, p1...
java
public static Point2D getPathIntersect(final WiresConnection connection, final MultiPath path, final Point2D c, final int pointIndex) { final Point2DArray plist = connection.getConnector().getLine().getPoint2DArray(); Point2D p = plist.get(pointIndex).copy(); final Point2D offsetP = ...
java
public static final Point2DArray getCardinals(final BoundingBox box, final Direction[] requestedCardinals) { final Set<Direction> set = new HashSet<>(Arrays.asList(requestedCardinals)); final Point2DArray points = new Point2DArray(); final Point2D c = findCenter(box); final ...
java
public static Point2D findIntersection(final int x, final int y, final MultiPath path) { final Point2D pointerPosition = new Point2D(x, y); final BoundingBox box = path.getBoundingBox(); final Point2D center = findCenter(box); // length just needs to ensure the c to xy is ...
java
public static final String toBrowserRGB(final int r, final int g, final int b) { return "rgb(" + fixRGB(r) + "," + fixRGB(g) + "," + fixRGB(b) + ")"; }
java
public static final String toBrowserRGBA(final int r, final int g, final int b, final double a) { return "rgba(" + fixRGB(r) + "," + fixRGB(g) + "," + fixRGB(g) + "," + fixAlpha(a) + ")"; }
java
public static final Color hex2RGB(final String hex) { String r, g, b; final int len = hex.length(); if (len == 7) { r = hex.substring(1, 3); g = hex.substring(3, 5); b = hex.substring(5, 7); } else if (len == 4) { ...
java
private static final Direction drawOrthogonalLineSegment(final NFastDoubleArrayJSO buffer, final Direction direction, Direction nextDirection, final double p1x, final double p1y, final double p2x, final double p2y, final double p3x, final double p3y, final boolean write) { if (nextDirection == null) ...
java
private static Direction getNextDirection(final Direction direction, final double p1x, final double p1y, final double p2x, final double p2y) { Direction next_direction; switch (direction) { case NORTH: if (p2y < p1y) { next_dir...
java
private static Direction getTailDirection(final Point2DArray points, final NFastDoubleArrayJSO buffer, final Direction lastDirection, Direction tailDirection, final double correction, final OrthogonalPolyLine pline, final double p0x, final double p0y, final double p1x, final double p1y) { final double offse...
java
public LienzoPanel setCursor(final Cursor cursor) { if ((cursor != null) && (cursor != m_active_cursor)) { m_active_cursor = cursor; // Need to defer this, sometimes, if the browser is busy, etc, changing cursors does not take effect till events are done processing ...
java
public LienzoPanel setBackgroundColor(final String color) { if (null != color) { getElement().getStyle().setBackgroundColor(color); } return this; }
java
public static void copyOutput (Logger target, String name, Process process) { new StreamReader(target, name + " stdout", process.getInputStream()).start(); new StreamReader(target, name + " stderr", process.getErrorStream()).start(); }
java
protected void configureDatabaseIdent (String dbident) { _dbident = dbident; // give the repository a chance to do any schema migration before things get further // underway try { executeUpdate(new Operation<Object>() { public Object invoke (Connection co...
java
protected <V> V execute (Operation<V> op) throws PersistenceException { return execute(op, true, true); }
java
protected <V> V executeUpdate (Operation<V> op) throws PersistenceException { return execute(op, true, false); }
java
protected int update (final String query) throws PersistenceException { return executeUpdate(new Operation<Integer>() { public Integer invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { Statement stmt ...
java
protected void checkedUpdate (final String query, final int count) throws PersistenceException { executeUpdate(new Operation<Object>() { public Object invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { ...
java
protected void maintenance (final String action, final String table) throws PersistenceException { executeUpdate(new Operation<Object>() { public Object invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { ...
java
public static String loadAndGet (File propFile, String key) { try { return load(propFile).getProperty(key); } catch (IOException ioe) { return null; } }
java
public boolean add (int[] values) { boolean modified = false; int vlength = values.length; for (int i = 0; i < vlength; i++) { modified = (add(values[i]) || modified); } return modified; }
java
public boolean remove (int[] values) { boolean modified = false; int vcount = values.length; for (int i = 0; i < vcount; i++) { modified = (remove(values[i]) || modified); } return modified; }
java
public void setSelectedIndex (int selidx) { // update the display updateSelection(selidx); // let the model know what's up Object item = (selidx == -1) ? null : _model.getElementAt(selidx); _model.setSelectedItem(item); }
java