JAVA library padeg - new year's gift to habr

    Yes, this is the same padeg.dll library, but it works everywhere where 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 decline my name and position for one corporate project. In principle, this functionality was not in the requirements of the customer, but “buns” were needed, and automatic declination is just one of the buns.
    Pretty quickly I managed to contact one of the authors of the library, and after transferring a small amount, the source code for Delphi was received, which was then ported to JAVA. According to the initial idea of ​​java and delphi, the sources should have been as close as possible, so that later it was possible to make parallel edits. It was done this way: source code was taken on delphi, pas → java extensions were changed, and added to the project. Next came the editing of the syntax. But actually, the delphi code had to be strongly refactored, because it consisted mainly of multi-story ifs and internal procedures, contained global variables and was not adapted for multi-threaded work.
    Be that as it may, 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 to use a tool that can be used in the domestic java developer. In addition, a feast on 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 tinker a bit more with multithreading (volatile variables were used to work with the exception dictionary);
    The API is made as similar as possible to the padeg.dll API;
    The encoding of the resources contained in the library is windows-1251 (for compatibility with the original library). If you need to connect an external exception file, it must also be in windows-1251 encoding. It is also possible to load exceptions using an iterator, for example, from a database table (
    Iterator
    )
    The test application can be viewed on OpenShift ; The library itself is also in the same place (the haberstore only accepts pictures, so you have to load the library directly from the resources of the test application).
    The source code of the test application
    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 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 getResultItems() {
    		if (resultItems == null) {
    			declAll();
    		}
    		return resultItems;
    	}
    	public void declAll() {
    		resultItems = new ArrayList();
    		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

    Also popular now: