code
stringlengths
73
34.1k
label
stringclasses
1 value
protected void loadConfigs() { configs = new Properties(); // If run as a jar, find in file system classpath first, if not found, then get resource in jar. if (ClassPathUtil.testRunMainInJar()) { String[] classPathsInFileSystem = ClassPathUtil.getAllClassPathNotInJar(); ...
java
protected void modifyConfig(IConfigKey key, String value) throws IOException { if (propertiesFilePath == null) { LOGGER.warn("Config " + propertiesAbsoluteClassPath + " is not a file, maybe just a resource in library."); } if (configs == null) { loadConfigs(); ...
java
protected boolean insertToCollection(IQueueMessage<ID, DATA> msg) { getCollection().insertOne(toDocument(msg)); return true; }
java
public T get(final int key) { final int hash = hashOf(key); int index = hash & mask; if (containsKey(key, index)) { return (T)values[index]; } if (states[index] == FREE) { return missingEntries; } int j = index; for (int perturb...
java
private T doRemove(int index) { keys[index] = 0; states[index] = REMOVED; final Object previous = values[index]; values[index] = missingEntries; --size; ++count; return (T)previous; }
java
protected byte[] serialize(IQueueMessage<ID, DATA> queueMsg) { return queueMsg != null ? SerializationUtils.toByteArray(queueMsg) : null; }
java
private RRBudget10Document getRRBudget10() { deleteAutoGenNarratives(); RRBudget10Document rrBudgetDocument = RRBudget10Document.Factory .newInstance(); RRBudget10 rrBudget = RRBudget10.Factory.newInstance(); rrBudget.setFormVersion(FormVersion.v1_1.getVersion())...
java
private IndirectCosts getIndirectCosts(BudgetPeriodDto periodInfo) { IndirectCosts indirectCosts = null; if (periodInfo != null && periodInfo.getIndirectCosts() != null && periodInfo.getIndirectCosts().getIndirectCostDetails() != null) { List<IndirectCosts....
java
private void setOthersForOtherDirectCosts(OtherDirectCosts otherDirectCosts, BudgetPeriodDto periodInfo) { if (periodInfo != null && periodInfo.getOtherDirectCosts() != null) { for (OtherDirectCostInfoDto otherDirectCostInfo : periodInfo.getOtherDirectCosts()) { gov.grants.apply.form...
java
private PostDocAssociates getPostDocAssociates( OtherPersonnelDto otherPersonnel) { PostDocAssociates postDocAssociates = PostDocAssociates.Factory .newInstance(); if (otherPersonnel != null) { postDocAssociates.setNumberOfPersonnel(otherPersonnel ...
java
private GraduateStudents getGraduateStudents( OtherPersonnelDto otherPersonnel) { GraduateStudents graduate = GraduateStudents.Factory.newInstance(); if (otherPersonnel != null) { graduate.setNumberOfPersonnel(otherPersonnel.getNumberPersonnel()); graduate.setProject...
java
private UndergraduateStudents getUndergraduateStudents( OtherPersonnelDto otherPersonnel) { UndergraduateStudents undergraduate = UndergraduateStudents.Factory .newInstance(); if (otherPersonnel != null) { undergraduate.setNumberOfPersonnel(otherPersonnel ...
java
private SecretarialClerical getSecretarialClerical( OtherPersonnelDto otherPersonnel) { SecretarialClerical secretarialClerical = SecretarialClerical.Factory .newInstance(); if (otherPersonnel != null) { secretarialClerical.setNumberOfPersonnel(otherPersonnel ...
java
private List<File> listFiles(File file, List<File> files) { File[] children = file.listFiles(); if (children != null) { for (File child : children) { files.add(child); listFiles(child, files); } } return files; ...
java
public static void associateCommand(String commandName, BaseUIComponent component, IAction action) { getCommand(commandName, true).bind(component, action); }
java
public static void dissociateCommand(String commandName, BaseUIComponent component) { Command command = getCommand(commandName, false); if (command != null) { command.unbind(component); } }
java
public static void dissociateAll(BaseUIComponent component) { for (Command command : CommandRegistry.getInstance()) { command.unbind(component); } }
java
public static Command getCommand(String commandName, boolean forceCreate) { return CommandRegistry.getInstance().get(commandName, forceCreate); }
java
private static void addShortcut(StringBuilder sb, Set<String> shortcuts) { if (sb.length() > 0) { String shortcut = validateShortcut(sb.toString()); if (shortcut != null) { shortcuts.add(shortcut); } sb.delete(0, sb.length...
java
private File resolveIndexDirectoryPath() throws IOException { if (StringUtils.isEmpty(indexDirectoryPath)) { indexDirectoryPath = System.getProperty("java.io.tmpdir") + appContext.getApplicationName(); } File dir = new File(indexDirectoryPath, getClass().getPackage().getName...
java
@Override public void indexHelpModule(HelpModule helpModule) { try { if (indexTracker.isSame(helpModule)) { return; } unindexHelpModule(helpModule); log.info("Indexing help module " + helpModule.getLocalizedId()); int i...
java
@Override public void unindexHelpModule(HelpModule helpModule) { try { log.info("Removing index for help module " + helpModule.getLocalizedId()); Term term = new Term("module", helpModule.getLocalizedId()); writer.deleteDocuments(term); writer.commit(); ...
java
private void indexDocument(HelpModule helpModule, Resource resource) throws Exception { String title = getTitle(resource); try (InputStream is = resource.getInputStream()) { Document document = new Document(); document.add(new TextField("module", helpModule.getLocalizedI...
java
private String getTitle(Resource resource) { String title = null; try (InputStream is = resource.getInputStream()) { Iterator<String> iter = IOUtils.lineIterator(is, "UTF-8"); while (iter.hasNext()) { String line = iter.next().trim(); ...
java
@Override public void search(String words, Collection<IHelpSet> helpSets, IHelpSearchListener listener) { try { if (queryBuilder == null) { initQueryBuilder(); } Query searchForWords = queryBuilder.createBooleanQuery("content", words, Occur.MU...
java
public void init() throws IOException { File path = resolveIndexDirectoryPath(); indexTracker = new IndexTracker(path); indexDirectory = FSDirectory.open(path); tika = new Tika(null, new HtmlParser()); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig config =...
java
private synchronized void initQueryBuilder() throws IOException { if (queryBuilder == null) { indexReader = DirectoryReader.open(indexDirectory); indexSearcher = new IndexSearcher(indexReader); queryBuilder = new QueryBuilder(writer.getAnalyzer()); } }
java
public static AlertContainer render(BaseComponent parent, BaseComponent child) { AlertContainer container = new AlertContainer(child); parent.addChild(container, 0); return container; }
java
@Override public void doAction(Action action) { BaseComponent parent = getParent(); switch (action) { case REMOVE: ActionListener.unbindActionListeners(this, actionListeners); detach(); break; case HIDE: ...
java
public void assertSubscriptions() { for (String channel : subscribers.keySet()) { try { subscribers.put(channel, null); subscribe(channel); } catch (Throwable e) { break; } } }
java
public void removeSubscriptions() { for (TopicSubscriber subscriber : subscribers.values()) { try { subscriber.close(); } catch (Throwable e) { log.debug("Error closing subscriber", e);//is level appropriate - previously hidden exception -afranken ...
java
public String getCaption() { return caption != null && caption.toLowerCase().startsWith("label:") ? StrUtil.getLabel(caption.substring(6)) : caption; }
java
public Element createDOMNode(Element parent) { Element domNode = parent.getOwnerDocument().createElement(tagName); LayoutUtil.copyAttributes(attributes, domNode); parent.appendChild(domNode); return domNode; }
java
public void reset() throws IOException { if (t1==null || t2==null) { throw new IllegalStateException("Cannot reset after close."); } if (!isEmpty(getOutput())) { toggle = !toggle; // reset the new output PathTools.deleteRecursive(getOutput(), false); } else { throw new IOException("Cannot swap to...
java
public void close() throws IOException { if (t1==null || t2==null) { return; } try { if (!isEmpty(getOutput())) { Optional<? extends IOException> ex = output.apply(getOutput()); if (ex.isPresent()) { throw ex.get(); } } else if (!isEmpty(getInput())) { Optional<? extends IOException>...
java
public void setDetail(String name, Object value) { if (value == null) { details.remove(name); } else { details.put(name, value); } if (log.isDebugEnabled()) { if (value == null) { log.debug("Detail removed: " + name); ...
java
public Object getDetail(String name) { return name == null ? null : details.get(name); }
java
public void init() { IUser user = SecurityUtil.getAuthenticatedUser(); publisherInfo.setUserId(user == null ? null : user.getLogicalId()); publisherInfo.setUserName(user == null ? "" : user.getFullName()); publisherInfo.setAppName(getAppName()); publisherInfo.setConsumerId(consum...
java
@Override public void fireRemoteEvent(String eventName, Serializable eventData, Recipient... recipients) { Message message = new EventMessage(eventName, eventData); producer.publish(EventUtil.getChannelName(eventName), message, recipients); }
java
protected String getAppName() { if (appName == null && FrameworkUtil.isInitialized()) { setAppName(FrameworkUtil.getAppName()); } return appName; }
java
public static HelpViewerMode getViewerMode(Page page) { return page == null || !page.hasAttribute(EMBEDDED_ATTRIB) ? defaultMode : (HelpViewerMode) page.getAttribute(EMBEDDED_ATTRIB); }
java
public static void setViewerMode(Page page, HelpViewerMode mode) { if (getViewerMode(page) != mode) { removeViewer(page, true); } page.setAttribute(EMBEDDED_ATTRIB, mode); }
java
public static IHelpViewer getViewer(boolean forceCreate) { Page page = getPage(); IHelpViewer viewer = (IHelpViewer) page.getAttribute(VIEWER_ATTRIB); return viewer != null ? viewer : forceCreate ? createViewer(page) : null; }
java
private static IHelpViewer createViewer(Page page) { IHelpViewer viewer; if (getViewerMode(page) == HelpViewerMode.POPUP) { viewer = new HelpViewerProxy(page); } else { BaseComponent root = PageUtil.createPage(VIEWER_URL, page).get(0); viewer = (IHelpViewer) ...
java
protected static void removeViewer(Page page, boolean close) { IHelpViewer viewer = (IHelpViewer) page.removeAttribute(VIEWER_ATTRIB); if (viewer != null && close) { viewer.close(); } }
java
protected static void removeViewer(Page page, IHelpViewer viewer, boolean close) { if (viewer != null && viewer == page.getAttribute(VIEWER_ATTRIB)) { removeViewer(page, close); } }
java
public static String getUrl(String path) { if (path == null) { return path; } ServletContext sc = ExecutionContext.getSession().getServletContext(); if (path.startsWith("jar:")) { int i = path.indexOf("!"); path = i < 0 ? path : path.substring(++i); ...
java
public static void show(String module, String topic, String label) { getViewer(true).show(module, topic, label); }
java
public static void showCSH(BaseComponent component) { while (component != null) { HelpContext target = (HelpContext) component.getAttribute(CSH_TARGET); if (target != null) { HelpUtil.show(target); break; } component = component.ge...
java
public static void associateCSH(BaseUIComponent component, HelpContext helpContext, BaseUIComponent commandTarget) { if (component != null) { component.setAttribute(CSH_TARGET, helpContext); CommandUtil.associateCommand("help", component, commandTarget); } }
java
public static void dissociateCSH(BaseUIComponent component) { if (component != null && component.hasAttribute(CSH_TARGET)) { CommandUtil.dissociateCommand("help", component); component.removeAttribute(CSH_TARGET); } }
java
public static void subtract(double[] array1, double[] array2) { assert (array1.length == array2.length); for (int i=0; i<array1.length; i++) { array1[i] -= array2[i]; } }
java
public static void multiply(double[] array1, double[] array2) { assert (array1.length == array2.length); for (int i=0; i<array1.length; i++) { array1[i] *= array2[i]; } }
java
public static void divide(double[] array1, double[] array2) { assert (array1.length == array2.length); for (int i=0; i<array1.length; i++) { array1[i] /= array2[i]; } }
java
public static int indexOf(double[] array, double val) { for (int i=0; i<array.length; i++) { if (array[i] == val) { return i; } } return -1; }
java
public static int lastIndexOf(double[] array, double val) { for (int i=array.length-1; i >= 0; i--) { if (array[i] == val) { return i; } } return -1; }
java
public static Provider<String> getPropertyProvider(Binder binder, String propertyName) { return binder.getProvider(getPropertyKey(propertyName)); }
java
public static Provider<String> bindDefault(Binder binder, String propertyName, String defaultValue) { Key<String> propertyKey = getPropertyKey(propertyName); OptionalBinder<String> optionalBinder = OptionalBinder. newOptionalBinder(binder, propertyKey); optionalBinder.setDefault(...
java
public static <T> Collector<T, List<T>> toList() { return new Collector<T, List<T>>() { @Override public List<T> collect(Stream<? extends T> stream) { return Lists.newArrayList(stream.iterator()); } }; }
java
public static <T> Collector<T, Set<T>> toSet() { return new Collector<T, Set<T>>() { @Override public Set<T> collect(Stream<? extends T> stream) { return Sets.newHashSet(stream.iterator()); } }; }
java
@Override public void transform(InputStream inputStream, OutputStream outputStream) throws Exception { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, CS_WIN1252))) { String line; String closingTag = null; Stack<String> stack = new Stack...
java
@Override public void registerDestructionCallback(String name, Runnable callback) { synchronized (this) { destructionCallbacks.put(name, callback); } }
java
public void destroy() { for (Entry<String, Runnable> entry : destructionCallbacks.entrySet()) { try { entry.getValue().run(); } catch (Throwable t) { log.error("Error during destruction callback for bean " + entry.getKey(), t); } } ...
java
@Override public String getProperty(String name) { return name.startsWith(LABEL_PREFIX) ? StrUtil.getLabel(name.substring(LABEL_PREFIX.length())) : null; }
java
private void setAddress(Address address, RolodexContract rolodex) { if (rolodex != null) { address.setStreet1(rolodex.getAddressLine1()); address.setStreet2(rolodex.getAddressLine2()); address.setCity(checkNull(rolodex.getCity())); address.setCounty(rolodex.getCou...
java
private Set<ChmEntry> buildEntryList() throws TikaException { Set<ChmEntry> entries = new TreeSet<>(); for (DirectoryListingEntry entry : chmExtractor.getChmDirList().getDirectoryListingEntryList()) { String name = entry.getName(); if (name.startsWith("/") && !name.equals("/") ...
java
private ChmEntry findEntry(String file) { for (ChmEntry entry : entries) { if (file.equals(entry.getSourcePath())) { return entry; } } return null; }
java
public boolean hasChanged() { Object currentValue = getValue(); return value == null || currentValue == null ? value != currentValue : !value.equals(currentValue); }
java
protected void init(Object target, PropertyInfo propInfo, PropertyGrid propGrid) { this.target = target; this.propInfo = propInfo; this.propGrid = propGrid; this.index = propGrid.getEditorCount(); wireController(); }
java
public boolean commit() { try { setWrongValueMessage(null); propInfo.setPropertyValue(target, getValue()); updateValue(); return true; } catch (Exception e) { setWrongValueException(e); return false; } }
java
public boolean revert() { try { setWrongValueMessage(null); setValue(propInfo.getPropertyValue(target)); updateValue(); return true; } catch (Exception e) { setWrongValueException(e); return false; } }
java
public List<String> nextParagraphs() { return nextParagraphs(Math.min(Math.max(4 + (int) (random.nextGaussian() * 3d), 1), 8)); }
java
public List<String> nextParagraphs(int num) { List<String> paragraphs = new ArrayList<String>(num); for(int i = 0; i < num; i++) { paragraphs.add(nextParagraph()); } return paragraphs; }
java
public String nextParagraph(int totalSentences) { StringBuilder out = new StringBuilder(); List<String> lastWords = new ArrayList<String>(); lastWords.add(null); lastWords.add(null); int numSentences = 0; boolean inSentence = false; boolean inQuote = false; ...
java
public Map<String, String> getEOStateReview(ProposalDevelopmentDocumentContract pdDoc) { Map<String, String> stateReview = new HashMap<>(); List<? extends AnswerHeaderContract> answerHeaders = propDevQuestionAnswerService.getQuestionnaireAnswerHeaders(pdDoc.getDevelopmentProposal().getProposalNumber());...
java
public String getDivisionName(ProposalDevelopmentDocumentContract pdDoc) { String divisionName = null; if (pdDoc != null && pdDoc.getDevelopmentProposal().getOwnedByUnit() != null) { UnitContract ownedByUnit = pdDoc.getDevelopmentProposal().getOwnedByUnit(); // traverse through t...
java
public void registerTransform(String pattern, AbstractTransform transform) { transforms.add(new Transform(new WildcardFileFilter(pattern.split("\\,")), transform)); }
java
public String replaceURLs(String line) { StringBuffer sb = new StringBuffer(); Matcher matcher = URL_PATTERN.matcher(line); String newPath = "web/" + getResourceBase() + "/"; while (matcher.find()) { char dlm = line.charAt(matcher.start() - 1); int i = li...
java
protected boolean transform(IResource resource) throws Exception { String name = StringUtils.trimToEmpty(resource.getSourcePath()); if (resource.isDirectory() || mojo.isExcluded(name)) { return false; } AbstractTransform transform = getTransform(name); ...
java
private AbstractTransform getTransform(String fileName) { File file = new File(fileName); for (Transform transform : transforms) { if (transform.filter.accept(file)) { return transform.transform; } } return null; }
java
public static String substringBefore(final String str, final String separator) { if (Strings.isNullOrEmpty(str)) { return str; } final int pos = str.indexOf(separator); if (pos == -1) { return str; } return str.substring(0, pos); }
java
public static IAction getRegisteredAction(String id) { IAction action = getRegistry(false).get(id); return action == null ? getRegistry(true).get(id) : action; }
java
public static Collection<IAction> getRegisteredActions(ActionScope scope) { Map<String, IAction> actions = new HashMap<>(); if (scope == ActionScope.BOTH || scope == ActionScope.GLOBAL) { actions.putAll(getRegistry(true).map); } if (scope == ActionScope.BOTH...
java
private static ActionRegistry getRegistry(boolean global) { if (global) { return instance; } Page page = ExecutionContext.getPage(); ActionRegistry registry = (ActionRegistry) page.getAttribute(ATTR_LOCAL_REGISTRY); if (registry == null) { ...
java
ProgressEvent updateProgress(double val, long now) { if (val<0 || val>1) { throw new IllegalArgumentException("Value out of range [0, 1]: " + val); } if (val<=progress.getProgress()) { reset(start); } double pD = val - progress.getProgress(); long tD = now - tstamp; if (step > 0) { step = step * ...
java
private boolean connect() { if (this.factory == null) { return false; } if (isConnected()) { return true; } try { this.connection = this.factory.createConnection(); this.session = (TopicSession) this.connection.cre...
java
private void disconnect() { if (this.session != null) { try { this.session.close(); } catch (Exception e) { log.error("Error closing JMS topic session.", e); } } if (this.connection != null) { try { ...
java
public static ElementUI getAssociatedElement(BaseComponent component) { return component == null ? null : (ElementUI) component.getAttribute(ASSOC_ELEMENT); }
java
public static Menupopup getDesignContextMenu(BaseComponent component) { return component == null ? null : (Menupopup) component.getAttribute(CONTEXT_MENU); }
java
protected String getTemplateUrl() { return "web/" + getClass().getPackage().getName().replace(".", "/") + "/" + StringUtils.uncapitalize(getClass().getSimpleName()) + ".fsp"; }
java
@Override public void setDesignMode(boolean designMode) { super.setDesignMode(designMode); for (ElementTrigger trigger : triggers) { trigger.setDesignMode(designMode); } setDesignContextMenu(designMode ? DesignContextMenu.getInstance().getMenupopup() : null); ma...
java
@Override protected void afterParentChanged(ElementBase oldParent) { if (getParent() != null) { if (!getDefinition().isInternal()) { bind(); } setDesignMode(getParent().isDesignMode()); } }
java
private ElementUI getVisibleChild(boolean first) { int count = getChildCount(); int start = first ? 0 : count - 1; int inc = first ? 1 : -1; for (int i = start; i >= 0 && i < count; i += inc) { ElementUI child = (ElementUI) getChild(i); if (child.isVisib...
java
public ElementUI getNextSibling(boolean visibleOnly) { ElementUI parent = getParent(); if (parent != null) { int count = parent.getChildCount(); for (int i = getIndex() + 1; i < count; i++) { ElementUI child = (ElementUI) parent.getChild(i); ...
java
@Override protected void afterMoveChild(ElementBase child, ElementBase before) { moveChild(((ElementUI) child).getOuterComponent(), ((ElementUI) before).getOuterComponent()); updateMasks(); }
java
protected void applyColor(BaseUIComponent comp) { if (comp instanceof BaseLabeledComponent) { comp.invoke(comp.sub("lbl"), "css", "color", getColor()); } else if (comp != null) { comp.addStyle("background-color", getColor()); } }
java
protected boolean hasVisibleElements(BaseUIComponent component) { for (BaseUIComponent child : component.getChildren(BaseUIComponent.class)) { ElementUI ele = getAssociatedElement(child); if (ele != null && ele.isVisible()) { return true; } ...
java
public void set(int i, byte value) { if (i < 0 || i >= size) { throw new IndexOutOfBoundsException(); } elements[i] = value; }
java
public void add(byte[] values) { ensureCapacity(size + values.length); for (byte element : values) { this.add(element); } }
java
public static double normalizeProps(double[] props) { double propSum = DoubleArrays.sum(props); if (propSum == 0) { for (int d = 0; d < props.length; d++) { props[d] = 1.0 / (double)props.length; } } else if (propSum == Double.POSITIVE_INFINITY) { ...
java