Example usage for org.apache.commons.lang3.text StrBuilder size

List of usage examples for org.apache.commons.lang3.text StrBuilder size

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text StrBuilder size.

Prototype

int size

To view the source code for org.apache.commons.lang3.text StrBuilder size.

Click Source Link

Document

Current size of the buffer.

Usage

From source file:de.vandermeer.skb.datatool.commons.EntryObject.java

/**
 * Loads an entry object from a given map with tests against expected keys.
 * @param keyStart string used to start a key
 * @param data the data to load information from, usually a mapping of strings to objects
 * @param loadedTypes loaded types as lookup for links
 * @param cs core settings required for loading data
 * @throws URISyntaxException if creating a URI for an SKB link failed
 * @throws IllegalArgumentException if any of the required arguments or map entries are not set or empty
 *///ww  w.  j a v a  2 s .  c  o  m
default void load(String keyStart, Object data, LoadedTypeMap loadedTypes, CoreSettings cs)
        throws URISyntaxException {
    StrBuilder err = this.getSchema().testSchema(data);
    if (err.size() > 0) {
        throw new IllegalArgumentException(err.toString());
    }
    this.loadObject(keyStart, data, loadedTypes, cs);
}

From source file:de.vandermeer.skb.datatool.commons.DataEntry.java

/**
 * Loads the entry content using a given loader.
 * @param keyStart string used to start a key
 * @param data the data to load information from, usually a mapping of strings to objects
 * @param cs core settings required for loading data
 * @throws IllegalArgumentException if any of the required arguments or map entries are not set or empty
 * @throws URISyntaxException if an SKB link is used to de-reference an entry and the URL is not formed well
 *//*from  w  ww  .j av  a  2 s .  c o  m*/
default void load(String keyStart, Map<String, Object> data, CoreSettings cs) throws URISyntaxException {
    StrBuilder err = this.getSchema().testSchema(data);
    if (err.size() > 0) {
        throw new IllegalArgumentException(err.toString());
    }
    this.loadEntry(keyStart, data, cs);
    this.setKey(this.toKey(this.getKey()));
}

From source file:de.vandermeer.skb.datatool.entries.date.edate.ObjectEDate.java

@Override
public void loadObject(String keyStart, Object data, LoadedTypeMap loadedTypes, CoreSettings cs)
        throws URISyntaxException {
    if (!(data instanceof Map)) {
        throw new IllegalArgumentException("object edate - data must be a map");
    }// w  w w .ja  v a 2  s  . c  om

    this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, (Map<?, ?>) data, loadedTypes, cs);

    this.entryMap.put(ObjectEDateKeys.LOCAL_OBJ_EDATE_MONTH_LINK,
            DataUtilities.loadDataString(ObjectEDateKeys.OBJ_EDATE_MONTH_LINK, (Map<?, ?>) data));
    this.entryMap.put(ObjectEDateKeys.LOCAL_OBJ_EDATE_MONTH_START_LINK,
            DataUtilities.loadDataString(ObjectEDateKeys.OBJ_EDATE_MONTH_START_LINK, (Map<?, ?>) data));
    this.entryMap.put(ObjectEDateKeys.LOCAL_OBJ_EDATE_MONTH_END_LINK,
            DataUtilities.loadDataString(ObjectEDateKeys.OBJ_EDATE_MONTH_END_LINK, (Map<?, ?>) data));

    StrBuilder msg = new StrBuilder(50);

    if (msg.size() > 0) {
        throw new IllegalArgumentException(msg.toString());
    }
}

From source file:de.vandermeer.skb.mvn.pm.model.PM_Model.java

/**
 * Update dependencies for each loaded project.
 * Once all projects and the build version dependencies are loaded, we can update the dependencies for each individual project.
 * This allows forward definition of dependencies.
 *//*from   ww  w . j av  a2s  .  c  om*/
public void updateProjectDependencies() {
    StrBuilder error = new StrBuilder();
    for (Model_ManagedProject mp : this.projects.values()) {
        error.appendSeparator('\n');
        error.append(mp.updateDependencies());
    }
    if (error.size() > 0) {
        throw new IllegalArgumentException("problems updating dependencies, see below\n" + error.toString());
    }
}

From source file:de.vandermeer.skb.mvn.pm.model.PM_Context.java

