List of usage examples for java.util LinkedHashMap get
public V get(Object key)
From source file:com.smartitengineering.dao.impl.hbase.CommonDao.java
protected void put(Template[] states, final boolean merge) throws IllegalStateException { LinkedHashMap<String, List<Put>> allPuts = new LinkedHashMap<String, List<Put>>(); for (Template state : states) { if (!state.isValid()) { throw new IllegalStateException("Entity not in valid state!"); }/* w w w. j ava 2 s .c o m*/ final LinkedHashMap<String, Put> puts; puts = getConverter().objectToRows(state, executorService, getLockType().equals(LockType.PESSIMISTIC)); for (Map.Entry<String, Put> put : puts.entrySet()) { final List<Put> putList; if (allPuts.containsKey(put.getKey())) { putList = allPuts.get(put.getKey()); } else { putList = new ArrayList<Put>(); allPuts.put(put.getKey(), putList); } putList.add(put.getValue()); } } for (Map.Entry<String, List<Put>> puts : allPuts.entrySet()) { if (LockType.OPTIMISTIC.equals(getLockType()) && infoProvider.getVersionColumnFamily() != null && infoProvider.getVersionColumnQualifier() != null) { putOptimistically(puts, merge, states); } else { putNonOptimistically(puts, merge, states); } } }
From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java
public List<OptMapResultNode> getBreakResult(LinkedHashMap<String, DataNode> optrefmap, GenomicPosNode unwantedRegion) { if (parentFrag == null || optrefmap == null) return null; List<OptMapResultNode> resultList = new ArrayList<OptMapResultNode>(); if (!isUsed()) { resultList.add(new OptMapResultNode(this)); return resultList; }//from www . jav a 2s .co m DataNode ref = optrefmap.get(mappedRegion.ref); String precigar = this.cigar.getPrecigar(); int lastrefpos = -1; int lastfragpos = -1; int currentrefpos = subrefstart; int currentfragpos = subfragstart; int lastrefstart = -1; int lastfragstart = -1; for (char c : precigar.toCharArray()) { switch (c) { case 'M': if (lastrefpos != -1) { if (lastrefstart == -1) { lastrefstart = lastrefpos; lastfragstart = lastfragpos; } GenomicPosNode currentRegion = new GenomicPosNode(ref.name, ref.refp[lastrefstart - 1], ref.refp[currentrefpos - 1]); boolean pass = !(unwantedRegion.overlapSize(currentRegion) > 0); if (!pass) { if (lastfragstart != lastfragpos) resultList.add(this.getSubResult(ref, lastfragstart, lastfragpos - mappedstrand)); lastrefstart = -1; lastfragstart = -1; } else { if (pass && currentrefpos == subrefstop + 1) { resultList.add(this.getSubResult(ref, lastfragstart, subfragstop)); lastrefstart = -1; lastfragstart = -1; } } } lastrefpos = currentrefpos; lastfragpos = currentfragpos; currentfragpos += mappedstrand; currentrefpos += 1; break; case 'I': currentfragpos += mappedstrand; break; case 'D': currentrefpos += 1; break; default: ; } } return resultList; }
From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java
private void putOneEntry(TemporaryEntry entry, boolean isAggregatedEntry, LinkedHashMap<Long, List<RecipientEntry>> entryMap, List<RecipientEntry> nonAggregatedEntries, Set<String> existingDestinations) { if (existingDestinations.contains(entry.destination)) { return;//from w w w .j a va2 s . co m } existingDestinations.add(entry.destination); if (!isAggregatedEntry) { nonAggregatedEntries.add(RecipientEntry.constructTopLevelEntry(entry.displayName, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString)); } else if (entryMap.containsKey(entry.contactId)) { // We already have a section for the person. final List<RecipientEntry> entryList = entryMap.get(entry.contactId); entryList.add(RecipientEntry.constructSecondLevelEntry(entry.displayName, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString)); } else { final List<RecipientEntry> entryList = new ArrayList<RecipientEntry>(); entryList.add(RecipientEntry.constructTopLevelEntry(entry.displayName, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString)); entryMap.put(entry.contactId, entryList); } }
From source file:org.openmeetings.app.remote.UserService.java
/** * /*ww w . j ava 2 s . c o m*/ * @param SID * @param regObjectObj * @return */ @SuppressWarnings({ "rawtypes" }) public Long saveOrUpdateUser(String SID, Object regObjectObj) { try { LinkedHashMap argObjectMap = (LinkedHashMap) regObjectObj; Long user_idClient = null; if (argObjectMap.get("user_idClient") != null) { user_idClient = Long.valueOf(argObjectMap.get("user_idClient").toString()).longValue(); } Long users_id = sessionManagement.checkSession(SID); Long user_level = userManagement.getUserLevelByID(users_id); List<?> orgO = (List<?>) argObjectMap.get("organisations"); List<Long> orgIds = new ArrayList<Long>(orgO.size()); for (Object o : orgO) { orgIds.add(Long.valueOf((Integer) o)); } Date age = null; if (argObjectMap.get("userage") instanceof Date) { age = (Date) argObjectMap.get("userage"); } log.debug("Mail : " + argObjectMap.get("email").toString()); log.debug("Phone : " + argObjectMap.get("phone").toString()); if (user_idClient == null || user_idClient == 0) { return userManagement.registerUserInit(user_level, Long.valueOf(argObjectMap.get("level_id").toString()).longValue(), Integer.valueOf(argObjectMap.get("availible").toString()).intValue(), Integer.valueOf(argObjectMap.get("status").toString()).intValue(), argObjectMap.get("login").toString(), argObjectMap.get("password").toString(), argObjectMap.get("lastname").toString(), argObjectMap.get("firstname").toString(), argObjectMap.get("email").toString(), age, argObjectMap.get("street").toString(), argObjectMap.get("additionalname").toString(), argObjectMap.get("fax").toString(), argObjectMap.get("zip").toString(), Long.valueOf(argObjectMap.get("states_id").toString()).longValue(), argObjectMap.get("town").toString(), new Long(argObjectMap.get("language_id").toString()), true, orgIds, argObjectMap.get("phone").toString(), "", false, argObjectMap.get("sip_user").toString(), argObjectMap.get("sip_pass").toString(), argObjectMap.get("sip_auth").toString(), Boolean.valueOf(argObjectMap.get("generateSipUserData").toString()).booleanValue(), argObjectMap.get("jNameTimeZone").toString(), Boolean.valueOf(argObjectMap.get("forceTimeZoneCheck").toString()).booleanValue(), argObjectMap.get("userOffers").toString(), argObjectMap.get("userSearchs").toString(), Boolean.valueOf(argObjectMap.get("showContactData").toString()).booleanValue(), Boolean.valueOf(argObjectMap.get("showContactDataToContacts").toString()).booleanValue()); } else { return userManagement.updateUser(user_level, user_idClient, Long.valueOf(argObjectMap.get("level_id").toString()).longValue(), argObjectMap.get("login").toString(), argObjectMap.get("password").toString(), argObjectMap.get("lastname").toString(), argObjectMap.get("firstname").toString(), age, argObjectMap.get("street").toString(), argObjectMap.get("additionalname").toString(), argObjectMap.get("zip").toString(), Long.valueOf(argObjectMap.get("states_id").toString()).longValue(), argObjectMap.get("town").toString(), new Long(argObjectMap.get("language_id").toString()), Integer.valueOf(argObjectMap.get("availible").toString()).intValue(), argObjectMap.get("telefon").toString(), argObjectMap.get("fax").toString(), argObjectMap.get("mobil").toString(), argObjectMap.get("email").toString(), argObjectMap.get("comment").toString(), Integer.valueOf(argObjectMap.get("status").toString()).intValue(), orgIds, Integer.valueOf(argObjectMap.get("title_id").toString()).intValue(), argObjectMap.get("phone").toString(), argObjectMap.get("sip_user").toString(), argObjectMap.get("sip_pass").toString(), argObjectMap.get("sip_auth").toString(), Boolean.valueOf(argObjectMap.get("generateSipUserData").toString()).booleanValue(), argObjectMap.get("jNameTimeZone").toString(), Boolean.valueOf(argObjectMap.get("forceTimeZoneCheck").toString()).booleanValue(), argObjectMap.get("userOffers").toString(), argObjectMap.get("userSearchs").toString(), Boolean.valueOf(argObjectMap.get("showContactData").toString()).booleanValue(), Boolean.valueOf(argObjectMap.get("showContactDataToContacts").toString()).booleanValue()); } } catch (Exception ex) { log.error("[saveOrUpdateUser]: ", ex); } return null; }
From source file:com.opengamma.analytics.financial.curve.ParameterUnderlyingSensitivityCalculator.java
/** * Computes the sensitivity with respect to the parameters from the point sensitivities to the continuously compounded rate. * @param sensitivity The point sensitivity. * @param fixedCurves The fixed curves names (for which the parameter sensitivity are not computed even if they are necessary for the instrument pricing). * The curve in the list may or may not be in the bundle. Not null. * @param bundle The curve bundle with all the curves with respect to which the sensitivity should be computed. Not null. * @return The sensitivity (as a DoubleMatrix1D). *//*from w ww . j a v a 2s. co m*/ @Override public DoubleMatrix1D pointToParameterSensitivity(final InterestRateCurveSensitivity sensitivity, final Set<String> fixedCurves, final YieldCurveBundle bundle) { Integer nbCurve = 0; LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>(); for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { curveNum.put(name, nbCurve++); } } nbCurve = 0; int[] nbNewParameters = new int[curveNum.size()]; // Implementation note: int[] startCleanParameter = new int[curveNum.size()]; // Implementation note: int[][] startDirtyParameter = new int[curveNum.size()][]; int[][] indexOther = new int[curveNum.size()][]; // Implementation note: the start of the different blocs of parameters. First the other curves, then the new part. int nbCleanParameters = 0; int currentDirtyStart = 0; for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); startCleanParameter[nbCurve] = nbCleanParameters; nbNewParameters[nbCurve] = curve.getNumberOfParameters(); List<Integer> indexOtherList = new ArrayList<Integer>(); List<Integer> startDirtyParameterList = new ArrayList<Integer>(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { indexOtherList.add(i); nbNewParameters[nbCurve] -= nbNewParameters[i]; startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[i]; } } startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[nbCurve]; indexOther[nbCurve] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0])); startDirtyParameter[nbCurve] = ArrayUtils .toPrimitive(startDirtyParameterList.toArray(new Integer[0])); nbCleanParameters += nbNewParameters[nbCurve]; nbCurve++; } } final List<Double> sensiDirtyList = new ArrayList<Double>(); for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Double> oneCurveSensitivity = pointToParameterSensitivity( sensitivity.getSensitivities().get(name), curve); sensiDirtyList.addAll(oneCurveSensitivity); } } double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0])); double[] sensiClean = new double[nbCleanParameters]; for (int loopcurve = 0; loopcurve < nbCurve; loopcurve++) { for (int loopo = 0; loopo < indexOther[loopcurve].length; loopo++) { for (int loops = 0; loops < nbNewParameters[indexOther[loopcurve][loopo]]; loops++) { sensiClean[startCleanParameter[indexOther[loopcurve][loopo]] + loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops]; } } for (int loops = 0; loops < nbNewParameters[loopcurve]; loops++) { sensiClean[startCleanParameter[loopcurve] + loops] += sensiDirty[startDirtyParameter[loopcurve][indexOther[loopcurve].length] + loops]; } } return new DoubleMatrix1D(sensiClean); }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
/** * @author ymli set the formats; fix the bug:0013463 * @param fomats/*from w ww .j av a 2 s .co m*/ * @return */ public boolean setDisplayFormat(LinkedHashMap<String, String> fomats) { Iterator<String> isos = Util.iso2lang.keySet().iterator(); while (isos.hasNext()) { String lang = isos.next(); removeAppInfos("X_Display_Format_" + lang.toUpperCase());//$NON-NLS-1$ } Iterator<String> isoIter = fomats.keySet().iterator(); while (isoIter.hasNext()) { String iso = isoIter.next(); removeAppInfos("X_Display_Format_" + iso.toUpperCase());//$NON-NLS-1$ addAppInfo("X_Display_Format_" + iso.toUpperCase(), fomats.get(iso));//$NON-NLS-1$ } hasChanged = true; return true; }
From source file:com.smartitengineering.dao.impl.hbase.CommonDao.java
protected void deleteNonOptimistically(Template[] states) throws IllegalStateException { LinkedHashMap<String, List<Delete>> allDels = new LinkedHashMap<String, List<Delete>>(); for (Template state : states) { if (!state.isValid()) { throw new IllegalStateException("Entity not in valid state!"); }/*from w ww . ja v a 2s.c om*/ LinkedHashMap<String, Delete> dels = getConverter().objectToDeleteableRows(state, executorService, getLockType().equals(LockType.PESSIMISTIC)); for (Map.Entry<String, Delete> del : dels.entrySet()) { final List<Delete> putList; if (allDels.containsKey(del.getKey())) { putList = allDels.get(del.getKey()); } else { putList = new ArrayList<Delete>(); allDels.put(del.getKey(), putList); } putList.add(del.getValue()); } } for (final Map.Entry<String, List<Delete>> dels : allDels.entrySet()) { try { executorService.execute(dels.getKey(), new Callback<Void>() { @Override public Void call(HTableInterface tableInterface) throws Exception { final List<Delete> value = dels.getValue(); if (logger.isInfoEnabled()) { logger.info("Attempting to DELETE " + value); } final ArrayList<Delete> list = new ArrayList<Delete>(value); tableInterface.delete(list); return null; } }); } finally { for (Template state : states) { lockAttainer.unlockAndEvictFromCache(state); } } } }
From source file:com.egt.core.db.ddl.MapaClases.java
private void addClaves(LinkedHashMap tablas, String sql) throws SQLException { this.resultSet = TLC.getAgenteSql().executeQuery(sql); if (this.resultSet.next()) { Integer keytype = null;/*w w w . j a v a 2 s. c o m*/ String tabname = null; String refname = null; String keyname = null; Integer colid = null; String colname = null; String deleterule = null; String updaterule = null; Long property = null; String tabla_anterior = null; String clave_anterior = null; Tabla t = null; Clave k = null; do { keytype = (Integer) this.resultSet.getObject("keytype"); tabname = this.resultSet.getString("tabname"); refname = this.resultSet.getString("refname"); keyname = this.resultSet.getString("keyname"); colid = (Integer) this.resultSet.getObject("colid"); colname = this.resultSet.getString("colname"); deleterule = this.resultSet.getString("deleterule"); updaterule = this.resultSet.getString("updaterule"); property = (Long) this.resultSet.getObject("property"); if (!tabname.equals(tabla_anterior)) { tabla_anterior = tabname; clave_anterior = null; t = (Tabla) tablas.get(tabname); } if (t != null) { if (!keyname.equals(clave_anterior)) { clave_anterior = keyname; k = t.addClave(keyname, keytype); if (refname != null) { Tabla r = (Tabla) tablas.get(refname); if (r == null) { k.setNombreTablaReferenciada(refname); } else { k.setNombreTablaReferenciada(r.getNombre()); } k.setReglaDelete(deleterule); k.setReglaUpdate(updaterule); } } k.addColumna(t.getColumna(colname, property)); } } while (this.resultSet.next()); } this.resultSet.close(); }
From source file:jp.primecloud.auto.ui.mock.service.MockInstanceService.java
@Override public List<InstanceDto> getInstances(Long farmNo) { List<InstanceDto> result = new ArrayList<InstanceDto>(); List<Instance> instances = XmlDataLoader.getData("instance.xml", Instance.class); List<ComponentInstance> componentInstances = XmlDataLoader.getData("componentInstance.xml", ComponentInstance.class); List<InstanceConfig> instanceConfigs = XmlDataLoader.getData("instanceConfig.xml", InstanceConfig.class); List<AwsInstance> awsInstances = XmlDataLoader.getData("awsInstance.xml", AwsInstance.class); List<VmwareInstance> vmwareInstances = XmlDataLoader.getData("vmwareInstance.xml", VmwareInstance.class); List<NiftyInstance> niftyInstances = XmlDataLoader.getData("niftyInstance.xml", NiftyInstance.class); List<Component> components = XmlDataLoader.getData("component.xml", Component.class); List<CloudstackInstance> cloudstackInstances = XmlDataLoader.getData("cloudstackInstance.xml", CloudstackInstance.class); //Platform/*from ww w . j ava 2 s . c om*/ LinkedHashMap<Long, Platform> platformMap = getPlatformMap(); LinkedHashMap<Long, PlatformAws> platformAwsMap = getPlatformAwsMap(); LinkedHashMap<Long, PlatformVmware> platformVmwareMap = getPlatformVmwareMap(); LinkedHashMap<Long, PlatformNifty> platformNiftyMap = getPlatformNiftyMap(); LinkedHashMap<Long, PlatformCloudstack> platformCloudstackMap = getPlatformCloudstackMap(); //Image LinkedHashMap<Long, Image> imageMap = getImageMap(); LinkedHashMap<Long, ImageAws> imageAwsMap = getImageAwsMap(); LinkedHashMap<Long, ImageVmware> imageVmwareMap = getImageVmwareMap(); LinkedHashMap<Long, ImageNifty> imageNiftyMap = getImageNiftyMap(); LinkedHashMap<Long, ImageCloudstack> imageCloudstackMap = getImageCloudstackMap(); for (Instance instance : instances) { //Platform PlatformDto platformDto = new PlatformDto(); platformDto.setPlatform(platformMap.get(instance.getPlatformNo())); platformDto.setPlatformAws(platformAwsMap.get(instance.getPlatformNo())); platformDto.setPlatformVmware(platformVmwareMap.get(instance.getPlatformNo())); platformDto.setPlatformNifty(platformNiftyMap.get(instance.getPlatformNo())); platformDto.setPlatformCloudstack(platformCloudstackMap.get(instance.getPlatformNo())); //Image ImageDto imageDto = new ImageDto(); imageDto.setImage(imageMap.get(instance.getImageNo())); imageDto.setImageAws(imageAwsMap.get(instance.getImageNo())); imageDto.setImageVmware(imageVmwareMap.get(instance.getImageNo())); imageDto.setImageNifty(imageNiftyMap.get(instance.getImageNo())); imageDto.setImageCloudstack(imageCloudstackMap.get(instance.getImageNo())); AwsInstance awsInstance = null; for (AwsInstance tmp : awsInstances) { if (tmp.getInstanceNo().equals(instance.getInstanceNo())) { awsInstance = tmp; break; } } AwsAddress awsAddress = null; //ElasticIP? if (instance.getInstanceNo() == 6L) { awsAddress = new AwsAddress(); awsAddress.setAddressNo(1L); awsAddress.setUserNo(1L); awsAddress.setPlatformNo(instance.getPlatformNo()); awsAddress.setPublicIp(instance.getPublicIp()); awsAddress.setComment(null); awsAddress.setInstanceNo(instance.getInstanceNo()); awsAddress.setInstanceId(awsInstance.getInstanceId()); } List<AwsVolume> awsVolumes = null; CloudstackInstance cloudstackInstance = null; for (CloudstackInstance tempCsInstance : cloudstackInstances) { if (instance.getInstanceNo().equals(tempCsInstance.getInstanceNo())) { cloudstackInstance = tempCsInstance; } } CloudstackAddress cloudstackAddress = new CloudstackAddress(); cloudstackAddress.setAddressId("1"); cloudstackAddress.setIpaddress("111.222.333.444"); List<CloudstackVolume> cloudstackVolumes = null; VmwareInstance vmwareInstance = null; for (VmwareInstance tmp : vmwareInstances) { if (tmp.getInstanceNo().equals(instance.getInstanceNo())) { vmwareInstance = tmp; break; } } VmwareAddress vmwareAddress = new VmwareAddress(); if (vmwareInstance != null) { vmwareAddress.setIpAddress("172.0.0.1"); vmwareAddress.setEnabled(false); vmwareAddress.setDefaultGateway("172.0.0.1"); vmwareAddress.setSubnetMask("255.255.0.0"); vmwareAddress.setInstanceNo(instance.getInstanceNo()); } VmwareKeyPair vmwareKeyPair = null; if (vmwareInstance != null) { vmwareKeyPair = new VmwareKeyPair(); vmwareKeyPair.setKeyNo(1L); vmwareKeyPair.setKeyName("key01"); vmwareKeyPair.setUserNo(1L); vmwareKeyPair.setKeyPublic("keypublic"); } List<VmwareDisk> vmwareDisks = null; NiftyInstance niftyInstance = null; for (NiftyInstance tmp : niftyInstances) { if (tmp.getInstanceNo().equals(instance.getInstanceNo())) { niftyInstance = tmp; break; } } NiftyKeyPair niftyKeyPair = null; if (niftyInstance != null) { niftyKeyPair = new NiftyKeyPair(); niftyKeyPair.setKeyNo(niftyInstance.getKeyPairNo()); niftyKeyPair.setKeyName("key0" + niftyInstance.getKeyPairNo()); niftyKeyPair.setUserNo(1L); } InstanceDto dto = new InstanceDto(); // if ("STARTING".equals(instance.getStatus())) { instance.setProgress((int) (Math.random() * 100)); if (instance.getProgress() > 90) { instance.setProgress(100); instance.setStatus("RUNNING"); } } instance.setPublicIp(String.valueOf((int) (Math.random() * 100))); List<ComponentInstanceDto> componentInstanceDtos = new ArrayList<ComponentInstanceDto>(); for (ComponentInstance componentInstance : componentInstances) { ComponentInstanceDto componentInstanceDto = new ComponentInstanceDto(); componentInstanceDto.setComponentInstance(componentInstance); Component component = null; for (Component tmpComponent : components) { if (componentInstance.getComponentNo().equals(tmpComponent.getComponentNo())) { component = tmpComponent; break; } } String url = createUrl(instance.getPublicIp(), component.getComponentTypeNo()); componentInstanceDto.setUrl(url); componentInstanceDtos.add(componentInstanceDto); } AwsCertificate awsCertificate = null; if (platformAwsMap.get(instance.getPlatformNo()) != null) { awsCertificate = new AwsCertificate(); awsCertificate.setPlatformNo(instance.getPlatformNo()); awsCertificate.setDefSubnet("subnet-00000001"); } dto.setInstance(instance); dto.setPlatform(platformDto); dto.setImage(imageDto); dto.setInstanceConfigs(instanceConfigs); dto.setComponentInstances(componentInstanceDtos); dto.setAwsInstance(awsInstance); dto.setAwsAddress(awsAddress); dto.setAwsVolumes(awsVolumes); dto.setAwsCertificate(awsCertificate); dto.setCloudstackInstance(cloudstackInstance); dto.setCloudstackAddress(cloudstackAddress); dto.setCloudstackVolumes(cloudstackVolumes); dto.setVmwareInstance(vmwareInstance); dto.setVmwareAddress(vmwareAddress); dto.setVmwareKeyPair(vmwareKeyPair); dto.setVmwareDisks(vmwareDisks); dto.setNiftyInstance(niftyInstance); dto.setNiftyKeyPair(niftyKeyPair); result.add(dto); } return result; }
From source file:es.uvigo.ei.sing.adops.datatypes.ProjectExperiment.java
private String checkFastaFile() throws IllegalArgumentException { final Set<Character> aminos = new HashSet<Character>( Arrays.asList('a', 'c', 't', 'g', 'A', 'C', 'T', 'G', '-')); BufferedReader br = null;/*from w w w . ja va 2s . c o m*/ try { final StringBuilder sb = new StringBuilder(); final LinkedHashMap<String, StringBuilder> replacements = new LinkedHashMap<String, StringBuilder>(); br = new BufferedReader(new FileReader(this.fastaFile)); String line = null; while ((line = br.readLine()) != null && !line.startsWith(">")) { sb.append(line).append('\n'); } String seqId = null; String seq = null; while (line != null) { seqId = line; seq = ""; while ((line = br.readLine()) != null && !line.startsWith(">")) { seq += line; } // Non ACTG characters replacement char[] charSequence = seq.toCharArray(); String data = ""; for (int i = 0; i < charSequence.length; i++) { if (aminos.contains(charSequence[i])) { data += charSequence[i]; } else { if (replacements.containsKey(seqId)) { replacements.get(seqId).append(String.format(", [%d,%c]", i + 1, charSequence[i])); } else { replacements.put(seqId, new StringBuilder(String.format("[%d,%c]", i + 1, charSequence[i]))); } data += '-'; } } // Incomplete codons replacement charSequence = data.toCharArray(); data = ""; String codon = ""; for (int i = 0; i < charSequence.length; i++) { codon += Character.toString(charSequence[i]); if ((i + 1) % 3 == 0) { if (codon.contains("-")) { data += "---"; if (replacements.containsKey(seqId)) { replacements.get(seqId).append(String.format(", [%s,---]", codon)); } else { replacements.put(seqId, new StringBuilder(String.format("[%s,---]", codon))); } } else { data += codon; } codon = ""; } } sb.append(seqId).append('\n'); sb.append(data).append('\n'); } FileUtils.write(this.fastaFile, sb.toString()); if (replacements.isEmpty()) { return ""; } else { final StringBuilder summary = new StringBuilder("Replacements done on input file\n"); for (Map.Entry<String, StringBuilder> replacement : replacements.entrySet()) { summary.append(replacement.getKey()).append('\n'); summary.append(replacement.getValue()).append('\n'); } summary.append("\n-----\n"); return summary.toString(); } } catch (Exception e) { throw new IllegalArgumentException("Input file is not a valida Fasta file"); } finally { if (br != null) { try { br.close(); } catch (IOException ioe) { } } } }