Example usage for java.util Locale ENGLISH

List of usage examples for java.util Locale ENGLISH

Introduction

In this page you can find the example usage for java.util Locale ENGLISH.

Prototype

Locale ENGLISH

To view the source code for java.util Locale ENGLISH.

Click Source Link

Document

Useful constant for language.

Usage

From source file:jenkins.branch.NameMangler.java

public static String apply(String name) {
    if (name.length() <= MAX_SAFE_LENGTH) {
        boolean unsafe = false;
        boolean first = true;
        for (char c : name.toCharArray()) {
            if (first) {
                if (c == '-') {
                    // no leading dash
                    unsafe = true;/* w  w  w . ja  v a2  s.co  m*/
                    break;
                }
                first = false;
            }
            if (!isSafe(c)) {
                unsafe = true;
                break;
            }
        }
        // See https://msdn.microsoft.com/en-us/library/aa365247 we need to consistently reserve names across all OS
        if (!unsafe) {
            // we know it is only US-ASCII if we got to here
            switch (name.toLowerCase(Locale.ENGLISH)) {
            case ".":
            case "..":
            case "con":
            case "prn":
            case "aux":
            case "nul":
            case "com1":
            case "com2":
            case "com3":
            case "com4":
            case "com5":
            case "com6":
            case "com7":
            case "com8":
            case "com9":
            case "lpt1":
            case "lpt2":
            case "lpt3":
            case "lpt4":
            case "lpt5":
            case "lpt6":
            case "lpt7":
            case "lpt8":
            case "lpt9":
                unsafe = true;
                break;
            default:
                if (name.endsWith(".")) {
                    unsafe = true;
                }
                break;
            }
        }
        if (!unsafe) {
            return name;
        }
    }
    StringBuilder buf = new StringBuilder(name.length() + 16);
    for (char c : name.toCharArray()) {
        if (isSafe(c)) {
            buf.append(c);
        } else if (c == '/' || c == '\\' || c == ' ' || c == '.' || c == '_') {
            if (buf.length() == 0) {
                buf.append("0-");
            } else {
                buf.append('-');
            }
        } else if (c <= 0xff) {
            if (buf.length() == 0) {
                buf.append("0_");
            } else {
                buf.append('_');
            }
            buf.append(StringUtils.leftPad(Integer.toHexString(c & 0xff), 2, '0'));
        } else {
            if (buf.length() == 0) {
                buf.append("0_");
            } else {
                buf.append('_');
            }
            buf.append(StringUtils.leftPad(Integer.toHexString(((c & 0xffff) >> 8) & 0xff), 2, '0'));
            buf.append('_');
            buf.append(StringUtils.leftPad(Integer.toHexString(c & 0xff), 2, '0'));
        }
    }
    // use the digest of the original name
    String digest;
    try {
        MessageDigest sha = MessageDigest.getInstance("SHA-1");
        byte[] bytes = sha.digest(name.getBytes(StandardCharsets.UTF_8));
        int bits = 0;
        int data = 0;
        StringBuffer dd = new StringBuffer(32);
        for (byte b : bytes) {
            while (bits >= 5) {
                dd.append(toDigit(data & 0x1f));
                bits -= 5;
                data = data >> 5;
            }
            data = data | ((b & 0xff) << bits);
            bits += 8;
        }
        digest = dd.toString();
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("SHA-1 not installed", e); // impossible
    }
    if (buf.length() <= MAX_SAFE_LENGTH - MIN_HASH_LENGTH - 1) {
        // we have room to add the min hash
        buf.append('.');
        buf.append(StringUtils.right(digest, MIN_HASH_LENGTH));
        return buf.toString();
    }
    // buf now holds the mangled string, we will now try and rip the middle out to put in some of the digest
    int overage = buf.length() - MAX_SAFE_LENGTH;
    String hash;
    if (overage <= MIN_HASH_LENGTH) {
        hash = "." + StringUtils.right(digest, MIN_HASH_LENGTH) + ".";
    } else if (overage > MAX_HASH_LENGTH) {
        hash = "." + StringUtils.right(digest, MAX_HASH_LENGTH) + ".";
    } else {
        hash = "." + StringUtils.right(digest, overage) + ".";
    }
    int start = (MAX_SAFE_LENGTH - hash.length()) / 2;
    buf.delete(start, start + hash.length() + overage);
    buf.insert(start, hash);
    return buf.toString();
}

From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java

/**
 * Construct instance which allows investigating the exception.
 *
 * @param originalException exception to investigate
 *//*from w  w  w. j a va 2  s.  co m*/
public ExceptionUtil(Throwable originalException) {
    this.originalException = originalException;
    isRetryable = false;
    isRecoverable = true;
    Throwable exc = originalException;
    Throwable lastCause = exc;
    StringBuilder concat = new StringBuilder();

    if (exc instanceof InvocationTargetException && null != exc.getCause()) {
        exc = exc.getCause();
    }

    for (Throwable c = exc; c != null; c = getCause(c)) {
        if (concat.length() > 0) {
            concat.append("; ");
        }
        concat.append(getMessage(c));

        String cn = c.getClass().getName().toLowerCase(Locale.ENGLISH);
        String em = c.getMessage();
        if (em == null) {
            em = "";
        }
        em = em.toLowerCase(Locale.ENGLISH);
        if (c instanceof java.rmi.UnmarshalException || c instanceof InvalidClassException
                || c instanceof ClassNotFoundException || c instanceof LinkageError
                || c instanceof VirtualMachineError || c instanceof IllegalAccessException) {
            isRecoverable = false;
        } else {
            if (cn.contains("deadlock") || em.contains("deadlock") || cn.contains("staleobjectexception")
                    || em.contains("staleobjectexception") || cn.contains("sockettimeoutexception")
                    || em.contains("sockettimeoutexception") || cn.contains("communicationexception")
                    || em.contains("communicationexception")
                    || cn.contains("concurrentmodificationexception")) {
                isRetryable = true;
            }
        }
    }

    concatenatedMessage = concat.toString();
    shortMessage = getMessage(lastCause);
}

From source file:de.tynne.benchmarksuite.Main.java

private static String format(Args args, double number) throws IOException {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
    nf.setGroupingUsed(false);//from   w w w.  j a v  a  2s . c o m
    String string = nf.format(number);
    return string.replaceAll("\\.", args.getDecimalDot());
}

From source file:be.dnsbelgium.rdap.jackson.ContactSerializer.java

@Override
public void serialize(Contact contact, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartArray();/*from  www .j  a v a 2  s.  c o m*/
    // start write version
    jsonGenerator.writeStartArray();
    jsonGenerator.writeString("version");
    jsonGenerator.writeStartObject();
    jsonGenerator.writeEndObject();
    jsonGenerator.writeString("text");
    jsonGenerator.writeString("4.0");
    jsonGenerator.writeEndArray();
    // end write version
    for (Contact.Property property : contact.getProperties()) {
        // start write property
        jsonGenerator.writeStartArray();
        // start write property name
        String key = (property.getGroup() == null) ? property.getName()
                : property.getGroup() + "." + property.getName();
        jsonGenerator.writeString(property.getName().toLowerCase(Locale.ENGLISH));
        // end write property name
        // start write property parameters
        jsonGenerator.writeStartObject();
        if (property.getGroup() != null) {
            jsonGenerator.writeFieldName("group");
            jsonGenerator.writeString(property.getGroup());
        }
        if (property.getParameters() != null) {

            Iterator<String> it = property.getParameters().keys();
            while (it.hasNext()) {
                String k = it.next();
                if (k.equalsIgnoreCase("value")) {
                    continue;
                }
                Set<String> values = property.getParameters().get(k);
                if (values.size() == 0) {
                    // no parameters for this property, skip this step
                    continue;
                }
                jsonGenerator.writeFieldName(k.toLowerCase(Locale.ENGLISH));
                if (values.size() == 1) {
                    jsonGenerator.writeString(values.toArray(new String[values.size()])[0]);
                    continue;
                }
                // start write all property parameter values (array)
                jsonGenerator.writeStartArray();
                for (String str : property.getParameters().get(k)) {
                    jsonGenerator.writeString(str);
                }
                jsonGenerator.writeEndArray();
                // end write all property parameter values (array)

            }
        }
        jsonGenerator.writeEndObject();
        // end write property parameters
        // start write property type
        String value = "text";
        if (property.getParameters() != null) {
            Set<String> types = property.getParameters().get("VALUE");
            if (types != null) {
                value = types.iterator().next();
            }
        }
        jsonGenerator.writeString(value);
        // end write property type
        // start write property value
        JsonSerializer s = serializerProvider.findValueSerializer(property.getValue().getClass(), null);
        s.serialize(property.getValue(), jsonGenerator, serializerProvider);
        // end write property value
        jsonGenerator.writeEndArray();
        // end write property
    }
    jsonGenerator.writeEndArray();
}

