Example usage for java.util Collections EMPTY_SET

List of usage examples for java.util Collections EMPTY_SET

Introduction

In this page you can find the example usage for java.util Collections EMPTY_SET.

Prototype

Set EMPTY_SET

To view the source code for java.util Collections EMPTY_SET.

Click Source Link

Document

The empty set (immutable).

Usage

From source file:org.opens.tgol.controller.AbstractUserAndContractsController.java

/**
* This method gets data from a property file to fill-in the inscription
* e-mail//from w w w .  j  av  a 2  s.c  o  m
* @param user
*/
private void sendEmailInscription(User user) {
    String emailFrom = exposablePropertyPlaceholderConfigurer.getResolvedProps().get(EMAIL_FROM_KEY);
    String[] emailTo = exposablePropertyPlaceholderConfigurer.getResolvedProps().get(EMAIL_TO_KEY).split(",");
    Set<String> emailToSet = new HashSet<String>();
    emailToSet.addAll(Arrays.asList(emailTo));
    String emailSubject = exposablePropertyPlaceholderConfigurer.getResolvedProps().get(EMAIL_SUBJECT_KEY);
    String emailContent = exposablePropertyPlaceholderConfigurer.getResolvedProps().get(EMAIL_CONTENT_KEY);
    emailContent = emailContent.replace(EMAIL_KEY, user.getEmail1());
    emailContent = emailContent.replace(URL_KEY, user.getWebUrl1());
    if (user.getName() != null) {
        emailContent = emailContent.replace(LAST_NAME_KEY, user.getName());
    } else {
        emailContent = emailContent.replace(LAST_NAME_KEY, "");
    }
    if (user.getFirstName() != null) {
        emailContent = emailContent.replace(FIRST_NAME_KEY, user.getFirstName());
    } else {
        emailContent = emailContent.replace(FIRST_NAME_KEY, "");
    }
    if (user.getPhoneNumber() != null) {
        emailContent = emailContent.replace(PHONE_NUMBER_KEY, user.getPhoneNumber());
    } else {
        emailContent = emailContent.replace(PHONE_NUMBER_KEY, "");
    }
    emailSender.sendEmail(emailFrom, emailToSet, Collections.EMPTY_SET, StringUtils.EMPTY, emailSubject,
            emailContent);
}

From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java

/**
 * Creates a stream (from FOP's PDF library) from a PDF page parsed with PDFBox.
 * @param sourceDoc the source PDF the given page to be copied belongs to
 * @param page the page to transform into a stream
 * @param key value to use as key for the stream
 * @param atdoc adjustment for stream//  w w  w  .j  a va2s . c o m
 * @param fontinfo fonts
 * @param pos rectangle
 * @return the stream
 * @throws IOException if an I/O error occurs
 */
