Search in sources :

Example 6 with StringUtils.trim

use of org.apache.commons.lang3.StringUtils.trim in project eol-globi-data by jhpoelen.

the class StudyImporterForHurlbert method importInteraction.

protected void importInteraction(Set<String> regions, Set<String> locales, Set<String> habitats, Record record, Study study, String preyTaxonName, String predatorName) throws StudyImporterException {
    try {
        Taxon predatorTaxon = new TaxonImpl(predatorName);
        Specimen predatorSpecimen = nodeFactory.createSpecimen(study, predatorTaxon);
        setBasisOfRecordAsLiterature(predatorSpecimen);
        Taxon preyTaxon = new TaxonImpl(preyTaxonName);
        String preyNameId = StringUtils.trim(columnValueOrNull(record, "Prey_Name_ITIS_ID"));
        if (NumberUtils.isDigits(preyNameId)) {
            preyTaxon.setExternalId(TaxonomyProvider.ITIS.getIdPrefix() + preyNameId);
        }
        Specimen preySpecimen = nodeFactory.createSpecimen(study, preyTaxon);
        setBasisOfRecordAsLiterature(preySpecimen);
        String preyStage = StringUtils.trim(columnValueOrNull(record, "Prey_Stage"));
        if (StringUtils.isNotBlank(preyStage)) {
            Term lifeStage = nodeFactory.getOrCreateLifeStage("HULBERT:" + StringUtils.replace(preyStage, " ", "_"), preyStage);
            preySpecimen.setLifeStage(lifeStage);
        }
        String preyPart = StringUtils.trim(columnValueOrNull(record, "Prey_Part"));
        if (StringUtils.isNotBlank(preyPart)) {
            Term term = nodeFactory.getOrCreateBodyPart("HULBERT:" + StringUtils.replace(preyPart, " ", "_"), preyPart);
            preySpecimen.setBodyPart(term);
        }
        Date date = addCollectionDate(record, study);
        nodeFactory.setUnixEpochProperty(predatorSpecimen, date);
        nodeFactory.setUnixEpochProperty(preySpecimen, date);
        LocationImpl location = new LocationImpl(null, null, null, null);
        String longitude = columnValueOrNull(record, "Longitude_dd");
        String latitude = columnValueOrNull(record, "Latitude_dd");
        if (NumberUtils.isNumber(latitude) && NumberUtils.isNumber(longitude)) {
            try {
                LatLng latLng = LocationUtil.parseLatLng(latitude, longitude);
                String altitude = columnValueOrNull(record, "Altitude_mean_m");
                Double altitudeD = NumberUtils.isNumber(altitude) ? Double.parseDouble(altitude) : null;
                location = new LocationImpl(latLng.getLat(), latLng.getLng(), altitudeD, null);
            } catch (InvalidLocationException e) {
                getLogger().warn(study, "found invalid (lat,lng) pair: (" + latitude + "," + longitude + ")");
            }
        }
        String locationRegion = columnValueOrNull(record, "Location_Region");
        String locationSpecific = columnValueOrNull(record, "Location_Specific");
        location.setLocality(StringUtils.join(Arrays.asList(locationRegion, locationSpecific), ":"));
        Location locationNode = nodeFactory.getOrCreateLocation(location);
        String habitat_type = columnValueOrNull(record, "Habitat_type");
        List<Term> habitatList = Arrays.stream(StringUtils.split(StringUtils.defaultIfBlank(habitat_type, ""), ";")).map(StringUtils::trim).map(habitat -> new TermImpl(idForHabitat(habitat), habitat)).collect(Collectors.toList());
        nodeFactory.addEnvironmentToLocation(locationNode, habitatList);
        preySpecimen.caughtIn(locationNode);
        predatorSpecimen.caughtIn(locationNode);
        predatorSpecimen.ate(preySpecimen);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create interaction between [" + predatorName + "] and [" + preyTaxonName + "]", e);
    }
}
Also used : TsvParser(com.univocity.parsers.tsv.TsvParser) DateUtil(org.eol.globi.util.DateUtil) StringUtils(org.apache.commons.lang.StringUtils) CitationUtil(org.globalbioticinteractions.dataset.CitationUtil) Arrays(java.util.Arrays) Record(com.univocity.parsers.common.record.Record) Term(org.eol.globi.domain.Term) Specimen(org.eol.globi.domain.Specimen) Location(org.eol.globi.domain.Location) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) LocationImpl(org.eol.globi.domain.LocationImpl) HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) Map(java.util.Map) LatLng(org.eol.globi.geo.LatLng) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) InvalidLocationException(org.eol.globi.util.InvalidLocationException) DateTime(org.joda.time.DateTime) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) List(java.util.List) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Study(org.eol.globi.domain.Study) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) InvalidLocationException(org.eol.globi.util.InvalidLocationException) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) Term(org.eol.globi.domain.Term) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Specimen(org.eol.globi.domain.Specimen) StringUtils(org.apache.commons.lang.StringUtils) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 7 with StringUtils.trim

