Перейти к содержимому

Фото
- - - - -

[Java] фильтр по условиям


  • Вы не можете создать новую тему
  • Please log in to reply
Пока никто не отвечал в этой теме...

#1 ParadoxL

ParadoxL
  • Постоялец
  • 5 023 сообщений
  • Откуда:Edinburg

Отправлено 11 июля 2005 - 12:18

Суть следующая. Довелось мне по работе капаться в чужих кодах, баги фиксить да юзабельность расширять. Проект (http://x-tee.riik.ee). Ну так вот ... суть проблемы в следующем. Дан набор из n строк, каждая строка этого набора является неким словием фильтрации выходного контента SOAP сообщения и сотоит из следующей записи <поле><условие><константа>. Задача, нарисовать грамотный парсер на Java, который будет создовать некий масив, например conditions[n][3], из n-строк где каждий элемент будет содержать массив из трех элементов. 0 - поле , 2 - кондишен, 3- константа. То есть элементарный парсинг и разбиение на составные части. Помагите ... сам написал, но не нравится скорость. Выкладываейте только код одной функции или класса, которая/ый будет выполнять саму задачу. Флейма не надо. Суть на английском ... может кому-то будет попроще:

############################### Outputs hide conditions ###################
# To enable filtering output data set field 'filter' to 'true'. Content beetwen fields
# <proc.procedure_name.filter> and </proc.procedure_name.filter> should contain
# records with filtering conditions. Each record has next format :
#  <variable><condition><value>
# Where :
# <variable>  -  name of a field above which is made condition check.
# <condition> -  condition. Must be one of :
#  '='  - Equal. That is value of <variable> is completely identical to <value> value.
#  '<>' or '!='  - Not equally. That is value of <variable> distinct from <value> value.
#  '>'  - Bigger than. That is value of <variable> is bigger than <value> value. Can be used only for date and numeretic types.
#  '<'  - Less than. That is value of <variable> is less than <value> value. Can be used only for date and numeretic types.
#  '>='  - Bigger or equal. That is <variable> value is bigger or equals to <value> value. Can be used only for date and numeretic types.
#  '<='  - Less or equal. That is <variable> value is less or to equals value of <value> Can be used only for date and numeretic types.
# <value>    - constant value to which compares contents of field <variable>.
#  The format and type should coincide completely with field <variable> characteristics.
#  It is possible to use a constant 'NULL' which specifies empty value (Do not confuse to zero value).
#  Strings should be limited by symbol '"'(inverted commas). Entry "" means empty string (not null).
#  Examples : "boroda" , "habba habba habba", "" (empty string)
#  Date must have next format : "DD/MM/YYYY HH24:MM:SS:III".
#  Where :
#    DD - Day. [01;31].
#    MM - Month. [01 - Januar;12 - December].
#    YYYY - Year. [1900;2229].
#    HH24 - Hour in 24 format. [00;23]
#    MM  - Minutes. [00;59]
#    SS  - Seconds. [00;59]
#    III  - Milliseconds. [000;999]
#  Examples: "01/01/2001 17:55:05:001","03/12/2005","5/5/1980 13:32"
# Example :
# <proc.pRR41.filter>
# # Do not write to output elements with name 'isik.variable1' if his value not defined(equals NULL).
# isik.variable1=NULL
# # Skip if value of field mass equals 0. Field mass must be defined as numeretic type.
# mass=0
# # Skip if 'infringementDate' date bigger or equals to 24 feb 1992. Field 'infringementDate' must be defined as date type.
# infringementDate >= "24/02/1992"
# </proc.pRR41.filter>


Пример :

---- Входищие данные
isik.variable1=NULL
# Skip if value of field mass equals 0. Field mass must be defined as numeretic type.
mass=0 #zerro, not null.
# Skip if 'infringementDate' date bigger or equals to 24 feb 1992.
# Field 'infringementDate' must be defined as date type.
infringementDate >= "24/02/1992"
# String parsing.
boroda <> "123 # 123" # quoted inside string must be parsed correctly

---- Выходящие
conditions[4][3] = {{'isik.variable1','=',null},
{'mass','=',0},
{'infringementDate','>=',"24/02/1992"},
{'boroda','<>',"123 # 123"}}

ЗЫ! Символ # - коментарий (после данного символа можно писать коментраии, как в примере). Необходимо правильно определять коментарий это или просто часть строки (как в примере последнее условие).

Заранее благодарен.

Сообщение изменено: CyBurglar (11 июля 2005 - 12:19 )

  • 0
Victoria nulla est, Quam quae confessos animo quoque subjugat hostes ...
Верю в смерть после жизни, любовь после секса и в крем после бритья ...