From source file:com.devnexus.ting.model.support.PresentationSearchQuery.java

public static PresentationSearchQuery create(Event event, Long trackId, String trackName,
        String presentationTypeName, String skillLevelName, String presentationTagsAsString) {

    if (trackId == null && trackName == null && presentationTypeName == null && skillLevelName == null
            && presentationTagsAsString == null) {
        return null;
    }//  w w w.  j  a v  a  2 s. c  om

    final PresentationSearchQuery presentationSearchQuery = new PresentationSearchQuery();
    presentationSearchQuery.setEvent(event);

    if (trackId != null) {
        final Track track = new Track();
        track.setId(trackId);
        presentationSearchQuery.setTrack(track);
    } else if (StringUtils.hasText(trackName)) {
        final Track track = new Track();
        track.setName(StringUtils.trimWhitespace(trackName).toLowerCase(Locale.ENGLISH));
        presentationSearchQuery.setTrack(track);
    }

    if (StringUtils.hasText(presentationTypeName)) {
        final PresentationType presentationType = PresentationType
                .valueOf(StringUtils.trimWhitespace(presentationTypeName).toUpperCase(Locale.ENGLISH));
        presentationSearchQuery.setPresentationType(presentationType);
    }

    if (StringUtils.hasText(skillLevelName)) {
        final SkillLevel skillLevel = SkillLevel
                .valueOf(StringUtils.trimWhitespace(skillLevelName).toUpperCase(Locale.ENGLISH));
        presentationSearchQuery.setSkillLevel(skillLevel);
    }

    if (StringUtils.hasText(presentationTagsAsString)) {

        final Set<String> tagNames = StringUtils.commaDelimitedListToSet(presentationTagsAsString);

        for (String tagName : tagNames) {
            PresentationTag presentationTag = new PresentationTag();
            presentationTag.setName(tagName);
            presentationSearchQuery.getPresentationTags().add(presentationTag);
        }
    }

    return presentationSearchQuery;
}

From source file:com.hypersocket.i18n.I18NServiceImpl.java

@PostConstruct
private void postConstruct() {

    registerBundle(RESOURCE_BUNDLE);//from  w w w.j  a v a 2 s. c o  m
    registerBundle(ConfigurationService.RESOURCE_BUNDLE);
    registerBundle(AuthenticationService.RESOURCE_BUNDLE);
    registerBundle(CertificateResourceService.RESOURCE_BUNDLE);
    registerBundle(EmailNotificationService.RESOURCE_BUNDLE);
    registerBundle(LocalRealmProvider.RESOURCE_BUNDLE);
    registerBundle(PermissionService.RESOURCE_BUNDLE);
    registerBundle(RealmService.RESOURCE_BUNDLE);
    registerBundle(SessionService.RESOURCE_BUNDLE);
    registerBundle(USER_INTERFACE_BUNDLE);

    supportedLocales.add(Locale.ENGLISH);
    //      supportedLocales.add(getLocale("da"));
    //      supportedLocales.add(getLocale("nl"));
    //      supportedLocales.add(getLocale("fi"));
    //      supportedLocales.add(getLocale("fr"));
    //      supportedLocales.add(getLocale("de"));
    //      supportedLocales.add(getLocale("it"));
    //      supportedLocales.add(getLocale("ja"));
    //      supportedLocales.add(getLocale("no"));
    //      supportedLocales.add(getLocale("pl"));
    //      supportedLocales.add(getLocale("ru"));
    //      supportedLocales.add(getLocale("es"));
    //      supportedLocales.add(getLocale("sv"));

}

From source file:com.vrem.wifianalyzer.wifi.channelavailable.ChannelAvailableAdapter.java

@NonNull
@Override/*from   w  w  w.  ja  v  a  2  s  . c o m*/
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(R.layout.channel_available_details, parent, false);
    }

    WiFiChannelCountry wiFiChannelCountry = getItem(position);
    ((TextView) view.findViewById(R.id.channel_available_country))
            .setText(wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName());
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_2)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ2.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_2))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ","));
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_5)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ5.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_5))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ","));
    return view;
}

From source file:ch.ralscha.extdirectspring.provider.SseProvider.java

@ExtDirectMethod(value = ExtDirectMethodType.SSE, group = "group2", entryClass = String.class)
public SSEvent message2(HttpServletResponse response, HttpServletRequest request, HttpSession session,
        Locale locale) {/*  www.ja  v  a 2  s .  c  o m*/
    assertThat(response).isNotNull();
    assertThat(request).isNotNull();
    assertThat(session).isNotNull();
    assertThat(locale).isEqualTo(Locale.ENGLISH);

    Date now = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd 'at' hh:mm:ss");

    SSEvent event = new SSEvent();
    event.setRetry(200000);
    event.setData("Successfully polled at: " + formatter.format(now));
    return event;
}

From source file:org.openmrs.web.controller.concept.ConceptProposalFormControllerTest.java

/**
 * @see ConceptProposalFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)
 */// w w w . ja  va 2  s .  c  om
@Test
@Verifies(value = "should create a single unique synonym and obs for all similar proposals", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)")
public void onSubmit_shouldCreateASingleUniqueSynonymAndObsForAllSimilarProposals() throws Exception {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-proposals.xml");

    ConceptService cs = Context.getConceptService();
    ObsService os = Context.getObsService();
    final Integer conceptproposalId = 5;
    ConceptProposal cp = cs.getConceptProposal(conceptproposalId);
    Concept obsConcept = cp.getObsConcept();
    Concept conceptToMap = cs.getConcept(5);
    Locale locale = Locale.ENGLISH;
    //sanity checks
    Assert.assertFalse(conceptToMap.hasName(cp.getOriginalText(), locale));
    Assert.assertEquals(0,
            os.getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), obsConcept).size());
    List<ConceptProposal> proposals = cs.getConceptProposals(cp.getOriginalText());
    Assert.assertEquals(5, proposals.size());
    for (ConceptProposal conceptProposal : proposals) {
        Assert.assertNull(conceptProposal.getObs());
    }

    // set up the controller
    ConceptProposalFormController controller = (ConceptProposalFormController) applicationContext
            .getBean("conceptProposalForm");
    controller.setApplicationContext(applicationContext);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockHttpSession(null));
    request.setMethod("POST");
    request.addParameter("conceptProposalId", conceptproposalId.toString());
    request.addParameter("finalText", cp.getOriginalText());
    request.addParameter("conceptId", conceptToMap.getConceptId().toString());
    request.addParameter("conceptNamelocale", locale.toString());
    request.addParameter("action", "");
    request.addParameter("actionToTake", "saveAsSynonym");

    HttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mav = controller.handleRequest(request, response);
    assertNotNull(mav);
    assertTrue(mav.getModel().isEmpty());

    Assert.assertEquals(cp.getOriginalText(), cp.getFinalText());
    Assert.assertTrue(conceptToMap.hasName(cp.getOriginalText(), locale));
    Assert.assertNotNull(cp.getObs());
    //Obs should have been created for the 2 proposals with same text, obsConcept but different encounters
    Assert.assertEquals(2,
            os.getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), obsConcept).size());

    //The proposal with a different obs concept should have been skipped
    proposals = cs.getConceptProposals(cp.getFinalText());
    Assert.assertEquals(1, proposals.size());
    Assert.assertEquals(21, proposals.get(0).getObsConcept().getConceptId().intValue());
}

From source file:com.isalnikov.config.MessageTest.java

@Test
public void testHelloConfigurer() {
    System.out.println(messageHelper.getMessage("hello"));
    System.out.println(messageHelper.getMessage(Locale.CANADA, "hello"));
    System.out.println(messageHelper.getMessage(Locale.ENGLISH, "hello"));
    System.out.println(messageHelper.getMessage(new Locale("ru"), "hello"));
    System.out.println(messageHelper.getMessage(new Locale("ru_RU"), "hello"));
}