/**
 * Sets the build version information on the context (creates {@link Ctxt_BuildVersion} objects).
 * @param buildVersions the build version properties
 * @throws IllegalArgumentException if any argument was problematic
 *///from w  w  w  .  j ava  2 s  . c  o m
public void setBuildVersions(Properties buildVersions) {
    StrBuilder errors = new StrBuilder();
    for (Entry<Object, Object> p : buildVersions.entrySet()) {
        try {
            Ctxt_BuildVersion bv = new Ctxt_BuildVersion(p.getKey().toString(), p.getValue().toString());
            this.buildVersions.put(bv.getId(), bv);
        } catch (Exception ex) {
            errors.append(ex.getMessage()).appendNewLine();
        }
    }
    if (errors.size() > 0) {
        throw new IllegalArgumentException(
                "PM Context, problems loading build versions, see below\n" + errors.toString());
    }
}

From source file:de.vandermeer.skb.mvn.pm.model.ModelLoader.java

/**
 * Creates a new model loader.// w  w w .  j av a2  s  .  c  o m
 * @param mc model context
 * @param folders collection of project folders
 * @throws NullPointerException if the collection or any member was null
 * @throws IllegalArgumentException if any collection member resulted in a was a blank string or pointed to an unreadable/unwritable directory
 */
public ModelLoader(PM_Context mc, Collection<Object> folders) {
    Validate.notNull(mc);
    this.mc = mc;

    this.projectFiles = new LinkedHashMap<>();

    StrBuilder errors = new StrBuilder();
    StrBuilder _err;
    for (Object o : folders) {
        File prjDir = new File(o.toString());

        //set the loaded map entry
        this.projectFiles.put(prjDir,
                Pair.of(new File(prjDir + File.separator + this.mc.getProjectPmDir()),
                        new File(prjDir + File.separator + this.mc.getProjectPmDir() + File.separator
                                + ProjectFiles.MANAGED_PROJECT_PROPERTIES.getFileName())));

        _err = this.testProjectDirectory(prjDir);
        errors.append(_err);
        if (_err.size() == 0) {
            _err = this.testProjectPmDirectory(this.projectFiles.get(prjDir).getKey());
            errors.append(_err);
            if (_err.size() == 0) {
                _err = this.testProjectPmFiles(this.projectFiles.get(prjDir).getValue());
                errors.append(_err);
            }
        }
    }

    if (errors.size() > 0) {
        throw new IllegalArgumentException(
                "pm loader: problems with one or more directories, see below\n" + errors.toString());
    }
}

From source file:de.vandermeer.skb.interfaces.transformers.textformat.Text_To_WrappedFormat.java