use of org.apache.commons.lang3.StringUtils.trim in project AntennaPod by AntennaPod.

the class FeedInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feedinfo);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
    imgvCover = (ImageView) findViewById(R.id.imgvCover);
    txtvTitle = (TextView) findViewById(R.id.txtvTitle);
    txtvDescription = (TextView) findViewById(R.id.txtvDescription);
    lblLanguage = (TextView) findViewById(R.id.lblLanguage);
    txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
    lblAuthor = (TextView) findViewById(R.id.lblAuthor);
    txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
    txtvUrl = (TextView) findViewById(R.id.txtvUrl);
    cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
    cbxKeepUpdated = (CheckBox) findViewById(R.id.cbxKeepUpdated);
    spnAutoDelete = (Spinner) findViewById(R.id.spnAutoDelete);
    etxtUsername = (EditText) findViewById(R.id.etxtUsername);
    etxtPassword = (EditText) findViewById(R.id.etxtPassword);
    etxtFilterText = (EditText) findViewById(R.id.etxtEpisodeFilterText);
    rdoFilterInclude = (RadioButton) findViewById(R.id.radio_filter_include);
    rdoFilterInclude.setOnClickListener(v -> {
        filterInclude = true;
        filterTextChanged = true;
    });
    rdoFilterExclude = (RadioButton) findViewById(R.id.radio_filter_exclude);
    rdoFilterExclude.setOnClickListener(v -> {
        filterInclude = false;
        filterTextChanged = true;
    });
    txtvUrl.setOnClickListener(copyUrlToClipboard);
    subscription = Observable.fromCallable(() -> DBReader.getFeed(feedId)).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        if (result == null) {
            Log.e(TAG, "Activity was started with invalid arguments");
            finish();
        }
        feed = result;
        Log.d(TAG, "Language is " + feed.getLanguage());
        Log.d(TAG, "Author is " + feed.getAuthor());
        Log.d(TAG, "URL is " + feed.getDownload_url());
        FeedPreferences prefs = feed.getPreferences();
        Glide.with(FeedInfoActivity.this).load(feed.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(imgvCover);
        txtvTitle.setText(feed.getTitle());
        String description = feed.getDescription();
        if (description != null) {
            if (Feed.TYPE_ATOM1.equals(feed.getType())) {
                HtmlToPlainText formatter = new HtmlToPlainText();
                Document feedDescription = Jsoup.parse(feed.getDescription());
                description = StringUtils.trim(formatter.getPlainText(feedDescription));
            }
        } else {
            description = "";
        }
        txtvDescription.setText(description);
        if (!TextUtils.isEmpty(feed.getAuthor())) {
            txtvAuthor.setText(feed.getAuthor());
        } else {
            lblAuthor.setVisibility(View.GONE);
            txtvAuthor.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(feed.getLanguage())) {
            txtvLanguage.setText(LangUtils.getLanguageString(feed.getLanguage()));
        } else {
            lblLanguage.setVisibility(View.GONE);
            txtvLanguage.setVisibility(View.GONE);
        }
        txtvUrl.setText(feed.getDownload_url() + " {fa-paperclip}");
        Iconify.addIcons(txtvUrl);
        cbxAutoDownload.setEnabled(UserPreferences.isEnableAutodownload());
        cbxAutoDownload.setChecked(prefs.getAutoDownload());
        cbxAutoDownload.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setAutoDownload(checked);
            feed.savePreferences(FeedInfoActivity.this);
            updateAutoDownloadSettings();
            ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(FeedInfoActivity.this, feed, checked);
            dialog.createNewDialog().show();
        });
        cbxKeepUpdated.setChecked(prefs.getKeepUpdated());
        cbxKeepUpdated.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setKeepUpdated(checked);
            feed.savePreferences(FeedInfoActivity.this);
        });
        spnAutoDelete.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                FeedPreferences.AutoDeleteAction auto_delete_action;
                switch(parent.getSelectedItemPosition()) {
                    case 0:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.GLOBAL;
                        break;
                    case 1:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.YES;
                        break;
                    case 2:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.NO;
                        break;
                    default:
                        return;
                }
                feed.getPreferences().setAutoDeleteAction(auto_delete_action);
                autoDeleteChanged = true;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        spnAutoDelete.setSelection(prefs.getAutoDeleteAction().ordinal());
        etxtUsername.setText(prefs.getUsername());
        etxtPassword.setText(prefs.getPassword());
        etxtUsername.addTextChangedListener(authTextWatcher);
        etxtPassword.addTextChangedListener(authTextWatcher);
        FeedFilter filter = prefs.getFilter();
        if (filter.includeOnly()) {
            etxtFilterText.setText(filter.getIncludeFilter());
            rdoFilterInclude.setChecked(true);
            rdoFilterExclude.setChecked(false);
            filterInclude = true;
        } else if (filter.excludeOnly()) {
            etxtFilterText.setText(filter.getExcludeFilter());
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(true);
            filterInclude = false;
        } else {
            Log.d(TAG, "No filter set");
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(false);
            etxtFilterText.setText("");
        }
        etxtFilterText.addTextChangedListener(filterTextWatcher);
        supportInvalidateOptionsMenu();
        updateAutoDownloadSettings();
    }, error -> {
        Log.d(TAG, Log.getStackTraceString(error));
        finish();
    });
}
Also used : FeedMenuHandler(de.danoeh.antennapod.menuhandler.FeedMenuHandler) Context(android.content.Context) Bundle(android.os.Bundle) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog) Uri(android.net.Uri) ImageView(android.widget.ImageView) RadioButton(android.widget.RadioButton) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) ApGlideSettings(de.danoeh.antennapod.core.glide.ApGlideSettings) StringUtils(org.apache.commons.lang3.StringUtils) Editable(android.text.Editable) DownloadRequestErrorDialogCreator(de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator) MenuItem(android.view.MenuItem) Observable(rx.Observable) ClipData(android.content.ClipData) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Feed(de.danoeh.antennapod.core.feed.Feed) AdapterView(android.widget.AdapterView) Log(android.util.Log) DialogInterface(android.content.DialogInterface) IntentUtils(de.danoeh.antennapod.core.util.IntentUtils) R(de.danoeh.antennapod.R) TextUtils(android.text.TextUtils) AppCompatActivity(android.support.v7.app.AppCompatActivity) Spinner(android.widget.Spinner) LangUtils(de.danoeh.antennapod.core.util.LangUtils) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Iconify(com.joanzapata.iconify.Iconify) Document(org.jsoup.nodes.Document) DBReader(de.danoeh.antennapod.core.storage.DBReader) Jsoup(org.jsoup.Jsoup) Subscription(rx.Subscription) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AdapterView(android.widget.AdapterView) Document(org.jsoup.nodes.Document) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 8 with StringUtils.trim

