id
stringlengths
7
14
text
stringlengths
1
106k
3526892_3
public static double getNormalizedP_simple(double q_exp) { return 0.5 + Math.sqrt(q_exp) / 2; }
3526892_4
public static double getNormalizedQexp_simple(double p) { return Math.pow(2 * (p - 0.5), 2); }
3526892_5
public static Double probabilityCorrect(Double p, Integer k) { if (k < 0) return null; if (k == 0) return 0.5; if (p > 1) return null; if (p < 0) return null; if (p == 0.5) return 0.5; if (p < 0.5) { p = 1 - p; } Double result = 0.0; int low = (int) Math.ceil(0.5 * k + 0.5); for (int i = low; i <=...
3526892_6
public static Double probabilityCorrect(Double p, Integer k) { if (k < 0) return null; if (k == 0) return 0.5; if (p > 1) return null; if (p < 0) return null; if (p == 0.5) return 0.5; if (p < 0.5) { p = 1 - p; } Double result = 0.0; int low = (int) Math.ceil(0.5 * k + 0.5); for (int i = low; i <=...
3526892_7
public static Double probabilityCorrect(Double p, Integer k) { if (k < 0) return null; if (k == 0) return 0.5; if (p > 1) return null; if (p < 0) return null; if (p == 0.5) return 0.5; if (p < 0.5) { p = 1 - p; } Double result = 0.0; int low = (int) Math.ceil(0.5 * k + 0.5); for (int i = low; i <=...
3526892_8
public static Double pricingFactor(double from, double to) { // We do not handle any corner cases (e.g., to==1, or from<=0.5 if (from <= 0.5 || from >= 1) return null; if (to <= 0.5 || to >= 1) return null; if (from == to) return 1.0; // We ensure that from is lower than to. If not, we reverse and return //...
3526892_9
@Override public void compute(){ estimate(epsilon, iterations); }
3536819_0
@NotNull public DebugSession startDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalStateException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } if (debugSessions.containsKey(messageReceiver)) { throw...
3536819_1
@NotNull public DebugSession startDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalStateException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } if (debugSessions.containsKey(messageReceiver)) { throw...
3536819_2
@NotNull public DebugSession stopDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalArgumentException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } DebugSession debugSession = getDebugSession(messageReceiver);...
3536819_3
@NotNull public DebugSession stopDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalArgumentException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } DebugSession debugSession = getDebugSession(messageReceiver);...
3536819_4
public List<String> getCompiledOutput() { if (!isClosed()) { throw new IllegalStateException("Debug session must be closed to get compiled output."); } return getDebugSubscription().getRecordedMessages(); }
3536819_5
boolean subscribeToDebugBroadcast(@NotNull DebugSubscription subscription) { synchronized (debugSubscriptions) { if (!debugSubscriptions.contains(subscription)) { debugSubscriptions.add(subscription); return true; } return false; } }
3536819_6
String[] removeInitialArg(String[] args) { String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); return newArgs; }
3536819_7
public String[] joinArgsForKnownCommands(String[] args) { CommandTree tree = this; CommandTree lastTree = null; CommandKey key = null; int commandArgLength = 0; for (int i = 0; i < args.length; i++) { String lowerName = args[i].toLowerCase(); key = tree.keyMap.get(lowerName); ...
3536819_8
public String[] joinArgsForKnownCommands(String[] args) { CommandTree tree = this; CommandTree lastTree = null; CommandKey key = null; int commandArgLength = 0; for (int i = 0; i < args.length; i++) { String lowerName = args[i].toLowerCase(); key = tree.keyMap.get(lowerName); ...
3536819_9
public String[] joinArgsForKnownCommands(String[] args) { CommandTree tree = this; CommandTree lastTree = null; CommandKey key = null; int commandArgLength = 0; for (int i = 0; i < args.length; i++) { String lowerName = args[i].toLowerCase(); key = tree.keyMap.get(lowerName); ...
3548254_0
@Override public boolean supports(KeyInformation information, TitanPredicate titanPredicate) { Class<?> dataType = information.getDataType(); Mapping mapping = Mapping.getMapping(information); if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false; if(information.getCardinality(...
3548254_1
public static String convertToWktString(Geoshape fieldValue) throws BackendException { if (fieldValue.getType() == Geoshape.Type.POINT) { Geoshape.Point point = fieldValue.getPoint(); return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")"; } else { throw new PermanentBa...
3548254_2
@Override public boolean supports(KeyInformation information, TitanPredicate titanPredicate) { if (information.getCardinality()!= Cardinality.SINGLE) return false; Class<?> dataType = information.getDataType(); Mapping mapping = Mapping.getMapping(information); if (mapping!=Mapping.DEFAULT && !Attribute...
3548254_3
@Override public boolean supports(KeyInformation information, TitanPredicate titanPredicate) { Class<?> dataType = information.getDataType(); Mapping mapping = Mapping.getMapping(information); if (mapping!=Mapping.DEFAULT && !AttributeUtil.isString(dataType)) return false; if (Number.class.isAssignableF...
3548254_4
@Override public void close() throws BackendException { if (node != null && !node.isClosed()) { node.close(); } client.close(); }
3548254_5
@Override public List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException { SearchRequestBuilder srb = client.prepareSearch(indexName); srb.setTypes(query.getStore()); srb.setQuery(QueryBuilders.matchAllQuery()); srb.setPostFilter(getFi...
3548254_6
public CLevel getWriteConsistencyLevel() { return write; }
3548254_7
public CLevel getReadConsistencyLevel() { return read; }
3551455_0
public Parser build() { return build("start"); }
3551455_1
public Parser build() { return build("start"); }
3551455_2
public Parser build() { return build("start"); }
3551455_3
public Parser build() { return build("start"); }
3551455_4
public Parser build() { return build("start"); }
3551455_5
public Parser build() { return build("start"); }
3551455_6
public Parser build() { return build("start"); }
3551455_7
public Parser build() { return build("start"); }
3551455_8
protected final void def(String name, Parser parser) { if (parsers.containsKey(name)) { throw new IllegalStateException("Duplicate production: " + name); } parsers.put(Objects.requireNonNull(name), Objects.requireNonNull(parser)); }
3551455_9
protected final void redef(String name, Parser parser) { if (!parsers.containsKey(name)) { throw new IllegalStateException("Undefined production: " + name); } parsers.put(Objects.requireNonNull(name), Objects.requireNonNull(parser)); }
3555504_0
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_1
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_2
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_3
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_4
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_5
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_6
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_7
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_8
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3555504_9
static String toString(Object obj) { if (obj == null) { return "null"; } if (obj instanceof CharSequence) { return '"' + printableToString(obj.toString()) + '"'; } Class<?> cls = obj.getClass(); if (Byte.class == cls) { return byteToString((Byte) obj); } if (cls.i...
3570915_0
public static String stripXmlTags(final String xml) { if (org.apache.commons.lang3.StringUtils.isBlank(xml)) { return xml; } // 1. Remove xml tags String strippedXml = xml.replaceAll(XML_TAG_PATTERN, org.apache.commons.lang3.StringUtils.EMPTY); // 2. Unescape xml strippedXml = ...
3570915_1
@Override public StringBuffer format(double duration, StringBuffer toAppendTo, FieldPosition pos) { if (displayAsHoursAndMinutes()) { toAppendTo.append(formatAsHoursAndMinutes(duration)); } else { toAppendTo.append(DURATION_FORMAT.format(duration)); } return toAppendTo; }
3570915_2
public static int[] parseToHourAndMinutes(final String timeString) throws ParseException { String time = timeString; time = Strings.nullToEmpty(time).trim(); if (time.length() == 0) { throw new ParseException("String is empty", 1); } time = normalize(time); String[] splitt...
3570915_3
public static int[] parseToHourAndMinutes(final String timeString) throws ParseException { String time = timeString; time = Strings.nullToEmpty(time).trim(); if (time.length() == 0) { throw new ParseException("String is empty", 1); } time = normalize(time); String[] splitt...
3570915_4
public static int[] parseToHourAndMinutes(final String timeString) throws ParseException { String time = timeString; time = Strings.nullToEmpty(time).trim(); if (time.length() == 0) { throw new ParseException("String is empty", 1); } time = normalize(time); String[] splitt...
3570915_5
public static int[] parseToHourAndMinutes(final String timeString) throws ParseException { String time = timeString; time = Strings.nullToEmpty(time).trim(); if (time.length() == 0) { throw new ParseException("String is empty", 1); } time = normalize(time); String[] splitt...
3570915_6
public final double getDuration() { final long timeMilliSec = end.getMillis() - start.getMillis(); final double timeMin = timeMilliSec / 1000.0 / 60.0; return timeMin / 60.0; }
3570915_7
public void setEndTime(final int hours, final int minutes) { DateTime endDate = getEnd(); if (hours == endDate.getHourOfDay() && minutes == endDate.getMinuteOfHour()) { return; } if (endDate.getHourOfDay() == 0 && endDate.getMinuteOfHour() == 0) { // adjust day if old end was on midnight ...
3570915_8
public void setDay(final DateTime day) { DateTime newStartDay = getStart(); this.start = newStartDay.withYear(day.getYear()).withMonthOfYear(day.getMonthOfYear()) .withDayOfMonth(day.getDayOfMonth()); DateTime newEndDay = getEnd(); newEndDay = newEndDay.withYear(day.getYear()).withMonthOfYear(da...
3580492_0
@Override public int run(String[] args) throws Exception { if(args.length != 3) { failArguments("Invalid number of arguments"); return -1; } String input = args[0]; String output = args[1]; Integer nDaysAverage = Integer.parseInt(args[2]); delete(output); // Configure schema, sort and group by List<Field> f...
3580492_1
@Override public int run(String[] args) throws Exception { if(args.length != 3) { failArguments("Wrong number of arguments"); return -1; } Path tweetsPath = new Path(args[0]); Path retweetsPath = new Path(args[1]); Path outputPath = new Path(args[2]); delete(outputPath.toString()); TupleMRBuilder mr = new Tu...
3580492_2
@Override public int run(String[] args) throws Exception { if (args.length != 2) { failArguments("Wrong number of arguments"); return -1; } delete(args[1]); TupleMRBuilder mr = new TupleMRBuilder(conf, "Pangool Topical Word Count"); mr.addIntermediateSchema(getSchema()); mr.setGroupByFields("my_avro...
3580492_3
@Override public int run(String[] args) throws Exception { if(args.length != 3) { failArguments("Invalid number of arguments"); return -1; } String input = args[0]; String output = args[1]; int n = Integer.parseInt(args[2]); delete(output); // Configure schema, sort and group by List<Field> fields = new Arr...
3580492_4
@Override public int run(String[] args) throws Exception { if(args.length != 2) { failArguments("Invalid number of arguments"); return -1; } String input = args[0]; String output = args[1]; delete(output); List<Field> fields = new ArrayList<Field>(); fields.add(Field.create("intField", Type.INT)); fields.ad...
3580492_5
protected static byte[] longToBytes(long initialState) { byte[] b = new byte[8]; for(int i = 0; i < 8; i++) { b[7 - i] = (byte) (initialState >>> (i * 8)); } return b; }
3580492_6
public void nextCycle() throws GameOfLifeException { // We initialize the next state as a x + 1, y + 1 of current state // We do this so next cells can be born around past state emptyMatrix(auxMatrix, MAX_X, MAX_Y); for(int i = 0; i < MAX_X; i++) { for(int j = 0; j < MAX_Y; j++) { if(matrix[i][j] == 1) { i...
3580492_7
protected byte[][] getMatrix() { return matrix; }
3580492_8
protected byte[][] getMatrix() { return matrix; }
3580492_9
@Override public int run(String[] args) throws Exception { if(args.length != 3) { failArguments("Wrong number of arguments"); return -1; } String output = args[0]; String input = GameOfLifeJob.class.getName() + "-prepared-input"; delete(output); delete(input); final int gridSize = Integer.parseInt(args[1]); ...
358370_10
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT); } if(XMLStreamConstants.START_...
358370_11
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT); } if(XMLStreamConstants.START_...
358370_12
@Override public Long call() throws Exception { if(!inputFile.isFile()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a file!"); } if(!inputFile.canRead()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a readable!"); } long fileSize =...
358370_13
@Override public Long call() throws Exception { if(!inputFile.isFile()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a file!"); } if(!inputFile.canRead()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a readable!"); } long fileSize =...
358370_14
@Override @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.CloseResource"}) public Long call() throws Exception { if(!inputFile.isFile()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a file!"); } if(!inputFile.canRead()) { throw new IllegalArgumentException...
358370_15
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT || !RECORD_NODE.equals(reader.getL...
358370_16
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT || !RECORD_NODE.equals(reader.getL...
358370_17
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT || !RECORD_NODE.equals(reader.getL...
358370_18
@Override public LoggingEvent read(XMLStreamReader reader) throws XMLStreamException { int type = reader.getEventType(); if(XMLStreamConstants.START_DOCUMENT == type) { do { reader.next(); type = reader.getEventType(); } while(type != XMLStreamConstants.START_ELEMENT || !RECORD_NODE.equals(reader.getL...
358381_10
public InputStream getResourceAsStream(final String resourceBaseName, final String[] suffixes, final Locale locale) { if(object != null) { return Resources.getResourceAsStream(clazz, resourceBaseName, suffixes, resolveLocale(locale)); } return Resources.getResourceAsStream(clazz, resourceBaseName, suffixes, local...
358381_11
public Map<String, Object> getLocalResourceMap(final String bundleBaseName, final Locale locale) { if(object != null) { return ResourceMaps.getLocalResourceMap(clazz, bundleBaseName, resolveLocale(locale)); } return ResourceMaps.getLocalResourceMap(clazz, bundleBaseName, locale); }
358381_12
public Map<String, Object> getResourceMap(final String bundleBaseName, final Locale locale) { if(object != null) { return ResourceMaps.getResourceMap(clazz, bundleBaseName, resolveLocale(locale)); } return ResourceMaps.getResourceMap(clazz, bundleBaseName, locale); }
358381_13
public static String resolvePath(String basePath, String path) { final Logger logger = LoggerFactory.getLogger(PathTools.class); if(basePath == null) { IllegalArgumentException ex = new IllegalArgumentException("basePath must not be null!"); if(logger.isDebugEnabled()) { logger.debug("Parameter 'basePath' o...
358381_14
public static String evaluatePath(String path) { List<String> pathStack = getPathStack(path, true); return getPathStackString(pathStack); }
358381_15
public static String getAbsolutePath(String basePath, String path) { String resolvedPath = resolvePath(basePath, path); String result = evaluatePath(resolvedPath); if(result.isEmpty() || result.charAt(0) != '/') { final Logger logger = LoggerFactory.getLogger(PathTools.class); // path is not absolute - returnin...
358381_16
public static String getParentPath(String path) { return evaluatePath(resolvePath(path, "..")); }
358381_17
public static String getCompatiblePath(String path) { List<String> pathStack = getPathStack(path, true); if(pathStack.isEmpty()) { return ""; } String first = pathStack.get(0); if(isDotPattern(first)) { pathStack.remove(0); int len = first.length(); for(int i = 1; i < len; i++) { pathStack.add(0, "....
358381_18
public static boolean isDotPattern(String s) { for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c != '.') { return false; } } return true; }
358381_19
public static List<String> getPathStack(String path, boolean evaluateDots) { List<String> pathStack = new ArrayList<>(); boolean wasAbsolute = false; if(!path.isEmpty() && path.charAt(0) =='/') { // remember absolute path... wasAbsolute = true; } int underflowCounter = 0; StringTokenizer tok = new StringToke...
358381_20
public static String getPathStackString(List<String> pathStack) { StringBuilder result = new StringBuilder(); boolean rootFound = false; if(!pathStack.isEmpty()) { rootFound = true; String currentEntry = pathStack.remove(0); if(!"/".equals(currentEntry)) { rootFound = false; result.append(currentEntry...
358381_21
public static URL[] getLocalResources(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { return getLocalResources(clazz, resourceBaseName, suffixes, locale, false); }
358381_22
public static URL getLocalResource(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { URL[] results = getLocalResources(clazz, resourceBaseName, suffixes, locale, true); if(results.length == 0) { return null; } return results[0]; }
358381_23
public static InputStream getLocalResourceAsStream(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { return getResourceStream(clazz, resourceBaseName, suffixes, locale, true); }
358381_24
public static URL[] getResources(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { return getResources(clazz, resourceBaseName, suffixes, locale, false); }
358381_25
public static URL getResource(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { URL[] resourceUrls = getResources(clazz, resourceBaseName, suffixes, locale, true); if(resourceUrls.length == 0) { return null; } return resourceUrls[0]; }
358381_26
public static InputStream getResourceAsStream(final Class clazz, final String resourceBaseName, final String[] suffixes, final Locale locale) { return getResourceStream(clazz, resourceBaseName, suffixes, locale, false); }
358381_27
public static String getShortClassName(final Class clazz) { String fullName = clazz.getName(); int idx = fullName.lastIndexOf('.'); if(idx == -1) { return fullName; } idx++; return fullName.substring(idx); }
358381_28
public static String[] getLocaleSuffixArray(final Locale locale) { String[] localeSuf = getSingleLocaleSuffixArray(locale); String[] defaultSuf = getSingleLocaleSuffixArray(Locale.getDefault()); List<String> resultList = new ArrayList<>(localeSuf.length + defaultSuf.length); for(String currentSuffix : localeSuf) {...
358381_29
public static String[] getSingleLocaleSuffixArray(final Locale locale) { if(locale == null) { return EMPTY_STRING_ARRAY; } final String language = locale.getLanguage(); final int languageLength = language.length(); final String country = locale.getCountry(); final int countryLength = country.length(); final S...
358381_30
public static String getPathToClass(final Class clazz) { String className = clazz.getName(); // use subdirs for internal classes instead return "/" + className.replace('.', '/').replace('$', '/'); }
358381_31
public static String getPathToPackage(final Class clazz) { Package p = clazz.getPackage(); if(p == null) { return "/"; } return "/" + p.getName().replace('.', '/'); }
358381_32
public static Map<String, Object> getResourceMap(final Class clazz, final String resourceMapBaseName, final Locale locale) { return getResourceMap(clazz, resourceMapBaseName, locale, false); }
358381_33
public static Map<String, Object> getLocalResourceMap(final Class clazz, final String resourceMapBaseName, final Locale locale) { return getResourceMap(clazz, resourceMapBaseName, locale, true); }
358381_34
@Override public boolean equals(Object o) { if(this == o) return true; if(o == null || getClass() != o.getClass()) return false; final And and = (And) o; return !(conditions != null ? !conditions.equals(and.conditions) : and.conditions != null); }
358381_35
@Override public boolean equals(Object o) { if(this == o) return true; if(o == null || getClass() != o.getClass()) return false; final And and = (And) o; return !(conditions != null ? !conditions.equals(and.conditions) : and.conditions != null); }
358381_36
@Override public boolean equals(Object o) { if(this == o) return true; if(o == null || getClass() != o.getClass()) return false; final Not not = (Not) o; return !(condition != null ? !condition.equals(not.condition) : not.condition != null); }