📜 ⬆️ ⬇️

JAVA library padeg - New Year's gift habr

Yes, yes, this is the same library padeg.dll, but it works wherever there is java. Authors Sergey V. Plahov aka Seer and Gennady Pokatashkin
Actually, the story is simple. It began in 2007, when I urgently needed to incline names and positions for a single corporate project. In principle, this functionality was not in the requirements of the customer, but they needed “buns”, and automatic declensions are just one of the buns.
I quickly managed to contact one of the authors of the library, and after transferring a small amount, the source code was received in Delphi, which was then ported to JAVA. Initially, the java and delphi sources should coincide as much as possible, so that you can make parallel edits later. It was done this way: source codes were taken on delphi, pas → java extensions were changed, and added to the project. Next was the editing of the syntax. But in fact, the delphi code had to be strongly refactored, since it consisted mainly of multi-level if-s and internal procedures, contained global variables and was not adapted for multi-threaded operation.
Anyway, the library is ported. When asked about copyright, I was allowed to do anything with the result, but since the delphi-library was distributed under the terms of shareware, I did not publish the java-port.
5 years have passed since then, and I think it’s enough for one person to use a tool that can be used in the household of a domestic java developer. In addition, a holiday at the nose. Therefore, download

Technical information


The library is compatible with java 1.5, but, in principle, nothing prevents to make the port in previous versions of java. It will only be necessary to remove the typing of collections, and to tinker a bit more with the multithreading (volatile variables were used to work with the dictionary of exceptions);
The API is made as close as possible to the padeg.dll API;
The library contains the coding of resources contained in windows-1251 (for compatibility with the original library). If it is necessary to connect an external exclusion file, then it must also be in windows-1251 encoding. It is also possible to load exceptions using an iterator, for example, from a DB table (
Iterator<String> 
).
Test application can be viewed on OpenShift ; In the same place and the library itself (the storage store accepts only drawings, so you have to load the library directly from the resources of the test application).
Test application source code
 import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.model.SelectItem; import padeg.lib.Padeg; @ManagedBean public class PadegBean implements Serializable { private static final long serialVersionUID = 1L; public class ResultItem implements Serializable { private static final long serialVersionUID = 1L; private int padeg; private String fio; private String appointment; private String office; public int getPadeg() { return padeg; } public String getFio() { return fio; } public String getAppointment() { return appointment; } public String getOffice() { return office; } } public PadegBean() { } private String lastName = ""; private String firstName = ""; private String middleName; private String appointment = "  "; private String office = "        "; private String sexStr = "true"; private static final SelectItem[] sexItems = { new SelectItem("true",""), new SelectItem("false",""), new SelectItem("auto","  ") }; private List<ResultItem> resultItems; public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getMiddleName() { return middleName; } public void setMiddleName(String middleName) { this.middleName = middleName; } public String getAppointment() { return appointment; } public void setAppointment(String appointment) { this.appointment = appointment; } public String getOffice() { return office; } public void setOffice(String office) { this.office = office; } public String getSexStr() { return sexStr; } public void setSexStr(String sexStr) { this.sexStr = sexStr; } public SelectItem[] getSexItems() { return sexItems; } public List<ResultItem> getResultItems() { if (resultItems == null) { declAll(); } return resultItems; } public void declAll() { resultItems = new ArrayList<PadegBean.ResultItem>(); for (int i=1;i<=6;i++) { ResultItem item = new ResultItem(); item.padeg = i; resultItems.add(item); try { if ("auto".equals(sexStr)) { item.fio = Padeg.getFIOPadegAS(lastName, firstName, middleName, i); } else { boolean sex = Boolean.parseBoolean(sexStr); item.fio = Padeg.getFIOPadeg(lastName, firstName, middleName, sex, i); } } catch (Exception e) { item.fio = e.getMessage(); } try { //item.appointment = Padeg.getFullAppointmentPadeg(appointment, office, i); item.appointment = Padeg.getAppointmentPadeg(appointment, i); } catch (Exception e) { item.appointment = e.getMessage(); } try { item.office = Padeg.getOfficePadeg(office, i); } catch (Exception e) { item.office = e.getMessage(); } } } } 


UPD: link to the original padeg.dll library

')

Source: https://habr.com/ru/post/161335/


All Articles