Example usage for java.lang Character equals

List of usage examples for java.lang Character equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object against the specified object.

Usage

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

/**
 * @see WcmService#lock(Long, Character, org.gatein.wcm.domain.UserWcm)
 *///w  w  w . jav a2 s .c  o m
@Override
public void lock(Long originId, Character type, UserWcm user) throws WcmLockException, WcmException {
    if (originId == null || type == null || user == null) {
        throw new WcmException("Illegal lock() invocation");
    }
    try {
        LockPK pk = new LockPK();
        pk.setOriginId(originId);
        pk.setType(type);
        Lock lock = em.find(Lock.class, pk);
        if (lock != null && !lock.getUsername().equals(user.getUsername())) {
            String msg = "Lock for ";
            if (type.equals(Wcm.LOCK.POST)) {
                msg += " Post ID " + originId;
            } else if (type.equals(Wcm.LOCK.CATEGORY)) {
                msg += " Category ID " + originId;
            } else if (type.equals(Wcm.LOCK.UPLOAD)) {
                msg += " Upload ID " + originId;
            } else if (type.equals(Wcm.LOCK.TEMPLATE)) {
                msg += " Template ID " + originId;
            }
            msg += " by user: " + lock.getUsername() + " at " + ParseDates.parse(lock.getCreated());
            throw new WcmLockException(msg);
        }
        if (lock == null) {
            lock = new Lock();
            lock.setOriginId(originId);
            lock.setType(type);
            lock.setUsername(user.getUsername());
            lock.setCreated(Calendar.getInstance());
            em.persist(lock);
        }
    } catch (WcmLockException e) {
        throw new WcmLockException(e.getMessage());
    } catch (Exception e) {
        throw new WcmException(e);
    }
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private Map<Long, Long> updateCategories(List<Category> categories, Character strategy) throws Exception {
    Map<Long, Long> mCategories = new HashMap<Long, Long>();

    for (Category newC : categories) {
        Category oldC = em.find(Category.class, newC.getId());
        if (oldC == null) {
            Long importId, newId;

            importId = newC.getId();/* w  w  w.  ja  va 2 s  . c  o  m*/
            newC = em.merge(newC);
            newId = newC.getId();
            // We are trying to import a previous detached object and EM can return a new ID
            // We need to maintain a table with new IDs to update references in next objects
            mCategories.put(importId, newId);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldC.setName(newC.getName());
                oldC.setType(newC.getType());

                em.merge(oldC);
                // Existing object with same ID, but we will add it to the table to use a similiar process for processing
                mCategories.put(oldC.getId(), oldC.getId());
            }
        }
    }

    return mCategories;
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private List<PostHistoryPK> updatePostsHistory(List<PostHistory> posts, Character strategy,
        Map<Long, Long> mPosts) throws Exception {
    List<PostHistoryPK> mPostsHistory = new ArrayList<PostHistoryPK>();

    for (PostHistory newP : posts) {
        // Update ID reference
        Long newId = mPosts.get(newP.getId());
        if (newId == null)
            newId = newP.getId();/*from   w  w w.  ja  va2  s  .  com*/
        newP.setId(newId);

        PostHistoryPK pk = new PostHistoryPK();
        pk.setId(newP.getId());
        pk.setVersion(newP.getVersion());
        PostHistory oldP = em.find(PostHistory.class, pk);
        if (oldP == null) {
            em.persist(newP);
            mPostsHistory.add(pk);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldP.setAuthor(newP.getAuthor());
                oldP.setContent(newP.getContent());
                oldP.setCreated(newP.getCreated());
                oldP.setDeleted(newP.getDeleted());
                oldP.setExcerpt(newP.getExcerpt());
                oldP.setLocale(newP.getLocale());
                oldP.setModified(newP.getModified());
                oldP.setPostStatus(newP.getPostStatus());
                oldP.setTitle(newP.getTitle());
                oldP.setVersion(newP.getVersion());

                em.merge(oldP);
                mPostsHistory.add(pk);
            }
        }
    }

    return mPostsHistory;
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private Map<Long, Long> updateUploads(List<Upload> uploads, Character strategy, String uploadsFolder,
        String targetFolder) throws Exception {
    Map<Long, Long> mUploads = new HashMap<Long, Long>();

    for (Upload newU : uploads) {
        Upload oldU = em.find(Upload.class, newU.getId());
        String tempPath = uploadsFolder + "/" + newU.getStoredName();
        String newPath = targetFolder + "/" + newU.getStoredName();
        if (oldU == null) {
            Long importId, newId;

            importId = newU.getId();/*from www .j a v  a  2s .  co m*/
            newU = em.merge(newU);
            newId = newU.getId();

            mUploads.put(importId, newId);
            FileAux.moveFile(tempPath, newPath);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldU.setCreated(newU.getCreated());
                oldU.setDescription(newU.getDescription());
                oldU.setFileName(newU.getFileName());
                oldU.setMimeType(newU.getMimeType());
                oldU.setModified(newU.getModified());
                oldU.setStoredName(newU.getStoredName());
                oldU.setUser(newU.getUser());
                oldU.setVersion(newU.getVersion());

                em.merge(oldU);
                mUploads.put(oldU.getId(), oldU.getId());
                FileAux.moveFile(tempPath, newPath);
            }
        }
    }

    return mUploads;
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private List<TemplateHistoryPK> updateTemplatesHistory(List<TemplateHistory> templates, Character strategy,
        Map<Long, Long> mTemplates) throws Exception {
    List<TemplateHistoryPK> mTemplatesHistory = new ArrayList<TemplateHistoryPK>();

    for (TemplateHistory newT : templates) {
        // Update ID reference
        Long newId = mTemplates.get(newT.getId());
        if (newId == null)
            newId = newT.getId();/*from ww w .j av  a  2  s . co  m*/
        newT.setId(newId);

        TemplateHistoryPK pk = new TemplateHistoryPK();
        pk.setId(newT.getId());
        pk.setVersion(newT.getVersion());
        TemplateHistory oldT = em.find(TemplateHistory.class, pk);
        if (oldT == null) {
            em.persist(newT);
            mTemplatesHistory.add(pk);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldT.setCreated(newT.getCreated());
                oldT.setContent(newT.getContent());
                oldT.setDeleted(newT.getDeleted());
                oldT.setLocale(newT.getLocale());
                oldT.setModified(newT.getModified());
                oldT.setName(newT.getName());
                oldT.setUser(newT.getUser());
                oldT.setVersion(newT.getVersion());

                em.merge(oldT);
                mTemplatesHistory.add(pk);
            }
        }
    }

    return mTemplatesHistory;
}