public String createStreamFromPDFBoxPage(PDDocument sourceDoc, PDPage page, String key, AffineTransform atdoc,
        FontInfo fontinfo, Rectangle pos) throws IOException {
    handleAnnotations(sourceDoc, page, atdoc);
    if (pageNumbers.containsKey(targetPage.getPageIndex())) {
        pageNumbers.get(targetPage.getPageIndex()).set(0, targetPage.makeReference());
    }
    PDResources sourcePageResources = page.getResources();
    PDStream pdStream = getContents(page);

    COSDictionary fonts = (COSDictionary) sourcePageResources.getCOSObject().getDictionaryObject(COSName.FONT);
    COSDictionary fontsBackup = null;
    UniqueName uniqueName = new UniqueName(key, sourcePageResources);
    String newStream = null;
    if (fonts != null && pdfDoc.isMergeFontsEnabled()) {
        fontsBackup = new COSDictionary(fonts);
        MergeFontsPDFWriter m = new MergeFontsPDFWriter(fonts, fontinfo, uniqueName, parentFonts, currentMCID);
        newStream = m.writeText(pdStream);
        //            if (newStream != null) {
        //                for (Object f : fonts.keySet().toArray()) {
        //                    COSDictionary fontdata = (COSDictionary)fonts.getDictionaryObject((COSName)f);
        //                    if (getUniqueFontName(fontdata) != null) {
        //                        fonts.removeItem((COSName)f);
        //                    }
        //                }
        //            }
    }
    if (newStream == null) {
        PDFWriter writer = new PDFWriter(uniqueName, currentMCID);
        newStream = writer.writeText(pdStream);
        currentMCID = writer.getCurrentMCID();

    }
    pdStream = new PDStream(sourceDoc, new ByteArrayInputStream(newStream.getBytes("ISO-8859-1")));
    mergeXObj(sourcePageResources.getCOSObject(), fontinfo, uniqueName);
    PDFDictionary pageResources = (PDFDictionary) cloneForNewDocument(sourcePageResources.getCOSObject());

    PDFDictionary fontDict = (PDFDictionary) pageResources.get("Font");
    if (fontDict != null && pdfDoc.isMergeFontsEnabled()) {
        for (Map.Entry<String, Typeface> fontEntry : fontinfo.getUsedFonts().entrySet()) {
            Typeface font = fontEntry.getValue();
            if (font instanceof FOPPDFFont) {
                FOPPDFFont pdfFont = (FOPPDFFont) font;
                if (pdfFont.getRef() == null) {
                    pdfFont.setRef(new PDFDictionary());
                    pdfDoc.assignObjectNumber(pdfFont.getRef());
                }
                fontDict.put(fontEntry.getKey(), pdfFont.getRef());
            }
        }
    }
    updateXObj(sourcePageResources.getCOSObject(), pageResources);
    if (fontsBackup != null) {
        sourcePageResources.getCOSObject().setItem(COSName.FONT, fontsBackup);
    }

    COSStream originalPageContents = pdStream.getCOSObject();

    bindOptionalContent(sourceDoc);

    PDFStream pageStream;
    Set filter;
    //        if (originalPageContents instanceof COSStreamArray) {
    //            COSStreamArray array = (COSStreamArray)originalPageContents;
    //            pageStream = new PDFStream();
    //            InputStream in = array.getUnfilteredStream();
    //            OutputStream out = pageStream.getBufferOutputStream();
    //            IOUtils.copyLarge(in, out);
    //            filter = FILTER_FILTER;
    //        } else {
    pageStream = (PDFStream) cloneForNewDocument(originalPageContents);
    filter = Collections.EMPTY_SET;
    //        }
    if (pageStream == null) {
        pageStream = new PDFStream();
    }
    if (originalPageContents != null) {
        transferDict(originalPageContents, pageStream, filter);
    }

    transferPageDict(fonts, uniqueName, sourcePageResources);

    PDRectangle mediaBox = page.getMediaBox();
    PDRectangle cropBox = page.getCropBox();
    PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;

    //Handle the /Rotation entry on the page dict
    int rotation = PDFUtil.getNormalizedRotation(page);

    //Transform to FOP's user space
    float w = (float) pos.getWidth() / 1000f;
    float h = (float) pos.getHeight() / 1000f;
    if (rotation == 90 || rotation == 270) {
        float tmp = w;
        w = h;
        h = tmp;
    }
    atdoc.setTransform(AffineTransform.getScaleInstance(w / viewBox.getWidth(), h / viewBox.getHeight()));
    atdoc.translate(0, viewBox.getHeight());
    atdoc.rotate(-Math.PI);
    atdoc.scale(-1, 1);
    atdoc.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY());

    rotate(rotation, viewBox, atdoc);

    StringBuilder boxStr = new StringBuilder();
    boxStr.append(PDFNumber.doubleOut(mediaBox.getLowerLeftX())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getLowerLeftY())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getWidth())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getHeight())).append(" re W n\n");
    return boxStr.toString() + IOUtils.toString(pdStream.createInputStream(null), "ISO-8859-1");
}

From source file:org.tanaguru.webapp.controller.AbstractUserAndContractsController.java

/**
* This method gets data from a property file to fill-in the inscription
* e-mail// w ww .  ja v  a  2  s  .c o  m
* @param user
*/
private void sendEmailInscription(User user) {
    String emailFrom = exposablePropertyPlaceholderConfigurer.getResolvedProps()
            .get(TgolKeyStore.EMAIL_FROM_KEY);
    String[] emailTo = exposablePropertyPlaceholderConfigurer.getResolvedProps().get(TgolKeyStore.EMAIL_TO_KEY)
            .split(",");
    Set<String> emailToSet = new HashSet();
    emailToSet.addAll(Arrays.asList(emailTo));
    String emailSubject = exposablePropertyPlaceholderConfigurer.getResolvedProps()
            .get(TgolKeyStore.EMAIL_SUBJECT_KEY);
    String emailContent = exposablePropertyPlaceholderConfigurer.getResolvedProps()
            .get(TgolKeyStore.EMAIL_CONTENT_KEY);
    emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_EMAIL_KEY, user.getEmail1());
    emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_URL_KEY, user.getWebUrl1());
    if (user.getName() != null) {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_LAST_NAME_KEY, user.getName());
    } else {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_LAST_NAME_KEY, "");
    }
    if (user.getFirstName() != null) {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_FIRST_NAME_KEY, user.getFirstName());
    } else {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_FIRST_NAME_KEY, "");
    }
    if (user.getPhoneNumber() != null) {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_PHONE_NUMBER_KEY, user.getPhoneNumber());
    } else {
        emailContent = emailContent.replace(TgolKeyStore.EMAIL_CONTENT_PHONE_NUMBER_KEY, "");
    }
    emailSender.sendEmail(emailFrom, emailToSet, Collections.EMPTY_SET, StringUtils.EMPTY, emailSubject,
            emailContent);
}

From source file:com.nagarro.core.v1.controller.ProductsController.java

protected List<String> validateAndSplitCatalog(final String catalog) throws RequestParameterException {
    final List<String> catalogInfo = new ArrayList<>();
    if (StringUtils.isNotEmpty(catalog)) {
        catalogInfo/*from  w ww.  ja  v a  2 s  .  c  o  m*/
                .addAll(Lists.newArrayList(Splitter.on(':').trimResults().omitEmptyStrings().split(catalog)));
        if (catalogInfo.size() == 2) {
            catalogFacade.getProductCatalogVersionForTheCurrentSite(catalogInfo.get(CATALOG_ID_POS),
                    catalogInfo.get(CATALOG_VERSION_POS), Collections.EMPTY_SET);
        } else if (!catalogInfo.isEmpty()) {
            throw new RequestParameterException(
                    "Invalid format. You have to provide catalog as 'catalogId:catalogVersion'",
                    RequestParameterException.INVALID, "catalog");
        }
    }
    return catalogInfo;
}

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testRemoveByRangeWithLimit() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    Range range = new Range(new Key("aaaa"), new Key("ffff"), 100, "", 0);

    updateService.removeByRange("bucket", range, new Predicate(null));
    expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once();

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(
            "http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff&limit=100");
    client.executeMethod(method);/*www. j a  v  a  2 s .  c  o  m*/

    assertEquals(HttpStatus.SC_OK, method.getStatusCode());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}

From source file:com.petalmd.armor.AbstractUnitTest.java

