List of usage examples for org.apache.commons.collections4 KeyValue getValue
V getValue();
From source file:net.ctalkobt.syllogism.Context.java
/************************************************************************ * Determines if a given syllogism for an equivalence type is valid. * * @param memeKey//from w w w . ja v a 2s .c o m * @param equivalence * @param memeValue * @return result if known, otherwise optional.empty(). ***********************************************************************/ public Optional<Boolean> interrogate(Term memeKey, Copula equivalence, Term memeValue) { Collection<KeyValue<Copula, Term>> memeRelations = (Collection<KeyValue<Copula, Term>>) memeAssociations .get(memeKey); if (memeRelations == null || memeRelations.isEmpty()) { return Optional.empty(); } Optional<KeyValue<Copula, Term>> result = memeRelations.parallelStream().findFirst() .filter((KeyValue<Copula, Term> kv) -> { if (kv.getKey().equals(equivalence) && kv.getValue().equals(memeValue)) { return true; } else { Optional<Boolean> result1 = interrogate(kv.getValue(), equivalence, memeValue); return result1.isPresent(); } }); if (result.isPresent()) { return Optional.of(equivalence.getTruthEquivalency()); } return Optional.empty(); }
From source file:io.wcm.testing.mock.sling.servlet.MockSlingHttpServletResponse.java
@Override public Collection<String> getHeaders(final String name) { List<String> values = new ArrayList<>(); for (KeyValue<String, String> entry : headers) { if (StringUtils.equals(entry.getKey(), name)) { values.add(entry.getValue()); }// ww w .j av a 2s . c om } return values; }
From source file:be.bittich.dynaorm.repository.GenericDynaRepository.java
@Override public Boolean delete(T t) throws EntityDoesNotExistException { try {/*from ww w. j a va2 s. com*/ T tFromDB = this.findById(t); if (tFromDB == null) { throw new EntityDoesNotExistException(); } Map<Field, PrimaryKey> fieldPrimary = getAnnotedFields(t, PrimaryKey.class); String req = dialect.delete(tableColumn.getTableName()); KeyValue<String, List<String>> pkBuilt = conditionPrimaryKeysBuilder(t, fieldPrimary, dialect); req = req.concat(pkBuilt.getKey()); runner.update(req, pkBuilt.getValue().toArray()); return true; } catch (RequestInvalidException ex) { LOG.log(Level.SEVERE, null, ex); } catch (SQLException ex) { LOG.log(Level.SEVERE, ex.getSQLState(), ex); } return false; }
From source file:be.bittich.dynaorm.repository.GenericDynaRepository.java
/** * Persist the given object in the db//from w w w .java2 s .c om * * @param t */ protected void persist(T t) { try { ColumnMapping mappingUtil = getColumnMapping(); KeyValue<List<String>, List<String>> colVal = mappingUtil.getColumnsValuesMap(t, tableColumn); String request = dialect.insert(tableColumn.getTableName(), colVal.getKey(), colVal.getValue()); List<String> filteredValues = applyFilterValue(colVal.getValue()); runner.update(request, filteredValues.toArray()); } catch (IllegalAccessException | SQLException ex) { LOG.log(Level.SEVERE, null, ex); } }
From source file:be.bittich.dynaorm.repository.GenericDynaRepository.java
/** * Update an entity to the db/*from w w w. j av a 2s.com*/ * @param t */ protected void merge(T t) { try { Map<Field, PrimaryKey> fieldPrimary = getAnnotedFields(t, PrimaryKey.class); KeyValue<String, List<String>> pkBuilt = conditionPrimaryKeysBuilder(t, fieldPrimary, dialect); //where... String conditions = pkBuilt.getKey(); ColumnMapping mappingUtil = getColumnMapping(); KeyValue<List<String>, List<String>> colVal = mappingUtil.getColumnsValuesMap(t, tableColumn); String request = dialect.update(tableColumn.getTableName(), colVal.getKey(), colVal.getValue(), conditions); colVal.getValue().addAll(pkBuilt.getValue()); List<String> filteredValues = applyFilterValue(colVal.getValue()); runner.update(request, filteredValues.toArray()); } catch (IllegalAccessException | SQLException | RequestInvalidException ex) { LOG.log(Level.SEVERE, null, ex); } }
From source file:be.bittich.dynaorm.repository.GenericDynaRepository.java
@Override public T findById(T t) { //get the primary keys Map<Field, PrimaryKey> fieldPrimary = getAnnotedFields(t, PrimaryKey.class); String req = dialect.selectAll(tableColumn.getTableName()); try {/*from w w w. ja v a2 s . com*/ //construct the request with parameters as a list of string(key is the request) KeyValue<String, List<String>> pkBuilt = conditionPrimaryKeysBuilder(t, fieldPrimary, dialect); //select * from T where .. req = req.concat(pkBuilt.getKey()); T result = runner.query(req, getHandler(), pkBuilt.getValue().toArray()); //just before returning the result if (result != null) { this.loadInvoker(result); } return result; } catch (SQLException ex) { Logger.getLogger(GenericDynaRepository.class.getName()).log(Level.SEVERE, ex.getSQLState(), ex); } catch (RequestInvalidException ex) { Logger.getLogger(GenericDynaRepository.class.getName()).log(Level.SEVERE, null, ex); } throw new RuntimeException("Id Not found"); }