List of usage examples for java.lang Short intValue
public int intValue()
From source file:Main.java
public static void main(String[] args) { Short shortObject = new Short("10"); int i = shortObject.intValue(); System.out.println("int:" + i); }
From source file:Main.java
public static void main(String[] args) { Short sObj = new Short("10"); byte b = sObj.byteValue(); System.out.println(b);/*w w w . j a v a 2 s. c om*/ short s = sObj.shortValue(); System.out.println(s); int i = sObj.intValue(); System.out.println(i); float f = sObj.floatValue(); System.out.println(f); double d = sObj.doubleValue(); System.out.println(d); long l = sObj.longValue(); System.out.println(l); }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Safely converts a number to an integer. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object number to parse// www .jav a 2 s .c o m * @return parsed number * @throws ArithmeticException on overflow */ public static int toInteger(Object obj) { /* Switch on class and convert to an int */ String type = obj.getClass().getSimpleName(); int parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = by.intValue(); break; case "Short": Short sh = (Short) obj; parsed = sh.intValue(); break; case "Integer": Integer in = (Integer) obj; parsed = in.intValue(); break; case "Long": Long lo = (Long) obj; if (!OverFlowUtil.intOverflow(lo)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = lo.intValue(); break; case "Float": Float fl = (Float) obj; if (!OverFlowUtil.intOverflow(fl)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = fl.intValue(); break; case "BigInteger": BigInteger bi = (BigInteger) obj; if (!OverFlowUtil.intOverflow(bi)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = bi.intValue(); break; case "BigDecimal": BigDecimal bd = (BigDecimal) obj; if (!OverFlowUtil.intOverflow(bd)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = bd.intValue(); break; case "Double": Double db = (Double) obj; if (!OverFlowUtil.intOverflow(db)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = db.intValue(); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Safely converts a number to an integer. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number number to parse// w w w . j a v a 2 s . c om * @return parsed number * @throws ArithmeticException on overflow */ public static int toInteger(Number number) { /* Switch on class and convert to an int */ String type = number.getClass().getSimpleName(); int parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = by.intValue(); break; case "Short": Short sh = (Short) number; parsed = sh.intValue(); break; case "Integer": Integer in = (Integer) number; parsed = in.intValue(); break; case "Long": Long lo = (Long) number; if (!OverFlowUtil.intOverflow(lo)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = lo.intValue(); break; case "Float": Float fl = (Float) number; if (!OverFlowUtil.intOverflow(fl)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = fl.intValue(); break; case "BigInteger": BigInteger bi = (BigInteger) number; if (!OverFlowUtil.intOverflow(bi)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = bi.intValue(); break; case "BigDecimal": BigDecimal bd = (BigDecimal) number; if (!OverFlowUtil.intOverflow(bd)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = bd.intValue(); break; case "Double": Double db = (Double) number; if (!OverFlowUtil.intOverflow(db)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = db.intValue(); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:org.osgp.adapter.protocol.dlms.application.mapping.DataObjectToEventListConverter.java
private Event getEvent(final DataObject eventDataObject, final EventLogCategory eventLogCategory) throws ProtocolAdapterException { final List<DataObject> eventData = eventDataObject.value(); if (eventData == null) { throw new ProtocolAdapterException("eventData DataObject should not be null"); }/*from w w w . java 2s.c o m*/ if (eventData.size() != eventLogCategory.getNumberOfEventElements()) { throw new ProtocolAdapterException( "eventData size should be " + eventLogCategory.getNumberOfEventElements()); } final DateTime dateTime = this.dlmsHelperService.convertDataObjectToDateTime(eventData.get(0)).asDateTime(); if (dateTime == null) { throw new ProtocolAdapterException("eventData time is null/unspecified"); } if (!eventData.get(1).isNumber()) { throw new ProtocolAdapterException("eventData value is not a number"); } final Short code = eventData.get(1).value(); Integer eventCounter = null; if (eventLogCategory.getNumberOfEventElements() == 3) { if (!eventData.get(2).isNumber()) { throw new ProtocolAdapterException("eventData value is not a number"); } eventCounter = eventData.get(2).value(); } LOGGER.info("Event time is {}, event code is {} and event counter is {}", dateTime, code, eventCounter); return new Event(dateTime, code.intValue(), eventCounter); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * //w w w. ja va 2s. c om */ protected void setupUI(final boolean isPostSave) throws QueryTask.QueryBuilderContextException { if (!isHeadless && !SwingUtilities.isEventDispatchThread()) { throw new RuntimeException("Method called from invalid thread."); } queryFieldsPanel.removeAll(); queryFieldItems.clear(); queryFieldsPanel.validate(); columnDefStr = null; tableList.clearSelection(); contextPanel.setVisible(query == null); tableList.setSelectedIndex(-1); if (query != null) { //query.forceLoad(true); Short tblId = query.getContextTableId(); if (tblId != null) { for (int i = 0; i < tableList.getModel().getSize(); i++) { TableQRI qri = (TableQRI) tableList.getModel().getElementAt(i); if (qri.getTableInfo().getTableId() == tblId.intValue()) { tableList.setSelectedIndex(i); break; } } } } List<QueryFieldPanel> qfps = null; boolean dirty = false; List<String> missingFlds = new LinkedList<String>(); boolean doAutoMap = query == null || query.getId() == null; if (query != null) { TableQRI qri = (TableQRI) tableList.getSelectedValue(); if (qri == null) { //throw new RuntimeException("Invalid context for query."); throw ((QueryTask) task).new QueryBuilderContextException(); } //query.forceLoad(true); qfps = !isExportMapping ? getQueryFieldPanels(this, query.getFields(), tableTree, tableTreeHash, saveBtn, missingFlds) : getQueryFieldPanelsForMapping(this, query.getFields(), tableTree, tableTreeHash, saveBtn, schemaMapping, missingFlds, (doAutoMap ? ConceptMapUtils.getDefaultDarwinCoreMappings() : null)); if (missingFlds.size() > 0) { JList list = new JList(new Vector<String>(missingFlds)); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p:g,2px,f:p:g")); pb.add(UIHelper.createI18NLabel("QB_FIELDS_NOT_ADDED"), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(list), cc.xy(1, 3)); pb.setDefaultDialogBorder(); dirty = qfps.size() > 0; CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), UIRegistry.getResourceString("QB_FIELD_MISSING_TITLE"), true, CustomDialog.OK_BTN, pb.getPanel()); dlg.setOkLabel(UIRegistry.getResourceString("CLOSE")); dlg.setVisible(true); } } boolean header = true; for (final QueryFieldPanel qfp : qfps) { if (header) { header = false; this.queryFieldsScroll.setColumnHeaderView(qfp); } else { queryFieldItems.add(qfp); qfp.addMouseListener(new MouseInputAdapter() { @Override public void mousePressed(MouseEvent e) { selectQFP(qfp); } }); qfp.resetValidator(); queryFieldsPanel.add(qfp); //doAutoMap &= qfp.getFieldQRI() == null; } } qualifyFieldLabels(); for (QueryFieldPanel qfp : queryFieldItems) { if (qfp.isAutoMapped()) { SpQueryField qf = new SpQueryField(); qf.initialize(); qf.setFieldName(qfp.getFieldQRI().getFieldName()); qf.setStringId(qfp.getFieldQRI().getStringId()); qfp.setQueryFieldForAutomapping(qf); query.addReference(qf, "fields"); addNewMapping(qfp.getFieldQRI(), qf, qfp, false); dirty = true; qfp.setAutoMapped(false); } } /*if (doAutoMap) { for (QueryFieldPanel qfp : queryFieldItems) { if (!qfp.isConditionForSchema()) { Vector<MappedFieldInfo> mappedTos = ConceptMapUtils.getDefaultDarwinCoreMappings().get(qfp.getSchemaItem().getFieldName().toLowerCase()); if (mappedTos != null) { for (MappedFieldInfo mappedTo : mappedTos) { FieldQRI fqri = getFieldQRI(tableTree, mappedTo .getFieldName(), mappedTo.isRel(), mappedTo .getStringId(), getTableIds(mappedTo .getTableIds()), 0, tableTreeHash); if (fqri != null) { SpQueryField qf = new SpQueryField(); qf.initialize(); qf.setFieldName(fqri.getFieldName()); qf.setStringId(fqri.getStringId()); query.addReference(qf, "fields"); addNewMapping(fqri, qf, qfp); dirty = true; break; } } } } } }*/ fillNextList(tableList); updateAvailableConcepts(); SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { distinctChk.setSelected(query.isSelectDistinct()); countOnlyChk.setSelected(query.getCountOnly() == null ? false : query.getCountOnly()); countOnly = countOnlyChk.isSelected(); searchSynonymyChk.setSelected( query.getSearchSynonymy() == null ? searchSynonymy : query.getSearchSynonymy()); searchSynonymy = searchSynonymyChk.isSelected(); smushedChk.setSelected(query.getSmushed() == null ? smushed : query.getSmushed()); smushed = smushedChk.isSelected(); } }); final boolean saveBtnEnabled = dirty; if (!isHeadless) { SwingUtilities.invokeLater(new Runnable() { public void run() { adjustPanelUI(saveBtnEnabled, isPostSave); } }); } else { adjustPanelUI(saveBtnEnabled, isPostSave); } }
From source file:com.znsx.cms.service.impl.DeviceManagerImpl.java
@Override public String createControlDevice(String name, String standardNumber, String dasId, String organId, Integer period, String stakeNumber, String longitude, String latitude, Short type, Short subType, String note, String navigation, Integer height, Integer width, Short sectionType, String reserve, String ip, Integer port) { ControlDevice cd = null;//from w w w. j a va2 s . co m if (type.intValue() == TypeDefinition.DEVICE_TYPE_CMS) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_BRIDGE) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_ROAD) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_TOLLGATE)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceCms(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_FAN) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceFan(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_LIGHT) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceLight(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_RD) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceRd(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_WP) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceWp(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_RAIL) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_TOLLGATE)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceRail(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_IS) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_ROAD) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_BRIDGE)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceIs(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_TSL) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_ROAD) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_BRIDGE)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceTsl(); } else if (type.intValue() == TypeDefinition.DEVICE_TYPE_LIL) { // ? Organ organ = organDAO.findById(organId); if (!organ.getType().equals(TypeDefinition.ORGAN_TYPE_TUNNEL) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_TOLLGATE) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_ROAD) && !organ.getType().equals(TypeDefinition.ORGAN_TYPE_BRIDGE)) { throw new BusinessException(ErrorCode.DETECTOR_MAPPING_ORGAN_ERROR, "detector mapping organ ," + type.toString() + ", is error"); } cd = new ControlDeviceLil(); } else { throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Parameter type[" + type + "] invalid !"); } // standardNumber?? LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("standardNumber", standardNumber); List<ControlDevice> list = controlDeviceDAO.findByPropertys(params); if (list.size() >= 1) { throw new BusinessException(ErrorCode.UNIQUE_PROPERTY_DUPLICATE, "standardNumber[" + standardNumber + "] is already exist !"); } // name?? // params.clear(); // params.put("name", name); // list = controlDeviceDAO.findByPropertys(params); // if (list.size() >= 1) { // throw new BusinessException(ErrorCode.NAME_EXIST, "name[" + name // + "] is already exist !"); // } cd.setCreateTime(System.currentTimeMillis()); cd.setDas(dasDAO.findById(dasId)); cd.setLatitude(latitude); cd.setLongitude(longitude); cd.setName(name); cd.setNote(note); cd.setOrgan(organDAO.findById(organId)); cd.setPeriod(period); cd.setStakeNumber(stakeNumber); cd.setStandardNumber(standardNumber); cd.setSubType(subType); cd.setNavigation(navigation); cd.setHeight(height); cd.setWidth(width); cd.setSectionType(sectionType); cd.setReserve(reserve); cd.setIp(ip); cd.setPort(port); controlDeviceDAO.save(cd); // ?SN syncSN(null, standardNumber, TypeDefinition.RESOURCE_TYPE_CD); return cd.getId(); }
From source file:org.biomart.configurator.controller.MartController.java
/** * @param fksToBeDropped//from w w w. ja v a2s.c om * @param dmd * @param schema * @param catalog * @param stepSize * @throws SQLException * @throws DataModelException */ public void synchroniseKeysUsingDMD(final SourceSchema ss, final Collection<ForeignKey> fksToBeDropped, final DatabaseMetaData dmd, final String schema, final String catalog) throws SQLException, DataModelException { Log.debug("Running DMD key synchronisation"); // Loop through all the tables in the database, which is the same // as looping through all the primary keys. Log.debug("Finding tables"); for (final Iterator<Table> i = ss.getTables().iterator(); i.hasNext();) { // Obtain the table and its primary key. final SourceTable pkTable = (SourceTable) i.next(); final PrimaryKey pk = pkTable.getPrimaryKey(); // Skip all tables which have no primary key. if (pk == null) continue; Log.debug("Processing primary key " + pk); // Make a list of relations that already exist in this schema, // from some previous run. Any relations that are left in this // list by the end of the loop for this table no longer exist in // the database, and will be dropped. final Collection<Relation> relationsToBeDropped = new TreeSet<Relation>(pk.getRelations()); // Tree for // order // Identify all foreign keys in the database metadata that refer // to the current primary key. Log.debug("Finding referring foreign keys"); String searchCatalog = catalog; String searchSchema = schema; final ResultSet dbTblFKCols = dmd.getExportedKeys(searchCatalog, searchSchema, pkTable.getName()); // Loop through the results. There will be one result row per // column per key, so we need to build up a set of key columns // in a map. // The map keys represent the column position within a key. Each // map value is a list of columns. In essence the map is a 2-D // representation of the foreign keys which refer to this PK, // with the keys of the map (Y-axis) representing the column // position in the FK, and the values of the map (X-axis) // representing each individual FK. In all cases, FK columns are // assumed to be in the same order as the PK columns. The map is // sorted by key column position. // An assumption is made that the query will return columns from // the FK in the same order as all other FKs, ie. all column 1s // will be returned before any 2s, and then all 2s will be // returned // in the same order as the 1s they are associated with, etc. final TreeMap<Short, List<Column>> dbFKs = new TreeMap<Short, List<Column>>(); while (dbTblFKCols.next()) { final String fkTblName = dbTblFKCols.getString("FKTABLE_NAME"); final String fkColName = dbTblFKCols.getString("FKCOLUMN_NAME"); final Short fkColSeq = new Short(dbTblFKCols.getShort("KEY_SEQ")); if (fkTblName != null && fkTblName.contains("$")) { // exclude ORACLE's temporary tables (unlikely to be // found here though) continue; } // Note the column. if (!dbFKs.containsKey(fkColSeq)) dbFKs.put(fkColSeq, new ArrayList<Column>()); // In some dbs, FKs can be invalid, so we need to check // them. final Table fkTbl = ss.getTableByName(fkTblName); if (fkTbl != null) { final Column fkCol = (Column) fkTbl.getColumnByName(fkColName); if (fkCol != null) (dbFKs.get(fkColSeq)).add(fkCol); } } dbTblFKCols.close(); // Sort foreign keys by name (case insensitive) for (List<Column> columnList : dbFKs.values()) { Collections.sort(columnList); } // Only construct FKs if we actually found any. if (!dbFKs.isEmpty()) { // Identify the sequence of the first column, which may be 0 // or 1, depending on database implementation. final int firstColSeq = ((Short) dbFKs.firstKey()).intValue(); // How many columns are in the PK? final int pkColCount = pkTable.getPrimaryKey().getColumns().size(); // How many FKs do we have? final int fkCount = dbFKs.get(dbFKs.firstKey()).size(); // Loop through the FKs, and construct each one at a time. for (int j = 0; j < fkCount; j++) { // Set up an array to hold the FK columns. final List<Column> candidateFKColumns = new ArrayList<Column>(); // For each FK column name, look up the actual column in // the table. for (final Iterator<Map.Entry<Short, List<Column>>> k = dbFKs.entrySet().iterator(); k .hasNext();) { final Map.Entry<Short, List<Column>> entry = k.next(); final Short keySeq = (Short) entry.getKey(); // Convert the db-specific column index to a // 0-indexed figure for the array of fk columns. final int fkColSeq = keySeq.intValue() - firstColSeq; candidateFKColumns.add((Column) (entry.getValue()).get(j)); } // Create a template foreign key based around the set // of candidate columns we found. ForeignKey fkObject; try { List<Column> columns = new ArrayList<Column>(); for (int k = 0; k < candidateFKColumns.size(); k++) { columns.add(candidateFKColumns.get(k)); } fkObject = new ForeignKey(columns); // new KeyController(fkObject); } catch (final Throwable t) { throw new BioMartError(t); } final Table fkTable = fkObject.getTable(); // If any FK already exists on the target table with the // same columns in the same order, then reuse it. boolean fkAlreadyExists = false; for (final Iterator<ForeignKey> f = fkTable.getForeignKeys().iterator(); f.hasNext() && !fkAlreadyExists;) { final ForeignKey candidateFK = f.next(); if (candidateFK.equals(fkObject)) { // Found one. Reuse it! fkObject = candidateFK; // Update the status to indicate that the FK is // backed by the database, if previously it was // handmade. if (fkObject.getStatus().equals(ComponentStatus.HANDMADE)) fkObject.setStatus(ComponentStatus.INFERRED); // Remove the FK from the list to be dropped // later, as it definitely exists now. fksToBeDropped.remove(candidateFK); // Flag the key as existing. fkAlreadyExists = true; } } // Has the key been reused, or is it a new one? if (!fkAlreadyExists) try { fkTable.getForeignKeys().add(fkObject); // fkTable.getForeignKeys().add(fk); } catch (final Throwable t) { throw new BioMartError(t); } // Work out whether the relation from the FK to // the PK should be 1:M or 1:1. The rule is that // it will be 1:M in all cases except where the // FK table has a PK with identical columns to // the FK, in which case it is 1:1, as the FK // is unique. Cardinality card = Cardinality.MANY_A; final PrimaryKey fkPK = fkTable.getPrimaryKey(); if (fkPK != null && fkObject.getColumns().equals(fkPK.getColumns())) card = Cardinality.ONE; // Check to see if it already has a relation. boolean relationExists = false; for (final Iterator<Relation> f = fkObject.getRelations().iterator(); f.hasNext();) { // Obtain the next relation. final Relation candidateRel = f.next(); // a) a relation already exists between the FK // and the PK. if (candidateRel.getOtherKey(fkObject).equals(pk)) { // If cardinality matches, make it // inferred. If doesn't match, make it // modified and update original cardinality. try { if (card.equals(candidateRel.getCardinality())) { if (!candidateRel.getStatus().equals(ComponentStatus.INFERRED_INCORRECT)) candidateRel.setStatus(ComponentStatus.INFERRED); } else { if (!candidateRel.getStatus().equals(ComponentStatus.INFERRED_INCORRECT)) candidateRel.setStatus(ComponentStatus.MODIFIED); candidateRel.setOriginalCardinality(card); } } catch (final AssociationException ae) { throw new BioMartError(ae); } // Don't drop it at the end of the loop. relationsToBeDropped.remove(candidateRel); // Say we've found it. relationExists = true; } // b) a handmade relation exists elsewhere which // should not be dropped. All other relations // elsewhere will be dropped. else if (candidateRel.getStatus().equals(ComponentStatus.HANDMADE)) // Don't drop it at the end of the loop. relationsToBeDropped.remove(candidateRel); } // If relation did not already exist, create it. if (!relationExists && !pk.equals(fkObject)) { // Establish the relation. try { new RelationSource(pk, fkObject, card); // pk.getObject().addRelation(relation); // fk.getObject().addRelation(relation); } catch (final Throwable t) { throw new BioMartError(t); } } } } // Remove any relations that we didn't find in the database (but // leave the handmade ones behind). for (final Iterator<Relation> j = relationsToBeDropped.iterator(); j.hasNext();) { final Relation r = j.next(); if (r.getStatus().equals(ComponentStatus.HANDMADE)) continue; r.getFirstKey().removeRelation(r); r.getSecondKey().removeRelation(r); } } }
From source file:org.datacleaner.configuration.JaxbConfigurationReader.java
private void updateTaskRunnerIfSpecified(Configuration configuration, TemporaryMutableDataCleanerEnvironment environment, DataCleanerConfiguration temporaryConfiguration) { final SinglethreadedTaskrunnerType singlethreadedTaskrunner = configuration.getSinglethreadedTaskrunner(); final MultithreadedTaskrunnerType multithreadedTaskrunner = configuration.getMultithreadedTaskrunner(); final CustomElementType customTaskrunner = configuration.getCustomTaskrunner(); if (singlethreadedTaskrunner != null) { final TaskRunner taskRunner = new SingleThreadedTaskRunner(); environment.setTaskRunner(taskRunner); } else if (multithreadedTaskrunner != null) { Short maxThreads = multithreadedTaskrunner.getMaxThreads(); final TaskRunner taskRunner; if (maxThreads != null) { taskRunner = new MultiThreadedTaskRunner(maxThreads.intValue()); } else {//w w w.j av a2 s. c o m taskRunner = new MultiThreadedTaskRunner(); } environment.setTaskRunner(taskRunner); } else if (customTaskrunner != null) { final TaskRunner taskRunner = createCustomElement(customTaskrunner, TaskRunner.class, temporaryConfiguration, true); environment.setTaskRunner(taskRunner); } }
From source file:org.eobjects.analyzer.configuration.JaxbConfigurationReader.java
private TaskRunner createTaskRunner(Configuration configuration, InjectionManager injectionManager) { SinglethreadedTaskrunnerType singlethreadedTaskrunner = configuration.getSinglethreadedTaskrunner(); MultithreadedTaskrunnerType multithreadedTaskrunner = configuration.getMultithreadedTaskrunner(); CustomElementType customTaskrunner = configuration.getCustomTaskrunner(); TaskRunner taskRunner;//from ww w. ja v a 2 s.c o m if (singlethreadedTaskrunner != null) { taskRunner = new SingleThreadedTaskRunner(); } else if (multithreadedTaskrunner != null) { Short maxThreads = multithreadedTaskrunner.getMaxThreads(); if (maxThreads != null) { taskRunner = new MultiThreadedTaskRunner(maxThreads.intValue()); } else { taskRunner = new MultiThreadedTaskRunner(); } } else if (customTaskrunner != null) { taskRunner = createCustomElement(customTaskrunner, TaskRunner.class, injectionManager, true); } else { // default task runner type is multithreaded taskRunner = new MultiThreadedTaskRunner(); } return taskRunner; }