protected final Tuple<JestResult, HttpResponse> executeSearch(final String file, final String[] indices,
        final String[] types, final boolean mustBeSuccesfull, final boolean connectFromLocalhost)
        throws Exception {

    client = getJestClient(getServerUri(connectFromLocalhost), username, password);

    final Tuple<JestResult, HttpResponse> restu = client.executeE(new Search.Builder(loadFile(file))
            .addIndex(indices == null ? Collections.EMPTY_SET : Arrays.asList(indices))
            .addType(types == null ? Collections.EMPTY_SET : Arrays.asList(types)).refresh(true)
            .setHeader(headers).build());

    final JestResult res = restu.v1();

    if (mustBeSuccesfull) {
        if (res.getErrorMessage() != null) {
            log.error("Search operation result: {}", res.getErrorMessage());
        }//w  ww  .  j  ava2 s . co  m
        Assert.assertTrue("Error msg: " + res.getErrorMessage() + res.getJsonString(), res.isSucceeded());
    } else {
        log.debug("Search operation fails as expected");
        Assert.assertTrue(!res.isSucceeded());
    }
    return restu;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

@SuppressWarnings("unchecked")
public static Set<String> listParams(final CharSequence sequence, final String startDelimiter,
        final String endDelimiter) {
    if (isBlankOrNull(sequence)) {
        return Collections.EMPTY_SET;
    }//from   w w w .  j a va2s .c  o  m
    String str = sequence.toString();
    int idx0 = str.indexOf(startDelimiter);
    if (idx0 < 0) {
        return Collections.EMPTY_SET;
    }

    Set<String> set = new HashSet<String>();
    while (idx0 >= 0) {
        int idx1 = str.indexOf(endDelimiter, idx0);
        if (idx1 <= idx0) {
            return set;
        }
        set.add(str.substring(idx0 + startDelimiter.length(), idx1));
        idx0 = str.indexOf(startDelimiter, idx1);
    }
    return set;
}

From source file:org.opens.tgol.orchestrator.TanaguruOrchestratorImpl.java

/**
 * /*from   www  .ja v a2s  .com*/
 * @param emailFrom
 * @param emailToSet
 * @param emailSubject
 * @param emailMessage 
 */
private void sendEmail(String emailFrom, Set<String> emailToSet, String emailSubject, String emailMessage) {
    emailSender.sendEmail(emailFrom, emailToSet, Collections.EMPTY_SET, StringUtils.EMPTY, emailSubject,
            emailMessage);
}

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testRemoveByRangeWithPredicate() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    Range range = new Range(new Key("aaaa"), new Key("ffff"), 100, "", 10000L);

    updateService.removeByRange("bucket", range, new Predicate("condition:some"));
    expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once();

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(
            "http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff&limit=100&timeToLive=10000&predicate=condition:some");
    client.executeMethod(method);/*from w  w  w .  ja  v  a  2  s  . c  om*/

    assertEquals(HttpStatus.SC_OK, method.getStatusCode());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}

From source file:com.tesora.dve.tools.aitemplatebuilder.AiTemplateBuilder.java

/**
 * Get bonus % for a given column.//w  w  w  .  j  av  a 2s.c  o  m
 * Bonus AI columns which are generally safe and ideal for the Range
 * distribution.
 * Also slightly bonus integral types which are often good candidates for
 * Ranging.
 * 
 * In the "Safe Mode" only AI columns get non-zero score.
 */
public static Set<ScoreBonus> getBonusesForColumn(final TableColumn column, final boolean isSafeMode) {
    if (isSafeMode) {
        if (!isAutoIncrement(column)) {
            return Collections.singleton(ScoreBonus.UNSAFE_RANGE_COLUMN);
        }
    } else {
        final Set<ScoreBonus> bonuses = new LinkedHashSet<ScoreBonus>();
        if (isAutoIncrement(column)) {
            bonuses.add(ScoreBonus.AI_RANGE_COLUMN);
        } else if (column.getType().isIntegralType()) {
            bonuses.add(ScoreBonus.INTEGRAL_RANGE_COLUMN);
        }

        if (column.getUpdateCount() > 0) {
            bonuses.add(ScoreBonus.UPDATED_RANGE_COLUMN);
        }

        return bonuses;
    }

    return Collections.EMPTY_SET;
}