use of org.apache.commons.lang3.StringUtils.trim in project gatk-protected by broadinstitute.

the class PoNTestUtils method readTsvIntoMatrix.

/**
     * Reads a very basic tsv (numbers separated by tabs) into a RealMatrix.
     * <p>Very little error checking happens in this method</p>
     *
     * @param inputFile readable file.  Not {@code null}
     * @return never {@code null}
     */
public static RealMatrix readTsvIntoMatrix(final File inputFile) {
    IOUtils.canReadFile(inputFile);
    final List<double[]> allData = new ArrayList<>();
    int ctr = 0;
    try {
        final CSVReader reader = new CSVReader(new FileReader(inputFile), '\t', CSVWriter.NO_QUOTE_CHARACTER);
        String[] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            ctr++;
            allData.add(Arrays.stream(nextLine).filter(s -> StringUtils.trim(s).length() > 0).map(s -> Double.parseDouble(StringUtils.trim(s))).mapToDouble(d -> d).toArray());
        }
    } catch (final IOException ioe) {
        Assert.fail("Could not open test file: " + inputFile, ioe);
    }
    final RealMatrix result = new Array2DRowRealMatrix(allData.size(), allData.get(0).length);
    for (int i = 0; i < result.getRowDimension(); i++) {
        result.setRow(i, allData.get(i));
    }
    return result;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Arrays(java.util.Arrays) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) CSVWriter(au.com.bytecode.opencsv.CSVWriter) CSVReader(com.opencsv.CSVReader) HDF5PCACoveragePoNCreationUtils(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoNCreationUtils) IOException(java.io.IOException) TargetArgumentCollection(org.broadinstitute.hellbender.tools.exome.TargetArgumentCollection) StringUtils(org.apache.commons.lang3.StringUtils) CreatePanelOfNormals(org.broadinstitute.hellbender.tools.exome.CreatePanelOfNormals) OptionalInt(java.util.OptionalInt) ParamUtils(org.broadinstitute.hellbender.utils.param.ParamUtils) File(java.io.File) ArrayList(java.util.ArrayList) HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) List(java.util.List) PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.PCACoveragePoN) Assert(org.testng.Assert) Target(org.broadinstitute.hellbender.tools.exome.Target) Utils(org.broadinstitute.hellbender.utils.Utils) RealMatrix(org.apache.commons.math3.linear.RealMatrix) HDF5File(org.broadinstitute.hdf5.HDF5File) FileReader(java.io.FileReader) TargetCollection(org.broadinstitute.hellbender.tools.exome.TargetCollection) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)6 List (java.util.List)4 Map (java.util.Map)3 CSVWriter (au.com.bytecode.opencsv.CSVWriter)2 CSVReader (com.opencsv.CSVReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 DateTime (org.joda.time.DateTime)2 PaypalManager (alfio.manager.PaypalManager)1 alfio.model (alfio.model)1 ValidationResult (alfio.model.result.ValidationResult)1 PaymentProxy (alfio.model.transaction.PaymentProxy)1 ErrorsCode (alfio.util.ErrorsCode)1 Validator (alfio.util.Validator)1