@Override
default Pair<ArrayList<String>, ArrayList<String>> transform(String input) {
    Validate.notBlank(input);//from w  w w  .  ja  va  2s .  com
    Validate.isTrue(this.getWidth() > 0);

    ArrayList<String> topList = new ArrayList<>();
    ArrayList<String> bottomList = new ArrayList<>();

    //an emergency break, counting loops to avoid endless loops
    int count;

    String text = StringUtils.replacePattern(input, "\\r\\n|\\r|\\n", LINEBREAK);
    text = StringUtils.replace(text, "<br>", LINEBREAK);
    text = StringUtils.replace(text, "<br/>", LINEBREAK);

    StrBuilder sb = new StrBuilder(text);
    if (this.getTopSettings() != null) {
        //we have a top request, do that one first
        Validate.notNull(this.getTopSettings().getLeft());
        Validate.notNull(this.getTopSettings().getRight());
        Validate.isTrue(this.getTopSettings().getLeft() > 0);
        Validate.isTrue(this.getTopSettings().getRight() > 0);

        int topLines = this.getTopSettings().getLeft();
        int topWidth = this.getTopSettings().getRight();
        count = 0;

        while (sb.size() > 0 && topLines > 0 && count++ < 200) {
            if (sb.startsWith(LINEBREAK)) {
                sb.replaceFirst(LINEBREAK, "");
            }
            String s = null;
            boolean wln = false;
            if (sb.indexOf(LINEBREAK) > 0) {
                s = sb.substring(0, sb.indexOf(LINEBREAK));
                wln = true;
                //sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), "");
            } else {
                s = sb.toString();
                //sb.clear();
            }
            String wrap = WordUtils.wrap(s, topWidth, LINEBREAK, true);
            StrTokenizer tok = new StrTokenizer(wrap, LINEBREAK).setIgnoreEmptyTokens(false);
            String[] ar = tok.getTokenArray();
            if (ar.length <= topLines) {
                //all lines done, cleanup
                for (String str : ar) {
                    topList.add(str.trim());
                }
                if (wln == true) {
                    //if we had a conditional linebreak there might be more text, remove the line we processed
                    sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), "");
                } else {
                    //no conditional line break, clean builder
                    sb.clear();
                }
                topLines = 0;
            } else {
                //we have more lines than we need, so remove the text we have from the builder and copy processed lines
                StrBuilder replace = new StrBuilder();
                for (int i = 0; i < topLines; i++) {
                    topList.add(ar[i].trim());
                    replace.appendSeparator(' ').append(ar[i]);
                }
                if (wln == true) {
                    replace.append(LINEBREAK);
                }
                sb.replaceFirst(replace.toString(), "");
                topLines = 0;
            }
        }
    }

    //no top, simple wrapping with recognition of conditional line breaks
    count = 0;
    while (sb.size() > 0 && count++ < 200) {
        if (sb.startsWith(LINEBREAK)) {
            sb.replaceFirst(LINEBREAK, "");
        }
        String s = null;
        if (sb.indexOf(LINEBREAK) > 0) {
            s = sb.substring(0, sb.indexOf(LINEBREAK));
            sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), "");
        } else {
            s = sb.toString();
            sb.clear();
        }
        s = WordUtils.wrap(s, this.getWidth(), LINEBREAK, true);
        StrTokenizer tok = new StrTokenizer(s, LINEBREAK).setIgnoreEmptyTokens(false);
        for (String str : tok.getTokenArray()) {
            bottomList.add(str.trim());
        }
    }

    return Pair.of(topList, bottomList);
}

From source file:de.vandermeer.skb.datatool.entries.conferences.ConferenceEntry.java

@Override
public void loadEntry(String keyStart, Map<String, Object> data, CoreSettings cs) throws URISyntaxException {
    this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, data, this.loadedTypes, cs);

    this.entryMap.put(EntryKeys.LOCAL_ACRONYM_LINK, DataUtilities.loadDataString(EntryKeys.ACRONYM, data));
    //      this.entryMap.put(AffiliationKeys.LOCAL_AFF_TYPE_LINK, DataUtilities.loadDataString(AffiliationKeys.AFF_TYPE, data));

    StrBuilder msg = new StrBuilder(50);
    //      if(this.getName()==null){
    //         if(this.getAcronymLink()==null){
    //            msg.appendSeparator(", ");
    //            msg.append("no long name and no acronym given");
    //         }//from  www .  j a v a  2s. c  o  m
    //      }
    //      else{
    //         if(this.getAcronymLink()==null && this.getShortName()==null){
    //            msg.appendSeparator(", ");
    //            msg.append("no short name nor acronym given");
    //         }
    //         if(this.getAcronymLink()!=null && this.getShortName()!=null){
    //            msg.appendSeparator(", ");
    //            msg.append("no short name and acronym given");
    //         }
    //      }

    if (this.getKey() != null) {
        this.entryMap.put(CommonKeys.KEY, keyStart + this.getKey());
    } else if (this.getAcronymLink() != null) {
        //         this.entryMap.put(AffiliationKeys.AFF_LONG, this.getAcronym().getLong());
        //         this.entryMap.put(AffiliationKeys.AFF_SHORT, this.getAcronym().getShort());
        this.entryMap.put(CommonKeys.KEY, keyStart + this.getAcronym().getShort());
    } else {
        msg.appendSeparator(", ");
        msg.append("cannot generate key");
    }

    if (msg.size() > 0) {
        throw new IllegalArgumentException(msg.toString());
    }
}

From source file:de.vandermeer.skb.datatool.entries.affiliations.AffiliationEntry.java

