code
stringlengths
73
34.1k
label
stringclasses
1 value
public static StringBuilder concat(final String... message) { final StringBuilder builder = new StringBuilder(); for (final String mess : message) { builder.append(mess); builder.append(" "); } return builder; }
java
public IMetaEntry put(final IMetaEntry pKey, final IMetaEntry pVal) { return mMetaMap.put(pKey, pVal); }
java
@Override public Void call() throws TTException { updateOnly(); if (mCommit == EShredderCommit.COMMIT) { mWtx.commit(); } return null; }
java
private void updateOnly() throws TTException { try { // Initialize variables. mLevelInToShredder = 0; // mElemsParsed = 0; // mIsLastNode = false; mMovedToRightSibling = false; boolean firstEvent = true; // // If structure alre...
java
private void processStartTag(final StartElement paramElem) throws IOException, XMLStreamException, TTException { assert paramElem != null; // Initialize variables. initializeVars(); // Main algorithm to determine if same, insert or a delete has to be // made. al...
java
private void processCharacters(final Characters paramText) throws IOException, XMLStreamException, TTException { assert paramText != null; // Initialize variables. initializeVars(); final String text = paramText.getData().toString(); if (!text.isEmpty()) { // ...
java
private void processEndTag() throws XMLStreamException, TTException { mLevelInToShredder--; if (mInserted) { mInsertedEndTag = true; } if (mRemovedNode) { mRemovedNode = false; } else { // Move cursor to parent. if (mWtx.getNode(...
java
private void algorithm(final XMLEvent paramEvent) throws IOException, XMLStreamException, TTIOException { assert paramEvent != null; do { /* * Check if a node in the shreddered file on the same level equals * the current element node. */ if ...
java
private boolean checkText(final Characters paramEvent) { assert paramEvent != null; final String text = paramEvent.getData().trim(); return mWtx.getNode().getKind() == IConstants.TEXT && mWtx.getValueOfCurrentNode().equals(text); }
java
private void sameTextNode() throws TTIOException, XMLStreamException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkIf...
java
private void sameElementNode() throws XMLStreamException, TTException { // Update variables. mInsert = EInsert.NOINSERT; mDelete = EDelete.NODELETE; mInserted = false; mInsertedEndTag = false; mRemovedNode = false; // Check if last node reached. // checkI...
java
private void skipWhitespaces(final XMLEventReader paramReader) throws XMLStreamException { while (paramReader.peek().getEventType() == XMLStreamConstants.CHARACTERS && paramReader.peek().asCharacters().isWhiteSpace()) { paramReader.nextEvent(); } }
java
private void insertElementNode(final StartElement paramElement) throws TTException, XMLStreamException { assert paramElement != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * fo...
java
private void insertTextNode(final Characters paramText) throws TTException, XMLStreamException { assert paramText != null; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the ...
java
private void deleteNode() throws TTException { /* * If found in one of the rightsiblings in the current shreddered * structure remove all nodes until the transaction points to the found * node (keyMatches). */ if (mInserted && !mMovedToRightSibling) { mIns...
java
private void initializeVars() { mNodeKey = mWtx.getNode().getDataKey(); mFound = false; mIsRightSibling = false; mKeyMatches = -1; }
java
private boolean checkElement(final StartElement mEvent) throws TTIOException { assert mEvent != null; boolean retVal = false; // Matching element names? if (mWtx.getNode().getKind() == IConstants.ELEMENT && mWtx.getQNameOfCurrentNode().equals(mEvent.getName())) { ...
java
@Override @SuppressWarnings({ "unchecked" }) public synchronized Enumeration<Object> keys() { Enumeration<Object> keysEnum = super.keys(); @SuppressWarnings("rawtypes") Vector keyList = new Vector<>(); // NOPMD - vector used on purpose here... while (keysEnum.hasMoreElements()) { keyList.add(keysEnum.nextE...
java
public void setException(Throwable t) { if (err == null) { t.printStackTrace(); } else { err.emit(t); } }
java
public boolean processErrors(MessageEmit err) { if (valErrors.size() == 0) { return false; } for (ValError ve: valErrors) { processError(err, ve); } valErrors.clear(); return true; }
java
public static boolean createResource(String name, AbstractModule module) throws StorageAlreadyExistsException, TTException { File file = new File(ROOT_PATH); File storageFile = new File(STORAGE_PATH); if (!file.exists() || !storageFile.exists()) { file.mkdirs(); ...
java
public static List<String> getResources() { File resources = new File(STORAGE_PATH + File.separator + "/resources"); File[] children = resources.listFiles(); if (children == null) { return new ArrayList<String>(); } List<String> storages = new ArrayList<String>(); ...
java
public static ISession getSession(String resourceName) throws ResourceNotExistingException, TTException { File storageFile = new File(STORAGE_PATH); ISession session = null; if (!storageFile.exists()) { throw new ResourceNotExistingException(); } else { new Stor...
java
public static void removeResource(String pResourceName) throws TTException, ResourceNotExistingException { ISession session = getSession(pResourceName); session.truncate(); }
java
private void generateElement(final INodeReadTrx paramRtx) throws TTIOException { final AttributesImpl atts = new AttributesImpl(); final long key = paramRtx.getNode().getDataKey(); try { // Process namespace nodes. for (int i = 0, namesCount = ((ElementNode)paramRtx.getN...
java
private void generateText(final INodeReadTrx paramRtx) { try { mContHandler.characters(paramRtx.getValueOfCurrentNode().toCharArray(), 0, paramRtx .getValueOfCurrentNode().length()); } catch (final SAXException exc) { exc.printStackTrace(); } }
java
@SuppressWarnings("unchecked") public static Object getMBean(final Class c, final String name) throws Throwable { final MBeanServer server = getMbeanServer(); // return MBeanProxyExt.create(c, name, server); return JMX.newMBeanProxy(server, new ObjectName(name), c); }
java
public static void register(final Server s) { final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.pr...
java
public IData getData(final long pDataKey) throws TTIOException { checkArgument(pDataKey >= 0); checkState(!mClose, "Transaction already closed"); // Calculate bucket and data part for given datakey. final long seqBucketKey = pDataKey >> IConstants.INDIRECT_BUCKET_COUNT[3]; final ...
java
public boolean close() throws TTIOException { if (!mClose) { mSession.deregisterBucketTrx(this); mBucketReader.close(); mClose = true; return true; } else { return false; } }
java
protected final List<DataBucket> getSnapshotBuckets(final long pSeqDataBucketKey) throws TTIOException { // Return Value, since the revision iterates a flexible number of version, this has to be a list // first. final List<DataBucket> dataBuckets = new ArrayList<DataBucket>(); // Getti...
java
protected static final int dataBucketOffset(final long pDataKey) { // INDIRECT_BUCKET_COUNT[3] is only taken to get the difference between 2^7 and the actual // datakey as offset. It has nothing to do with the levels. final long dataBucketOffset = (pDataKey - ((pDataKey >> IConstants...
java
protected static final long[] dereferenceLeafOfTree(final IBackendReader pReader, final long pStartKey, final long pSeqBucketKey) throws TTIOException { final long[] orderNumber = getOrderNumbers(pSeqBucketKey); // Initial state pointing to the indirect bucket of level 0. final long[] ...
java
public static OptionsI getOptions(final String globalPrefix, final String appPrefix, final String optionsFile, final String outerTagName) throws OptionsException { try { Object o = Class.forName(envclas...
java
public static Options fromStream(final String globalPrefix, final String appPrefix, final String outerTagName, final InputStream is) throws OptionsException { Options opts = new Options(); opts.init(globalP...
java
private void addLeafLabel() { final int nodeKind = mRtx.getNode().getKind(); if (!mLeafLabels.containsKey(nodeKind)) { mLeafLabels.put(nodeKind, new ArrayList<ITreeData>()); } mLeafLabels.get(nodeKind).add(mRtx.getNode()); }
java
public FilterGlobals getGlobals(final HttpServletRequest req) { HttpSession sess = req.getSession(); if (sess == null) { // We're screwed return null; } Object o = sess.getAttribute(globalsName); FilterGlobals fg; if (o == null) { fg = newFilterGlobals(); sess.setAttri...
java
@PUT @Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML }) public Response putResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers, final InputStream xml) { final ...
java
@DELETE public Response deleteResource(@PathParam(JaxRxConstants.SYSTEM) final String system, @PathParam(JaxRxConstants.RESOURCE) final String resource, @Context final HttpHeaders headers) { final JaxRx impl = Systems.getInstance(system); final String info = impl.delete(new ResourcePath(res...
java
public static InputStream getCommandResult( CommandLine cmdLine, File dir, int expectedExit, long timeout, InputStream input) throws IOException { DefaultExecutor executor = getDefaultExecutor(dir, expectedExit, timeout); try (ByteArrayOutputStream outStr = new ByteArrayOutputStream()) { executor.setStrea...
java
public IMetaEntry deserializeEntry(final DataInput pData) throws TTIOException { try { final int kind = pData.readInt(); switch (kind) { case KEY: return new MetaKey(pData.readInt()); case VALUE: final int valSize = pData.readInt();...
java
public static boolean isZip(String fileName) { if (fileName == null) { return false; } String tl = fileName.toLowerCase(); for (String element : ZIP_EXTENSIONS) { if (tl.endsWith(element)) { return true; } } return false; }
java
public static void findZip(String zipName, InputStream zipInput, FileFilter searchFilter, List<String> results) throws IOException { ZipInputStream zin = new ZipInputStream(zipInput); while (true) { final ZipEntry en; try { en = zin.getNextEntry(); } catch (IOException | IllegalArgumentException e) ...
java
@SuppressWarnings("resource") public static InputStream getZipContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { ...
java
public static String getZipStringContentsRecursive(final String file) throws IOException { // return local file directly int pos = file.indexOf('!'); if (pos == -1) { if (!new File(file).exists()) { throw new IOException("File " + file + " does not exist"); } try { try (InputStream str = new Fil...
java
public static void extractZip(File zip, File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } try (ZipFile zipFile = new ZipFile(zip)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) {...
java
public static void extractZip(InputStream zip, final File toDir) throws IOException{ if(!toDir.exists()) { throw new IOException("Directory '" + toDir + "' does not exist."); } // Use the ZipFileVisitor to walk all the entries in the Zip-Stream and create // directories and files accordingly new ZipFileVi...
java
public static void replaceInZip(String zipFile, String data, String encoding) throws IOException { if(!isFileInZip(zipFile)) { throw new IOException("Parameter should specify a file inside a ZIP file, but had: " + zipFile); } File zip = new File(zipFile.substring(0, zipFile.indexOf(ZIP_DELIMITER))); String ...
java
public static void replaceInZip(File zip, String file, String data, String encoding) throws IOException { // open the output side File zipOutFile = File.createTempFile("ZipReplace", ".zip"); try { FileOutputStream fos = new FileOutputStream(zipOutFile); try (ZipOutputStream zos = new ZipOutputStream(fos)) {...
java
public static GeoPosition getPosition(Point2D pixelCoordinate, int zoom, TileFactoryInfo info) { // p(" --bitmap to latlon : " + coord + " " + zoom); double wx = pixelCoordinate.getX(); double wy = pixelCoordinate.getY(); // this reverses getBitmapCoordinates double flon = (w...
java
public GeoPosition pixelToGeo(Point2D pixelCoordinate, int zoom) { return GeoUtil.getPosition(pixelCoordinate, zoom, getInfo()); }
java
public Point2D geoToPixel(GeoPosition c, int zoomLevel) { return GeoUtil.getBitmapCoordinate(c, zoomLevel, getInfo()); }
java
private void doPaintComponent(Graphics g) {/* * if (isOpaque() || isDesignTime()) { g.setColor(getBackground()); g.fillRect(0,0,getWidth(),getHeight()); } */ if (isDesignTime()) { // do nothing } else { int z = getZoom(); ...
java
public void setZoom(int zoom) { if (zoom == this.zoomLevel) { return; } TileFactoryInfo info = getTileFactory().getInfo(); // don't repaint if we are out of the valid zoom levels if (info != null && (zoom < info.getMinimumZoomLevel() || zoom > in...
java
public void setAddressLocation(GeoPosition addressLocation) { GeoPosition old = getAddressLocation(); this.addressLocation = addressLocation; setCenter(getTileFactory().geoToPixel(addressLocation, getZoom())); firePropertyChange("addressLocation", old, getAddressLocation()); ...
java
public void setDrawTileBorders(boolean drawTileBorders) { boolean old = isDrawTileBorders(); this.drawTileBorders = drawTileBorders; firePropertyChange("drawTileBorders", old, isDrawTileBorders()); repaint(); }
java
public void setCenterPosition(GeoPosition geoPosition) { GeoPosition oldVal = getCenterPosition(); setCenter(getTileFactory().geoToPixel(geoPosition, zoomLevel)); repaint(); GeoPosition newVal = getCenterPosition(); firePropertyChange("centerPosition", oldVal, newVal); ...
java
public void setCenter(Point2D center) { Point2D old = this.getCenter(); double centerX = center.getX(); double centerY = center.getY(); Dimension mapSize = getTileFactory().getMapSize(getZoom()); int mapHeight = (int) mapSize.getHeight() * getTileFactory().getTileSi...
java
public void calculateZoomFrom(Set<GeoPosition> positions) { // u.p("calculating a zoom based on: "); // u.p(positions); if (positions.size() < 2) { return; } int zoom = getZoom(); Rectangle2D rect = generateBoundingRect(positions, zoom);...
java
public void zoomToBestFit(Set<GeoPosition> positions, double maxFraction) { if (positions.isEmpty()) return; if (maxFraction <= 0 || maxFraction > 1) throw new IllegalArgumentException("maxFraction must be between 0 and 1"); TileFactory tileFactory = getTile...
java
public GeoPosition convertPointToGeoPosition(Point2D pt) { // convert from local to world bitmap Rectangle bounds = getViewportBounds(); Point2D pt2 = new Point2D.Double(pt.getX() + bounds.getX(), pt.getY() + bounds.getY()); // convert from world bitmap to geo GeoPosi...
java
public void put(URI uri, byte[] bimg, BufferedImage img) { synchronized (bytemap) { while (bytesize > 1000 * 1000 * 50) { URI olduri = bytemapAccessQueue.removeFirst(); byte[] oldbimg = bytemap.remove(olduri); bytesize -= oldbim...
java
protected synchronized ExecutorService getService() { if (service == null) { // System.out.println("creating an executor service with a threadpool of size " + threadPoolSize); service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() { ...
java
public void setUserAgent(String userAgent) { if (userAgent == null || userAgent.isEmpty()) { throw new IllegalArgumentException("User agent can't be null or empty."); } this.userAgent = userAgent; }
java
public synchronized void promote(Tile tile) { if (tileQueue.contains(tile)) { try { tileQueue.remove(tile); tile.setPriority(Tile.Priority.High); tileQueue.put(tile); } catch (Exception ex) { ...
java
public final BufferedImageOp[] getFilters() { BufferedImageOp[] results = new BufferedImageOp[filters.length]; System.arraycopy(filters, 0, results, 0, results.length); return results; }
java
public void setAntialiasing(boolean value) { boolean old = isAntialiasing(); antialiasing = value; if (old != value) setDirty(true); firePropertyChange("antialiasing", old, isAntialiasing()); }
java
public void setInterpolation(Interpolation value) { Object old = getInterpolation(); this.interpolation = value == null ? Interpolation.NearestNeighbor : value; if (old != value) setDirty(true); firePropertyChange("interpolation", old, getInterpolation()); }
java
protected void setDirty(boolean d) { boolean old = isDirty(); this.dirty = d; firePropertyChange("dirty", old, isDirty()); if (isDirty()) { clearCache(); } }
java
public void addPainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.add(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).addPropertyChangeListener(handler...
java
public void removePainter(Painter<T> painter) { Collection<Painter<T>> old = new ArrayList<Painter<T>>(getPainters()); this.painters.remove(painter); if (painter instanceof AbstractPainter) { ((AbstractPainter<?>) painter).removePropertyChangeListener(ha...
java
public void setClipPreserved(boolean shouldRestoreState) { boolean oldShouldRestoreState = isClipPreserved(); this.clipPreserved = shouldRestoreState; setDirty(true); firePropertyChange("clipPreserved", oldShouldRestoreState, shouldRestoreState); }
java
public void setTransform(AffineTransform transform) { AffineTransform old = getTransform(); this.transform = transform; setDirty(true); firePropertyChange("transform", old, transform); }
java
@Override public Tile getTile(int x, int y, int zoom) { return new Tile(x, y, zoom) { @Override public synchronized boolean isLoaded() { return true; } @Override public BufferedImage getImage() {...
java
@Deprecated public static void installResponseCache(String baseURL, File cacheDir, boolean checkForUpdates) { ResponseCache.setDefault(new LocalResponseCache(baseURL, cacheDir, checkForUpdates)); }
java
public void setZoom(int zoom) { zoomChanging = true; mainMap.setZoom(zoom); miniMap.setZoom(mainMap.getZoom() + 4); if (sliderReversed) { zoomSlider.setValue(zoomSlider.getMaximum() - zoom); } else { zoomSlider.setVal...
java
public Action getZoomOutAction() { Action act = new AbstractAction() { /** * */ private static final long serialVersionUID = 5525706163434375107L; @Override public void actionPerformed(ActionEvent e) { ...
java
public void setMiniMapVisible(boolean miniMapVisible) { boolean old = this.isMiniMapVisible(); this.miniMapVisible = miniMapVisible; miniMap.setVisible(miniMapVisible); firePropertyChange("miniMapVisible", old, this.isMiniMapVisible()); }
java
public void setZoomSliderVisible(boolean zoomSliderVisible) { boolean old = this.isZoomSliderVisible(); this.zoomSliderVisible = zoomSliderVisible; zoomSlider.setVisible(zoomSliderVisible); firePropertyChange("zoomSliderVisible", old, this.isZoomSliderVisible()); }
java
public void setZoomButtonsVisible(boolean zoomButtonsVisible) { boolean old = this.isZoomButtonsVisible(); this.zoomButtonsVisible = zoomButtonsVisible; zoomInButton.setVisible(zoomButtonsVisible); zoomOutButton.setVisible(zoomButtonsVisible); firePropertyChange("zoomBu...
java
public void setTileFactory(TileFactory fact) { mainMap.setTileFactory(fact); mainMap.setZoom(fact.getInfo().getDefaultZoomLevel()); mainMap.setCenterPosition(new GeoPosition(0, 0)); miniMap.setTileFactory(fact); miniMap.setZoom(fact.getInfo().getDefaultZoomLevel() + 3);...
java
public File getLocalFile(URL remoteUri) { StringBuilder sb = new StringBuilder(); String host = remoteUri.getHost(); String query = remoteUri.getQuery(); String path = remoteUri.getPath(); if (host != null) { sb.append(host); } ...
java
public void setPosition(GeoPosition coordinate) { GeoPosition old = getPosition(); this.position = coordinate; firePropertyChange("position", old, getPosition()); }
java
public String toWMSURL(int x, int y, int zoom, int tileSize) { String format = "image/jpeg"; String styles = ""; String srs = "EPSG:4326"; int ts = tileSize; int circumference = widthOfWorldInPixels(zoom, tileSize); double radius = circumference / (2 * Math.PI); ...
java
public static BufferedImage convertToBufferedImage(Image img) { BufferedImage buff = createCompatibleTranslucentImage( img.getWidth(null), img.getHeight(null)); Graphics2D g2 = buff.createGraphics(); try { g2.drawImage(img, 0, 0, null); } finally { ...
java
public static void clear(Image img) { Graphics g = img.getGraphics(); try { if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Clear); } else { g.setColor(new Color(0, 0, 0, 0)); } ...
java
public static void tileStretchPaint(Graphics g, JComponent comp, BufferedImage img, Insets ins) { int left = ins.left; int right = ins.right; int top = ins.top; int bottom = ins.bottom; // top g.drawImage(...
java
@Override public void mouseClicked(MouseEvent evt) { final boolean left = SwingUtilities.isLeftMouseButton(evt); final boolean singleClick = (evt.getClickCount() == 1); if ((left && singleClick)) { Rectangle bounds = viewer.getViewportBounds(); int x = bounds.x + evt...
java
private void setRect(double minLat, double minLng, double maxLat, double maxLng) { if (!(minLat < maxLat)) { throw new IllegalArgumentException("GeoBounds is not valid - minLat must be less that maxLat."); } if (!(minLng < maxLng)) { if (minLng > 0 && ...
java
public boolean intersects(GeoBounds other) { boolean rv = false; for (Rectangle2D r1 : rects) { for (Rectangle2D r2 : other.rects) { rv = r1.intersects(r2); if (rv) { break; } ...
java
public GeoPosition getSouthEast() { Rectangle2D r = rects[0]; if (rects.length > 1) { r = rects[1]; } return new GeoPosition(r.getY(), r.getMaxX()); }
java
public ExecuterManager bindListener(Class<? extends IExecutersListener> listener) throws IllegalAccessException, InstantiationException { if (listener != null) { this.executerListeners.add(listener.newInstance()); } return this; }
java
public static void save(byte[] bytes,String filePath,String fileName) throws IOException { Path path = Paths.get(filePath, fileName); mkirDirs(path.getParent()); String pathStr = path.toString(); File file = new File(pathStr); write(bytes,file); }
java
public static void write(byte[] bytes,File file) throws IOException { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); outputStream.write(bytes); outputStream.close(); }
java
public static char forDigit(int digit, int radix) { if (digit >= 0 && digit < radix && radix >= Character.MIN_RADIX && radix <= MAX_RADIX) { return digits[digit]; } return '\u0000'; }
java
public RequestResponse setRequestData(Object requestData) { this.requestData = requestData; requestJson = requestData != null ? (requestData instanceof JsonNode ? (JsonNode) requestData : SerializationUtils.toJson(requestData)) : null; retu...
java
public RequestResponse setResponseData(byte[] responseData) { this.responseData = responseData; try { responseJson = responseData != null ? SerializationUtils.readJson(responseData) : null; } catch (Exception e) { responseJson = null; LOGGER.error(e.getMessage...
java
public String create(Request request, Response response, Long duration) { return createStringBuilder(request, response, duration).toString(); }
java
public static long getMacAddr() { if (macAddr == 0) { try { InetAddress ip = InetAddress.getLocalHost(); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); for (byte temp : mac) ...
java
public static long waitTillNextMillisec(long currentMillisec) { long nextMillisec = System.currentTimeMillis(); for (; nextMillisec <= currentMillisec; nextMillisec = System.currentTimeMillis()) { Thread.yield(); } return nextMillisec; }
java