/** like "database..table". */ protected String getTableNameWithDBAndSchema( final String dbName, final String schema, String tableName) { if (tableName == null || EMPTY.equals(tableName.trim())) { tableName = QueryUtil.DEFAULT_TABLE_NAME; } final StringBuffer tableNameWithDBAndSchema = new StringBuffer(); // if (dbName != null && !EMPTY.equals(dbName)) { /* * should not add quote always. */ setForceAddQuote(false); tableNameWithDBAndSchema.append(checkContextAndAddQuote(dbName)); revertAddQuoteSetting(); tableNameWithDBAndSchema.append(getSQLFieldConnector()); // schema is special empty "." tableNameWithDBAndSchema.append(getSQLFieldConnector()); } // // setForceAddQuote(true); //FIXME, if add quote always, should be opened tableNameWithDBAndSchema.append(checkContextAndAddQuote(tableName)); // revertAddQuoteSetting(); return tableNameWithDBAndSchema.toString(); }
@Override public void validate() { if (stillBirthRegistration.getDateOfEvent() != null && stillBirthRegistration.getDateOfEvent().after(DateUtils.today())) addActionError(getMessage("dateOfEvent.today.validate")); if (stillBirthRegistration.getRegistrationDate() != null && stillBirthRegistration.getDateOfEvent() != null && stillBirthRegistration .getDateOfEvent() .after(stillBirthRegistration.getRegistrationDate())) addActionError(getMessage("dateOfEvent.registration.validate")); if (placeTypeTemp != null && !EMPTY.equals(placeTypeTemp) && BndConstants.HOSPTIAL.equalsIgnoreCase(placeTypeTemp) && stillBirthRegistration.getEstablishment() == null) addActionError(getMessage("hospitalname.required")); // For Offline mode validating registration number.... if (OFFLINE.equals(mode) && stillBirthRegistration.getRegistrationNo() != null && !EMPTY.equals(stillBirthRegistration.getRegistrationNo().trim())) if (stillBirthRegistration.getRegistrationUnit() != null && birthRegistrationService.checkUniqueRegistrationNumber( stillBirthRegistration.getRegistrationUnit().getId(), stillBirthRegistration.getId(), stillBirthRegistration.getRegistrationNo(), BndConstants.REGISTRATIONDATE.equalsIgnoreCase(numberGenKey) ? stillBirthRegistration.getRegistrationDate() : stillBirthRegistration.getDateOfEvent(), BndConstants.STILLBIRTHNUM)) addActionError(getMessage("registration.number.exists")); else if (BndUtils.isNum(stillBirthRegistration.getRegistrationNo().trim())) { final int eventYear = BndConstants.REGISTRATIONDATE.equalsIgnoreCase(numberGenKey) ? BndDateUtils.getCurrentYear(stillBirthRegistration.getRegistrationDate()) : BndDateUtils.getCurrentYear(stillBirthRegistration.getDateOfEvent()); final RegKeys regNumRange = regKeyService.getRegKeyByRegUnitAndDate( stillBirthRegistration.getRegistrationUnit(), eventYear, numberGenerationService.buildObjectType( stillBirthRegistration, eventYear, BndConstants.STILLBIRTHNUM)); if (regNumRange != null) { final Integer regNumber = Integer.valueOf(stillBirthRegistration.getRegistrationNo()); if (regNumber >= regNumRange.getMinValue()) addActionError( getMessage("regNumber.minvalue.validate") .concat(" ") .concat(regNumRange.getMinValue().toString())); } } }
private void configure(String broadcasterLifeCyclePolicy) { int maxIdleTime = 5 * 60 * 1000; String idleTime = config.getInitParameter(ApplicationConfig.BROADCASTER_LIFECYCLE_POLICY_IDLETIME); if (idleTime != null) { maxIdleTime = Integer.parseInt(idleTime); } if (EMPTY.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder().policy(EMPTY).build(); } else if (EMPTY_DESTROY.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder().policy(EMPTY_DESTROY).build(); } else if (IDLE.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder().policy(IDLE).idleTimeInMS(maxIdleTime).build(); } else if (IDLE_DESTROY.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder() .policy(IDLE_DESTROY) .idleTimeInMS(maxIdleTime) .build(); } else if (IDLE_RESUME.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder() .policy(IDLE_RESUME) .idleTimeInMS(maxIdleTime) .build(); } else if (NEVER.name().equalsIgnoreCase(broadcasterLifeCyclePolicy)) { policy = new BroadcasterLifeCyclePolicy.Builder().policy(NEVER).build(); } else { logger.warn("Unsupported BroadcasterLifeCyclePolicy policy {}", broadcasterLifeCyclePolicy); } }
@Override protected void load(MappedByteBuffer mmap) throws IOException { String name = Util.readUTFString(mmap); this.name = EMPTY.equals(name) ? null : name; int len = mmap.getInt(); this.nodes = new Node[len]; MapInfo mapInfo = State.getInstance().getMapInfo(); for (int i = 0; i < len; i++) { this.nodes[i] = mapInfo.getNode(mmap.getInt()); } this.wayInfo = WayInfo.loadFromInput(mmap); }
@Override protected void load(DataInput input) throws IOException { String name = input.readUTF(); this.name = EMPTY.equals(name) ? null : name; int len = input.readInt(); this.nodes = new Node[len]; MapInfo mapInfo = State.getInstance().getMapInfo(); for (int i = 0; i < len; i++) { this.nodes[i] = mapInfo.getNode(input.readInt()); } this.wayInfo = WayInfo.loadFromInput(input); }
public void testUseAsDefaultsForComposition() { assertEquals(EMPTY.user("c"), test("a", "b", "c")); assertEquals(EMPTY.user("c"), test("a", null, "c")); assertEquals(EMPTY.user("c"), test(null, "b", "c")); assertEquals(EMPTY.user("b"), test("a", "b", null)); assertEquals(EMPTY.user("a"), test("a", null, null)); assertEquals(EMPTY.user("b"), test(null, "b", null)); }
@Test public void noSwapForEmptyMark() { assertEquals(EMPTY, EMPTY.swapMark()); }
@Test public void convertsEmptyMarkToString() { assertEquals("", EMPTY.getString()); }
// algorithm: treat sentence snippets as miniature documents // we can intersect these with the postings lists via BreakIterator.preceding(offset),s // score each sentence as norm(sentenceStartOffset) * sum(weight * tf(freq)) private Passage[] highlightDoc( String field, BytesRef terms[], int contentLength, BreakIterator bi, int doc, TermsEnum termsEnum, DocsAndPositionsEnum[] postings, int n) throws IOException { PassageScorer scorer = getScorer(field); if (scorer == null) { throw new NullPointerException("PassageScorer cannot be null"); } PriorityQueue<OffsetsEnum> pq = new PriorityQueue<>(); float weights[] = new float[terms.length]; // initialize postings for (int i = 0; i < terms.length; i++) { DocsAndPositionsEnum de = postings[i]; int pDoc; if (de == EMPTY) { continue; } else if (de == null) { postings[i] = EMPTY; // initially if (!termsEnum.seekExact(terms[i])) { continue; // term not found } de = postings[i] = termsEnum.docsAndPositions(null, null, DocsAndPositionsEnum.FLAG_OFFSETS); if (de == null) { // no positions available throw new IllegalArgumentException( "field '" + field + "' was indexed without offsets, cannot highlight"); } pDoc = de.advance(doc); } else { pDoc = de.docID(); if (pDoc < doc) { pDoc = de.advance(doc); } } if (doc == pDoc) { weights[i] = scorer.weight(contentLength, de.freq()); de.nextPosition(); pq.add(new OffsetsEnum(de, i)); } } pq.add(new OffsetsEnum(EMPTY, Integer.MAX_VALUE)); // a sentinel for termination PriorityQueue<Passage> passageQueue = new PriorityQueue<>( n, new Comparator<Passage>() { @Override public int compare(Passage left, Passage right) { if (left.score < right.score) { return -1; } else if (left.score > right.score) { return 1; } else { return left.startOffset - right.startOffset; } } }); Passage current = new Passage(); OffsetsEnum off; while ((off = pq.poll()) != null) { final DocsAndPositionsEnum dp = off.dp; int start = dp.startOffset(); if (start == -1) { throw new IllegalArgumentException( "field '" + field + "' was indexed without offsets, cannot highlight"); } int end = dp.endOffset(); // LUCENE-5166: this hit would span the content limit... however more valid // hits may exist (they are sorted by start). so we pretend like we never // saw this term, it won't cause a passage to be added to passageQueue or anything. assert EMPTY.startOffset() == Integer.MAX_VALUE; if (start < contentLength && end > contentLength) { continue; } if (start >= current.endOffset) { if (current.startOffset >= 0) { // finalize current current.score *= scorer.norm(current.startOffset); // new sentence: first add 'current' to queue if (passageQueue.size() == n && current.score < passageQueue.peek().score) { current.reset(); // can't compete, just reset it } else { passageQueue.offer(current); if (passageQueue.size() > n) { current = passageQueue.poll(); current.reset(); } else { current = new Passage(); } } } // if we exceed limit, we are done if (start >= contentLength) { Passage passages[] = new Passage[passageQueue.size()]; passageQueue.toArray(passages); for (Passage p : passages) { p.sort(); } // sort in ascending order Arrays.sort( passages, new Comparator<Passage>() { @Override public int compare(Passage left, Passage right) { return left.startOffset - right.startOffset; } }); return passages; } // advance breakiterator assert BreakIterator.DONE < 0; current.startOffset = Math.max(bi.preceding(start + 1), 0); current.endOffset = Math.min(bi.next(), contentLength); } int tf = 0; while (true) { tf++; BytesRef term = terms[off.id]; if (term == null) { // multitermquery match, pull from payload term = off.dp.getPayload(); assert term != null; } current.addMatch(start, end, term); if (off.pos == dp.freq()) { break; // removed from pq } else { off.pos++; dp.nextPosition(); start = dp.startOffset(); end = dp.endOffset(); } if (start >= current.endOffset || end > contentLength) { pq.offer(off); break; } } current.score += weights[off.id] * scorer.tf(tf, current.endOffset - current.startOffset); } // Dead code but compiler disagrees: assert false; return null; }
public FileAttributes test(String defaultDefaultUser, String defaultUser, String user) { return EMPTY .user(defaultDefaultUser) .useAsDefaultsFor(EMPTY.user(defaultUser)) .useAsDefaultsFor(EMPTY.user(user)); }
public void testEquals() { assertEquals(EMPTY, EMPTY); assertFalse(EMPTY.user("trygve").equals(EMPTY)); }