blob: c98559e307623e8be7b46624f7ce822eeff40a87 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.xtext.entitymock.common.filler;
import java.util.Locale;
import java.util.Set;
public class TextProvider {
private final TextConfigurator fConfigurator;
private final BaseProvider fBaseProvider;
public TextProvider(BaseProvider baseProvider, Locale locale) {
fBaseProvider = baseProvider;
fConfigurator = new TextConfigurator(locale);
}
public String paragraph(int count) {
return combine(fConfigurator.getParagraphs(), "\r\n", count);
}
public String sentence(int count) {
return combine(fConfigurator.getSentences(), ".", count);
}
public String word(int count) {
return combine(fConfigurator.getWords(), " ", count);
}
private String combine(Set<String> options, String glue, int count) {
String[] items = options.toArray(new String[0]);
String result = null;
for (int i = 0; i < count; i++) {
if (result == null) {
result = "";
}
else {
result += glue;
}
result += items[fBaseProvider.randomBetween(0, items.length-1)];
}
return result;
}
}