From source file:ffx.potential.parsers.BiojavaFilter.java

/**
 * Convert possibly duplicate chain IDs into unique segIDs.
 *
 * @param c chain ID just read./*from  w w w.j a  v a  2 s  .  co  m*/
 * @return a unique segID.
 */
private String getSegID(Character c) {
    if (c.equals(' ')) {
        c = 'A';
    }

    // If the chain ID has not changed, return the existing segID.
    if (c.equals(currentChainID)) {
        return currentSegID;
    }

    // Loop through existing segIDs to find the first one that is unused.
    int n = segIDs.size();
    int count = 0;
    for (int i = 0; i < n; i++) {
        String segID = segIDs.get(i);
        if (segID.endsWith(c.toString())) {
            count++;
        }
    }

    // If the count is greater than 0, then append it.
    String newSegID;
    if (count == 0) {
        newSegID = c.toString();
    } else {
        newSegID = Integer.toString(count) + c.toString();
    }

    segIDs.add(newSegID);
    currentChainID = c;
    currentSegID = newSegID;

    return newSegID;
}

From source file:ffx.potential.parsers.PDBFilter.java

/**
 * Convert possibly duplicate chain IDs into unique segIDs.
 *
 * @param c chain ID just read./*from   ww w. j a  v  a2s .  co m*/
 * @return a unique segID.
 */
private String getSegID(Character c) {
    if (c.equals(' ')) {
        c = 'A';
    }

    // If the chain ID has not changed, return the existing segID.
    if (c.equals(currentChainID)) {
        return currentSegID;
    }

    // Loop through existing segIDs to find the first one that is unused.
    int n = segIDs.size();
    int count = 0;
    for (int i = 0; i < n; i++) {
        String segID = segIDs.get(i);
        if (segID.endsWith(c.toString())) {
            count++;
        }
    }

    // If the count is greater than 0, then append it.
    String newSegID;
    if (count == 0) {
        newSegID = c.toString();
    } else {
        newSegID = Integer.toString(count) + c.toString();
    }

    segIDs.add(newSegID);
    currentChainID = c;
    currentSegID = newSegID;

    if (segidMap.containsKey(c)) {
        segidMap.get(c).add(newSegID);
    } else {
        List<String> newChainList = new ArrayList<>();
        newChainList.add(newSegID);
        segidMap.put(c, newChainList);
    }

    return newSegID;
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private List<UploadHistoryPK> updateUploadsHistory(List<UploadHistory> uploads, Character strategy,
        String uploadsFolder, String targetFolder, Map<Long, Long> mUploads) throws Exception {
    List<UploadHistoryPK> mUploadsHistory = new ArrayList<UploadHistoryPK>();

    for (UploadHistory newU : uploads) {
        // Update ID reference
        Long newId = mUploads.get(newU.getId());
        if (newId == null)
            newId = newU.getId();//  w  w w .j  a  v a2  s .c  om
        newU.setId(newId);

        UploadHistoryPK pk = new UploadHistoryPK();
        pk.setId(newU.getId());
        pk.setVersion(newU.getVersion());
        UploadHistory oldU = em.find(UploadHistory.class, pk);
        String tempPath = uploadsFolder + "/" + newU.getStoredName();
        String newPath = targetFolder + "/" + newU.getStoredName();
        if (oldU == null) {
            em.persist(newU);
            mUploadsHistory.add(pk);
            FileAux.moveFile(tempPath, newPath);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldU.setCreated(newU.getCreated());
                oldU.setDeleted(newU.getDeleted());
                oldU.setDescription(newU.getDescription());
                oldU.setFileName(newU.getFileName());
                oldU.setMimeType(newU.getMimeType());
                oldU.setModified(newU.getModified());
                oldU.setStoredName(newU.getStoredName());
                oldU.setUser(newU.getUser());
                oldU.setVersion(newU.getVersion());

                em.merge(oldU);
                mUploadsHistory.add(pk);
                FileAux.moveFile(tempPath, newPath);
            }
        }
    }

    return mUploadsHistory;
}

