All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javafaker.Company Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
package com.github.javafaker;

import com.github.javafaker.service.FakerIDN;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang3.StringUtils.join;

public class Company {

    private final Faker faker;

    Company(Faker faker) {
        this.faker = faker;
    }

    public String name() {
        return faker.fakeValuesService().resolve("company.name", this, faker);
    }

    public String suffix() {
        return faker.fakeValuesService().resolve("company.suffix", this, faker);
    }

    public String industry() {
        return faker.fakeValuesService().resolve("company.industry", this, faker);
    }

    public String profession() {
        return faker.fakeValuesService().resolve("company.profession", this, faker);
    }

    public String buzzword() {
        @SuppressWarnings("unchecked")
        List> buzzwordLists = (List>) faker.fakeValuesService().fetchObject("company.buzzwords");
        List buzzwords = new ArrayList();
        for (List buzzwordList : buzzwordLists) {
            buzzwords.addAll(buzzwordList);
        }
        return buzzwords.get(faker.random().nextInt(buzzwords.size()));
    }

    /**
     * Generate a buzzword-laden catch phrase.
     */
    public String catchPhrase() {
        @SuppressWarnings("unchecked")
        List> catchPhraseLists = (List>) faker.fakeValuesService().fetchObject("company.buzzwords");
        return joinSampleOfEachList(catchPhraseLists, " ");
    }

    /**
     * When a straight answer won't do, BS to the rescue!
     */
    public String bs() {
        @SuppressWarnings("unchecked")
        List> buzzwordLists = (List>) faker.fakeValuesService().fetchObject("company.bs");
        return joinSampleOfEachList(buzzwordLists, " ");
    }

    /**
     * Generate a random company logo url in PNG format.
     */
    public String logo() {
        int number = faker.random().nextInt(13) + 1;
        return "https://pigment.github.io/fake-logos/logos/medium/color/" + number + ".png";
    }

    public String url() {
        return join(new Object[]{
                "www",
                ".",
                FakerIDN.toASCII(domainName()),
                ".",
                domainSuffix()
        });
    }

    private String domainName(){
        return StringUtils.deleteWhitespace(name().toLowerCase().replaceAll(",", "").replaceAll("'", ""));
    }

    private String domainSuffix() {
        return faker.fakeValuesService().resolve("internet.domain_suffix", this, faker);
    }

    private String joinSampleOfEachList(List> listOfLists, String separator) {
        List words = new ArrayList();
        for (List list : listOfLists) {
           words.add(list.get(faker.random().nextInt(list.size())));
        }
        return join(words, separator);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy