Example usage for java.lang Character Character

List of usage examples for java.lang Character Character

Introduction

In this page you can find the example usage for java.lang Character Character.

Prototype

@Deprecated(since = "9")
public Character(char value) 

Source Link

Document

Constructs a newly allocated Character object that represents the specified char value.

Usage

From source file:org.docx4j.fonts.fop.fonts.SingleByteFont.java

/** {@inheritDoc} */
public int getWidth(int i, int size) {
    if (i < 256) {
        int idx = i - getFirstChar();
        if (idx >= 0 && idx < width.length) {
            return size * width[i - getFirstChar()];
        }//from  w  w  w.j  a v a  2s .c om
    } else if (this.additionalEncodings != null) {
        int encodingIndex = (i / 256) - 1;
        SimpleSingleByteEncoding encoding = getAdditionalEncoding(encodingIndex);
        int codePoint = i % 256;
        NamedCharacter nc = encoding.getCharacterForIndex(codePoint);
        UnencodedCharacter uc = (UnencodedCharacter) this.unencodedCharacters
                .get(new Character(nc.getSingleUnicodeValue()));
        return size * uc.getWidth();
    }
    return 0;
}

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

private static Character parseCharacter(String value) throws ParseException {
        if (value.length() != 1) {
            throw new ParseException("Cannot parse '" + value + "' as character", value.length());
        }/*w  w w .  j  a  va2s  .c  o m*/
        return new Character(value.charAt(0));
    }

From source file:Getopts.java

/**
 * Returns existence of an option./*  ww  w. ja  va 2s  .  c  om*/
 *
 * @return true of option 'c' exists, else return false.
 * @param c any character
 */
public boolean hasOption(char c) {
    if (options == null)
        return false;
    return options.containsKey(new Character(c));
}

From source file:org.gbif.portal.web.tag.AlphabetLinkTag.java

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
 *///from   w w  w  . j  av  a2 s. c  o m
@Override
public int doStartTag() throws JspException {
    if (letters == null || letters.isEmpty()) {
        return super.doStartTag();
    }

    StringBuffer sb = new StringBuffer();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String contextPath = request.getContextPath();
    List<Character> ignoreChars = new ArrayList<Character>();

    if (StringUtils.isNotEmpty(ignores)) {
        ignores = ignores.trim();
        StringTokenizer st = new StringTokenizer(ignores);
        while (st.hasMoreTokens()) {
            String ignoreChar = st.nextToken();
            if (ignoreChar.length() != 1) {
                throw new JspException("Invalid ignore list :" + ignoreChar);
            }
            ignoreChars.add(new Character(ignoreChar.charAt(0)));
        }
    }

    sb.append("<ul class=\"");
    sb.append(listClass);
    sb.append("\">");
    sb.append("<li class=\"lt\">");

    int indexOfSelected = letters.indexOf(selected);

    if (indexOfSelected > 0) {
        addLink(sb, contextPath, letters.get(indexOfSelected - 1), "&lt;&lt;");
    } else {
        sb.append("&lt;&lt;");
    }
    sb.append("</li>");

    List acceptedChars = Arrays.asList(accepted);
    for (Character letter : letters) {
        if (!ignoreChars.contains(letter) && acceptedChars.contains(letter.toString())) {
            sb.append("<li");
            if (selected != letter) {
                sb.append('>');
                addLink(sb, contextPath, letter);
            } else {
                sb.append(" id=\"chosen\">");
                sb.append(letter);
            }
            sb.append("</li>");
        }
    }

    sb.append("<li class=\"lt\">");

    if (indexOfSelected < (letters.size() - 1)) {
        addLink(sb, contextPath, letters.get(indexOfSelected + 1), "&gt;&gt;");
    } else {
        sb.append("&gt;&gt;");
    }
    sb.append("</li>");
    sb.append("</ul>");

    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }
    return super.doStartTag();
}

From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.array.CharArrayMorpher.java

public Object morph(Object array) {
    if (array == null) {
        return null;
    }//from   ww  w .j a va  2s.  co m

    if (CHAR_ARRAY_CLASS.isAssignableFrom(array.getClass())) {
        // no conversion needed
        return (char[]) array;
    }

    if (array.getClass().isArray()) {
        int length = Array.getLength(array);
        int dims = getDimensions(array.getClass());
        int[] dimensions = createDimensions(dims, length);
        Object result = Array.newInstance(char.class, dimensions);
        CharMorpher morpher = isUseDefault() ? new CharMorpher(defaultValue) : new CharMorpher();
        if (dims == 1) {
            for (int index = 0; index < length; index++) {
                Array.set(result, index, new Character(morpher.morph(Array.get(array, index))));
            }
        } else {
            for (int index = 0; index < length; index++) {
                Array.set(result, index, morph(Array.get(array, index)));
            }
        }
        return result;
    } else {
        throw new MorphException("argument is not an array: " + array.getClass());
    }
}

From source file:org.gatein.wcm.portlet.editor.views.ManagerActions.java

public String eventRemoveLock(ResourceRequest request, ResourceResponse response, UserWcm userWcm) {
    String namespace = request.getParameter("namespace");
    String lockid = request.getParameter("lockid");
    String locktype = request.getParameter("locktype");
    try {/*  w w w  .j a va 2  s .c  o m*/
        // Remove lock
        wcm.removeLock(new Long(lockid), new Character(locktype.charAt(0)), userWcm);
        // List of locks
        List<Lock> locks = wcm.findLocks(userWcm);
        Map<Long, Object> locksObjects = wcm.findLocksObjects(locks, userWcm);
        request.setAttribute("locks", locks);
        request.setAttribute("locksObjects", locksObjects);
        request.setAttribute("namespace", namespace);
    } catch (Exception e) {
        log.warning("Error locks");
        e.printStackTrace();
    }
    return "/jsp/manager/managerLocks.jsp";
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.person.EditPersonController.java

@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
    AddPersonCommand data = (AddPersonCommand) super.formBackingObject(request);

    String idString = request.getParameter("id");
    if (idString != null) {
        int id = Integer.parseInt(idString);

        log.debug("Loading person to command object for editing.");
        Person person = personDao.read(id);

        data.setId(id);/* w  w w  . j  ava  2s . c  om*/
        data.setGivenname(person.getGivenname());
        data.setSurname(person.getSurname());
        data.setDateOfBirth(ControllerUtils.getDateFormat().format(person.getDateOfBirth()));
        data.setGender(new Character(person.getGender()).toString());
        data.setEmail(person.getUsername());
        data.setPhoneNumber(person.getPhoneNumber());
        data.setNote(person.getNote());
        data.setOldEmail(person.getUsername());
    }

    return data;
}

From source file:fr.treeptik.cloudunit.cli.utils.AuthentificationUtils.java

/**
 * Methode de connexion// ww  w  .j  ava  2  s  .  c  om
 *
 * @param login
 * @param password
 * @param selectedHost
 * @return
 */
public String connect(String login, String password, String selectedHost) {

    if (!map.isEmpty()) {
        statusCommand.setExitStatut(0);
        return (ANSIConstants.ANSI_PURPLE + "You are already connected to CloudUnit servers"
                + ANSIConstants.ANSI_RESET);
    }

    if (fileUtils.isInFileExplorer()) {
        statusCommand.setExitStatut(1);
        return (ANSIConstants.ANSI_RED
                + "You are currently in a container file explorer. Please exit it with close-explorer command"
                + ANSIConstants.ANSI_RESET);

    }

    try {
        loop++;

        if (password.equalsIgnoreCase("")) {
            log.log(Level.INFO, "Enter your password : ");
            try {
                password = new ConsoleReader().readLine(new Character('*'));
            } catch (IOException e) {
                return ANSIConstants.ANSI_RED + e.getMessage() + ANSIConstants.ANSI_RESET;
            }
        }
        Map<String, Object> loginInfo = new HashMap<>();
        loginInfo.put("login", login);
        loginInfo.put("password", password);

        // check the host

        if (!selectedHost.isEmpty()) {
            log.log(Level.INFO, "Trying to connect to " + selectedHost);
            finalHost = selectedHost;

        } else {
            log.log(Level.INFO, "Trying to connect to default CloudUnit host...");
            finalHost = defaultHost;
        }

        // trying to connect with host manager
        String urlToCall = finalHost + urlLoader.connect;
        restUtils.connect(urlToCall, loginInfo).get("body");
        applicationUtils.setApplication(null);

        String response = null;
        String cloudunitInstance = "";
        try {
            response = restUtils.sendGetCommand(finalHost + urlLoader.getCloudUnitInstance, null).get("body");
            cloudunitInstance = JsonConverter.getCloudUnitInstance(response);
            if (cloudunitInstance != null) {
                cloudunitInstance = "-" + cloudunitInstance;
            }
            clPromptProvider.setCuInstanceName(cloudunitInstance);
        } catch (ManagerResponseException e) {
            statusCommand.setExitStatut(1);
            return ANSIConstants.ANSI_RED + e.getMessage() + ANSIConstants.ANSI_RESET;
        }

    } catch (ManagerResponseException e) {
        statusCommand.setExitStatut(1);
        if (loop >= 3) {
            return ANSIConstants.ANSI_RED + e.getMessage() + ANSIConstants.ANSI_RESET;
        }

        password = "";
        return this.connect(login, password, selectedHost);
    }

    map.put("login", login);
    map.put("password", password);
    loop = 0;

    try {
        Boolean checkingAPI = this.checkAPIVersion(finalHost);
    } catch (ManagerResponseException e) {
        statusCommand.setExitStatut(1);
        return ANSIConstants.ANSI_RED + e.getMessage() + ANSIConstants.ANSI_RESET;
    }

    // Test if connection was successful
    /*
    if (checkingAPI == null) {
     restUtils.localContext = null;
     this.map.clear();
     return null;
    }
    // Test if CLI is compatible to CU API
    if (!checkingAPI) {
     log.log(Level.SEVERE, "Please update your CLI");
     restUtils.localContext = null;
     this.map.clear();
     return null;
    }
    */
    statusCommand.setExitStatut(0);
    return "Connection established";

}

From source file:de.codesourcery.eve.skills.datamodel.UserAccount.java

public void syncWithServer(IUserAccountStore accountStore, Collection<IBaseCharacter> fromServer) {

    if (log.isDebugEnabled()) {
        log.debug("syncWithServer(): Syncing characters of account " + this + " with server");
    }/*from  w w  w  . j  a  va2  s. com*/

    final List<ICharacter> existing = new ArrayList<ICharacter>(getCharacters());

    for (ICharacter c : existing) {
        if (!containsCharacter(fromServer, c)) {
            if (log.isDebugEnabled()) {
                log.debug("syncWithServer(): Removing character " + c);
            }
            accountStore.notifyCharacterAboutToBeRemoved(this, c);
            removeCharacter(c.getCharacterId());
        }
    }

    for (IBaseCharacter c : fromServer) {
        if (containsCharacter(c)) {
            continue;
        }

        final Character newChar = new Character(c);
        if (log.isDebugEnabled()) {
            log.debug("syncWithServer(): Adding character " + newChar);
        }
        addCharacter(newChar);
        accountStore.notifyCharacterAdded(this, newChar);
    }

    if (log.isDebugEnabled()) {
        log.debug("syncWithServer(): Finished syncing : " + this);
    }
}

From source file:org.apache.fop.fonts.Typeface.java

/**
 * Provide proper warning if a glyph is not available.
 *
 * @param c/*from w ww.j  av  a  2 s  . c o  m*/
 *            the character which is missing.
 */
protected void warnMissingGlyph(char c) {
    // Give up, character is not available
    Character ch = new Character(c);
    if (warnedChars == null) {
        warnedChars = new HashSet<Character>();
    }
    if (warnedChars.size() < 8 && !warnedChars.contains(ch)) {
        warnedChars.add(ch);
        if (this.eventListener != null) {
            this.eventListener.glyphNotAvailable(this, c, getFontName());
        } else {
            if (warnedChars.size() == 8) {
                log.warn("Many requested glyphs are not available in font " + getFontName());
            } else {
                log.warn("Glyph " + (int) c + " (0x" + Integer.toHexString(c) + ", " + Glyphs.charToGlyphName(c)
                        + ") not available in font " + getFontName());
            }
        }
    }
}