From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java

private List<RelationshipPK> updateRelationships(List<Relationship> relationships, Character strategy,
        Map<Long, Long> mPosts, Map<Long, Long> mTemplates) throws Exception {
    List<RelationshipPK> mRelationships = new ArrayList<RelationshipPK>();

    for (Relationship newR : relationships) {
        if (newR.getType().equals(Wcm.RELATIONSHIP.POST)) {
            newR.setOriginId(mPosts.get(newR.getOriginId()));
            if (newR.getAliasId() != null) {
                newR.setAliasId(mPosts.get(newR.getAliasId()));
            }/*from w  ww . j  ava2s.c  om*/
        } else {
            newR.setOriginId(mTemplates.get(newR.getOriginId()));
            if (newR.getAliasId() != null) {
                newR.setAliasId(mTemplates.get(newR.getAliasId()));
            }
        }

        RelationshipPK pk = new RelationshipPK();
        pk.setKey(newR.getKey());
        pk.setOriginId(newR.getOriginId());
        pk.setType(newR.getType());
        Relationship oldR = em.find(Relationship.class, pk);
        if (oldR == null) {
            em.persist(newR);
            mRelationships.add(pk);
        } else {
            if (!strategy.equals(Wcm.IMPORT.STRATEGY.UPDATE)) {
                oldR.setKey(newR.getKey());
                oldR.setType(newR.getType());
                oldR.setAliasId(newR.getAliasId());
                oldR.setOriginId(newR.getOriginId());

                em.merge(oldR);
                mRelationships.add(pk);
            }
        }
    }

    return mRelationships;
}

From source file:ffx.potential.parsers.PDBFilter.java

@Override
public boolean readNext(boolean resetPosition) {
    // ^ is beginning of line, \\s+ means "one or more whitespace", (\\d+) means match and capture one or more digits.
    Pattern modelPatt = Pattern.compile("^MODEL\\s+(\\d+)");
    modelsRead = resetPosition ? 1 : modelsRead + 1;
    boolean eof = true;

    for (MolecularAssembly system : systems) {
        File file = system.getFile();
        currentFile = file;/*w w w .  jav  a  2  s. c  o  m*/
        try {
            BufferedReader currentReader;
            if (readers.containsKey(system)) {
                currentReader = readers.get(system);
                if (!currentReader.ready()) {
                    currentReader = new BufferedReader(new FileReader(currentFile));
                    readers.put(system, currentReader);
                }
            } else {
                currentReader = new BufferedReader(new FileReader(currentFile));
                readers.put(system, currentReader);
            }
            // Skip to appropriate model.
            String line = currentReader.readLine();
            while (line != null) {
                line = line.trim();
                Matcher m = modelPatt.matcher(line);
                if (m.find()) {
                    int modelNum = Integer.parseInt(m.group(1));
                    if (modelNum == modelsRead) {
                        logger.log(Level.INFO,
                                String.format(" Reading model %d for %s", modelNum, currentFile));
                        eof = false;
                        break;
                    }
                }
                line = currentReader.readLine();
            }

            if (eof) {
                logger.log(Level.INFO, String.format(" End of file reached for %s", file));
                currentReader.close();
                return false;
            }

            // Begin parsing the model.
            boolean modelDone = false;
            line = currentReader.readLine();
            while (line != null) {
                line = line.trim();
                String recID = line.substring(0, Math.min(6, line.length())).trim();
                try {
                    Record record = Record.valueOf(recID);
                    boolean hetatm = true;
                    switch (record) {
                    // =============================================================================
                    //
                    //  7 - 11        Integer       serial       Atom serial number.
                    // 13 - 16        Atom          name         Atom name.
                    // 17             Character     altLoc       Alternate location indicator.
                    // 18 - 20        Residue name  resName      Residue name.
                    // 22             Character     chainID      Chain identifier.
                    // 23 - 26        Integer       resSeq       Residue sequence number.
                    // 27             AChar         iCode        Code for insertion of residues.
                    // 31 - 38        Real(8.3)     x            Orthogonal coordinates for X in Angstroms.
                    // 39 - 46        Real(8.3)     y            Orthogonal coordinates for Y in Angstroms.
                    // 47 - 54        Real(8.3)     z            Orthogonal coordinates for Z in Angstroms.
                    // 55 - 60        Real(6.2)     occupancy    Occupancy.
                    // 61 - 66        Real(6.2)     tempFactor   Temperature factor.
                    // 77 - 78        LString(2)    element      Element symbol, right-justified.
                    // 79 - 80        LString(2)    charge       Charge  on the atom.
                    // =============================================================================
                    //         1         2         3         4         5         6         7
                    //123456789012345678901234567890123456789012345678901234567890123456789012345678
                    //ATOM      1  N   ILE A  16      60.614  71.140 -10.592  1.00  7.38           N
                    //ATOM      2  CA  ILE A  16      60.793  72.149  -9.511  1.00  6.91           C
                    case ATOM:
                        hetatm = false;
                    case HETATM:
                        if (!line.substring(17, 20).trim().equals("HOH")) {
                            //int serial = Hybrid36.decode(5, line.substring(6, 11));
                            String name = line.substring(12, 16).trim();
                            if (name.toUpperCase().contains("1H") || name.toUpperCase().contains("2H")
                                    || name.toUpperCase().contains("3H")) {
                                // VERSION3_2 is presently just a placeholder for "anything non-standard".
                                fileStandard = VERSION3_2;
                            }
                            Character altLoc = line.substring(16, 17).toUpperCase().charAt(0);
                            if (!altLoc.equals(' ') && !altLoc.equals('A') && !altLoc.equals(currentAltLoc)) {
                                break;
                            }
                            String resName = line.substring(17, 20).trim();
                            Character chainID = line.substring(21, 22).charAt(0);

                            List<String> segIDList = segidMap.get(chainID);
                            if (segIDList == null) {
                                logger.log(Level.WARNING,
                                        String.format(
                                                " No " + "known segment ID corresponds to " + "chain ID %s",
                                                chainID.toString()));
                                break;
                            }

                            String segID = segIDList.get(0);
                            if (segIDList.size() > 1) {
                                logger.log(Level.WARNING,
                                        String.format(
                                                " " + "Multiple segment IDs correspond to"
                                                        + "chain ID %s; assuming %s",
                                                chainID.toString(), segID));
                            }

                            int resSeq = Hybrid36.decode(4, line.substring(22, 26));

                            double[] d = new double[3];
                            d[0] = new Double(line.substring(30, 38).trim());
                            d[1] = new Double(line.substring(38, 46).trim());
                            d[2] = new Double(line.substring(46, 54).trim());
                            double occupancy = 1.0;
                            double tempFactor = 1.0;
                            Atom newAtom = new Atom(0, name, altLoc, d, resName, resSeq, chainID, occupancy,
                                    tempFactor, segID);
                            newAtom.setHetero(hetatm);
                            // Check if this is a modified residue.
                            if (modres.containsKey(resName.toUpperCase())) {
                                newAtom.setModRes(true);
                            }

                            Atom returnedAtom = activeMolecularAssembly.findAtom(newAtom);
                            if (returnedAtom != null) {
                                returnedAtom.setXYZ(d);
                                double[] retXYZ = new double[3];
                                returnedAtom.getXYZ(retXYZ);
                            } else {
                                String message = String.format(" " + "Could not find atom %s in assembly",
                                        newAtom.toString());
                                if (dieOnMissingAtom) {
                                    logger.severe(message);
                                } else {
                                    logger.warning(message);
                                }
                            }
                            break;
                        }
                    case ENDMDL:
                    case END: // Technically speaking, END should be at the end of the file, not end of the model.
                        logger.log(Level.FINE, String.format(" Model %d successfully read", modelsRead));
                        modelDone = true;
                    default:
                        break;
                    }
                } catch (Exception ex) {
                    // Do nothing; it's not an ATOM/HETATM line.
                }
                if (modelDone) {
                    break;
                }
                line = currentReader.readLine();

            }
            return true;
        } catch (IOException ex) {
            logger.info(String.format(" Exception in parsing frame %d of %s:" + " %s", modelsRead,
                    system.toString(), ex.toString()));
        }
    }
    return false;
}