code stringlengths 73 34.1k | label stringclasses 1 value |
|---|---|
private String chooseAlternations(final String expression) {
StrBuilder sb = new StrBuilder(expression);
int i = 0;
// Loop until an unescaped pipe symbol appears.
while (UNESCAPED_PIPE_PATTERN.matcher(sb.toString()).find()) {
for (; i < sb.length(); ++i) {
if (sb.charAt(i) == '|') {
if (sb.charAt(i - 1) == '\\') {
// escapet
continue;
}
int start = i;
// Backtrack until an opening bracket is found
// to limit the context of alternatives.
for (int closingCount = 0; start >= 0; --start) {
char c = sb.charAt(start);
if (c == '(') {
if (closingCount == 0) {
break;
}
--closingCount;
} else if (c == ')') {
++closingCount;
}
}
if (start >= 0) {
// If an opening brace was found
// search for a closing bracket.
int end = i;
for (int openingCount = 0; end < sb.length(); ++end) {
char c = sb.charAt(end);
if (c == '(') {
++openingCount;
} else if (c == ')') {
if (openingCount == 0) {
break;
}
--openingCount;
}
}
String alternative = random.getBoolean() ? sb.substring(start + 1, i) : sb.substring(i + 1, end);
sb.replace(start, end + 1, alternative);
i = start + alternative.length();
break;
}
String alternative = random.getBoolean() ? sb.substring(0, i) : sb.substring(i + 1);
sb.replace(0, sb.length() + 1, alternative);
break;
}
}
}
return sb.toString();
} | java |
public String negateString(final String input, int bad) {
int length = input.length();
Range[] ranges = getRanges();
int[] lengths = new int[ranges.length];
// arrange lengths
for (int i = 0; i < lengths.length; i++) {
Range r = ranges[i];
lengths[i] = r.getMin();
length -= r.getMin();
}
/**
* distribute remaining lengths
*/
int i = 0;
// only 1000 tries otherwise break as it just does not work
while (length > 0 && i < 1000) {
int index = i % lengths.length;
Range r = ranges[index];
if (lengths[index] < r.getMax()) {
lengths[index] += 1;
length--;
}
i++;
}
// generate completely negative string
String replaceString = generate(lengths, -2);
if (replaceString.length() == 0) {
log.warn("No negative characters possible in this expression. All characters are allowed.");
return input;
}
// now replace the #bad character in the input string
List<Integer> l = new ArrayList<Integer>(input.length());
for (i = 0; i < input.length(); i++) {
l.add(i);
}
if (bad == -2) {
// all false
bad = input.length();
} else if (bad == -1) {
bad = 1 + random.getInt(input.length() - 1);
}
Collections.shuffle(l);
StringBuffer base = new StringBuffer(input);
int j = 0;
for (i = 0; i < bad; i++) {
int index = l.remove(0);
char replaceChar = ' ';
if (index < replaceString.length()) {
replaceChar = replaceString.charAt(index);
}
while ((index == 0 || index >= replaceString.length() || index == input.length() - 1) && Character.isSpaceChar(replaceChar)) {
replaceChar = replaceString.charAt(j);
j = (j + 1) % replaceString.length();
}
base.setCharAt(index, replaceChar);
}
if (log.isDebugEnabled()) {
log.debug("False characters in string; " + input + " became " + base);
}
return base.toString();
} | java |
public Range[] getRanges() {
Range[] ranges = new Range[nodes.size()];
for (int i = 0; i < ranges.length; i++) {
ranges[i] = nodes.get(i).getRange();
}
return ranges;
} | java |
public String generate(final int[] nodeSizes, final int bad) {
buf.setLength(0);
for (int i = 0; i < nodes.size() && i < nodeSizes.length; i++) {
buf.append(nodes.get(i).getCharacters(nodeSizes[i], bad));
}
String value = buf.toString();
buf.setLength(0);
return value;
} | java |
public String generate(final int bad) {
int[] sizes = new int[nodes.size()];
for (int i = 0; i < sizes.length; i++) {
Range r = nodes.get(i).getRange();
sizes[i] = r.getMin() + r.getRange() / 2;
}
return generate(sizes, bad);
} | java |
public String generate(int total, final int bad) {
if (total < 0) {
if (log.isDebugEnabled()) {
log.debug("Character string cannot have a negative length!");
}
total = 0;
}
Range[] ranges = getRanges();
int[] lengths = new int[ranges.length];
int length = 0;
// first make sure every single node has at least its minimum length
for (int i = 0; i < ranges.length; i++) {
lengths[i] = ranges[i].getMin();
length += lengths[i];
}
// now increase each node chosen randomly by one until the extra is consumed
int index = 0;
boolean increase = length < total;
if (increase) {
boolean maxedOut = total > getRange().getMax();
while (length < total) {
// if maxed out is true, we have more than normal max characters, so
// we ignore the local max; if not maxed out, the nodes are not bigger than max
if ((maxedOut || ranges[index].getMax() > lengths[index]) && choice.get()) {
lengths[index]++;
length++;
}
index = (index + 1) % lengths.length;
}
} else {
boolean minOut = total < getRange().getMin();
while (length > total) {
// if min out is true, we have less than normal min characters, so
// we ignore the local min; if not min out, the nodes are not smaller than min
if ((minOut || ranges[index].getMin() > lengths[index]) && lengths[index] > 0 && choice.get()) {
lengths[index]--;
length--;
}
index = (index + 1) % lengths.length;
}
}
// now we have distributed the character number to all subnodes of this expression
// build buffer
return generate(lengths, bad);
} | java |
private static int intFromSubArray(final byte[] bytes, final int from, final int to) {
final byte[] subBytes = Arrays.copyOfRange(bytes, from, to);
final ByteBuffer wrap = ByteBuffer.wrap(subBytes);
return wrap.getInt();
} | java |
void startArchiving() {
if (isArchivingDisabled()) {
return;
}
String archiveName = configuration.get(JFunkConstants.ARCHIVE_FILE);
if (StringUtils.isBlank(archiveName)) {
archiveName = String.format(DIR_PATTERN, moduleMetaData.getModuleName(), Thread.currentThread().getName(),
FORMAT.format(moduleMetaData.getStartDate()));
}
moduleArchiveDir = new File(archiveDir, archiveName);
if (moduleArchiveDir.exists()) {
log.warn("Archive directory already exists: {}", moduleArchiveDir);
} else {
moduleArchiveDir.mkdirs();
}
addModuleAppender();
log.info("Started archiving: (module={}, moduleArchiveDir={})", moduleMetaData.getModuleName(), moduleArchiveDir);
} | java |
@Override
public String initValuesImpl(final FieldCase ca) {
if (ca == FieldCase.NULL || ca == FieldCase.BLANK) {
return null;
}
// If there still is an mandatory case, a value will be generated anyway
if (ca != null || last && constraint.hasNextCase() || generator.isIgnoreOptionalConstraints()) {
return constraint.initValues(ca);
}
if (choice.isNext()) {
last = true;
return constraint.initValues(null);
}
// Initialize the field below with 0 as optional equals false
last = false;
constraint.initValues(FieldCase.NULL);
return null;
} | java |
public static String spacesOptional(final String input) {
String output;
output = input.replaceAll("\\s", "\\\\s?");
return output;
} | java |
public static MozuUrl getDiscountSettingsUrl(Integer catalogId, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/catalog/admin/discountsettings/{catalogId}?responseFields={responseFields}");
formatter.formatUrl("catalogId", catalogId);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static Hml read(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return read(reader);
}
} | java |
byte[] readSignResponse() throws IOException {
// Read the first 9 bytes from the InputStream which are the SSH2_AGENT_SIGN_RESPONSE headers.
final byte[] headerBytes = readBytes(9, "SSH2_AGENT_SIGN_RESPONSE");
log.debug("Received SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.");
final SignResponseHeaders headers = SignResponseHeaders.from(headerBytes);
// Read the rest of the SSH2_AGENT_SIGN_RESPONSE message from ssh-agent.
// 5 is the sum of the number of bytes of response code and response length
final byte[] bytes = readBytes(headers.getLength() - 5);
final ByteIterator iterator = new ByteIterator(bytes);
final byte[] responseType = iterator.next();
final String signatureFormatId = new String(responseType);
if (!signatureFormatId.equals(Rsa.RSA_LABEL)) {
throw new RuntimeException("I unexpectedly got a non-Rsa signature format ID in the "
+ "SSH2_AGENT_SIGN_RESPONSE's signature blob.");
}
return iterator.next();
} | java |
public static MozuUrl getTaxableTerritoriesUrl()
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/settings/general/taxableterritories");
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl updateTaxableTerritoriesUrl()
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/settings/general/taxableterritories");
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static Iterable<VcfRecord> records(final Readable readable) throws IOException {
checkNotNull(readable);
ParseListener parseListener = new ParseListener();
VcfParser.parse(readable, parseListener);
return parseListener.getRecords();
} | java |
public Constraint createModel(final MathRandom random, final Element element) {
if (element == null) {
return null;
}
Class<? extends Constraint> classObject = null;
Constraint object = null;
try {
classObject = getClassObject(element);
Constructor<? extends Constraint> constructor = getConstructor(classObject);
object = getObject(random, element, constructor);
} catch (InvocationTargetException ex) {
throw new JFunkException("Could not initialise object of class " + classObject, ex.getCause());
} catch (Exception ex) {
throw new JFunkException("Could not initialise object of class " + classObject, ex);
}
putToCache(element, object);
return object;
} | java |
public Constraint getModel(final Element element) throws IdNotFoundException {
Attribute attr = element.getAttribute(XMLTags.ID);
if (attr == null) {
throw new IdNotFoundException(null);
}
Constraint c = null;
final String id = attr.getValue();
try {
c = getModel(id);
} catch (IdNotFoundException e) {
LOG.debug("DummyConstraint fuer id " + id);
}
if (c == null) {
c = new DummyConstraint();
putToCache(id, c);
}
return c;
} | java |
public Constraint getModel(final String id) throws IdNotFoundException {
Constraint e = map.get(id);
if (e == null) {
throw new IdNotFoundException(id);
}
return e;
} | java |
private Class<? extends Constraint> getClassObject(final Element element) throws ClassNotFoundException {
String className = element.getAttributeValue(XMLTags.CLASS);
className = className.indexOf('.') > 0 ? className : getClass().getPackage().getName() + '.' + className;
return Class.forName(className).asSubclass(Constraint.class);
} | java |
private Constructor<? extends Constraint> getConstructor(final Class<? extends Constraint> classObject) throws NoSuchMethodException {
return classObject.getConstructor(new Class[] { MathRandom.class, Element.class, Generator.class });
} | java |
private Constraint getObject(final MathRandom random, final Element element, final Constructor<? extends Constraint> constructor)
throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
LOG.debug("Creating constraint: " + element.getAttributes());
Constraint instance = constructor.newInstance(new Object[] { random, element, generator });
injector.injectMembers(instance);
return instance;
} | java |
private void putToCache(final Element element, final Constraint object) {
String id = element.getAttributeValue(XMLTags.ID);
if (id != null && id.length() > 0) {
Constraint old = putToCache(id, object);
if (old != null) {
LOG.warn("The id=" + id + " for object of type=" + old.getClass().getName()
+ " was already found. Please make sure this is ok and no mistake.");
}
}
} | java |
private Constraint putToCache(final String id, final Constraint object) {
Constraint c = this.map.put(id, object);
if (c instanceof DummyConstraint) {
((DummyConstraint) c).constraint = object;
return null;
}
return c;
} | java |
public static Analysis readAnalysis(final Reader reader) throws IOException {
checkNotNull(reader);
try {
JAXBContext context = JAXBContext.newInstance(Analysis.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL commonSchemaURL = SraReader.class.getResource("/org/nmdp/ngs/sra/xsd/SRA.common.xsd");
URL analysisSchemaURL = SraReader.class.getResource("/org/nmdp/ngs/sra/xsd/SRA.analysis.xsd");
Schema schema = schemaFactory.newSchema(new StreamSource[] { new StreamSource(commonSchemaURL.toString()), new StreamSource(analysisSchemaURL.toString()) });
unmarshaller.setSchema(schema);
return (Analysis) unmarshaller.unmarshal(reader);
}
catch (JAXBException | SAXException e) {
throw new IOException("could not unmarshal Analysis", e);
}
} | java |
public static Analysis readAnalysis(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readAnalysis(reader);
}
} | java |
public static Analysis readAnalysis(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readAnalysis(reader);
}
} | java |
public static Analysis readAnalysis(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readAnalysis(reader);
}
} | java |
public static Experiment readExperiment(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readExperiment(reader);
}
} | java |
public static Experiment readExperiment(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readExperiment(reader);
}
} | java |
public static Experiment readExperiment(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readExperiment(reader);
}
} | java |
public static RunSet readRunSet(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readRunSet(reader);
}
} | java |
public static RunSet readRunSet(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readRunSet(reader);
}
} | java |
public static RunSet readRunSet(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readRunSet(reader);
}
} | java |
public static Sample readSample(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readSample(reader);
}
} | java |
public static Sample readSample(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readSample(reader);
}
} | java |
public static Sample readSample(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readSample(reader);
}
} | java |
public static Study readStudy(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readStudy(reader);
}
} | java |
public static Study readStudy(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readStudy(reader);
}
} | java |
public static Study readStudy(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readStudy(reader);
}
} | java |
public static Submission readSubmission(final File file) throws IOException {
checkNotNull(file);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
return readSubmission(reader);
}
} | java |
public static Submission readSubmission(final URL url) throws IOException {
checkNotNull(url);
try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
return readSubmission(reader);
}
} | java |
public static Submission readSubmission(final InputStream inputStream) throws IOException {
checkNotNull(inputStream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return readSubmission(reader);
}
} | java |
protected <T> T getScopedObject(final Key<T> key, final Provider<T> unscoped, final Map<Key<?>, Object> scopeMap) {
// ok, because we know what we'd put in before
@SuppressWarnings("unchecked")
T value = (T) scopeMap.get(key);
if (value == null) {
/*
* no cache instance present, so we use the one we get from the unscoped provider and
* add it to the cache
*/
value = unscoped.get();
scopeMap.put(key, value);
}
return value;
} | java |
public static MozuUrl refreshUserAuthTicketUrl(String refreshToken, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/customer/authtickets/refresh?refreshToken={refreshToken}&responseFields={responseFields}");
formatter.formatUrl("refreshToken", refreshToken);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl createUserAuthTicketUrl(String responseFields, Integer tenantId)
{
UrlFormatter formatter = new UrlFormatter("/api/platform/adminuser/authtickets/tenants?tenantId={tenantId}&responseFields={responseFields}");
formatter.formatUrl("responseFields", responseFields);
formatter.formatUrl("tenantId", tenantId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.HOME_POD) ;
} | java |
public static MozuUrl deleteUserAuthTicketUrl(String refreshToken)
{
UrlFormatter formatter = new UrlFormatter("/api/platform/adminuser/authtickets/?refreshToken={refreshToken}");
formatter.formatUrl("refreshToken", refreshToken);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.HOME_POD) ;
} | java |
public static Iterable<BedRecord> read(final Readable readable) throws IOException {
checkNotNull(readable);
Collect collect = new Collect();
stream(readable, collect);
return collect.records();
} | java |
public static void stream(final Readable readable, final BedListener listener) throws IOException {
checkNotNull(readable);
checkNotNull(listener);
BedLineProcessor lineProcessor = new BedLineProcessor(listener);
CharStreams.readLines(readable, lineProcessor);
} | java |
public void copy(final File source) throws IOException {
if (!source.exists()) {
LOG.warn("File " + source + " cannot be copied as it does not exist");
return;
}
if (equals(source)) {
LOG.info("Skipping copying of " + source + " as it matches the target");
return;
}
File target = isDirectory() ? new File(this, source.getName()) : this;
FileUtils.copyFile(source, target);
} | java |
public void zip(final File zipFile) throws IOException {
File[] files = listFiles();
if (files.length == 0) {
return;
}
LOG.info("Creating zip file " + zipFile + " from directory " + this);
ZipOutputStream zipOut = null;
try {
zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
for (File file : files) {
zip("", file, zipOut);
}
} finally {
IOUtils.closeQuietly(zipOut);
}
} | java |
public static Module loadModulesFromProperties(final Module jFunkModule, final String propertiesFile)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
final List<Module> modules = Lists.newArrayList();
LOG.debug("Using jfunk.props.file=" + propertiesFile);
Properties props = loadProperties(propertiesFile);
for (final Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
String name = (String) en.nextElement();
if (name.startsWith("module.")) {
String className = props.getProperty(name);
LOG.info("Loading " + name + "=" + className);
Class<? extends Module> moduleClass = Class.forName(className).asSubclass(Module.class);
Module module = moduleClass.newInstance();
modules.add(module);
}
}
return Modules.override(jFunkModule).with(modules);
} | java |
public Range merge(final Range otherRange) {
int newMin = Math.min(otherRange.min, min);
int newMax = Math.max(otherRange.max, max);
return new Range(newMin, newMax);
} | java |
public Range sumBoundaries(final Range plus) {
int newMin = min + plus.min;
int newMax = max == RANGE_MAX || plus.max == RANGE_MAX ? RANGE_MAX : max + plus.max;
return new Range(newMin, newMax);
} | java |
public Range intersect(final Range outerRange) throws RangeException {
if (min > outerRange.max) {
throw new IllegalArgumentException("range maximum must be greater or equal than " + min);
}
if (max < outerRange.min) {
throw new IllegalArgumentException("range minimum must be less or equal than " + max);
}
int newMin = Math.max(min, outerRange.min);
int newMax = Math.min(max, outerRange.max);
return new Range(newMin, newMax);
} | java |
public List<Integer> listValues() {
ArrayList<Integer> list = new ArrayList<Integer>(getRange());
for (int i = getMin(); i <= getMax(); i++) {
list.add(i);
}
return list;
} | java |
public static MozuUrl getCartItemUrl(String cartItemId, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/carts/current/items/{cartItemId}?responseFields={responseFields}");
formatter.formatUrl("cartItemId", cartItemId);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl addItemsToCartUrl(Boolean throwErrorOnInvalidItems)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/carts/current/bulkitems?throwErrorOnInvalidItems={throwErrorOnInvalidItems}");
formatter.formatUrl("throwErrorOnInvalidItems", throwErrorOnInvalidItems);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl updateCartItemQuantityUrl(String cartItemId, Integer quantity, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/carts/current/items/{cartItemId}/{quantity}?responseFields={responseFields}");
formatter.formatUrl("cartItemId", cartItemId);
formatter.formatUrl("quantity", quantity);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl removeAllCartItemsUrl()
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/carts/current/items");
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl deleteCartItemUrl(String cartItemId)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/carts/current/items/{cartItemId}");
formatter.formatUrl("cartItemId", cartItemId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl processDigitalWalletUrl(String checkoutId, String digitalWalletType, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/checkouts/{checkoutId}/digitalWallet/{digitalWalletType}?responseFields={responseFields}");
formatter.formatUrl("checkoutId", checkoutId);
formatter.formatUrl("digitalWalletType", digitalWalletType);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static VcfHeader header(final Readable readable) throws IOException {
checkNotNull(readable);
ParseListener parseListener = new ParseListener();
VcfParser.parse(readable, parseListener);
return parseListener.getHeader();
} | java |
@Override
protected String initValuesImpl(final FieldCase ca) {
if (ca == FieldCase.NULL || ca == FieldCase.BLANK) {
return null;
}
return field.getString(control.getNext(ca));
} | java |
public static MozuUrl validateTargetRuleUrl()
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/targetrules/validate");
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static String formatLatitude(final Latitude latitude,
final PointLocationFormatType formatType)
throws FormatterException
{
if (latitude == null)
{
throw new FormatterException("No point location provided");
}
if (formatType == null)
{
throw new FormatterException("No format type provided");
}
final String formatted;
switch (formatType)
{
case HUMAN_LONG:
formatted = latitude.toString();
break;
case HUMAN_MEDIUM:
formatted = formatLatitudeHumanMedium(latitude);
break;
case LONG:
formatted = formatLatitudeLong(latitude);
break;
case MEDIUM:
formatted = formatLatitudeMedium(latitude);
break;
case SHORT:
formatted = formatLatitudeShort(latitude);
break;
case DECIMAL:
formatted = formatLatitudeWithDecimals(latitude);
break;
default:
throw new FormatterException("Unsupported format type");
}
return formatted;
} | java |
public static String formatLongitude(final Longitude longitude,
final PointLocationFormatType formatType)
throws FormatterException
{
if (longitude == null)
{
throw new FormatterException("No point location provided");
}
if (formatType == null)
{
throw new FormatterException("No format type provided");
}
final String formatted;
switch (formatType)
{
case HUMAN_LONG:
formatted = longitude.toString();
break;
case HUMAN_MEDIUM:
formatted = formatLongitudeHumanMedium(longitude);
break;
case LONG:
formatted = formatLongitudeLong(longitude);
break;
case MEDIUM:
formatted = formatLongitudeMedium(longitude);
break;
case SHORT:
formatted = formatLongitudeShort(longitude);
break;
case DECIMAL:
formatted = formatLongitudeWithDecimals(longitude);
break;
default:
throw new FormatterException("Unsupported format type");
}
return formatted;
} | java |
public static String formatPointLocation(final PointLocation pointLocation,
final PointLocationFormatType formatType)
throws FormatterException
{
if (pointLocation == null)
{
throw new FormatterException("No point location provided");
}
if (formatType == null)
{
throw new FormatterException("No format type provided");
}
final String formatted;
switch (formatType)
{
case HUMAN_LONG:
formatted = pointLocation.toString();
break;
case HUMAN_MEDIUM:
formatted = formatHumanMedium(pointLocation);
break;
case HUMAN_SHORT:
formatted = formatHumanShort(pointLocation);
break;
case LONG:
formatted = formatISO6709Long(pointLocation);
break;
case MEDIUM:
formatted = formatISO6709Medium(pointLocation);
break;
case SHORT:
formatted = formatISO6709Short(pointLocation);
break;
case DECIMAL:
formatted = formatISO6709WithDecimals(pointLocation);
break;
default:
throw new FormatterException("Unsupported format type");
}
return formatted;
} | java |
private static String formatISO6709WithDecimals(final PointLocation pointLocation)
{
final Latitude latitude = pointLocation.getLatitude();
final Longitude longitude = pointLocation.getLongitude();
String string = formatLatitudeWithDecimals(latitude) +
formatLongitudeWithDecimals(longitude);
final double altitude = pointLocation.getAltitude();
string = string + formatAltitudeWithSign(altitude);
final String crs = pointLocation.getCoordinateReferenceSystemIdentifier();
string = string + formatCoordinateReferenceSystemIdentifier(crs);
return string + "/";
} | java |
private int[] sexagesimalSplit(final double value)
{
final double absValue = Math.abs(value);
int units;
int minutes;
int seconds;
final int sign = value < 0? -1: 1;
// Calculate absolute integer units
units = (int) Math.floor(absValue);
seconds = (int) Math.round((absValue - units) * 3600D);
// Calculate absolute integer minutes
minutes = seconds / 60; // Integer arithmetic
if (minutes == 60)
{
minutes = 0;
units++;
}
// Calculate absolute integer seconds
seconds = seconds % 60;
// Correct for sign
units = units * sign;
minutes = minutes * sign;
seconds = seconds * sign;
return new int[] {
units, minutes, seconds
};
} | java |
public static <N extends Number & Comparable<? super N>> Point singleton(final N value) {
checkNotNull(value);
return Geometries.point(value.doubleValue(), 0.5d);
} | java |
public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) {
checkNotNull(range);
if (range.isEmpty()) {
throw new IllegalArgumentException("range must not be empty");
}
if (!range.hasLowerBound() || !range.hasUpperBound()) {
throw new IllegalArgumentException("range must have lower and upper bounds");
}
Number lowerEndpoint = range.lowerEndpoint();
BoundType lowerBoundType = range.lowerBoundType();
Number upperEndpoint = range.upperEndpoint();
BoundType upperBoundType = range.upperBoundType();
/*
Since we are representing genomic coordinate systems, the expectation is
that endpoints are instance of Integer, Long, or BigInteger; thus for open
lower and upper bounds we can safely add or substract 1.0 respectively.
Then by convention a rectangle with y1 0.0 and height of 1.0 is used.
closed(10, 20) --> (10.0, 0.0, 20.0, 1.0)
closedOpen(10, 20) --> (10.0, 0.0, 19.0, 1.0)
openClosed(10, 20) --> (11.0, 0.0, 20.0, 1.0)
open(10, 20) --> (11.0, 0.0, 19.0, 1.0);
closed(10, 11) --> (10.0, 0.0, 11.0, 1.0)
closedOpen(10, 11) --> (10.0, 0.0, 10.0, 1.0)
openClosed(10, 11) --> (11.0, 0.0, 11.0, 1.0)
open(10, 11) --> empty, throw exception
closed(10, 10) --> (10.0, 0.0, 10.0, 1.0)
closedOpen(10, 10) --> empty, throw exception
openClosed(10, 10) --> empty, throw exception
open(10, 10) --> empty, throw exception
*/
double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue();
double y1 = 0.0d;
double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue();
double y2 = 1.0d;
return Geometries.rectangle(x1, y1, x2, y2);
} | java |
static boolean isLeft(final Fastq fastq) {
checkNotNull(fastq);
return LEFT.matcher(fastq.getDescription()).matches();
} | java |
static boolean isRight(final Fastq fastq) {
checkNotNull(fastq);
return RIGHT.matcher(fastq.getDescription()).matches();
} | java |
static String prefix(final Fastq fastq) {
checkNotNull(fastq);
Matcher m = PREFIX.matcher(fastq.getDescription());
if (!m.matches()) {
throw new PairedEndFastqReaderException("could not parse prefix from description " + fastq.getDescription());
}
return m.group(1);
} | java |
public static GapPenalties create(final int match,
final int replace,
final int insert,
final int delete,
final int extend) {
return new GapPenalties((short) match, (short) replace, (short) insert, (short) delete, (short) extend);
} | java |
public static MozuUrl getAvailablePickupFulfillmentActionsUrl(String orderId, String pickupId)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/orders/{orderId}/pickups/{pickupId}/actions");
formatter.formatUrl("orderId", orderId);
formatter.formatUrl("pickupId", pickupId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl getPickupUrl(String orderId, String pickupId, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/orders/{orderId}/pickups/{pickupId}?responseFields={responseFields}");
formatter.formatUrl("orderId", orderId);
formatter.formatUrl("pickupId", pickupId);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public void setParameter(final String name, final String filename, final InputStream is) throws IOException {
boundary();
writeName(name);
write("; filename=\"");
write(filename);
write('"');
newline();
write("Content-Type: ");
String type = URLConnection.guessContentTypeFromName(filename);
if (type == null) {
type = "application/octet-stream";
}
writeln(type);
newline();
pipe(is, os);
newline();
} | java |
public static MozuUrl getTransactionsUrl(Integer accountId)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/customer/accounts/{accountId}/transactions");
formatter.formatUrl("accountId", accountId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl removeTransactionUrl(Integer accountId, String transactionId)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/customer/accounts/{accountId}/transactions/{transactionId}");
formatter.formatUrl("accountId", accountId);
formatter.formatUrl("transactionId", transactionId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public void send(final Message msg) throws MailException {
Transport transport = null;
try {
if (log.isDebugEnabled()) {
log.debug("Sending mail message [subject={}, recipients={}]", msg.getSubject(),
on(", ").join(msg.getAllRecipients()));
}
transport = sessionProvider.get().getTransport();
transport.connect();
transport.sendMessage(msg, msg.getAllRecipients());
} catch (MessagingException ex) {
throw new MailException("Error sending mail message", ex);
} finally {
try {
transport.close();
} catch (MessagingException ex) {
log.error(ex.getMessage(), ex);
}
}
} | java |
public static MozuUrl getQuoteByNameUrl(Integer customerAccountId, String quoteName, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/quotes/customers/{customerAccountId}/{quoteName}?responseFields={responseFields}");
formatter.formatUrl("customerAccountId", customerAccountId);
formatter.formatUrl("quoteName", quoteName);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl deleteQuoteUrl(String quoteId)
{
UrlFormatter formatter = new UrlFormatter("/api/commerce/quotes/{quoteId}");
formatter.formatUrl("quoteId", quoteId);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl getDBValueUrl(String dbEntryQuery, String responseFields)
{
UrlFormatter formatter = new UrlFormatter("/api/platform/tenantdata/{dbEntryQuery}?responseFields={responseFields}");
formatter.formatUrl("dbEntryQuery", dbEntryQuery);
formatter.formatUrl("responseFields", responseFields);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static MozuUrl createDBValueUrl(String dbEntryQuery)
{
UrlFormatter formatter = new UrlFormatter("/api/platform/tenantdata/{dbEntryQuery}");
formatter.formatUrl("dbEntryQuery", dbEntryQuery);
return new MozuUrl(formatter.getResourceUrl(), MozuUrl.UrlLocation.TENANT_POD) ;
} | java |
public static List<String> normalizeTagsForUpload(List<String> list) {
if (isNullOrEmpty(list)) {
return null;
}
List<String> tmp = new ArrayList<String>();
for (String s : list) {
if (s.contains(" ")) {
tmp.add("\"" + s + "\"");
} else {
tmp.add(s);
}
}
return tmp;
} | java |
public static Integer memberTypeToMemberTypeId(JinxConstants.MemberType memberType) {
if (memberType == null) {
return null;
}
Integer type;
switch (memberType) {
case narwhal:
type = 1;
break;
case member:
type = 2;
break;
case moderator:
type = 3;
break;
case admin:
type = 4;
break;
default:
type = null;
break;
}
return type;
} | java |
public static JinxConstants.MemberType typeIdToMemberType(Integer typeId) {
if (typeId == null) {
return null;
}
JinxConstants.MemberType memberType;
switch (typeId) {
case 1:
memberType = JinxConstants.MemberType.narwhal;
break;
case 2:
memberType = JinxConstants.MemberType.member;
break;
case 3:
memberType = JinxConstants.MemberType.moderator;
break;
case 4:
memberType = JinxConstants.MemberType.admin;
break;
default:
memberType = null;
break;
}
return memberType;
} | java |
public static Integer groupPrivacyEnumToPrivacyId(JinxConstants.GroupPrivacy privacy) {
if (privacy == null) {
return null;
}
Integer id;
switch (privacy) {
case group_private:
id = 1;
break;
case group_invite_only_public:
id = 2;
break;
case group_open_public:
id = 3;
break;
default:
id = null;
break;
}
return id;
} | java |
public static JinxConstants.GroupPrivacy privacyIdToGroupPrivacyEnum(Integer id) {
if (id == null) {
return null;
}
JinxConstants.GroupPrivacy privacy;
switch (id) {
case 1:
privacy = JinxConstants.GroupPrivacy.group_private;
break;
case 2:
privacy = JinxConstants.GroupPrivacy.group_invite_only_public;
break;
case 3:
privacy = JinxConstants.GroupPrivacy.group_open_public;
break;
default:
privacy = null;
break;
}
return privacy;
} | java |
public static Integer suggestionStatusToFlickrSuggestionStatusId(JinxConstants.SuggestionStatus status) {
if (status == null) {
return null;
}
Integer id;
switch (status) {
case pending:
id = 0;
break;
case approved:
id = 1;
break;
case rejected:
id = 2;
break;
default:
id = null;
break;
}
return id;
} | java |
public static JinxConstants.SuggestionStatus suggestionStatusIdToSuggestionStatusEnum(Integer id) {
if (id == null) {
return null;
}
JinxConstants.SuggestionStatus status;
switch (id) {
case 0:
status = JinxConstants.SuggestionStatus.pending;
break;
case 1:
status = JinxConstants.SuggestionStatus.approved;
break;
case 2:
status = JinxConstants.SuggestionStatus.rejected;
break;
default:
status = null;
break;
}
return status;
} | java |
public PhotosetInfo getInfo(String photosetId) throws JinxException {
JinxUtils.validateParams(photosetId);
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.photosets.getInfo");
params.put("photoset_id", photosetId);
return jinx.flickrGet(params, PhotosetInfo.class);
} | java |
public Domains getCollectionDomains(Date date, String collectionId, Integer perPage, Integer page) throws JinxException {
JinxUtils.validateParams(date);
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.stats.getCollectionDomains");
params.put("date", JinxUtils.formatDateAsYMD(date));
if (!JinxUtils.isNullOrEmpty(collectionId)) {
params.put("collection_id", collectionId);
}
if (perPage != null) {
params.put("per_page", perPage.toString());
}
if (page != null) {
params.put("page", page.toString());
}
return jinx.flickrGet(params, Domains.class);
} | java |
public Stats getPhotosetStats(Date date, String photosetId) throws JinxException {
JinxUtils.validateParams(date, photosetId);
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.stats.getPhotosetStats");
params.put("date", JinxUtils.formatDateAsYMD(date));
params.put("photoset_id", photosetId);
return jinx.flickrGet(params, Stats.class);
} | java |
public Photos getPopularPhotos(Date date, JinxConstants.PopularPhotoSort sort, Integer perPage, Integer page) throws JinxException {
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.stats.getPopularPhotos");
if (date != null) {
params.put("date", JinxUtils.formatDateAsYMD(date));
}
if (sort != null) {
params.put("sort", sort.toString());
}
if (perPage != null) {
params.put("per_page", perPage.toString());
}
if (page != null) {
params.put("page", page.toString());
}
return jinx.flickrGet(params, Photos.class);
} | java |
public GroupUrls getGroup(String groupId) throws JinxException {
JinxUtils.validateParams(groupId);
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.urls.getGroup");
params.put("group_id", groupId);
return jinx.flickrGet(params, GroupUrls.class, false);
} | java |
public UserUrls getUserPhotos(String userId) throws JinxException {
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.urls.getUserPhotos");
if (!JinxUtils.isNullOrEmpty(userId)) {
params.put("user_id", userId);
}
return jinx.flickrGet(params, UserUrls.class);
} | java |
public GalleryInfo lookupGallery(String url) throws JinxException {
JinxUtils.validateParams(url);
Map<String, String> params = new TreeMap<>();
params.put("method", "flickr.urls.lookupGallery");
params.put("url", url);
return jinx.flickrGet(params, GalleryInfo.class);
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.