@Override
public void loadEntry(String keyStart, Map<String, Object> data, CoreSettings cs) throws URISyntaxException {
    this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, data, this.loadedTypes, cs);

    this.entryMap.put(EntryKeys.LOCAL_ACRONYM_LINK, DataUtilities.loadDataString(EntryKeys.ACRONYM, data));
    this.entryMap.put(AffiliationKeys.LOCAL_AFF_TYPE_LINK,
            DataUtilities.loadDataString(AffiliationKeys.AFF_TYPE, data));

    StrBuilder msg = new StrBuilder(50);
    if (this.getName() == null) {
        if (this.getAcronymLink() == null) {
            msg.appendSeparator(", ");
            msg.append("no long name and no acronym given");
        }/*from ww  w.j ava2  s . c om*/
    } else {
        if (this.getAcronymLink() == null && this.getShortName() == null) {
            msg.appendSeparator(", ");
            msg.append("no short name nor acronym given");
        }
        if (this.getAcronymLink() != null && this.getShortName() != null) {
            msg.appendSeparator(", ");
            msg.append("no short name and acronym given");
        }
    }

    if (this.getKey() != null) {
        this.entryMap.put(CommonKeys.KEY, keyStart + this.getKey());
    } else if (this.getShortName() != null) {
        this.entryMap.put(CommonKeys.KEY, keyStart + this.getShortName());
    } else if (this.getAcronymLink() != null) {
        this.entryMap.put(AffiliationKeys.AFF_LONG, this.getAcronym().getLong());
        this.entryMap.put(AffiliationKeys.AFF_SHORT, this.getAcronym().getShort());
        this.entryMap.put(CommonKeys.KEY, keyStart + this.getShortName());
    } else {
        msg.appendSeparator(", ");
        msg.append("cannot generate key");
    }

    if (msg.size() > 0) {
        throw new IllegalArgumentException(msg.toString());
    }
}

From source file:de.vandermeer.skb.datatool.entries.geo.object.ObjectGeo.java

@Override
public void loadObject(String keyStart, Object data, LoadedTypeMap loadedTypes, CoreSettings cs)
        throws URISyntaxException {
    if (!(data instanceof Map)) {
        throw new IllegalArgumentException("object geo - data must be a map");
    }/*from w  w  w.j  ava2  s.  co m*/

    this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, (Map<?, ?>) data, loadedTypes, cs);

    this.entryMap.put(GeoKeys.LOCAL_GEO_CITY_LINK,
            DataUtilities.loadDataString(ObjectGeoKeys.OBJ_GEO_CITY_LINK, (Map<?, ?>) data));
    this.entryMap.put(GeoKeys.LOCAL_GEO_COUNTRY_LINK,
            DataUtilities.loadDataString(ObjectGeoKeys.OBJ_GEO_COUNTRY_LINK, (Map<?, ?>) data));

    StrBuilder msg = new StrBuilder(50);

    //      this.city = Utilities.getDataObject(GeoObjectConstants.EK_OBJ_GEO_CITY, entryMap, linkMap);
    //      this.cityLink = Utilities.getDataObject(GeoObjectConstants.EK_OBJ_GEO_CITY_LINK, entryMap, linkMap);
    //      if(this.cityLink!=null){
    //         try {
    //            Object obj = Utilities.getLinkObject(this.cityLink, linkMap);
    //            if(obj instanceof CityEntry){
    //               CityEntry city = (CityEntry)obj;
    //               this.cityExp = city.getName();
    //               if(city.getCountry()!=null){
    //                  this.countryLink = "skb://countries/" + city.getKey();//TODO
    //                  this.countryExp = city.getCountryEntry().getName();
    //               }
    //            }
    //            else{
    //               msg.appendSeparator(", ").append(obj);
    //            }
    //         }
    //         catch (URISyntaxException e) {
    //            msg.appendSeparator(", ").append(e.getMessage());
    //         }
    //      }
    //      else{
    //         this.country = Utilities.getDataObject(GeoObjectConstants.EK_OBJ_GEO_COUNTRY, entryMap, linkMap);
    //         this.countryLink = Utilities.getDataObject(GeoObjectConstants.EK_OBJ_GEO_COUNTRY_LINK, entryMap, linkMap);
    //         if(this.countryLink!=null){
    //            try {
    //               Object obj = Utilities.getLinkObject(this.countryLink, linkMap);
    //               if(obj instanceof CountryEntry){
    //                  this.countryExp = ((CountryEntry)obj).getName();
    //               }
    //            }
    //            catch (URISyntaxException e) {
    //               msg.appendSeparator(", ").append(e.getMessage());
    //            }
    //         }
    //      }
    //
    if (msg.size() > 0) {
        throw new IllegalArgumentException(msg.toString());
    }
}